From 6eceeee95b870a595fb86e6047e618254e7bbc90 Mon Sep 17 00:00:00 2001 From: Dmitry Yakovlev Date: Tue, 23 Apr 2024 17:55:58 +0300 Subject: [PATCH] hw/misc: Implement ESP32-S3 SHA Co-authored-by: Harshal Patil --- hw/misc/esp32s3_sha.c | 33 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 2 ++ include/hw/misc/esp32s3_sha.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 hw/misc/esp32s3_sha.c create mode 100644 include/hw/misc/esp32s3_sha.h diff --git a/hw/misc/esp32s3_sha.c b/hw/misc/esp32s3_sha.c new file mode 100644 index 0000000000..f187465d6d --- /dev/null +++ b/hw/misc/esp32s3_sha.c @@ -0,0 +1,33 @@ +/* + * ESP32S3 SHA accelerator + * + * Copyright (c) 2019 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/esp32s3_sha.h" + +static void esp32s3_sha_class_init(ObjectClass *klass, void *data) +{ + ESPShaClass* class = ESP_SHA_CLASS(klass); + class->message_len = ESP32S3_SHA_MESSAGE_SIZE; + class->date = ESP32S3_SHA_DATE_REG_VALUE; +} + +static const TypeInfo esp32s3_sha_info = { + .name = TYPE_ESP32S3_SHA, + .parent = TYPE_ESP_SHA, + .instance_size = sizeof(ESP32S3ShaState), + .class_init = esp32s3_sha_class_init, + .class_size = sizeof(ESP32S3ShaClass) +}; + +static void esp32s3_sha_register_types(void) +{ + type_register_static(&esp32s3_sha_info); +} + +type_init(esp32s3_sha_register_types) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b92d4c0afe..92ffb04320 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -161,6 +161,8 @@ system_ss.add(when: 'CONFIG_RISCV_ESP32C3', if_true: files( system_ss.add(when: 'CONFIG_XTENSA_ESP32S3', if_true: files( 'esp32s3_cache.c', 'ssi_psram.c', + 'esp_sha.c', + 'esp32s3_sha.c', )) if gcrypt.found() diff --git a/include/hw/misc/esp32s3_sha.h b/include/hw/misc/esp32s3_sha.h new file mode 100644 index 0000000000..bfea23ab87 --- /dev/null +++ b/include/hw/misc/esp32s3_sha.h @@ -0,0 +1,35 @@ +/* + * ESP32S3 SHA accelerator + * + * Copyright (c) 2019 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_sha.h" + +#define TYPE_ESP32S3_SHA "misc.esp32s3.sha" +#define ESP32S3_SHA(obj) OBJECT_CHECK(ESP32S3ShaState, (obj), TYPE_ESP32S3_SHA) + +#define ESP32S3_SHA_GET_CLASS(obj) OBJECT_GET_CLASS(ESP32S3ShaClass, obj, TYPE_ESP32S3_SHA) +#define ESP32S3_SHA_CLASS(klass) OBJECT_CLASS_CHECK(ESP32S3ShaClass, klass, TYPE_ESP32S3_SHA) + +/** + * @brief Size of the message array, in bytes + */ +#define ESP32S3_SHA_MESSAGE_SIZE 128 +#define ESP32S3_SHA_MESSAGE_WORDS (ESP32S3_SHA_MESSAGE_SIZE / sizeof(uint32_t)) + +#define ESP32S3_SHA_DATE_REG_VALUE 0x20190402 + +typedef struct ESP32S3ShaState { + ESPShaState parent; +} ESP32S3ShaState; + +typedef struct ESP32S3ShaClass { + ESPShaClass parent_class; +} ESP32S3ShaClass;