Fix bug in user_generate_specific_aes_key, add other read/write le/be funcs

This commit is contained in:
TuxSH 2018-03-07 15:11:53 +01:00
parent 71f01aaa43
commit 4f0e8b8467
3 changed files with 136 additions and 120 deletions

View file

@ -326,8 +326,8 @@ uint32_t user_generate_specific_aes_key(smc_args_t *args) {
} }
args->X[1] = key[0]; args->X[1] = read64le(key, 0);
args->X[2] = key[1]; args->X[2] = read64le(key, 8);
return 0; return 0;
} }

View file

@ -36,7 +36,7 @@ void calculate_mgf1_and_xor(void *masked, size_t masked_size, const void *seed,
size_t hash_buf_size = seed_size + 4; size_t hash_buf_size = seed_size + 4;
memcpy(hash_buf, seed, seed_size); memcpy(hash_buf, seed, seed_size);
uint32_t round = 0; uint32_t round_num = 0;
uint8_t *p_out = (uint8_t *)masked; uint8_t *p_out = (uint8_t *)masked;
@ -46,11 +46,7 @@ void calculate_mgf1_and_xor(void *masked, size_t masked_size, const void *seed,
cur_size = 0x20; cur_size = 0x20;
} }
hash_buf[seed_size + 0] = (uint8_t)((round >> 24) & 0xFF); write32be(hash_buf, seed_size, round_num++);
hash_buf[seed_size + 1] = (uint8_t)((round >> 16) & 0xFF);
hash_buf[seed_size + 2] = (uint8_t)((round >> 8) & 0xFF);
hash_buf[seed_size + 3] = (uint8_t)((round >> 0) & 0xFF);
round++;
flush_dcache_range(hash_buf, hash_buf + hash_buf_size); flush_dcache_range(hash_buf, hash_buf + hash_buf_size);
se_calculate_sha256(cur_hash, hash_buf, hash_buf_size); se_calculate_sha256(cur_hash, hash_buf, hash_buf_size);

View file

@ -78,6 +78,26 @@ static inline uint64_t read64le(const volatile void *qword, size_t offset) {
return *(uint64_t *)((uintptr_t)qword + offset); return *(uint64_t *)((uintptr_t)qword + offset);
} }
static inline uint32_t read64be(const volatile void *qword, size_t offset) {
return __builtin_bswap64(read64le(qword, offset));
}
static inline void write32le(volatile void *dword, size_t offset, uint32_t value) {
*(uint32_t *)((uintptr_t)dword + offset) = value;
}
static inline void write32be(volatile void *dword, size_t offset, uint32_t value) {
write32le(dword, offset, __builtin_bswap32(value));
}
static inline void write64le(volatile void *qword, size_t offset, uint64_t value) {
*(uint64_t *)((uintptr_t)qword + offset) = value;
}
static inline void write64be(volatile void *qword, size_t offset, uint64_t value) {
write64le(qword, offset, __builtin_bswap64(value));
}
static inline unsigned int get_core_id(void) { static inline unsigned int get_core_id(void) {
uint64_t core_id; uint64_t core_id;
__asm__ __volatile__ ("mrs %0, mpidr_el1" : "=r"(core_id)); __asm__ __volatile__ ("mrs %0, mpidr_el1" : "=r"(core_id));