diff options
-rw-r--r-- | rbutil/mkimxboot/mkimxboot.c | 2 | ||||
-rw-r--r-- | utils/imxtools/sbtools/crc.c | 4 | ||||
-rw-r--r-- | utils/imxtools/sbtools/crypto.cpp | 28 | ||||
-rw-r--r-- | utils/imxtools/sbtools/crypto.h | 22 | ||||
-rw-r--r-- | utils/imxtools/sbtools/dbparser.c | 2 | ||||
-rw-r--r-- | utils/imxtools/sbtools/misc.c | 8 | ||||
-rw-r--r-- | utils/imxtools/sbtools/misc.h | 5 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sb.c | 68 |
8 files changed, 69 insertions, 70 deletions
diff --git a/rbutil/mkimxboot/mkimxboot.c b/rbutil/mkimxboot/mkimxboot.c index 369c397d51..0483b5aeee 100644 --- a/rbutil/mkimxboot/mkimxboot.c +++ b/rbutil/mkimxboot/mkimxboot.c | |||
@@ -655,7 +655,7 @@ static enum imx_error_t find_model_by_md5sum(uint8_t file_md5sum[16], int *md5_i | |||
655 | } | 655 | } |
656 | for(int j = 0; j < 16; j++) | 656 | for(int j = 0; j < 16; j++) |
657 | { | 657 | { |
658 | byte a, b; | 658 | uint8_t a, b; |
659 | if(convxdigit(imx_sums[i].md5sum[2 * j], &a) || convxdigit(imx_sums[i].md5sum[2 * j + 1], &b)) | 659 | if(convxdigit(imx_sums[i].md5sum[2 * j], &a) || convxdigit(imx_sums[i].md5sum[2 * j + 1], &b)) |
660 | { | 660 | { |
661 | printf("[ERR][INTERNAL] Bad checksum format: %s\n", imx_sums[i].md5sum); | 661 | printf("[ERR][INTERNAL] Bad checksum format: %s\n", imx_sums[i].md5sum); |
diff --git a/utils/imxtools/sbtools/crc.c b/utils/imxtools/sbtools/crc.c index eaf257ddfe..9f7146881b 100644 --- a/utils/imxtools/sbtools/crc.c +++ b/utils/imxtools/sbtools/crc.c | |||
@@ -68,12 +68,12 @@ static uint32_t crc_table[256] = { | |||
68 | 0x0B8757BDA, 0x0B5365D03, 0x0B1F740B4 | 68 | 0x0B8757BDA, 0x0B5365D03, 0x0B1F740B4 |
69 | }; | 69 | }; |
70 | 70 | ||
71 | uint32_t crc(byte *data, int size) | 71 | uint32_t crc(uint8_t *data, int size) |
72 | { | 72 | { |
73 | return crc_continue(0xffffffff, data, size); | 73 | return crc_continue(0xffffffff, data, size); |
74 | } | 74 | } |
75 | 75 | ||
76 | uint32_t crc_continue(uint32_t previous_crc, byte *data, int size) | 76 | uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size) |
77 | { | 77 | { |
78 | uint32_t c = previous_crc; | 78 | uint32_t c = previous_crc; |
79 | /* normal CRC */ | 79 | /* normal CRC */ |
diff --git a/utils/imxtools/sbtools/crypto.cpp b/utils/imxtools/sbtools/crypto.cpp index d7ef04f098..5563fcfd3b 100644 --- a/utils/imxtools/sbtools/crypto.cpp +++ b/utils/imxtools/sbtools/crypto.cpp | |||
@@ -30,19 +30,19 @@ namespace | |||
30 | { | 30 | { |
31 | 31 | ||
32 | enum crypto_method_t g_cur_method = CRYPTO_NONE; | 32 | enum crypto_method_t g_cur_method = CRYPTO_NONE; |
33 | byte g_key[16]; | 33 | uint8_t g_key[16]; |
34 | CBC_Mode<AES>::Encryption g_aes_enc; | 34 | CBC_Mode<AES>::Encryption g_aes_enc; |
35 | CBC_Mode<AES>::Decryption g_aes_dec; | 35 | CBC_Mode<AES>::Decryption g_aes_dec; |
36 | bool g_aes_enc_key_dirty; /* true of g_aes_enc key needs to be updated */ | 36 | bool g_aes_enc_key_dirty; /* true of g_aes_enc key needs to be updated */ |
37 | bool g_aes_dec_key_dirty; /* same for g_aes_dec */ | 37 | bool g_aes_dec_key_dirty; /* same for g_aes_dec */ |
38 | 38 | ||
39 | int cbc_mac2( | 39 | int cbc_mac2( |
40 | const byte *in_data, /* Input data */ | 40 | const uint8_t *in_data, /* Input data */ |
41 | byte *out_data, /* Output data (or NULL) */ | 41 | uint8_t *out_data, /* Output data (or NULL) */ |
42 | int nr_blocks, /* Number of blocks to encrypt/decrypt (one block=16 bytes) */ | 42 | int nr_blocks, /* Number of blocks to encrypt/decrypt (one block=16 bytes) */ |
43 | byte key[16], /* Key */ | 43 | uint8_t key[16], /* Key */ |
44 | byte iv[16], /* Initialisation Vector */ | 44 | uint8_t iv[16], /* Initialisation Vector */ |
45 | byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ | 45 | uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ |
46 | bool encrypt /* 1 to encrypt, 0 to decrypt */ | 46 | bool encrypt /* 1 to encrypt, 0 to decrypt */ |
47 | ) | 47 | ) |
48 | { | 48 | { |
@@ -58,10 +58,10 @@ int cbc_mac2( | |||
58 | g_aes_enc_key_dirty = false; | 58 | g_aes_enc_key_dirty = false; |
59 | } | 59 | } |
60 | g_aes_enc.Resynchronize(iv, 16); | 60 | g_aes_enc.Resynchronize(iv, 16); |
61 | byte tmp[16]; | 61 | uint8_t tmp[16]; |
62 | /* we need some output buffer, either a temporary one if we are CBC-MACing | 62 | /* we need some output buffer, either a temporary one if we are CBC-MACing |
63 | * only, or use output buffer if available */ | 63 | * only, or use output buffer if available */ |
64 | byte *out_ptr = (out_data == NULL) ? tmp : out_data; | 64 | uint8_t *out_ptr = (out_data == NULL) ? tmp : out_data; |
65 | while(nr_blocks-- > 0) | 65 | while(nr_blocks-- > 0) |
66 | { | 66 | { |
67 | g_aes_enc.ProcessData(out_ptr, in_data, 16); | 67 | g_aes_enc.ProcessData(out_ptr, in_data, 16); |
@@ -113,11 +113,11 @@ int crypto_setup(struct crypto_key_t *key) | |||
113 | } | 113 | } |
114 | 114 | ||
115 | int crypto_apply( | 115 | int crypto_apply( |
116 | byte *in_data, /* Input data */ | 116 | uint8_t *in_data, /* Input data */ |
117 | byte *out_data, /* Output data (or NULL) */ | 117 | uint8_t *out_data, /* Output data (or NULL) */ |
118 | int nr_blocks, /* Number of blocks (one block=16 bytes) */ | 118 | int nr_blocks, /* Number of blocks (one block=16 bytes) */ |
119 | byte iv[16], /* Key */ | 119 | uint8_t iv[16], /* Key */ |
120 | byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ | 120 | uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ |
121 | bool encrypt) | 121 | bool encrypt) |
122 | { | 122 | { |
123 | if(g_cur_method == CRYPTO_KEY) | 123 | if(g_cur_method == CRYPTO_KEY) |
@@ -131,7 +131,7 @@ void sha_1_init(struct sha_1_params_t *params) | |||
131 | params->object = new SHA1; | 131 | params->object = new SHA1; |
132 | } | 132 | } |
133 | 133 | ||
134 | void sha_1_update(struct sha_1_params_t *params, byte *buffer, int size) | 134 | void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size) |
135 | { | 135 | { |
136 | reinterpret_cast<SHA1 *>(params->object)->Update(buffer, size); | 136 | reinterpret_cast<SHA1 *>(params->object)->Update(buffer, size); |
137 | } | 137 | } |
@@ -143,7 +143,7 @@ void sha_1_finish(struct sha_1_params_t *params) | |||
143 | delete obj; | 143 | delete obj; |
144 | } | 144 | } |
145 | 145 | ||
146 | void sha_1_output(struct sha_1_params_t *params, byte *out) | 146 | void sha_1_output(struct sha_1_params_t *params, uint8_t *out) |
147 | { | 147 | { |
148 | memcpy(out, params->hash, 20); | 148 | memcpy(out, params->hash, 20); |
149 | } | 149 | } |
diff --git a/utils/imxtools/sbtools/crypto.h b/utils/imxtools/sbtools/crypto.h index 169197790b..bdb94bb881 100644 --- a/utils/imxtools/sbtools/crypto.h +++ b/utils/imxtools/sbtools/crypto.h | |||
@@ -30,8 +30,6 @@ | |||
30 | extern "C" { | 30 | extern "C" { |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | typedef uint8_t byte; | ||
34 | |||
35 | /* crypto.cpp */ | 33 | /* crypto.cpp */ |
36 | enum crypto_method_t | 34 | enum crypto_method_t |
37 | { | 35 | { |
@@ -52,7 +50,7 @@ struct crypto_key_t | |||
52 | enum crypto_method_t method; | 50 | enum crypto_method_t method; |
53 | union | 51 | union |
54 | { | 52 | { |
55 | byte key[16]; | 53 | uint8_t key[16]; |
56 | union xorcrypt_key_t xor_key[2]; | 54 | union xorcrypt_key_t xor_key[2]; |
57 | }u; | 55 | }u; |
58 | }; | 56 | }; |
@@ -68,28 +66,28 @@ int crypto_setup(struct crypto_key_t *key); | |||
68 | 66 | ||
69 | /* return 0 on success, <0 on error */ | 67 | /* return 0 on success, <0 on error */ |
70 | int crypto_apply( | 68 | int crypto_apply( |
71 | byte *in_data, /* Input data */ | 69 | uint8_t *in_data, /* Input data */ |
72 | byte *out_data, /* Output data (or NULL) */ | 70 | uint8_t *out_data, /* Output data (or NULL) */ |
73 | int nr_blocks, /* Number of blocks (one block=16 bytes) */ | 71 | int nr_blocks, /* Number of blocks (one block=16 bytes) */ |
74 | byte iv[16], /* IV */ | 72 | uint8_t iv[16], /* IV */ |
75 | byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ | 73 | uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */ |
76 | bool encrypt); | 74 | bool encrypt); |
77 | 75 | ||
78 | /* crc.c */ | 76 | /* crc.c */ |
79 | uint32_t crc(byte *data, int size); | 77 | uint32_t crc(uint8_t *data, int size); |
80 | uint32_t crc_continue(uint32_t previous_crc, byte *data, int size); | 78 | uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size); |
81 | 79 | ||
82 | /* sha1.c */ | 80 | /* sha1.c */ |
83 | struct sha_1_params_t | 81 | struct sha_1_params_t |
84 | { | 82 | { |
85 | byte hash[20]; /* final hash */ | 83 | uint8_t hash[20]; /* final hash */ |
86 | void *object; /* pointer to CryptoPP::SHA1 object */ | 84 | void *object; /* pointer to CryptoPP::SHA1 object */ |
87 | }; | 85 | }; |
88 | 86 | ||
89 | void sha_1_init(struct sha_1_params_t *params); | 87 | void sha_1_init(struct sha_1_params_t *params); |
90 | void sha_1_update(struct sha_1_params_t *params, byte *buffer, int size); | 88 | void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size); |
91 | void sha_1_finish(struct sha_1_params_t *params); | 89 | void sha_1_finish(struct sha_1_params_t *params); |
92 | void sha_1_output(struct sha_1_params_t *params, byte *out); | 90 | void sha_1_output(struct sha_1_params_t *params, uint8_t *out); |
93 | 91 | ||
94 | /* xorcrypt.c */ | 92 | /* xorcrypt.c */ |
95 | 93 | ||
diff --git a/utils/imxtools/sbtools/dbparser.c b/utils/imxtools/sbtools/dbparser.c index 1e5ee7244a..cfec7c2cd5 100644 --- a/utils/imxtools/sbtools/dbparser.c +++ b/utils/imxtools/sbtools/dbparser.c | |||
@@ -207,7 +207,7 @@ static void parse_number(struct context_t *ctx, struct lexem_t *lexem) | |||
207 | { | 207 | { |
208 | if(base == 10 && !isdigit(cur_char(ctx))) | 208 | if(base == 10 && !isdigit(cur_char(ctx))) |
209 | break; | 209 | break; |
210 | byte v; | 210 | uint8_t v; |
211 | if(convxdigit(cur_char(ctx), &v)) | 211 | if(convxdigit(cur_char(ctx), &v)) |
212 | break; | 212 | break; |
213 | lexem->num = base * lexem->num + v; | 213 | lexem->num = base * lexem->num + v; |
diff --git a/utils/imxtools/sbtools/misc.c b/utils/imxtools/sbtools/misc.c index 6216ae612b..c5832b6bb9 100644 --- a/utils/imxtools/sbtools/misc.c +++ b/utils/imxtools/sbtools/misc.c | |||
@@ -58,7 +58,7 @@ void *xmalloc(size_t s) | |||
58 | return r; | 58 | return r; |
59 | } | 59 | } |
60 | 60 | ||
61 | int convxdigit(char digit, byte *val) | 61 | int convxdigit(char digit, uint8_t *val) |
62 | { | 62 | { |
63 | if(digit >= '0' && digit <= '9') | 63 | if(digit >= '0' && digit <= '9') |
64 | { | 64 | { |
@@ -127,7 +127,7 @@ bool parse_key(char **pstr, struct crypto_key_t *key) | |||
127 | { | 127 | { |
128 | for(int j = 0; j < 128; j++) | 128 | for(int j = 0; j < 128; j++) |
129 | { | 129 | { |
130 | byte a, b; | 130 | uint8_t a, b; |
131 | if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b)) | 131 | if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b)) |
132 | return false; | 132 | return false; |
133 | key->u.xor_key[j / 64].key[j % 64] = (a << 4) | b; | 133 | key->u.xor_key[j / 64].key[j % 64] = (a << 4) | b; |
@@ -143,7 +143,7 @@ bool parse_key(char **pstr, struct crypto_key_t *key) | |||
143 | return false; | 143 | return false; |
144 | for(int j = 0; j < 16; j++) | 144 | for(int j = 0; j < 16; j++) |
145 | { | 145 | { |
146 | byte a, b; | 146 | uint8_t a, b; |
147 | if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b)) | 147 | if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b)) |
148 | return false; | 148 | return false; |
149 | key->u.key[j] = (a << 4) | b; | 149 | key->u.key[j] = (a << 4) | b; |
@@ -243,7 +243,7 @@ bool add_keys_from_file(const char *key_file) | |||
243 | return true; | 243 | return true; |
244 | } | 244 | } |
245 | 245 | ||
246 | void print_hex(void *user, misc_printf_t printf, byte *data, int len, bool newline) | 246 | void print_hex(void *user, misc_printf_t printf, uint8_t *data, int len, bool newline) |
247 | { | 247 | { |
248 | for(int i = 0; i < len; i++) | 248 | for(int i = 0; i < len; i++) |
249 | printf(user, "%02X ", data[i]); | 249 | printf(user, "%02X ", data[i]); |
diff --git a/utils/imxtools/sbtools/misc.h b/utils/imxtools/sbtools/misc.h index 5c6b2fc007..65386a728f 100644 --- a/utils/imxtools/sbtools/misc.h +++ b/utils/imxtools/sbtools/misc.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #define __MISC_H__ | 22 | #define __MISC_H__ |
23 | 23 | ||
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | #include <stdint.h> | ||
25 | #include "crypto.h" | 26 | #include "crypto.h" |
26 | 27 | ||
27 | #define _STR(a) #a | 28 | #define _STR(a) #a |
@@ -53,8 +54,8 @@ void augment_array_ex(void **arr, size_t elem_sz, int *cnt, int *capacity, | |||
53 | void *aug, int aug_cnt); | 54 | void *aug, int aug_cnt); |
54 | void generate_random_data(void *buf, size_t sz); | 55 | void generate_random_data(void *buf, size_t sz); |
55 | void *xmalloc(size_t s); | 56 | void *xmalloc(size_t s); |
56 | int convxdigit(char digit, byte *val); | 57 | int convxdigit(char digit, uint8_t *val); |
57 | void print_hex(void *user, misc_printf_t printf, byte *data, int len, bool newline); | 58 | void print_hex(void *user, misc_printf_t printf, uint8_t *data, int len, bool newline); |
58 | void add_keys(key_array_t ka, int kac); | 59 | void add_keys(key_array_t ka, int kac); |
59 | bool parse_key(char **str, struct crypto_key_t *key); | 60 | bool parse_key(char **str, struct crypto_key_t *key); |
60 | bool add_keys_from_file(const char *key_file); | 61 | bool add_keys_from_file(const char *key_file); |
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c index cbeacf9c3f..04acc2a6ad 100644 --- a/utils/imxtools/sbtools/sb.c +++ b/utils/imxtools/sbtools/sb.c | |||
@@ -223,7 +223,7 @@ static void produce_sb_section_header(struct sb_section_t *sec, | |||
223 | static uint8_t instruction_checksum(struct sb_instruction_header_t *hdr) | 223 | static uint8_t instruction_checksum(struct sb_instruction_header_t *hdr) |
224 | { | 224 | { |
225 | uint8_t sum = 90; | 225 | uint8_t sum = 90; |
226 | byte *ptr = (byte *)hdr; | 226 | uint8_t *ptr = (uint8_t *)hdr; |
227 | for(int i = 1; i < 16; i++) | 227 | for(int i = 1; i < 16; i++) |
228 | sum += ptr[i]; | 228 | sum += ptr[i]; |
229 | return sum; | 229 | return sum; |
@@ -287,8 +287,8 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
287 | #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) | 287 | #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) |
288 | struct crypto_key_t real_key; | 288 | struct crypto_key_t real_key; |
289 | real_key.method = CRYPTO_KEY; | 289 | real_key.method = CRYPTO_KEY; |
290 | byte crypto_iv[16]; | 290 | uint8_t crypto_iv[16]; |
291 | byte (*cbc_macs)[16] = xmalloc(16 * g_nr_keys); | 291 | uint8_t (*cbc_macs)[16] = xmalloc(16 * g_nr_keys); |
292 | /* init CBC-MACs */ | 292 | /* init CBC-MACs */ |
293 | for(int i = 0; i < g_nr_keys; i++) | 293 | for(int i = 0; i < g_nr_keys; i++) |
294 | memset(cbc_macs[i], 0, 16); | 294 | memset(cbc_macs[i], 0, 16); |
@@ -319,8 +319,8 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
319 | struct sb_header_t sb_hdr; | 319 | struct sb_header_t sb_hdr; |
320 | produce_sb_header(sb, &sb_hdr); | 320 | produce_sb_header(sb, &sb_hdr); |
321 | /* allocate image */ | 321 | /* allocate image */ |
322 | byte *buf = xmalloc(sb_hdr.image_size * BLOCK_SIZE); | 322 | uint8_t *buf = xmalloc(sb_hdr.image_size * BLOCK_SIZE); |
323 | byte *buf_p = buf; | 323 | uint8_t *buf_p = buf; |
324 | #define write(p, sz) do { memcpy(buf_p, p, sz); buf_p += sz; } while(0) | 324 | #define write(p, sz) do { memcpy(buf_p, p, sz); buf_p += sz; } while(0) |
325 | #define check_crypto(expr) \ | 325 | #define check_crypto(expr) \ |
326 | do { int err = expr; \ | 326 | do { int err = expr; \ |
@@ -329,7 +329,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
329 | cprintf(u, true, GREY, "Crypto error: %d\n", err); \ | 329 | cprintf(u, true, GREY, "Crypto error: %d\n", err); \ |
330 | return SB_CRYPTO_ERROR; } } while(0) | 330 | return SB_CRYPTO_ERROR; } } while(0) |
331 | 331 | ||
332 | sha_1_update(&file_sha1, (byte *)&sb_hdr, sizeof(sb_hdr)); | 332 | sha_1_update(&file_sha1, (uint8_t *)&sb_hdr, sizeof(sb_hdr)); |
333 | write(&sb_hdr, sizeof(sb_hdr)); | 333 | write(&sb_hdr, sizeof(sb_hdr)); |
334 | 334 | ||
335 | memcpy(crypto_iv, &sb_hdr, 16); | 335 | memcpy(crypto_iv, &sb_hdr, 16); |
@@ -338,7 +338,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
338 | for(int i = 0; i < g_nr_keys; i++) | 338 | for(int i = 0; i < g_nr_keys; i++) |
339 | { | 339 | { |
340 | check_crypto(crypto_setup(&g_key_array[i])); | 340 | check_crypto(crypto_setup(&g_key_array[i])); |
341 | check_crypto(crypto_apply((byte *)&sb_hdr, NULL, sizeof(sb_hdr) / BLOCK_SIZE, | 341 | check_crypto(crypto_apply((uint8_t *)&sb_hdr, NULL, sizeof(sb_hdr) / BLOCK_SIZE, |
342 | cbc_macs[i], &cbc_macs[i], true)); | 342 | cbc_macs[i], &cbc_macs[i], true)); |
343 | } | 343 | } |
344 | 344 | ||
@@ -347,13 +347,13 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
347 | { | 347 | { |
348 | struct sb_section_header_t sb_sec_hdr; | 348 | struct sb_section_header_t sb_sec_hdr; |
349 | produce_sb_section_header(&sb->sections[i], &sb_sec_hdr); | 349 | produce_sb_section_header(&sb->sections[i], &sb_sec_hdr); |
350 | sha_1_update(&file_sha1, (byte *)&sb_sec_hdr, sizeof(sb_sec_hdr)); | 350 | sha_1_update(&file_sha1, (uint8_t *)&sb_sec_hdr, sizeof(sb_sec_hdr)); |
351 | write(&sb_sec_hdr, sizeof(sb_sec_hdr)); | 351 | write(&sb_sec_hdr, sizeof(sb_sec_hdr)); |
352 | /* update CBC-MACs */ | 352 | /* update CBC-MACs */ |
353 | for(int j = 0; j < g_nr_keys; j++) | 353 | for(int j = 0; j < g_nr_keys; j++) |
354 | { | 354 | { |
355 | check_crypto(crypto_setup(&g_key_array[j])); | 355 | check_crypto(crypto_setup(&g_key_array[j])); |
356 | check_crypto(crypto_apply((byte *)&sb_sec_hdr, NULL, | 356 | check_crypto(crypto_apply((uint8_t *)&sb_sec_hdr, NULL, |
357 | sizeof(sb_sec_hdr) / BLOCK_SIZE, cbc_macs[j], &cbc_macs[j], true)); | 357 | sizeof(sb_sec_hdr) / BLOCK_SIZE, cbc_macs[j], &cbc_macs[j], true)); |
358 | } | 358 | } |
359 | } | 359 | } |
@@ -365,7 +365,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
365 | check_crypto(crypto_setup(&g_key_array[i])); | 365 | check_crypto(crypto_setup(&g_key_array[i])); |
366 | check_crypto(crypto_apply(real_key.u.key, entry.key, 1, crypto_iv, NULL, true)); | 366 | check_crypto(crypto_apply(real_key.u.key, entry.key, 1, crypto_iv, NULL, true)); |
367 | write(&entry, sizeof(entry)); | 367 | write(&entry, sizeof(entry)); |
368 | sha_1_update(&file_sha1, (byte *)&entry, sizeof(entry)); | 368 | sha_1_update(&file_sha1, (uint8_t *)&entry, sizeof(entry)); |
369 | } | 369 | } |
370 | 370 | ||
371 | /* HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK */ | 371 | /* HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK */ |
@@ -391,7 +391,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
391 | unsigned init_gap = (sb->sections[0].file_offset - 1) * BLOCK_SIZE - (buf_p - buf); | 391 | unsigned init_gap = (sb->sections[0].file_offset - 1) * BLOCK_SIZE - (buf_p - buf); |
392 | if(init_gap > 0) | 392 | if(init_gap > 0) |
393 | { | 393 | { |
394 | byte *data = xmalloc(init_gap); | 394 | uint8_t *data = xmalloc(init_gap); |
395 | generate_random_data(data, init_gap); | 395 | generate_random_data(data, init_gap); |
396 | sha_1_update(&file_sha1, data, init_gap); | 396 | sha_1_update(&file_sha1, data, init_gap); |
397 | write(data, init_gap); | 397 | write(data, init_gap); |
@@ -407,13 +407,13 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
407 | produce_section_tag_cmd(&sb->sections[i], &tag_cmd, (i + 1) == sb_hdr.nr_sections); | 407 | produce_section_tag_cmd(&sb->sections[i], &tag_cmd, (i + 1) == sb_hdr.nr_sections); |
408 | if(g_nr_keys > 0) | 408 | if(g_nr_keys > 0) |
409 | { | 409 | { |
410 | check_crypto(crypto_apply((byte *)&tag_cmd, (byte *)&tag_cmd, | 410 | check_crypto(crypto_apply((uint8_t *)&tag_cmd, (uint8_t *)&tag_cmd, |
411 | sizeof(tag_cmd) / BLOCK_SIZE, crypto_iv, NULL, true)); | 411 | sizeof(tag_cmd) / BLOCK_SIZE, crypto_iv, NULL, true)); |
412 | } | 412 | } |
413 | sha_1_update(&file_sha1, (byte *)&tag_cmd, sizeof(tag_cmd)); | 413 | sha_1_update(&file_sha1, (uint8_t *)&tag_cmd, sizeof(tag_cmd)); |
414 | write(&tag_cmd, sizeof(tag_cmd)); | 414 | write(&tag_cmd, sizeof(tag_cmd)); |
415 | /* produce other commands */ | 415 | /* produce other commands */ |
416 | byte cur_cbc_mac[16]; | 416 | uint8_t cur_cbc_mac[16]; |
417 | memcpy(cur_cbc_mac, crypto_iv, 16); | 417 | memcpy(cur_cbc_mac, crypto_iv, 16); |
418 | for(int j = 0; j < sb->sections[i].nr_insts; j++) | 418 | for(int j = 0; j < sb->sections[i].nr_insts; j++) |
419 | { | 419 | { |
@@ -425,17 +425,17 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
425 | produce_sb_instruction(inst, &cmd, u, cprintf); | 425 | produce_sb_instruction(inst, &cmd, u, cprintf); |
426 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) | 426 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) |
427 | { | 427 | { |
428 | check_crypto(crypto_apply((byte *)&cmd, (byte *)&cmd, | 428 | check_crypto(crypto_apply((uint8_t *)&cmd, (uint8_t *)&cmd, |
429 | sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true)); | 429 | sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true)); |
430 | } | 430 | } |
431 | sha_1_update(&file_sha1, (byte *)&cmd, sizeof(cmd)); | 431 | sha_1_update(&file_sha1, (uint8_t *)&cmd, sizeof(cmd)); |
432 | write(&cmd, sizeof(cmd)); | 432 | write(&cmd, sizeof(cmd)); |
433 | } | 433 | } |
434 | /* data */ | 434 | /* data */ |
435 | if(inst->inst == SB_INST_LOAD || inst->inst == SB_INST_DATA) | 435 | if(inst->inst == SB_INST_LOAD || inst->inst == SB_INST_DATA) |
436 | { | 436 | { |
437 | uint32_t sz = inst->size + inst->padding_size; | 437 | uint32_t sz = inst->size + inst->padding_size; |
438 | byte *data = xmalloc(sz); | 438 | uint8_t *data = xmalloc(sz); |
439 | memcpy(data, inst->data, inst->size); | 439 | memcpy(data, inst->data, inst->size); |
440 | memcpy(data + inst->size, inst->padding, inst->padding_size); | 440 | memcpy(data + inst->size, inst->padding, inst->padding_size); |
441 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) | 441 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) |
@@ -452,7 +452,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
452 | uint32_t pad_size = sb->sections[i].pad_size; | 452 | uint32_t pad_size = sb->sections[i].pad_size; |
453 | if(sb->sections[i].is_data) | 453 | if(sb->sections[i].is_data) |
454 | { | 454 | { |
455 | byte *data = xmalloc(pad_size * BLOCK_SIZE); | 455 | uint8_t *data = xmalloc(pad_size * BLOCK_SIZE); |
456 | generate_random_data(data, pad_size * BLOCK_SIZE); | 456 | generate_random_data(data, pad_size * BLOCK_SIZE); |
457 | sha_1_update(&file_sha1, data, pad_size * BLOCK_SIZE); | 457 | sha_1_update(&file_sha1, data, pad_size * BLOCK_SIZE); |
458 | write(data, pad_size * BLOCK_SIZE); | 458 | write(data, pad_size * BLOCK_SIZE); |
@@ -468,16 +468,16 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
468 | cmd.hdr.checksum = instruction_checksum(&cmd.hdr); | 468 | cmd.hdr.checksum = instruction_checksum(&cmd.hdr); |
469 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) | 469 | if(g_nr_keys > 0 && !sb->sections[i].is_cleartext) |
470 | { | 470 | { |
471 | check_crypto(crypto_apply((byte *)&cmd, (byte *)&cmd, | 471 | check_crypto(crypto_apply((uint8_t *)&cmd, (uint8_t *)&cmd, |
472 | sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true)); | 472 | sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true)); |
473 | } | 473 | } |
474 | sha_1_update(&file_sha1, (byte *)&cmd, sizeof(cmd)); | 474 | sha_1_update(&file_sha1, (uint8_t *)&cmd, sizeof(cmd)); |
475 | write(&cmd, sizeof(cmd)); | 475 | write(&cmd, sizeof(cmd)); |
476 | } | 476 | } |
477 | } | 477 | } |
478 | } | 478 | } |
479 | /* write file SHA-1 */ | 479 | /* write file SHA-1 */ |
480 | byte final_sig[32]; | 480 | uint8_t final_sig[32]; |
481 | sha_1_finish(&file_sha1); | 481 | sha_1_finish(&file_sha1); |
482 | sha_1_output(&file_sha1, final_sig); | 482 | sha_1_output(&file_sha1, final_sig); |
483 | generate_random_data(final_sig + 20, 12); | 483 | generate_random_data(final_sig + 20, 12); |
@@ -513,7 +513,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void * | |||
513 | #undef printf | 513 | #undef printf |
514 | } | 514 | } |
515 | 515 | ||
516 | static struct sb_section_t *read_section(bool data_sec, uint32_t id, byte *buf, | 516 | static struct sb_section_t *read_section(bool data_sec, uint32_t id, uint8_t *buf, |
517 | int size, const char *indent, void *u, generic_printf_t cprintf, enum sb_error_t *err) | 517 | int size, const char *indent, void *u, generic_printf_t cprintf, enum sb_error_t *err) |
518 | { | 518 | { |
519 | #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) | 519 | #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) |
@@ -758,7 +758,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
758 | fatal(SB_CRYPTO_ERROR, "Crypto error: %d\n", err); } while(0) | 758 | fatal(SB_CRYPTO_ERROR, "Crypto error: %d\n", err); } while(0) |
759 | 759 | ||
760 | struct sha_1_params_t sha_1_params; | 760 | struct sha_1_params_t sha_1_params; |
761 | byte (*cbcmacs)[16] = xmalloc(16 * g_nr_keys); | 761 | uint8_t (*cbcmacs)[16] = xmalloc(16 * g_nr_keys); |
762 | sb_file = xmalloc(sizeof(struct sb_file_t)); | 762 | sb_file = xmalloc(sizeof(struct sb_file_t)); |
763 | memset(sb_file, 0, sizeof(struct sb_file_t)); | 763 | memset(sb_file, 0, sizeof(struct sb_file_t)); |
764 | struct sb_header_t *sb_header = (struct sb_header_t *)buf; | 764 | struct sb_header_t *sb_header = (struct sb_header_t *)buf; |
@@ -790,10 +790,10 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
790 | printf(GREEN, " SB version: "); | 790 | printf(GREEN, " SB version: "); |
791 | printf(YELLOW, "%d.%d\n", sb_header->major_ver, sb_header->minor_ver); | 791 | printf(YELLOW, "%d.%d\n", sb_header->major_ver, sb_header->minor_ver); |
792 | printf(GREEN, " Header SHA-1: "); | 792 | printf(GREEN, " Header SHA-1: "); |
793 | byte *hdr_sha1 = sb_header->sha1_header; | 793 | uint8_t *hdr_sha1 = sb_header->sha1_header; |
794 | print_hex(YELLOW, hdr_sha1, 20, false); | 794 | print_hex(YELLOW, hdr_sha1, 20, false); |
795 | /* Check SHA1 sum */ | 795 | /* Check SHA1 sum */ |
796 | byte computed_sha1[20]; | 796 | uint8_t computed_sha1[20]; |
797 | sha_1_init(&sha_1_params); | 797 | sha_1_init(&sha_1_params); |
798 | sha_1_update(&sha_1_params, &sb_header->signature[0], | 798 | sha_1_update(&sha_1_params, &sb_header->signature[0], |
799 | sizeof(struct sb_header_t) - sizeof(sb_header->sha1_header)); | 799 | sizeof(struct sb_header_t) - sizeof(sb_header->sha1_header)); |
@@ -876,7 +876,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
876 | print_key(&printer, sb_printer, &g_key_array[i], true); | 876 | print_key(&printer, sb_printer, &g_key_array[i], true); |
877 | printf(GREEN, " CBC-MAC: "); | 877 | printf(GREEN, " CBC-MAC: "); |
878 | /* check it */ | 878 | /* check it */ |
879 | byte zero[16]; | 879 | uint8_t zero[16]; |
880 | memset(zero, 0, 16); | 880 | memset(zero, 0, 16); |
881 | check_crypto(crypto_setup(&g_key_array[i])); | 881 | check_crypto(crypto_setup(&g_key_array[i])); |
882 | check_crypto(crypto_apply(buf, NULL, sb_header->header_size + | 882 | check_crypto(crypto_apply(buf, NULL, sb_header->header_size + |
@@ -906,8 +906,8 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
906 | { | 906 | { |
907 | printf(RED, " Match\n"); | 907 | printf(RED, " Match\n"); |
908 | /* decrypt */ | 908 | /* decrypt */ |
909 | byte decrypted_key[16]; | 909 | uint8_t decrypted_key[16]; |
910 | byte iv[16]; | 910 | uint8_t iv[16]; |
911 | memcpy(iv, buf, 16); /* uses the first 16-bytes of SHA-1 sig as IV */ | 911 | memcpy(iv, buf, 16); /* uses the first 16-bytes of SHA-1 sig as IV */ |
912 | check_crypto(crypto_setup(&g_key_array[idx])); | 912 | check_crypto(crypto_setup(&g_key_array[idx])); |
913 | check_crypto(crypto_apply(dict_entry->key, decrypted_key, 1, iv, NULL, false)); | 913 | check_crypto(crypto_apply(dict_entry->key, decrypted_key, 1, iv, NULL, false)); |
@@ -1008,7 +1008,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
1008 | } | 1008 | } |
1009 | 1009 | ||
1010 | /* save it */ | 1010 | /* save it */ |
1011 | byte *sec = xmalloc(size); | 1011 | uint8_t *sec = xmalloc(size); |
1012 | if(encrypted) | 1012 | if(encrypted) |
1013 | check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false)); | 1013 | check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false)); |
1014 | else | 1014 | else |
@@ -1034,13 +1034,13 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
1034 | /* advanced raw mode */ | 1034 | /* advanced raw mode */ |
1035 | printf(BLUE, "Commands\n"); | 1035 | printf(BLUE, "Commands\n"); |
1036 | uint32_t offset = sb_header->first_boot_tag_off * BLOCK_SIZE; | 1036 | uint32_t offset = sb_header->first_boot_tag_off * BLOCK_SIZE; |
1037 | byte iv[16]; | 1037 | uint8_t iv[16]; |
1038 | const char *indent = " "; | 1038 | const char *indent = " "; |
1039 | while(true) | 1039 | while(true) |
1040 | { | 1040 | { |
1041 | /* restart with IV */ | 1041 | /* restart with IV */ |
1042 | memcpy(iv, buf, 16); | 1042 | memcpy(iv, buf, 16); |
1043 | byte cmd[BLOCK_SIZE]; | 1043 | uint8_t cmd[BLOCK_SIZE]; |
1044 | if(sb_header->nr_keys > 0) | 1044 | if(sb_header->nr_keys > 0) |
1045 | check_crypto(crypto_apply(buf + offset, cmd, 1, iv, &iv, false)); | 1045 | check_crypto(crypto_apply(buf + offset, cmd, 1, iv, &iv, false)); |
1046 | else | 1046 | else |
@@ -1106,7 +1106,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | /* save it */ | 1108 | /* save it */ |
1109 | byte *sec = xmalloc(size); | 1109 | uint8_t *sec = xmalloc(size); |
1110 | if(encrypted) | 1110 | if(encrypted) |
1111 | check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false)); | 1111 | check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false)); |
1112 | else | 1112 | else |
@@ -1147,11 +1147,11 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo | |||
1147 | 1147 | ||
1148 | /* final signature */ | 1148 | /* final signature */ |
1149 | printf(BLUE, "Final signature:\n"); | 1149 | printf(BLUE, "Final signature:\n"); |
1150 | byte decrypted_block[32]; | 1150 | uint8_t decrypted_block[32]; |
1151 | if(sb_header->nr_keys > 0) | 1151 | if(sb_header->nr_keys > 0) |
1152 | { | 1152 | { |
1153 | printf(GREEN, " Encrypted SHA-1:\n"); | 1153 | printf(GREEN, " Encrypted SHA-1:\n"); |
1154 | byte *encrypted_block = &buf[filesize - 32]; | 1154 | uint8_t *encrypted_block = &buf[filesize - 32]; |
1155 | printf(OFF, " "); | 1155 | printf(OFF, " "); |
1156 | print_hex(YELLOW, encrypted_block, 16, true); | 1156 | print_hex(YELLOW, encrypted_block, 16, true); |
1157 | printf(OFF, " "); | 1157 | printf(OFF, " "); |