diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-01 20:48:05 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-16 19:58:24 +0100 |
commit | 2b20026dd755706934f8f8e1a192bffdfc3d717c (patch) | |
tree | 3c8bb119ab5e9d3f62093563e99609c7dc2a8f2f /utils/imxtools/sbtools/crypto.cpp | |
parent | cb8a98e365c0b69e068dc077eb5d68dd4a29a1ad (diff) | |
download | rockbox-2b20026dd755706934f8f8e1a192bffdfc3d717c.tar.gz rockbox-2b20026dd755706934f8f8e1a192bffdfc3d717c.zip |
imxtools/sbtools: rework cryptography
It was a mess, a mix of crypto_* and cbc_mac calls. I made everything call crypto
functions, and also separate key setup from cryptographic operations, this will
be useful to speed up the code in the upcoming commits. Drop support for "usbotp"
key, since the crypto code for that was never mainlined and we can always get the
keys from a device as long as we have code execution (using the DCP debug registers).
Change-Id: I7aa24d12207ffb744225d1b9cc7cb1dc7281dd22
Diffstat (limited to 'utils/imxtools/sbtools/crypto.cpp')
-rw-r--r-- | utils/imxtools/sbtools/crypto.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/crypto.cpp b/utils/imxtools/sbtools/crypto.cpp new file mode 100644 index 0000000000..35068c3e7d --- /dev/null +++ b/utils/imxtools/sbtools/crypto.cpp | |||
@@ -0,0 +1,55 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 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 "crypto.h" | ||
22 | #include "misc.h" | ||
23 | |||
24 | static enum crypto_method_t g_cur_method = CRYPTO_NONE; | ||
25 | static byte g_key[16]; | ||
26 | |||
27 | int crypto_setup(struct crypto_key_t *key) | ||
28 | { | ||
29 | g_cur_method = key->method; | ||
30 | switch(g_cur_method) | ||
31 | { | ||
32 | case CRYPTO_KEY: | ||
33 | memcpy(g_key, key->u.key, 16); | ||
34 | return CRYPTO_ERROR_SUCCESS; | ||
35 | default: | ||
36 | return CRYPTO_ERROR_BADSETUP; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | int crypto_apply( | ||
41 | byte *in_data, /* Input data */ | ||
42 | byte *out_data, /* Output data (or NULL) */ | ||
43 | int nr_blocks, /* Number of blocks (one block=16 bytes) */ | ||
44 | byte iv[16], /* Key */ | ||
45 | byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ | ||
46 | bool encrypt) | ||
47 | { | ||
48 | if(g_cur_method == CRYPTO_KEY) | ||
49 | { | ||
50 | cbc_mac(in_data, out_data, nr_blocks, g_key, iv, out_cbc_mac, encrypt); | ||
51 | return CRYPTO_ERROR_SUCCESS; | ||
52 | } | ||
53 | else | ||
54 | return CRYPTO_ERROR_BADSETUP; | ||
55 | } | ||