[sw] Move device code into sw/device folder
This change addresses issue #27. All device code is being moved to the
`sw/device` folder. Makefiles and Meson build files had been updated to
support the new directory structure.
Documentation, and top level and DV dependencies have been updated as
well.
Manual tests:
* ci/run_sw_build.sh
* ./meson_init.sh && ninja -C build-fpga && ninja -C build-verilator
diff --git a/sw/device/lib/hw_sha256.c b/sw/device/lib/hw_sha256.c
new file mode 100644
index 0000000..af67cae
--- /dev/null
+++ b/sw/device/lib/hw_sha256.c
@@ -0,0 +1,43 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "sw/device/lib/hw_sha256.h"
+
+#include "hmac.h"
+
+static const HASH_VTAB HW_SHA256_VTAB = {.init = &hw_SHA256_init,
+ .update = &hw_SHA256_update,
+ .final = &hw_SHA256_final,
+ .hash = &hw_SHA256_hash,
+ .size = SHA256_DIGEST_SIZE};
+
+static void sha256_init() {
+ hmac_cfg_t config = {.mode = HMAC_OP_SHA256,
+ .input_endian_swap = 1,
+ .digest_endian_swap = 1,
+ .keys = {0}};
+ hmac_init(config);
+}
+
+void hw_SHA256_init(HW_SHA256_CTX *ctx) {
+ // TODO: For security, need to make sure HMAC is not stuck in progress.
+ ctx->f = &HW_SHA256_VTAB;
+ sha256_init();
+}
+
+void hw_SHA256_update(HW_SHA256_CTX *ctx, const void *data, size_t len) {
+ hmac_update(data, len);
+}
+
+const uint8_t *hw_SHA256_final(HW_SHA256_CTX *ctx) {
+ hmac_done((uint32_t *)ctx->buf);
+ return ctx->buf;
+}
+
+const uint8_t *hw_SHA256_hash(const void *data, size_t len, uint8_t *digest) {
+ sha256_init();
+ hmac_update(data, len);
+ hmac_done((uint32_t *)digest);
+ return digest;
+}