1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
31 void xor_(byte
*a
, byte
*b
, int n
);
32 void EncryptAES(byte
*msg
, byte
*key
, byte
*c
);
33 void DecryptAES(byte
*c
, byte
*key
, byte
*m
);
34 void Pretty(byte
* b
,int len
,const char* label
);
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 */
48 CRYPTO_NONE
, /* disable */
50 CRYPTO_XOR_KEY
, /* XOR key */
51 CRYPTO_USBOTP
, /* use usbotp device */
55 * - CRYPTO_KEY: array of 16-bytes (the key)
56 * - CRYPTO_USBOTP: 32-bit integer: vid << 16 | pid */
57 void crypto_setup(enum crypto_method_t method
, void *param
);
59 #define CRYPTO_ERROR_SUCCESS 0
60 #define CRYPTO_ERROR_BADSETUP -1 /* bad crypto setup */
61 #define CRYPTO_ERROR_NODEVICE -2 /* no device with vid:pid */
62 #define CRYPTO_ERROR_BADENDP -3 /* device doesn't have the required endpoints */
63 #define CRYPTO_ERROR_CLAIMFAIL -4 /* device interface claim error */
64 #define CRYPTO_ERROR_DEVREJECT -5 /* device rejected cypto operation */
65 #define CRYPTO_ERROR_DEVSILENT -6 /* device did not notify completion */
66 #define CRYPTO_ERROR_DEVERR -7 /* device did something wrong (like return too small buffer) */
67 #define CRYPTO_NUM_ERRORS 8
68 /* return 0 on success, <0 on error */
70 byte
*in_data
, /* Input data */
71 byte
*out_data
, /* Output data (or NULL) */
72 int nr_blocks
, /* Number of blocks (one block=16 bytes) */
74 byte (*out_cbc_mac
)[16], /* CBC-MAC of the result (or NULL) */
83 /* all-in-one function */
86 enum crypto_method_t method
;
90 union xorcrypt_key_t xor_key
[2];
97 byte
*in_data
, /* Input data */
98 byte
*out_data
, /* Output data (or NULL) */
99 int nr_blocks
, /* Number of blocks (one block=16 bytes) */
100 struct crypto_key_t
*key
, /* Key */
101 byte iv
[16], /* IV */
102 byte (*out_cbc_mac
)[16], /* CBC-MAC of the result (or NULL) */
106 uint32_t crc(byte
*data
, int size
);
107 uint32_t crc_continue(uint32_t previous_crc
, byte
*data
, int size
);
110 struct sha_1_params_t
113 uint64_t buffer_nr_bits
;
117 void sha_1_init(struct sha_1_params_t
*params
);
118 void sha_1_block(struct sha_1_params_t
*params
, uint32_t cur_hash
[5], byte
*data
);
119 void sha_1_update(struct sha_1_params_t
*params
, byte
*buffer
, int size
);
120 void sha_1_finish(struct sha_1_params_t
*params
);
121 void sha_1_output(struct sha_1_params_t
*params
, byte
*out
);
125 // WARNING those functions modifies the keys !!
126 uint32_t xor_encrypt(union xorcrypt_key_t keys
[2], void *data
, int size
);
127 uint32_t xor_decrypt(union xorcrypt_key_t keys
[2], void *data
, int size
);
128 void xor_generate_key(uint32_t laserfuse
[3], union xorcrypt_key_t key
[2]);
130 #endif /* __CRYPTO_H__ */