mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
hw/vmapple/aes: Introduce aes engine
VMApple contains an "aes" engine device that it uses to encrypt and decrypt its nvram. It has trivial hard coded keys it uses for that purpose. Add device emulation for this device model. Signed-off-by: Alexander Graf <graf@amazon.com> Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-ID: <20241223221645.29911-10-phil@philjordan.eu> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
committed by
Philippe Mathieu-Daudé
parent
11fa056e79
commit
c960b38955
@@ -1 +1,4 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
config VMAPPLE_AES
|
||||
bool
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +1,3 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c'))
|
||||
|
||||
@@ -1,2 +1,16 @@
|
||||
# See docs/devel/tracing.rst for syntax documentation.
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# aes.c
|
||||
aes_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64
|
||||
aes_cmd_key_select_builtin(uint32_t ctx, uint32_t key_id, const char *direction, const char *cipher) "[%d] Selecting builtin key %d to %scrypt with %s"
|
||||
aes_cmd_key_select_new(uint32_t ctx, uint32_t key_len, const char *direction, const char *cipher) "[%d] Selecting new key size=%d to %scrypt with %s"
|
||||
aes_cmd_iv(uint32_t ctx, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] 0x%08x 0x%08x 0x%08x 0x%08x"
|
||||
aes_cmd_data(uint32_t key, uint32_t iv, uint64_t src, uint64_t dst, uint32_t len) "[key=%d iv=%d] src=0x%"PRIx64" dst=0x%"PRIx64" len=0x%x"
|
||||
aes_cmd_store_iv(uint32_t ctx, uint64_t addr, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] addr=0x%"PRIx64"x -> 0x%08x 0x%08x 0x%08x 0x%08x"
|
||||
aes_cmd_flag(uint32_t raise, uint32_t flag_info) "raise=%d flag_info=0x%x"
|
||||
aes_fifo_process(uint32_t cmd, bool success) "cmd=%d success=%d"
|
||||
aes_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64
|
||||
aes_2_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64
|
||||
aes_2_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64
|
||||
aes_dump_data(const char *desc, const char *hex) "%s%s"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Devices specific to the VMApple machine type
|
||||
*
|
||||
* Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef HW_VMAPPLE_VMAPPLE_H
|
||||
#define HW_VMAPPLE_VMAPPLE_H
|
||||
|
||||
#define TYPE_APPLE_AES "apple-aes"
|
||||
|
||||
#endif /* HW_VMAPPLE_VMAPPLE_H */
|
||||
@@ -302,4 +302,19 @@ GString *qemu_hexdump_line(GString *str, const void *buf, size_t len,
|
||||
void qemu_hexdump(FILE *fp, const char *prefix,
|
||||
const void *bufptr, size_t size);
|
||||
|
||||
/**
|
||||
* qemu_hexdump_to_buffer:
|
||||
* @buffer: output string buffer
|
||||
* @buffer_size: amount of available space in buffer. Must be at least
|
||||
* data_size*2+1.
|
||||
* @data: input bytes
|
||||
* @data_size: number of bytes in data
|
||||
*
|
||||
* Converts the @data_size bytes in @data into hex digit pairs, writing them to
|
||||
* @buffer. Finally, a nul terminating character is written; @buffer therefore
|
||||
* needs space for (data_size*2+1) chars.
|
||||
*/
|
||||
void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size,
|
||||
const uint8_t *restrict data, size_t data_size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/host-utils.h"
|
||||
|
||||
static inline char hexdump_nibble(unsigned x)
|
||||
{
|
||||
@@ -97,3 +98,20 @@ void qemu_hexdump(FILE *fp, const char *prefix,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size,
|
||||
const uint8_t *restrict data, size_t data_size)
|
||||
{
|
||||
size_t i;
|
||||
uint64_t required_buffer_size;
|
||||
bool overflow = umul64_overflow(data_size, 2, &required_buffer_size);
|
||||
overflow |= uadd64_overflow(required_buffer_size, 1, &required_buffer_size);
|
||||
assert(!overflow && buffer_size >= required_buffer_size);
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
uint8_t val = data[i];
|
||||
*(buffer++) = hexdump_nibble(val >> 4);
|
||||
*(buffer++) = hexdump_nibble(val & 0xf);
|
||||
}
|
||||
*buffer = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user