From f7ade96f03f0256f54d233a0f5cac3377a1f1dfb Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Tue, 11 Jul 2023 15:43:11 +0530 Subject: [PATCH] hw/misc: implement ESP32-C3 HMAC Added an internal HMAC implementation using the existing internal SHA APIs --- hw/misc/esp32c3_hmac.c | 33 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 2 ++ include/hw/misc/esp32c3_hmac.h | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 hw/misc/esp32c3_hmac.c create mode 100644 include/hw/misc/esp32c3_hmac.h diff --git a/hw/misc/esp32c3_hmac.c b/hw/misc/esp32c3_hmac.c new file mode 100644 index 0000000000..d3b37ce470 --- /dev/null +++ b/hw/misc/esp32c3_hmac.c @@ -0,0 +1,33 @@ +/* + * ESP32-C3 HMAC emulation + * + * Copyright (c) 2023 Espressif Systems (Shanghai) Co. Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "hw/misc/esp32c3_hmac.h" + +static void esp32c3_hmac_class_init(ObjectClass *klass, void *data) +{ + ESPHmacClass *class = ESP_HMAC_CLASS(klass); + class->date = ESP32C3_HMAC_DATE_REG_VALUE; +} + +static const TypeInfo esp32c3_hmac_info = { + .name = TYPE_ESP32C3_HMAC, + .parent = TYPE_ESP_HMAC, + .instance_size = sizeof(ESP32C3HmacState), + .class_init = esp32c3_hmac_class_init, + .class_size = sizeof(ESP32C3HmacClass) +}; + +static void esp32c3_hmac_register_types(void) +{ + type_register_static(&esp32c3_hmac_info); +} + +type_init(esp32c3_hmac_register_types) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b441d36497..522639a50a 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -154,6 +154,8 @@ system_ss.add(when: 'CONFIG_RISCV_ESP32C3', if_true: files( 'esp32c3_sha.c', 'esp32c3_jtag.c', 'esp32c3_rtc_cntl.c', + 'esp_hmac.c', + 'esp32c3_hmac.c' )) if gcrypt.found() system_ss.add(when: [gcrypt, 'CONFIG_XTENSA_ESP32'], if_true: files( diff --git a/include/hw/misc/esp32c3_hmac.h b/include/hw/misc/esp32c3_hmac.h new file mode 100644 index 0000000000..b034b68333 --- /dev/null +++ b/include/hw/misc/esp32c3_hmac.h @@ -0,0 +1,26 @@ +/* + * ESP32-C3 HMAC emulation + * + * Copyright (c) 2023 Espressif Systems (Shanghai) Co. Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#pragma once + +#include "hw/misc/esp_hmac.h" + +#define TYPE_ESP32C3_HMAC "misc.esp32c3.hmac" +#define ESP32C3_HMAC(obj) OBJECT_CHECK(ESP32C3HmacState, (obj), TYPE_ESP32C3_HMAC) + +#define ESP32C3_HMAC_DATE_REG_VALUE 0x20200618 + +typedef struct ESP32C3HmacState { + ESPHmacState parent; +} ESP32C3HmacState; + +typedef struct ESP32C3HmacClass { + ESPHmacClass parent_class; +} ESP32C3HmacClass;