summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/crypto.h
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-23 11:03:35 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-31 13:57:25 +0200
commita87a9ef37372b4380808ec2efa7c762e137668f1 (patch)
tree9c759088f0f9cf6717d96789b6805812f6b187ea /utils/imxtools/sbtools/crypto.h
parentba8e4367fb4d116ffc01c12cc619bfc714e582c9 (diff)
downloadrockbox-a87a9ef37372b4380808ec2efa7c762e137668f1.tar.gz
rockbox-a87a9ef37372b4380808ec2efa7c762e137668f1.zip
imxtools: move tools to a new sbtools/ subdirectory
Change-Id: I0d8d6831b35037725486f61fc363de87bc8ba92e
Diffstat (limited to 'utils/imxtools/sbtools/crypto.h')
-rw-r--r--utils/imxtools/sbtools/crypto.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/crypto.h b/utils/imxtools/sbtools/crypto.h
new file mode 100644
index 0000000000..452db6a28d
--- /dev/null
+++ b/utils/imxtools/sbtools/crypto.h
@@ -0,0 +1,115 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 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#ifndef __CRYPTO_H__
22#define __CRYPTO_H__
23
24#include <stdio.h>
25#include <stdint.h>
26#include <string.h>
27
28typedef uint8_t byte;
29
30/* aes128.c */
31void xor_(byte *a, byte *b, int n);
32void EncryptAES(byte *msg, byte *key, byte *c);
33void DecryptAES(byte *c, byte *key, byte *m);
34void Pretty(byte* b,int len,const char* label);
35void cbc_mac(
36 byte *in_data, /* Input data */
37 byte *out_data, /* Output data (or NULL) */
38 int nr_blocks, /* Number of blocks to encrypt/decrypt (one block=16 bytes) */
39 byte key[16], /* Key */
40 byte iv[16], /* Initialisation Vector */
41 byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
42 int encrypt /* 1 to encrypt, 0 to decrypt */
43 );
44
45/* crypto.c */
46enum crypto_method_t
47{
48 CRYPTO_NONE, /* disable */
49 CRYPTO_KEY, /* key */
50 CRYPTO_USBOTP, /* use usbotp device */
51};
52
53/* parameter can be:
54 * - CRYPTO_KEY: array of 16-bytes (the key)
55 * - CRYPTO_USBOTP: 32-bit integer: vid << 16 | pid */
56void crypto_setup(enum crypto_method_t method, void *param);
57
58#define CRYPTO_ERROR_SUCCESS 0
59#define CRYPTO_ERROR_BADSETUP -1 /* bad crypto setup */
60#define CRYPTO_ERROR_NODEVICE -2 /* no device with vid:pid */
61#define CRYPTO_ERROR_BADENDP -3 /* device doesn't have the required endpoints */
62#define CRYPTO_ERROR_CLAIMFAIL -4 /* device interface claim error */
63#define CRYPTO_ERROR_DEVREJECT -5 /* device rejected cypto operation */
64#define CRYPTO_ERROR_DEVSILENT -6 /* device did not notify completion */
65#define CRYPTO_ERROR_DEVERR -7 /* device did something wrong (like return too small buffer) */
66#define CRYPTO_NUM_ERRORS 8
67/* return 0 on success, <0 on error */
68int crypto_apply(
69 byte *in_data, /* Input data */
70 byte *out_data, /* Output data (or NULL) */
71 int nr_blocks, /* Number of blocks (one block=16 bytes) */
72 byte iv[16], /* IV */
73 byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
74 int encrypt);
75
76/* all-in-one function */
77struct crypto_key_t
78{
79 enum crypto_method_t method;
80 union
81 {
82 byte key[16];
83 uint32_t vid_pid;
84 byte param[0];
85 }u;
86};
87
88int crypto_cbc(
89 byte *in_data, /* Input data */
90 byte *out_data, /* Output data (or NULL) */
91 int nr_blocks, /* Number of blocks (one block=16 bytes) */
92 struct crypto_key_t *key, /* Key */
93 byte iv[16], /* IV */
94 byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
95 int encrypt);
96
97/* crc.c */
98uint32_t crc(byte *data, int size);
99uint32_t crc_continue(uint32_t previous_crc, byte *data, int size);
100
101/* sha1.c */
102struct sha_1_params_t
103{
104 uint32_t hash[5];
105 uint64_t buffer_nr_bits;
106 uint32_t w[80];
107};
108
109void sha_1_init(struct sha_1_params_t *params);
110void sha_1_block(struct sha_1_params_t *params, uint32_t cur_hash[5], byte *data);
111void sha_1_update(struct sha_1_params_t *params, byte *buffer, int size);
112void sha_1_finish(struct sha_1_params_t *params);
113void sha_1_output(struct sha_1_params_t *params, byte *out);
114
115#endif /* __CRYPTO_H__ */