mirror of
https://github.com/SciresM/hactool
synced 2024-11-22 12:03:11 +00:00
Fix aes buffer passing error (closes #59)
This commit is contained in:
parent
499f06ed9c
commit
3b399f2197
1 changed files with 22 additions and 1 deletions
23
aes.c
23
aes.c
|
@ -88,7 +88,21 @@ void aes_encrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l) {
|
|||
}
|
||||
|
||||
/* Decrypt with context. */
|
||||
void aes_decrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l) {
|
||||
void aes_decrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l)
|
||||
{
|
||||
bool src_equals_dst = false;
|
||||
|
||||
if (src == dst)
|
||||
{
|
||||
src_equals_dst = true;
|
||||
|
||||
dst = malloc(l);
|
||||
if (dst == NULL) {
|
||||
fprintf(stderr, "Error: AES buffer allocation failure!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
size_t out_len = 0;
|
||||
|
||||
/* Prepare context */
|
||||
|
@ -111,8 +125,15 @@ void aes_decrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l) {
|
|||
|
||||
/* Flush all data */
|
||||
mbedtls_cipher_finish(&ctx->cipher_dec, NULL, NULL);
|
||||
|
||||
if (src_equals_dst)
|
||||
{
|
||||
memcpy((void*)src, dst, l);
|
||||
free(dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void get_tweak(unsigned char *tweak, size_t sector) {
|
||||
for (int i = 0xF; i >= 0; i--) { /* Nintendo LE custom tweak... */
|
||||
tweak[i] = (unsigned char)(sector & 0xFF);
|
||||
|
|
Loading…
Reference in a new issue