Skip to content

Commit

Permalink
hw/misc: get rid of non-portable endian.h header in ESP32-C3 AES cont…
Browse files Browse the repository at this point in the history
…roller
  • Loading branch information
o-marshmallow committed Jul 3, 2023
1 parent d96ca95 commit 4d69be8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hw/misc/esp32c3_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "hw/misc/esp32c3_aes.h"
#include "qemu/error-report.h"
#include <gcrypt.h>
#include <endian.h>
#include "qemu/bswap.h"
#include "hw/irq.h"
#include "crypto/aes.h"

Expand Down Expand Up @@ -51,19 +51,19 @@ static void esp32c3_aes_ctr_add_counter(ESP32C3AesState *s, uint32_t blocks)
/* 128-bit mode, no native 128 integer type, use two 64-bit types */
uint64_t* low_ptr = (uint64_t*) (s->iv_mem + sizeof(uint64_t));
uint64_t* high_ptr = (uint64_t*) s->iv_mem;
const uint64_t original = be64toh(*low_ptr);
const uint64_t original = be64_to_cpu(*low_ptr);
uint64_t value = original + blocks;
*low_ptr = htobe64(value);
*low_ptr = cpu_to_be64(value);
/* If the value overflowed, we have to update the upper part too */
if (original > value) {
value = be64toh(*high_ptr) + 1;
*high_ptr = htobe64(value);
value = be64_to_cpu(*high_ptr) + 1;
*high_ptr = cpu_to_be64(value);
}
} else {
/* 32-bit mode */
uint32_t* counter_ptr = (uint32_t*) &s->iv_mem[ESP32C3_AES_IV_REG_CNT - sizeof(uint32_t)];
const uint32_t value = be32toh(*counter_ptr) + blocks;
*counter_ptr = htobe32(value);
const uint32_t value = be32_to_cpu(*counter_ptr) + blocks;
*counter_ptr = cpu_to_be32(value);
}
}

Expand Down

0 comments on commit 4d69be8

Please sign in to comment.