summaryrefslogtreecommitdiffstats
path: root/test/qemu-aes_guest.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-01-10 01:37:23 +0100
committerLouis Burda <quent.burda@gmail.com>2023-01-10 01:38:43 +0100
commit252b11a01e061fd17821e53a41c8451a1d2c27bd (patch)
treee887ead2faddc8691fc13da426655a0062351cdc /test/qemu-aes_guest.c
parent864f5fa9d539734d823b3d0613dbf1a43beec334 (diff)
downloadcachepc-252b11a01e061fd17821e53a41c8451a1d2c27bd.tar.gz
cachepc-252b11a01e061fd17821e53a41c8451a1d2c27bd.zip
Begin ioctl and test-case overhaul
Diffstat (limited to 'test/qemu-aes_guest.c')
-rw-r--r--test/qemu-aes_guest.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/qemu-aes_guest.c b/test/qemu-aes_guest.c
new file mode 100644
index 0000000..949c661
--- /dev/null
+++ b/test/qemu-aes_guest.c
@@ -0,0 +1,74 @@
+#include "cachepc/uapi.h"
+#include "kcapi.h"
+
+#include <sys/random.h>
+#include <err.h>
+#include <time.h>
+#include <assert.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static uint8_t key[16];
+
+void
+printhex(uint8_t *buf, size_t size)
+{
+ size_t i;
+
+ for (i = 0; i < size; i++)
+ printf("%02X", buf[i]);
+ printf("\n");
+}
+
+int
+main(int argc, const char **argv)
+{
+ struct kcapi_handle *kcapi;
+ uint8_t block[128];
+ uint8_t *buf;
+ size_t n;
+
+ buf = NULL;
+ if (posix_memalign((void *)&buf, L1_LINESIZE * L1_SETS, L1_LINESIZE * L1_SETS))
+ err(1, "memalign");
+ memset(buf, 0, L1_LINESIZE * L1_SETS);
+
+ while (1) {
+ CPC_DO_VMMCALL(CPC_GUEST_START_TRACK, 0);
+ buf[L1_LINESIZE * 5] += 1;
+ CPC_DO_VMMCALL(CPC_GUEST_STOP_TRACK, 0);
+ }
+
+ return 0;
+
+ kcapi = NULL;
+ if (kcapi_cipher_init(&kcapi, "ecb(aes)", 0))
+ err(1, "kcapi init");
+
+ for (n = 0; n < 16; n++)
+ key[n] = (uint8_t) n;
+
+ if (kcapi_cipher_setkey(kcapi, key, sizeof(key)))
+ err(1, "kcapi setkey");
+
+ while (1) {
+ printf("RUN %li\n", time(NULL));
+
+ memset(block, 0, sizeof(block));
+ strncpy((char *) block, "Hello world", sizeof(block));
+
+ printhex(block, sizeof(block));
+ n = kcapi_cipher_encrypt(kcapi, block, sizeof(block), NULL,
+ block, sizeof(block), KCAPI_ACCESS_HEURISTIC);
+ if (n != sizeof(block))
+ err(1, "encrypt");
+ printhex(block, sizeof(block));
+
+ sleep(1);
+ }
+
+ kcapi_cipher_destroy(kcapi);
+}