forked from len0rd/rockbox
imxtools: Replace use of "byte" with its underlying uint8_t.
libtomcrypt uses a macro "byte" which conflicts with this type. Since the underlying type is uint8_t and there's no real benefit from using a custom type use the actual underlying type. Change-Id: I982c9b8bdcb657b99fa645a5235303af7afda25b
This commit is contained in:
parent
387a45923c
commit
815b289cb3
8 changed files with 69 additions and 70 deletions
|
@ -655,7 +655,7 @@ static enum imx_error_t find_model_by_md5sum(uint8_t file_md5sum[16], int *md5_i
|
|||
}
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
byte a, b;
|
||||
uint8_t a, b;
|
||||
if(convxdigit(imx_sums[i].md5sum[2 * j], &a) || convxdigit(imx_sums[i].md5sum[2 * j + 1], &b))
|
||||
{
|
||||
printf("[ERR][INTERNAL] Bad checksum format: %s\n", imx_sums[i].md5sum);
|
||||
|
|
|
@ -68,12 +68,12 @@ static uint32_t crc_table[256] = {
|
|||
0x0B8757BDA, 0x0B5365D03, 0x0B1F740B4
|
||||
};
|
||||
|
||||
uint32_t crc(byte *data, int size)
|
||||
uint32_t crc(uint8_t *data, int size)
|
||||
{
|
||||
return crc_continue(0xffffffff, data, size);
|
||||
}
|
||||
|
||||
uint32_t crc_continue(uint32_t previous_crc, byte *data, int size)
|
||||
uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size)
|
||||
{
|
||||
uint32_t c = previous_crc;
|
||||
/* normal CRC */
|
||||
|
|
|
@ -30,19 +30,19 @@ namespace
|
|||
{
|
||||
|
||||
enum crypto_method_t g_cur_method = CRYPTO_NONE;
|
||||
byte g_key[16];
|
||||
uint8_t g_key[16];
|
||||
CBC_Mode<AES>::Encryption g_aes_enc;
|
||||
CBC_Mode<AES>::Decryption g_aes_dec;
|
||||
bool g_aes_enc_key_dirty; /* true of g_aes_enc key needs to be updated */
|
||||
bool g_aes_dec_key_dirty; /* same for g_aes_dec */
|
||||
|
||||
int cbc_mac2(
|
||||
const byte *in_data, /* Input data */
|
||||
byte *out_data, /* Output data (or NULL) */
|
||||
const uint8_t *in_data, /* Input data */
|
||||
uint8_t *out_data, /* Output data (or NULL) */
|
||||
int nr_blocks, /* Number of blocks to encrypt/decrypt (one block=16 bytes) */
|
||||
byte key[16], /* Key */
|
||||
byte iv[16], /* Initialisation Vector */
|
||||
byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
uint8_t key[16], /* Key */
|
||||
uint8_t iv[16], /* Initialisation Vector */
|
||||
uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
bool encrypt /* 1 to encrypt, 0 to decrypt */
|
||||
)
|
||||
{
|
||||
|
@ -58,10 +58,10 @@ int cbc_mac2(
|
|||
g_aes_enc_key_dirty = false;
|
||||
}
|
||||
g_aes_enc.Resynchronize(iv, 16);
|
||||
byte tmp[16];
|
||||
uint8_t tmp[16];
|
||||
/* we need some output buffer, either a temporary one if we are CBC-MACing
|
||||
* only, or use output buffer if available */
|
||||
byte *out_ptr = (out_data == NULL) ? tmp : out_data;
|
||||
uint8_t *out_ptr = (out_data == NULL) ? tmp : out_data;
|
||||
while(nr_blocks-- > 0)
|
||||
{
|
||||
g_aes_enc.ProcessData(out_ptr, in_data, 16);
|
||||
|
@ -113,11 +113,11 @@ int crypto_setup(struct crypto_key_t *key)
|
|||
}
|
||||
|
||||
int crypto_apply(
|
||||
byte *in_data, /* Input data */
|
||||
byte *out_data, /* Output data (or NULL) */
|
||||
uint8_t *in_data, /* Input data */
|
||||
uint8_t *out_data, /* Output data (or NULL) */
|
||||
int nr_blocks, /* Number of blocks (one block=16 bytes) */
|
||||
byte iv[16], /* Key */
|
||||
byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
uint8_t iv[16], /* Key */
|
||||
uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
bool encrypt)
|
||||
{
|
||||
if(g_cur_method == CRYPTO_KEY)
|
||||
|
@ -131,7 +131,7 @@ void sha_1_init(struct sha_1_params_t *params)
|
|||
params->object = new SHA1;
|
||||
}
|
||||
|
||||
void sha_1_update(struct sha_1_params_t *params, byte *buffer, int size)
|
||||
void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size)
|
||||
{
|
||||
reinterpret_cast<SHA1 *>(params->object)->Update(buffer, size);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void sha_1_finish(struct sha_1_params_t *params)
|
|||
delete obj;
|
||||
}
|
||||
|
||||
void sha_1_output(struct sha_1_params_t *params, byte *out)
|
||||
void sha_1_output(struct sha_1_params_t *params, uint8_t *out)
|
||||
{
|
||||
memcpy(out, params->hash, 20);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
/* crypto.cpp */
|
||||
enum crypto_method_t
|
||||
{
|
||||
|
@ -52,7 +50,7 @@ struct crypto_key_t
|
|||
enum crypto_method_t method;
|
||||
union
|
||||
{
|
||||
byte key[16];
|
||||
uint8_t key[16];
|
||||
union xorcrypt_key_t xor_key[2];
|
||||
}u;
|
||||
};
|
||||
|
@ -68,28 +66,28 @@ int crypto_setup(struct crypto_key_t *key);
|
|||
|
||||
/* return 0 on success, <0 on error */
|
||||
int crypto_apply(
|
||||
byte *in_data, /* Input data */
|
||||
byte *out_data, /* Output data (or NULL) */
|
||||
uint8_t *in_data, /* Input data */
|
||||
uint8_t *out_data, /* Output data (or NULL) */
|
||||
int nr_blocks, /* Number of blocks (one block=16 bytes) */
|
||||
byte iv[16], /* IV */
|
||||
byte (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
uint8_t iv[16], /* IV */
|
||||
uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
||||
bool encrypt);
|
||||
|
||||
/* crc.c */
|
||||
uint32_t crc(byte *data, int size);
|
||||
uint32_t crc_continue(uint32_t previous_crc, byte *data, int size);
|
||||
uint32_t crc(uint8_t *data, int size);
|
||||
uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size);
|
||||
|
||||
/* sha1.c */
|
||||
struct sha_1_params_t
|
||||
{
|
||||
byte hash[20]; /* final hash */
|
||||
uint8_t hash[20]; /* final hash */
|
||||
void *object; /* pointer to CryptoPP::SHA1 object */
|
||||
};
|
||||
|
||||
void sha_1_init(struct sha_1_params_t *params);
|
||||
void sha_1_update(struct sha_1_params_t *params, byte *buffer, int size);
|
||||
void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size);
|
||||
void sha_1_finish(struct sha_1_params_t *params);
|
||||
void sha_1_output(struct sha_1_params_t *params, byte *out);
|
||||
void sha_1_output(struct sha_1_params_t *params, uint8_t *out);
|
||||
|
||||
/* xorcrypt.c */
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ static void parse_number(struct context_t *ctx, struct lexem_t *lexem)
|
|||
{
|
||||
if(base == 10 && !isdigit(cur_char(ctx)))
|
||||
break;
|
||||
byte v;
|
||||
uint8_t v;
|
||||
if(convxdigit(cur_char(ctx), &v))
|
||||
break;
|
||||
lexem->num = base * lexem->num + v;
|
||||
|
|
|
@ -58,7 +58,7 @@ void *xmalloc(size_t s)
|
|||
return r;
|
||||
}
|
||||
|
||||
int convxdigit(char digit, byte *val)
|
||||
int convxdigit(char digit, uint8_t *val)
|
||||
{
|
||||
if(digit >= '0' && digit <= '9')
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ bool parse_key(char **pstr, struct crypto_key_t *key)
|
|||
{
|
||||
for(int j = 0; j < 128; j++)
|
||||
{
|
||||
byte a, b;
|
||||
uint8_t a, b;
|
||||
if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b))
|
||||
return false;
|
||||
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)
|
|||
return false;
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
byte a, b;
|
||||
uint8_t a, b;
|
||||
if(convxdigit(str[2 * j], &a) || convxdigit(str[2 * j + 1], &b))
|
||||
return false;
|
||||
key->u.key[j] = (a << 4) | b;
|
||||
|
@ -243,7 +243,7 @@ bool add_keys_from_file(const char *key_file)
|
|||
return true;
|
||||
}
|
||||
|
||||
void print_hex(void *user, misc_printf_t printf, byte *data, int len, bool newline)
|
||||
void print_hex(void *user, misc_printf_t printf, uint8_t *data, int len, bool newline)
|
||||
{
|
||||
for(int i = 0; i < len; i++)
|
||||
printf(user, "%02X ", data[i]);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define __MISC_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "crypto.h"
|
||||
|
||||
#define _STR(a) #a
|
||||
|
@ -53,8 +54,8 @@ void augment_array_ex(void **arr, size_t elem_sz, int *cnt, int *capacity,
|
|||
void *aug, int aug_cnt);
|
||||
void generate_random_data(void *buf, size_t sz);
|
||||
void *xmalloc(size_t s);
|
||||
int convxdigit(char digit, byte *val);
|
||||
void print_hex(void *user, misc_printf_t printf, byte *data, int len, bool newline);
|
||||
int convxdigit(char digit, uint8_t *val);
|
||||
void print_hex(void *user, misc_printf_t printf, uint8_t *data, int len, bool newline);
|
||||
void add_keys(key_array_t ka, int kac);
|
||||
bool parse_key(char **str, struct crypto_key_t *key);
|
||||
bool add_keys_from_file(const char *key_file);
|
||||
|
|
|
@ -223,7 +223,7 @@ static void produce_sb_section_header(struct sb_section_t *sec,
|
|||
static uint8_t instruction_checksum(struct sb_instruction_header_t *hdr)
|
||||
{
|
||||
uint8_t sum = 90;
|
||||
byte *ptr = (byte *)hdr;
|
||||
uint8_t *ptr = (uint8_t *)hdr;
|
||||
for(int i = 1; i < 16; i++)
|
||||
sum += ptr[i];
|
||||
return sum;
|
||||
|
@ -287,8 +287,8 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
#define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
|
||||
struct crypto_key_t real_key;
|
||||
real_key.method = CRYPTO_KEY;
|
||||
byte crypto_iv[16];
|
||||
byte (*cbc_macs)[16] = xmalloc(16 * g_nr_keys);
|
||||
uint8_t crypto_iv[16];
|
||||
uint8_t (*cbc_macs)[16] = xmalloc(16 * g_nr_keys);
|
||||
/* init CBC-MACs */
|
||||
for(int i = 0; i < g_nr_keys; i++)
|
||||
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 *
|
|||
struct sb_header_t sb_hdr;
|
||||
produce_sb_header(sb, &sb_hdr);
|
||||
/* allocate image */
|
||||
byte *buf = xmalloc(sb_hdr.image_size * BLOCK_SIZE);
|
||||
byte *buf_p = buf;
|
||||
uint8_t *buf = xmalloc(sb_hdr.image_size * BLOCK_SIZE);
|
||||
uint8_t *buf_p = buf;
|
||||
#define write(p, sz) do { memcpy(buf_p, p, sz); buf_p += sz; } while(0)
|
||||
#define check_crypto(expr) \
|
||||
do { int err = expr; \
|
||||
|
@ -329,7 +329,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
cprintf(u, true, GREY, "Crypto error: %d\n", err); \
|
||||
return SB_CRYPTO_ERROR; } } while(0)
|
||||
|
||||
sha_1_update(&file_sha1, (byte *)&sb_hdr, sizeof(sb_hdr));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&sb_hdr, sizeof(sb_hdr));
|
||||
write(&sb_hdr, sizeof(sb_hdr));
|
||||
|
||||
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 *
|
|||
for(int i = 0; i < g_nr_keys; i++)
|
||||
{
|
||||
check_crypto(crypto_setup(&g_key_array[i]));
|
||||
check_crypto(crypto_apply((byte *)&sb_hdr, NULL, sizeof(sb_hdr) / BLOCK_SIZE,
|
||||
check_crypto(crypto_apply((uint8_t *)&sb_hdr, NULL, sizeof(sb_hdr) / BLOCK_SIZE,
|
||||
cbc_macs[i], &cbc_macs[i], true));
|
||||
}
|
||||
|
||||
|
@ -347,13 +347,13 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
{
|
||||
struct sb_section_header_t sb_sec_hdr;
|
||||
produce_sb_section_header(&sb->sections[i], &sb_sec_hdr);
|
||||
sha_1_update(&file_sha1, (byte *)&sb_sec_hdr, sizeof(sb_sec_hdr));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&sb_sec_hdr, sizeof(sb_sec_hdr));
|
||||
write(&sb_sec_hdr, sizeof(sb_sec_hdr));
|
||||
/* update CBC-MACs */
|
||||
for(int j = 0; j < g_nr_keys; j++)
|
||||
{
|
||||
check_crypto(crypto_setup(&g_key_array[j]));
|
||||
check_crypto(crypto_apply((byte *)&sb_sec_hdr, NULL,
|
||||
check_crypto(crypto_apply((uint8_t *)&sb_sec_hdr, NULL,
|
||||
sizeof(sb_sec_hdr) / BLOCK_SIZE, cbc_macs[j], &cbc_macs[j], true));
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
check_crypto(crypto_setup(&g_key_array[i]));
|
||||
check_crypto(crypto_apply(real_key.u.key, entry.key, 1, crypto_iv, NULL, true));
|
||||
write(&entry, sizeof(entry));
|
||||
sha_1_update(&file_sha1, (byte *)&entry, sizeof(entry));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&entry, sizeof(entry));
|
||||
}
|
||||
|
||||
/* 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 *
|
|||
unsigned init_gap = (sb->sections[0].file_offset - 1) * BLOCK_SIZE - (buf_p - buf);
|
||||
if(init_gap > 0)
|
||||
{
|
||||
byte *data = xmalloc(init_gap);
|
||||
uint8_t *data = xmalloc(init_gap);
|
||||
generate_random_data(data, init_gap);
|
||||
sha_1_update(&file_sha1, data, init_gap);
|
||||
write(data, init_gap);
|
||||
|
@ -407,13 +407,13 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
produce_section_tag_cmd(&sb->sections[i], &tag_cmd, (i + 1) == sb_hdr.nr_sections);
|
||||
if(g_nr_keys > 0)
|
||||
{
|
||||
check_crypto(crypto_apply((byte *)&tag_cmd, (byte *)&tag_cmd,
|
||||
check_crypto(crypto_apply((uint8_t *)&tag_cmd, (uint8_t *)&tag_cmd,
|
||||
sizeof(tag_cmd) / BLOCK_SIZE, crypto_iv, NULL, true));
|
||||
}
|
||||
sha_1_update(&file_sha1, (byte *)&tag_cmd, sizeof(tag_cmd));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&tag_cmd, sizeof(tag_cmd));
|
||||
write(&tag_cmd, sizeof(tag_cmd));
|
||||
/* produce other commands */
|
||||
byte cur_cbc_mac[16];
|
||||
uint8_t cur_cbc_mac[16];
|
||||
memcpy(cur_cbc_mac, crypto_iv, 16);
|
||||
for(int j = 0; j < sb->sections[i].nr_insts; j++)
|
||||
{
|
||||
|
@ -425,17 +425,17 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename, void *
|
|||
produce_sb_instruction(inst, &cmd, u, cprintf);
|
||||
if(g_nr_keys > 0 && !sb->sections[i].is_cleartext)
|
||||
{
|
||||
check_crypto(crypto_apply((byte *)&cmd, (byte *)&cmd,
|
||||
check_crypto(crypto_apply((uint8_t *)&cmd, (uint8_t *)&cmd,
|
||||
sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true));
|
||||
}
|
||||
sha_1_update(&file_sha1, (byte *)&cmd, sizeof(cmd));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&cmd, sizeof(cmd));
|
||||
write(&cmd, sizeof(cmd));
|
||||
}
|
||||
/* data */
|
||||
if(inst->inst == SB_INST_LOAD || inst->inst == SB_INST_DATA)
|
||||
{
|
||||
uint32_t sz = inst->size + inst->padding_size;
|
||||
byte *data = xmalloc(sz);
|
||||
uint8_t *data = xmalloc(sz);
|
||||
memcpy(data, inst->data, inst->size);
|
||||
memcpy(data + inst->size, inst->padding, inst->padding_size);
|
||||
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 *
|
|||
uint32_t pad_size = sb->sections[i].pad_size;
|
||||
if(sb->sections[i].is_data)
|
||||
{
|
||||
byte *data = xmalloc(pad_size * BLOCK_SIZE);
|
||||
uint8_t *data = xmalloc(pad_size * BLOCK_SIZE);
|
||||
generate_random_data(data, pad_size * BLOCK_SIZE);
|
||||
sha_1_update(&file_sha1, data, pad_size * BLOCK_SIZE);
|
||||
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 *
|
|||
cmd.hdr.checksum = instruction_checksum(&cmd.hdr);
|
||||
if(g_nr_keys > 0 && !sb->sections[i].is_cleartext)
|
||||
{
|
||||
check_crypto(crypto_apply((byte *)&cmd, (byte *)&cmd,
|
||||
check_crypto(crypto_apply((uint8_t *)&cmd, (uint8_t *)&cmd,
|
||||
sizeof(cmd) / BLOCK_SIZE, cur_cbc_mac, &cur_cbc_mac, true));
|
||||
}
|
||||
sha_1_update(&file_sha1, (byte *)&cmd, sizeof(cmd));
|
||||
sha_1_update(&file_sha1, (uint8_t *)&cmd, sizeof(cmd));
|
||||
write(&cmd, sizeof(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
/* write file SHA-1 */
|
||||
byte final_sig[32];
|
||||
uint8_t final_sig[32];
|
||||
sha_1_finish(&file_sha1);
|
||||
sha_1_output(&file_sha1, final_sig);
|
||||
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 *
|
|||
#undef printf
|
||||
}
|
||||
|
||||
static struct sb_section_t *read_section(bool data_sec, uint32_t id, byte *buf,
|
||||
static struct sb_section_t *read_section(bool data_sec, uint32_t id, uint8_t *buf,
|
||||
int size, const char *indent, void *u, generic_printf_t cprintf, enum sb_error_t *err)
|
||||
{
|
||||
#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
|
|||
fatal(SB_CRYPTO_ERROR, "Crypto error: %d\n", err); } while(0)
|
||||
|
||||
struct sha_1_params_t sha_1_params;
|
||||
byte (*cbcmacs)[16] = xmalloc(16 * g_nr_keys);
|
||||
uint8_t (*cbcmacs)[16] = xmalloc(16 * g_nr_keys);
|
||||
sb_file = xmalloc(sizeof(struct sb_file_t));
|
||||
memset(sb_file, 0, sizeof(struct sb_file_t));
|
||||
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
|
|||
printf(GREEN, " SB version: ");
|
||||
printf(YELLOW, "%d.%d\n", sb_header->major_ver, sb_header->minor_ver);
|
||||
printf(GREEN, " Header SHA-1: ");
|
||||
byte *hdr_sha1 = sb_header->sha1_header;
|
||||
uint8_t *hdr_sha1 = sb_header->sha1_header;
|
||||
print_hex(YELLOW, hdr_sha1, 20, false);
|
||||
/* Check SHA1 sum */
|
||||
byte computed_sha1[20];
|
||||
uint8_t computed_sha1[20];
|
||||
sha_1_init(&sha_1_params);
|
||||
sha_1_update(&sha_1_params, &sb_header->signature[0],
|
||||
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
|
|||
print_key(&printer, sb_printer, &g_key_array[i], true);
|
||||
printf(GREEN, " CBC-MAC: ");
|
||||
/* check it */
|
||||
byte zero[16];
|
||||
uint8_t zero[16];
|
||||
memset(zero, 0, 16);
|
||||
check_crypto(crypto_setup(&g_key_array[i]));
|
||||
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
|
|||
{
|
||||
printf(RED, " Match\n");
|
||||
/* decrypt */
|
||||
byte decrypted_key[16];
|
||||
byte iv[16];
|
||||
uint8_t decrypted_key[16];
|
||||
uint8_t iv[16];
|
||||
memcpy(iv, buf, 16); /* uses the first 16-bytes of SHA-1 sig as IV */
|
||||
check_crypto(crypto_setup(&g_key_array[idx]));
|
||||
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
|
|||
}
|
||||
|
||||
/* save it */
|
||||
byte *sec = xmalloc(size);
|
||||
uint8_t *sec = xmalloc(size);
|
||||
if(encrypted)
|
||||
check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false));
|
||||
else
|
||||
|
@ -1034,13 +1034,13 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo
|
|||
/* advanced raw mode */
|
||||
printf(BLUE, "Commands\n");
|
||||
uint32_t offset = sb_header->first_boot_tag_off * BLOCK_SIZE;
|
||||
byte iv[16];
|
||||
uint8_t iv[16];
|
||||
const char *indent = " ";
|
||||
while(true)
|
||||
{
|
||||
/* restart with IV */
|
||||
memcpy(iv, buf, 16);
|
||||
byte cmd[BLOCK_SIZE];
|
||||
uint8_t cmd[BLOCK_SIZE];
|
||||
if(sb_header->nr_keys > 0)
|
||||
check_crypto(crypto_apply(buf + offset, cmd, 1, iv, &iv, false));
|
||||
else
|
||||
|
@ -1106,7 +1106,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo
|
|||
}
|
||||
|
||||
/* save it */
|
||||
byte *sec = xmalloc(size);
|
||||
uint8_t *sec = xmalloc(size);
|
||||
if(encrypted)
|
||||
check_crypto(crypto_apply(buf + pos, sec, size / BLOCK_SIZE, buf, NULL, false));
|
||||
else
|
||||
|
@ -1147,11 +1147,11 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, unsigned flags, vo
|
|||
|
||||
/* final signature */
|
||||
printf(BLUE, "Final signature:\n");
|
||||
byte decrypted_block[32];
|
||||
uint8_t decrypted_block[32];
|
||||
if(sb_header->nr_keys > 0)
|
||||
{
|
||||
printf(GREEN, " Encrypted SHA-1:\n");
|
||||
byte *encrypted_block = &buf[filesize - 32];
|
||||
uint8_t *encrypted_block = &buf[filesize - 32];
|
||||
printf(OFF, " ");
|
||||
print_hex(YELLOW, encrypted_block, 16, true);
|
||||
printf(OFF, " ");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue