Add ASPEED ACRY RSA model for the AST2600
Subsystems (2)
v2 cover Add ASPEED ACRY RSA model for the AST2600
This series adds a model of the ASPEED ACRY engine found on the AST2600 SoC, wires it into the SoC, and adds a qtest.
The ACRY engine performs RSA modular exponentiation (c = m^e mod n). It DMAs the operands (data, exponent, and modulus) from guest DRAM and writes the result to a dedicated 64 KiB SRAM region.
Guest firmware uses the engine for RSA signature verification during boot. Without a model, the guest starts the engine and waits indefinitely for a completion interrupt, causing the boot to hang.
The model uses QEMU's generic akcipher API to perform raw (unpadded) RSA. Raw RSA is currently supported only by the libgcrypt backend, which can be enabled alongside gnutls with -Dgcrypt=enabled, so a build does not have to choose between the two. When raw RSA is unavailable, the engine still completes and raises its interrupt, but returns an all-zero result. This allows the guest's signature verification to fail cleanly instead of hanging. The qtest is skipped when the selected crypto backend does not support raw RSA.
Although the hardware documentation describes both RSA and ECDSA support, ECDSA is known to be broken on this hardware and is therefore not modeled.
v1:
1. Add ASPEED ACRY RSA model for the AST2600
2. Add qtest for AST2600 ASPEED ACRY RSA model
v2:
1. squash "Add the ACRY model to AspeedSoCState" into "Wire up the ACRY model"
2. wrap the ACRY SRAM in a container mapped at offset 0 so the device addresses it by relative offset (drop the "sram-base" property)
3. build the scattered SRAM byte offsets on the fly instead of caching them in per-instance lookup tables
4. write the result with address_space_stl_le() and check the MemTxResult
Jamin Lin (4):
hw/misc/aspeed_acry: Add ASPEED ACRY model hw/arm/aspeed_ast2600: Introduce the ACRY SRAM hw/arm/aspeed_ast2600: Wire up the ACRY model tests/qtest/aspeed-acry-test: Add RSA ModExp tests
include/hw/arm/aspeed_soc.h | 4 + include/hw/misc/aspeed_acry.h | 39 +++ hw/arm/aspeed_ast2600.c | 34 +++ hw/misc/aspeed_acry.c | 455 +++++++++++++++++++++++++++++++++ tests/qtest/aspeed-acry-test.c | 395 ++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 6 + tests/qtest/meson.build | 5 +- 8 files changed, 938 insertions(+), 1 deletion(-) create mode 100644 include/hw/misc/aspeed_acry.h create mode 100644 hw/misc/aspeed_acry.c create mode 100644 tests/qtest/aspeed-acry-test.c
Signature · 1 line
2.53.0
PATCH v2 3/4 hw/arm/aspeed_ast2600: Wire up the ACRY model
Introduce the ASPEED_DEV_ACRY enum slot and add the ACRY model state to AspeedSoCState.
Instantiate the new ACRY model on the AST2600 SoC using its real-silicon register address and IRQ:
- ACRY register region 0x1e6fa000-0x1e6fafff
- IRQ 160
--- include/hw/arm/aspeed_soc.h | 3 +++ hw/arm/aspeed_ast2600.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+)
include/hw/arm/aspeed_soc.h +3 -0
@@ -25,6 +25,7 @@#include "hw/i2c/aspeed_i2c.h" #include "hw/i3c/aspeed_i3c.h" #include "hw/ssi/aspeed_smc.h" +#include "hw/misc/aspeed_acry.h" #include "hw/misc/aspeed_hace.h" #include "hw/misc/aspeed_sbc.h" #include "hw/misc/aspeed_sli.h"
@@ -82,6 +83,7 @@ struct AspeedSoCState {AspeedSCUState scu;AspeedSCUState scuio;AspeedHACEState hace; +AspeedACRYState acry;AspeedXDMAState xdma;AspeedADCState adc;AspeedSMCState fmc;
@@ -271,6 +273,7 @@ enum {ASPEED_DEV_EMMC ,ASPEED_DEV_KCS ,ASPEED_DEV_HACE , +ASPEED_DEV_ACRY ,ASPEED_DEV_DPMCU ,ASPEED_DEV_DP , ASPEED_DEV_I3C,
hw/arm/aspeed_ast2600.c +17 -0
@@ -52,6 +52,7 @@ static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_DP] = 0x1E6EB000, [ASPEED_DEV_PCIE_PHY1] = 0x1E6ED200, [ASPEED_DEV_SBC] = 0x1E6F2000, + [ASPEED_DEV_ACRY] = 0x1E6FA000, [ASPEED_DEV_EMMC_BC] = 0x1E6f5000, [ASPEED_DEV_VIDEO] = 0x1E700000, [ASPEED_DEV_SDHCI] = 0x1E740000,
@@ -144,6 +145,7 @@ static const int aspeed_soc_ast2600_irqmap[] = { [ASPEED_DEV_FSI1] = 100, [ASPEED_DEV_FSI2] = 101, [ASPEED_DEV_I3C] = 102, /* 102 -> 107 */ + [ASPEED_DEV_ACRY] = 160, };static qemu_irq aspeed_soc_ast2600_get_irq (AspeedSoCState *s,int dev)
@@ -269,6 +271,8 @@ static void aspeed_soc_ast2600_init(Object *obj)snprintf (typename,sizeof (typename),"aspeed.hace-%s" , socname);object_initialize_child (obj,"hace" , &s->hace, typename); +object_initialize_child (obj,"acry" , &s->acry,TYPE_ASPEED_ACRY ); +object_initialize_child (obj,"i3c" , &s->i3c,TYPE_ASPEED_I3C );object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_AST2600_SBC );
@@ -726,6 +730,19 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->hace),0 ,aspeed_soc_ast2600_get_irq (s,ASPEED_DEV_HACE )); +/* ACRY */ +object_property_set_link (OBJECT (&s->acry),"dram" ,OBJECT (s->dram_mr), + &error_abort); +object_property_set_link (OBJECT (&s->acry),"sram" ,OBJECT (&s->sram[1 ]), + &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->acry), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->acry),0 , + sc->memmap[ASPEED_DEV_ACRY ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->acry),0 , +aspeed_soc_ast2600_get_irq (s,ASPEED_DEV_ACRY )); +/* I3C */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->i3c), errp)) {return ;
Signature · 1 line
2.53.0
PATCH v2 2/4 hw/arm/aspeed_ast2600: Introduce the ACRY SRAM
In reply to Jamin LinReuse the existing SRAM array convention on AspeedSoCState to add the 64 KiB ACRY SRAM region to the AST2600 at its real-silicon address (0x1e710000-0x1e71ffff).
Wrap the RAM in a container mapped at offset 0 so the ACRY engine wired up in a later patch can address the SRAM by relative offset without the device model knowing its mapping address.
--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2600.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/hw/arm/aspeed_soc.h +1 -0
@@ -69,6 +69,7 @@ struct AspeedSoCState {MemoryRegion *dram_mr;MemoryRegion dram_container;MemoryRegion sram[ASPEED_SRAM_NUM ]; +MemoryRegion sram_container[ASPEED_SRAM_NUM ];MemoryRegion spi_boot_container;MemoryRegion spi_boot;MemoryRegion vbootrom;
hw/arm/aspeed_ast2600.c +17 -0
@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "qemu/units.h" #include "qapi/error.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h"
@@ -24,6 +25,7 @@static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_SPI_BOOT ] =0x00000000 , [ASPEED_DEV_SRAM0 ] =0x10000000 , + [ASPEED_DEV_SRAM1 ] =0x1E710000 ,/* ACRY SRAM */ [ASPEED_DEV_DPMCU ] =0x18000000 ,/* 0x16000000 0x17FFFFFF : AHB BUS do LPC Bus bridge */ [ASPEED_DEV_IOMEM ] =0x1E600000 ,
@@ -361,6 +363,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)AspeedSoCState *s =ASPEED_SOC (dev);AspeedSoCClass *sc =ASPEED_SOC_GET_CLASS (s);qemu_irq irq; + g_autofree char *sram1_name = NULL; g_autofree char *sram_name = NULL;int uart;
@@ -444,6 +447,19 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SRAM0 ], &s->sram[0 ]); +/* ACRY SRAM */ + sram1_name =g_strdup_printf ("aspeed.acry.sram.%d" , +CPU (&a->cpu[0 ])->cpu_index); +if (!memory_region_init_ram (&s->sram[1 ],OBJECT (s), sram1_name, + sc->sram_size[1 ], errp)) { +return ; + } +memory_region_init (&s->sram_container[1 ],OBJECT (s), +"aspeed.acry.sram-container" , sc->sram_size[1 ]); +memory_region_add_subregion (&s->sram_container[1 ],0 , &s->sram[1 ]); +memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SRAM1 ], + &s->sram_container[1 ]); +/* DPMCU */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->dpmcu), "aspeed.dpmcu",
@@ -765,6 +781,7 @@ static void aspeed_soc_ast2600_class_init(ObjectClass *oc, const void *data) sc->valid_cpu_types = valid_cpu_types; sc->silicon_rev =AST2600_A3_SILICON_REV ; sc->sram_size[0 ] =0x16400 ; + sc->sram_size[1 ] =64 * KiB;/* ACRY SRAM */ sc->spis_num =2 ; sc->ehcis_num =2 ; sc->wdts_num =4 ;
Signature · 1 line
2.53.0
PATCH v2 1/4 hw/misc/aspeed_acry: Add ASPEED ACRY model
In reply to Jamin LinIntroduce a ASPEED ACRY model, which performs RSA modular exponentiation. The datasheet documents the engine as supporting both RSA and ECDSA, but ECDSA is broken on this hardware, so only RSA is modelled.
The engine DMAs its operands (data, exponent, modulus) from a guest DRAM buffer and writes the result back into a memory-mapped SRAM region. Both regions share the same interleaved byte/dword layout:
repeating 12-dword blocks of [4 dwords exponent][4 dwords modulus][4 dwords data], index 0 holding the least-significant word/byte of each value.
The engine accesses DRAM by relative offset, so the CPU-visible address written to the DMA source register has its top (base) bit masked off.
The modular exponentiation itself is delegated to QEMU's generic akcipher crypto API (crypto/akcipher.c) using raw (unpadded) RSA, matching what the real hardware performs - PKCS1 padding is handled by the guest's software crypto stack, not by this engine.
The RSA public-key operand DER encoding needed by that API is built with crypto/der.h's generic encoder. Raw (unpadded) RSA is only implemented by that API's libgcrypt backend (its nettle backend rejects raw padding).
When that support is missing, the engine still completes and raises its completion IRQ as real hardware would, but produces an all-zero result so that whatever signature check the guest performs on it fails cleanly instead of the guest hanging forever waiting for an interrupt that would otherwise never come.
--- include/hw/misc/aspeed_acry.h | 39 +++ hw/misc/aspeed_acry.c | 455 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 6 + 4 files changed, 501 insertions(+) create mode 100644 include/hw/misc/aspeed_acry.h create mode 100644 hw/misc/aspeed_acry.c
include/hw/misc/aspeed_acry.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* ASPEED ACRY Engine +* +* Copyright (C) 2026 ASPEED Technology Inc. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef ASPEED_ACRY_H +#define ASPEED_ACRY_H + +#include "hw/core/sysbus.h" +#include "system/memory.h" + +#define TYPE_ASPEED_ACRY "aspeed.acry" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedACRYState, ASPEED_ACRY) + +#define ASPEED_ACRY_NR_REGS (0x400 >> 2) +/* Max size of the "data" (message) field within the SRAM buffer. */ +#define ASPEED_ACRY_DATA_MAX_LEN 0x800 +#define ASPEED_ACRY_MAX_BITS 4096 +/* Max exponent/modulus size for a 4096-bit RSA key, in bytes. */ +#define ASPEED_ACRY_MAX_BYTES (ASPEED_ACRY_MAX_BITS / 8) + +struct AspeedACRYState { +SysBusDevice parent_obj; + +MemoryRegion iomem; +qemu_irq irq; + +uint32_t regs[ASPEED_ACRY_NR_REGS ]; + +MemoryRegion *dram_mr; +MemoryRegion *sram_mr; +AddressSpace dram_as; +AddressSpace sram_as; +}; + +#endif /* ASPEED_ACRY_H */
hw/misc/aspeed_acry.c new file +455 -0
455 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -137,6 +137,7 @@ system_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c')) system_ss.add(when: 'CONFIG_PVPANIC_MMIO', if_true: files('pvpanic-mmio.c')) system_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( + 'aspeed_acry.c', 'aspeed_hace.c', 'aspeed_lpc.c', 'aspeed_ltpi.c',
hw/misc/trace-events +6 -0
@@ -331,6 +331,12 @@ aspeed_peci_read(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" aspeed_peci_write(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" PRIx64 aspeed_peci_raise_interrupt(uint32_t ctrl, uint32_t status) "ctrl 0x%" PRIx32 " status 0x%" PRIx32 +# aspeed_acry.c +aspeed_acry_read(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_acry_write(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_acry_rsa_trigger(uint64_t src_addr, uint32_t len) "src_addr 0x%" PRIx64 " len 0x%" PRIx32 +aspeed_acry_hexdump(const char *desc, uint32_t offset, const char *s) "%s: 0x%08x: %s" + # aspeed_hace.c aspeed_hace_read(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" PRIx64 aspeed_hace_write(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " data 0x%" PRIx64
Signature · 1 line
2.53.0
PATCH v2 4/4 tests/qtest/aspeed-acry-test: Add RSA ModExp tests
In reply to Jamin LinAdd qtest cases exercising the AST2600 ACRY RSA ModExp engine end to end. Each case lays out the exponent, modulus and message in the scattered SRAM byte layout the engine expects, triggers the engine, checks that both completion bits (RSA_ENG_DONE and RSA_DMA_DONE) are asserted together in the status register, reads the result back from the result SRAM, and checks the status bits clear afterwards.
Comparing the result against a known-answer ciphertext also validates the SRAM byte mapping end to end.
The cases cover raw (unpadded) public-exponent RSA, c = m^e mod n - exactly what the "rsa" akcipher transform backed by the ACRY FW performs, since PKCS1 padding is applied by a separate template layered on top in Linux, not by the ACRY hardware. QEMU's akcipher backend only implements raw RSA via libgcrypt, so the tests skip rather than fail when the build lacks it.
The 2048-bit and 4096-bit vectors are rsa_tv_template[2] and [3] from the Linux kernel crypto self-test suite (crypto/testmgr.h, v6.18).
--- tests/qtest/aspeed-acry-test.c | 395 +++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 5 +- 2 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/aspeed-acry-test.c
tests/qtest/aspeed-acry-test.c new file +395 -0
@@ -0,0 +1,395 @@ +/* +* QTest testcase for the ASPEED ACRY Engine +* +* Copyright (C) 2026 ASPEED Technology Inc. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu/bitops.h" +#include "crypto/akcipher.h" + +#define ACRY_TRIGGER 0x000 +#define ACRY_TRIGGER_RSA_DMA_DATA BIT(1) +#define ACRY_TRIGGER_RSA_START BIT(0) +#define ACRY_DMA_CMD 0x048 +#define ACRY_DMA_CMD_DMEM_AHB BIT(8) +#define ACRY_DMA_CMD_SRAM_MODE_RSA (0x3 << 4) +#define ACRY_DMA_SRC 0x04C +#define ACRY_DMA_LEN 0x050 +#define ACRY_RSA_KEY_LEN 0x058 +#define ACRY_INT_MASK 0x3F8 +#define ACRY_INT_MASK_RSA_DMA_MASK BIT(2) +#define ACRY_INT_MASK_RSA_ENG_MASK BIT(1) +#define ACRY_STATUS 0x3FC +#define ACRY_STATUS_RSA_DMA_DONE BIT(2) +#define ACRY_STATUS_RSA_ENG_DONE BIT(1) +#define ACRY_STATUS_RSA_DONE (ACRY_STATUS_RSA_ENG_DONE | \ + ACRY_STATUS_RSA_DMA_DONE) + +#define ACRY_DATA_MAX_LEN 0x800 +#define ACRY_SRAM_SIZE (3 * ACRY_DATA_MAX_LEN) +#define ACRY_MAX_BITS 4096 +#define ACRY_MAX_BYTES (ACRY_MAX_BITS / 8) + +/* Dwords into each 12-dword block where each operand's region starts. */ +#define ACRY_EXP_OFFSET 0 +#define ACRY_MOD_OFFSET 4 +#define ACRY_DATA_OFFSET 8 + +/* +* Raw (unpadded) RSA known-answer vectors: c = m^e mod n with +* e = 0x10001 (65537) - exactly what the "rsa" akcipher transform backed by +* the ACRY FW computes. PKCS1 padding is a separate "pkcs1pad(rsa)" template +* layered on top in Linux, not done by the ACRY hardware. +* +* rsa2048_* and rsa4096_* are from the Linux kernel crypto/testmgr.h (v6.18), +* rsa_tv_template[2] and [3]. Grep that file's own comment to find them: +* +* RSA test vectors. Borrowed from openSSL. +* +* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/crypto/testmgr.h?h=v6.18 +* +* There the modulus n is DER-encoded in the .key field (not a raw field), the +* ciphertext is .c, and every entry reuses the same 8-byte .m message. +*/ +/* rsa_tv_template[].m, shared by every entry */ +static const uint8_t rsa_m[8 ] = { +0x54 ,0x85 ,0x9B ,0x34 ,0x2C ,0x49 ,0xEA ,0x2A , +}; +/* public exponent e = 65537, DER-encoded in every .key */ +static const uint8_t rsa_e[3 ] = {0x01 ,0x00 ,0x01 }; + +/* rsa_tv_template[2].key, modulus n */ +static const uint8_t rsa2048_n[256 ] = { +0xDB ,0x10 ,0x1A ,0xC2 ,0xA3 ,0xF1 ,0xDC ,0xFF ,0x13 ,0x6B ,0xED ,0x44 , +0xDF ,0xF0 ,0x02 ,0x6D ,0x13 ,0xC7 ,0x88 ,0xDA ,0x70 ,0x6B ,0x54 ,0xF1 , +0xE8 ,0x27 ,0xDC ,0xC3 ,0x0F ,0x99 ,0x6A ,0xFA ,0xC6 ,0x67 ,0xFF ,0x1D , +0x1E ,0x3C ,0x1D ,0xC1 ,0xB5 ,0x5F ,0x6C ,0xC0 ,0xB2 ,0x07 ,0x3A ,0x6D , +0x41 ,0xE4 ,0x25 ,0x99 ,0xAC ,0xFC ,0xD2 ,0x0F ,0x02 ,0xD3 ,0xD1 ,0x54 , +0x06 ,0x1A ,0x51 ,0x77 ,0xBD ,0xB6 ,0xBF ,0xEA ,0xA7 ,0x5C ,0x06 ,0xA9 , +0x5D ,0x69 ,0x84 ,0x45 ,0xD7 ,0xF5 ,0x05 ,0xBA ,0x47 ,0xF0 ,0x1B ,0xD7 , +0x2B ,0x24 ,0xEC ,0xCB ,0x9B ,0x1B ,0x10 ,0x8D ,0x81 ,0xA0 ,0xBE ,0xB1 , +0x8C ,0x33 ,0xE4 ,0x36 ,0xB8 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4B ,0xE5 ,0x86 , +0xF3 ,0x50 ,0x4C ,0xBC ,0xC5 ,0xD3 ,0xF5 ,0x3A ,0x54 ,0xE1 ,0x36 ,0x3F , +0xE2 ,0x5A ,0xB4 ,0x37 ,0xC0 ,0xEB ,0x70 ,0x35 ,0xEC ,0xF6 ,0xB7 ,0xE8 , +0x44 ,0x3B ,0x7B ,0xF3 ,0xF1 ,0xF2 ,0x1E ,0xDB ,0x60 ,0x7D ,0xD5 ,0xBE , +0xF0 ,0x71 ,0x34 ,0x90 ,0x4C ,0xCB ,0xD4 ,0x35 ,0x51 ,0xC7 ,0xDD ,0xD8 , +0xC9 ,0x81 ,0xF5 ,0x5D ,0x57 ,0x46 ,0x2C ,0xB1 ,0x7B ,0x9B ,0xAA ,0xCB , +0xD1 ,0x22 ,0x25 ,0x49 ,0x44 ,0xA3 ,0xD4 ,0x6B ,0x29 ,0x7B ,0xD8 ,0xB2 , +0x07 ,0x93 ,0xBF ,0x3D ,0x52 ,0x49 ,0x84 ,0x79 ,0xEF ,0xB8 ,0xE5 ,0xC4 , +0xAD ,0xCA ,0xA8 ,0xC6 ,0xF6 ,0xA6 ,0x76 ,0x70 ,0x5B ,0x0B ,0xE5 ,0x83 , +0xC6 ,0x0E ,0xEF ,0x55 ,0xF2 ,0xE7 ,0xFF ,0x04 ,0xEA ,0xE6 ,0x13 ,0xBE , +0x40 ,0xE1 ,0x40 ,0x45 ,0x48 ,0x66 ,0x75 ,0x31 ,0xAE ,0x35 ,0x64 ,0x91 , +0x11 ,0x6F ,0xDA ,0xEE ,0x26 ,0x86 ,0x45 ,0x6F ,0x0B ,0xD5 ,0x9F ,0x03 , +0xB1 ,0x65 ,0x5B ,0xDB ,0xA4 ,0xE4 ,0xF9 ,0x45 , +}; + +/* +* Offset in the scattered buffer of byte 'op_byte' (0 = least significant) +* of the operand whose region starts 'region' dwords into each 12-dword +* block (0 = exp, 4 = mod, 8 = data). Reproduces the byte layout the ACRY +* engine mandates, so the test lays out its DMA input and decodes the +* result the same way the hardware does. +*/ +static int acry_operand_offset (int region,int op_byte) +{ +int byte_in_dword; +int op_dword; +int block; +int lane; + + op_dword = op_byte /4 ; + byte_in_dword = op_byte %4 ; + block = op_dword /4 ; + lane = op_dword %4 ; + +return (block *12 + region + lane) *4 + byte_in_dword; +} + +/* +* Write a big-endian (most significant byte first) bignum of 'be_len' bytes +* into the scattered buffer region 'region' (exp, mod, or data), placing +* significance level k at acry_operand_offset(region, k). +*/ +static void put_bignum_be_bytes (uint8_t *buf,int region, +const uint8_t *be,int be_len) +{ +int be_index; +int offset; +int k; + +/* be[0] (MSB) maps to the highest level; be_index walks up from 0. */ + be_index =0 ; +for (k = be_len -1 ; k >=0 ; k--) { + offset =acry_operand_offset (region, k); + buf[offset] = be[be_index++]; + } +} + +/* Inverse of put_bignum_be_bytes(): gather a big-endian bignum back out. */ +static void get_bignum_be_bytes (const uint8_t *buf,int region, +uint8_t *out_be,int be_len) +{ +int be_index; +int offset; +int k; + +/* Inverse of put_bignum_be_bytes(): highest level -> out_be[0] (MSB). */ + be_index =0 ; +for (k = be_len -1 ; k >=0 ; k--) { + offset =acry_operand_offset (region, k); + out_be[be_index++] = buf[offset]; + } +} + +typedef struct AspeedACRYModExp { +const char *name; +const uint8_t *n; +size_t n_len; +const uint8_t *e; +size_t e_len; +const uint8_t *m; +size_t m_len; +const uint8_t *c; +size_t c_len; +}AspeedACRYModExp ; + +static const AspeedACRYModExp acry_modexp_tests[] = { + { + .name ="modexp_rsa2048" , + .n = rsa2048_n, + .n_len =sizeof (rsa2048_n), + .e = rsa_e, + .e_len =sizeof (rsa_e), + .m = rsa_m, + .m_len =sizeof (rsa_m), + .c = rsa2048_c, + .c_len =sizeof (rsa2048_c), + }, + { + .name ="modexp_rsa4096" , + .n = rsa4096_n, + .n_len =sizeof (rsa4096_n), + .e = rsa_e, + .e_len =sizeof (rsa_e), + .m = rsa_m, + .m_len =sizeof (rsa_m), + .c = rsa4096_c, + .c_len =sizeof (rsa4096_c), + }, +}; + +typedef struct AspeedACRYTest { +const char *machine; +uint64_t dram_addr; +uint64_t sram_addr; +uint64_t acry_addr; +int index; +}AspeedACRYTest ; + +static void test_modexp_rsa (const void *opaque) +{ +const AspeedACRYTest *c = opaque; +const AspeedACRYModExp *t = &acry_modexp_tests[c->index]; +QTestState *qts =qtest_init (c->machine); +uint8_t dram_buf[ACRY_SRAM_SIZE ] = {0 }; +uint8_t sram_buf[ACRY_SRAM_SIZE ] = {0 }; +uint8_t result[ACRY_MAX_BYTES ] = {0 }; + + g_assert_cmpuint(t->c_len, <=, sizeof(result)); + +put_bignum_be_bytes (dram_buf,ACRY_EXP_OFFSET , t->e, t->e_len); +put_bignum_be_bytes (dram_buf,ACRY_MOD_OFFSET , t->n, t->n_len); +put_bignum_be_bytes (dram_buf,ACRY_DATA_OFFSET , t->m, t->m_len); + +qtest_memwrite (qts, c->dram_addr, dram_buf,sizeof (dram_buf)); + +qtest_writel (qts, c->acry_addr +ACRY_DMA_CMD ,ACRY_DMA_CMD_DMEM_AHB ); +qtest_writel (qts, c->acry_addr +ACRY_DMA_SRC , c->dram_addr); +qtest_writel (qts, c->acry_addr +ACRY_RSA_KEY_LEN , + ((uint32_t )(t->e_len *8 ) <<16 ) | (uint32_t )(t->n_len *8 )); +qtest_writel (qts, c->acry_addr +ACRY_DMA_LEN ,ACRY_SRAM_SIZE ); +qtest_writel (qts, c->acry_addr +ACRY_INT_MASK , +ACRY_INT_MASK_RSA_ENG_MASK |ACRY_INT_MASK_RSA_DMA_MASK ); +qtest_writel (qts, c->acry_addr +ACRY_DMA_CMD ,ACRY_DMA_CMD_SRAM_MODE_RSA ); +qtest_writel (qts, c->acry_addr +ACRY_TRIGGER , +ACRY_TRIGGER_RSA_START |ACRY_TRIGGER_RSA_DMA_DATA ); + +/* Completion requires both RSA_ENG_DONE and RSA_DMA_DONE to be asserted. */ + g_assert_cmphex(qtest_readl(qts, c->acry_addr + ACRY_STATUS), ==, +ACRY_STATUS_RSA_DONE ); + +qtest_memread (qts, c->sram_addr, sram_buf,sizeof (sram_buf)); +get_bignum_be_bytes (sram_buf,ACRY_DATA_OFFSET , result, t->c_len); +g_assert_cmpmem (result, t->c_len, t->c, t->c_len); + +/* Clear IRQ status and check it is deasserted */ +qtest_writel (qts, c->acry_addr +ACRY_STATUS ,ACRY_STATUS_RSA_DONE ); + g_assert_cmphex(qtest_readl(qts, c->acry_addr + ACRY_STATUS), ==, 0); + +qtest_quit (qts); +} + +static void aspeed_add_acry_tests (const char *prefix,const char *machine, +uint64_t acry_addr,uint64_t sram_addr, +uint64_t dram_addr) +{ +QCryptoAkCipherOptions opts = { + .alg =QCRYPTO_AK_CIPHER_ALGO_RSA , + .u.rsa.padding_alg =QCRYPTO_RSA_PADDING_ALGO_RAW , + }; +int i; + +if (!qcrypto_akcipher_supports (&opts)) { +g_printerr ("# skip ACRY tests: raw RSA not supported by the crypto " +"backend\n" ); +return ; + } + +for (i =0 ; i <ARRAY_SIZE (acry_modexp_tests); i++) { + g_autofree char *path = NULL; +AspeedACRYTest *t; + + path =g_strdup_printf ("%s/acry/%s" , prefix, + acry_modexp_tests[i].name); + t =g_new0 (AspeedACRYTest,1 ); + t->machine = machine; + t->acry_addr = acry_addr; + t->sram_addr = sram_addr; + t->dram_addr = dram_addr; + t->index = i; +qtest_add_data_func_full (path, t, test_modexp_rsa, g_free); + } +} + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); + +aspeed_add_acry_tests ("ast2600" ,"-machine ast2600-evb" , +0x1e6fa000 ,0x1e710000 ,0x80001000 ); + +return g_test_run (); +}
tests/qtest/meson.build +4 -1
@@ -220,7 +220,8 @@ qtests_npcm7xx = \ qtests_npcm8xx = \ ['npcm_gmac-test'] qtests_aspeed = \ - ['aspeed_gpio-test', + ['aspeed-acry-test', + 'aspeed_gpio-test', 'aspeed_hace-test', 'aspeed_scu-test', 'aspeed_smc-test']
@@ -392,6 +393,8 @@ if get_option('replication').allowed() endif qtests = { + 'aspeed-acry-test': [files('aspeed-acry-test.c'), + crypto], 'aspeed_hace-test': [files('aspeed-hace-utils.c', 'aspeed_hace-test.c'), crypto], 'aspeed_smc-test': files('aspeed-smc-utils.c', 'aspeed_smc-test.c'),
Signature · 1 line
2.53.0
Re: [PATCH v2 2/4] hw/arm/aspeed_ast2600: Introduce the ACRY SRAM
In reply to Jamin LinQuoted 75 lines · Jamin Lin
Reuse the existing SRAM array convention on AspeedSoCState to add the 64 KiB ACRY SRAM region to the AST2600 at its real-silicon address (0x1e710000-0x1e71ffff).
Wrap the RAM in a container mapped at offset 0 so the ACRY engine wired up in a later patch can address the SRAM by relative offset without the device model knowing its mapping address.
Signed-off-by Jamin Lin <[email protected]>--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2600.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/hw/arm/aspeed_soc.h +1
-0@@ -69,6 +69,7 @@ struct AspeedSoCState {MemoryRegion *dram_mr;MemoryRegion dram_container;MemoryRegion sram[ASPEED_SRAM_NUM ]; +MemoryRegion sram_container[ASPEED_SRAM_NUM ];MemoryRegion spi_boot_container;MemoryRegion spi_boot;MemoryRegion vbootrom;hw/arm/aspeed_ast2600.c +16
-0@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "qemu/units.h" #include "qapi/error.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" @@ -24,6 +25,7 @@static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_SPI_BOOT ] =0x00000000 , [ASPEED_DEV_SRAM0 ] =0x10000000 , + [ASPEED_DEV_SRAM1 ] =0x1E710000 ,/* ACRY SRAM */ [ASPEED_DEV_DPMCU ] =0x18000000 ,/* 0x16000000 0x17FFFFFF : AHB BUS do LPC Bus bridge */ [ASPEED_DEV_IOMEM ] =0x1E600000 ,@@ -361,6 +363,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)AspeedSoCState *s =ASPEED_SOC (dev);AspeedSoCClass *sc =ASPEED_SOC_GET_CLASS (s);qemu_irq irq; + g_autofree char *sram1_name = NULL; g_autofree char *sram_name = NULL;int uart;@@ -444,6 +447,19 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SRAM0 ], &s->sram[0 ]); +/* ACRY SRAM */ + sram1_name =g_strdup_printf ("aspeed.acry.sram.%d" , +CPU (&a->cpu[0 ])->cpu_index); +if (!memory_region_init_ram (&s->sram[1 ],OBJECT (s), sram1_name, + sc->sram_size[1 ], errp)) { +return ; + } +memory_region_init (&s->sram_container[1 ],OBJECT (s), +"aspeed.acry.sram-container" , sc->sram_size[1 ]); +memory_region_add_subregion (&s->sram_container[1 ],0 , &s->sram[1 ]); +memory_region_add_subregion (s->memory, sc->memmap[ASPEED_DEV_SRAM1 ], + &s->sram_container[1 ]); +/* DPMCU */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->dpmcu), "aspeed.dpmcu",
hw/arm/aspeed_ast2600.c static void aspeed_soc_ast2600_class_init(ObjectClass *oc, const void *data) · line 787
Quoted 7 lines
hw/arm/aspeed_ast2600.c +1
-0@@ -765,6 +781,7 @@ static void aspeed_soc_ast2600_class_init(ObjectClass *oc, const void *data) sc->valid_cpu_types = valid_cpu_types; sc->silicon_rev =AST2600_A3_SILICON_REV ; sc->sram_size[0 ] =0x16400 ; + sc->sram_size[1 ] =64 * KiB;/* ACRY SRAM */ sc->spis_num =2 ; sc->ehcis_num =2 ; sc->wdts_num =4 ;
Thanks,
C.
Re: [PATCH v2 3/4] hw/arm/aspeed_ast2600: Wire up the ACRY model
In reply to Jamin LinQuoted 82 lines · Jamin Lin
Introduce the
ASPEED_DEV_ACRYenum slot and add the ACRY model state to AspeedSoCState.Instantiate the new ACRY model on the AST2600 SoC using its real-silicon register address and IRQ:
- ACRY register region 0x1e6fa000-0x1e6fafff
- IRQ 160Signed-off-by Jamin Lin <[email protected]>--- include/hw/arm/aspeed_soc.h | 3 +++ hw/arm/aspeed_ast2600.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+)include/hw/arm/aspeed_soc.h +3
-0@@ -25,6 +25,7 @@#include "hw/i2c/aspeed_i2c.h" #include "hw/i3c/aspeed_i3c.h" #include "hw/ssi/aspeed_smc.h" +#include "hw/misc/aspeed_acry.h" #include "hw/misc/aspeed_hace.h" #include "hw/misc/aspeed_sbc.h" #include "hw/misc/aspeed_sli.h" @@ -82,6 +83,7 @@ struct AspeedSoCState {AspeedSCUState scu;AspeedSCUState scuio;AspeedHACEState hace; +AspeedACRYState acry;AspeedXDMAState xdma;AspeedADCState adc;AspeedSMCState fmc;@@ -271,6 +273,7 @@ enum {ASPEED_DEV_EMMC ,ASPEED_DEV_KCS ,ASPEED_DEV_HACE , +ASPEED_DEV_ACRY ,ASPEED_DEV_DPMCU ,ASPEED_DEV_DP , ASPEED_DEV_I3C,hw/arm/aspeed_ast2600.c +10
-0@@ -52,6 +52,7 @@ static const hwaddr aspeed_soc_ast2600_memmap[] = { [ASPEED_DEV_DP] = 0x1E6EB000, [ASPEED_DEV_PCIE_PHY1] = 0x1E6ED200, [ASPEED_DEV_SBC] = 0x1E6F2000, + [ASPEED_DEV_ACRY] = 0x1E6FA000, [ASPEED_DEV_EMMC_BC] = 0x1E6f5000, [ASPEED_DEV_VIDEO] = 0x1E700000, [ASPEED_DEV_SDHCI] = 0x1E740000,@@ -144,6 +145,7 @@ static const int aspeed_soc_ast2600_irqmap[] = { [ASPEED_DEV_FSI1] = 100, [ASPEED_DEV_FSI2] = 101, [ASPEED_DEV_I3C] = 102, /* 102 -> 107 */ + [ASPEED_DEV_ACRY] = 160, };static qemu_irq aspeed_soc_ast2600_get_irq (AspeedSoCState *s,int dev)@@ -269,6 +271,8 @@ static void aspeed_soc_ast2600_init(Object *obj)snprintf (typename,sizeof (typename),"aspeed.hace-%s" , socname);object_initialize_child (obj,"hace" , &s->hace, typename); +object_initialize_child (obj,"acry" , &s->acry,TYPE_ASPEED_ACRY ); +object_initialize_child (obj,"i3c" , &s->i3c,TYPE_ASPEED_I3C );object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_AST2600_SBC );@@ -726,6 +730,19 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->hace),0 ,aspeed_soc_ast2600_get_irq (s,ASPEED_DEV_HACE )); +/* ACRY */ +object_property_set_link (OBJECT (&s->acry),"dram" ,OBJECT (s->dram_mr), + &error_abort); +object_property_set_link (OBJECT (&s->acry),"sram" ,OBJECT (&s->sram[1 ]), + &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->acry), errp)) {
hw/arm/aspeed_ast2600.c static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) · line 748
Quoted 10 lines
hw/arm/aspeed_ast2600.c +7
-0+return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->acry),0 , + sc->memmap[ASPEED_DEV_ACRY ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->acry),0 , +aspeed_soc_ast2600_get_irq (s,ASPEED_DEV_ACRY )); +/* I3C */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->i3c), errp)) {return ;
Thanks,
C.