summaryrefslogtreecommitdiff
path: root/utils/nwztools/upgtools/fwp.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/upgtools/fwp.c')
-rw-r--r--utils/nwztools/upgtools/fwp.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/utils/nwztools/upgtools/fwp.c b/utils/nwztools/upgtools/fwp.c
new file mode 100644
index 0000000000..e739b8caef
--- /dev/null
+++ b/utils/nwztools/upgtools/fwp.c
@@ -0,0 +1,56 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include "fwp.h"
23#include "misc.h"
24#include "mg.h"
25#include <string.h>
26
27int fwp_read(void *in, int size, void *out, uint8_t *key)
28{
29 return mg_decrypt_fw(in, size, out, key);
30}
31
32static uint8_t g_key[NWZ_KEY_SIZE];
33
34void fwp_setkey(char key[NWZ_KEY_SIZE])
35{
36 memcpy(g_key, key, NWZ_KEY_SIZE);
37}
38
39int fwp_crypt(void *buf, int size, int mode)
40{
41 while(size >= NWZ_KEY_SIZE)
42 {
43 if(mode)
44 mg_decrypt_pass(buf, NWZ_KEY_SIZE, buf, g_key);
45 else
46 mg_encrypt_pass(buf, NWZ_KEY_SIZE, buf, g_key);
47 buf += NWZ_KEY_SIZE;
48 size -= NWZ_KEY_SIZE;
49 }
50 if(size != 0)
51 {
52 cprintf(GREY, "Cannot fwp_crypt non-multiple of 8!\n");
53 return -1;
54 }
55 return 0;
56} \ No newline at end of file