From 7fe11f67390ac8058eded21b40923eb6e3d9a335 Mon Sep 17 00:00:00 2001 From: Ryan Torok Date: Tue, 30 Jan 2024 18:30:56 +0000 Subject: [PATCH] [cryptotest] add ECDSA Verify test uJSON API definitions Signed-off-by: Ryan Torok --- sw/device/tests/crypto/cryptotest/json/BUILD | 7 +++ .../tests/crypto/cryptotest/json/commands.h | 1 + .../crypto/cryptotest/json/ecdsa_commands.c | 6 ++ .../crypto/cryptotest/json/ecdsa_commands.h | 63 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 sw/device/tests/crypto/cryptotest/json/ecdsa_commands.c create mode 100644 sw/device/tests/crypto/cryptotest/json/ecdsa_commands.h diff --git a/sw/device/tests/crypto/cryptotest/json/BUILD b/sw/device/tests/crypto/cryptotest/json/BUILD index 82e09300c191ca..d06dfd7c2f3ba0 100644 --- a/sw/device/tests/crypto/cryptotest/json/BUILD +++ b/sw/device/tests/crypto/cryptotest/json/BUILD @@ -18,6 +18,13 @@ cc_library( deps = ["//sw/device/lib/ujson"], ) +cc_library( + name = "ecdsa_commands", + srcs = ["ecdsa_commands.c"], + hdrs = ["ecdsa_commands.h"], + deps = ["//sw/device/lib/ujson"], +) + cc_library( name = "hmac_commands", srcs = ["hmac_commands.c"], diff --git a/sw/device/tests/crypto/cryptotest/json/commands.h b/sw/device/tests/crypto/cryptotest/json/commands.h index e70592d5c90f93..c05d4a50475fcf 100644 --- a/sw/device/tests/crypto/cryptotest/json/commands.h +++ b/sw/device/tests/crypto/cryptotest/json/commands.h @@ -13,6 +13,7 @@ extern "C" { #define COMMAND(_, value) \ value(_, Aes) \ + value(_, Ecdsa) \ value(_, Hmac) \ value(_, AesSca) \ value(_, IbexFi) \ diff --git a/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.c b/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.c new file mode 100644 index 00000000000000..b0e14d41403f8d --- /dev/null +++ b/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.c @@ -0,0 +1,6 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#define UJSON_SERDE_IMPL 1 +#include "ecdsa_commands.h" diff --git a/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.h b/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.h new file mode 100644 index 00000000000000..94113709d67a55 --- /dev/null +++ b/sw/device/tests/crypto/cryptotest/json/ecdsa_commands.h @@ -0,0 +1,63 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTITAN_SW_DEVICE_TESTS_CRYPTO_CRYPTOTEST_JSON_ECDSA_COMMANDS_H_ +#define OPENTITAN_SW_DEVICE_TESTS_CRYPTO_CRYPTOTEST_JSON_ECDSA_COMMANDS_H_ +#include "sw/device/lib/ujson/ujson_derive.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define ECDSA_CMD_MAX_MESSAGE_BYTES 64 +#define ECDSA_CMD_MAX_SIGNATURE_SCALAR_BYTES 64 +#define ECDSA_CMD_MAX_COORDINATE_BYTES 64 + +// clang-format off + +#define ECDSA_OPERATION(_, value) \ + value(_, Verify) +UJSON_SERDE_ENUM(CryptotestEcdsaOperation, cryptotest_ecdsa_operation_t, ECDSA_OPERATION); + +#define ECDSA_HASH_ALG(_, value) \ + value(_, Sha256) \ + value(_, Sha384) \ + value(_, Sha512) \ + value(_, Sha3_256) \ + value(_, Sha3_384) \ + value(_, Sha3_512) +UJSON_SERDE_ENUM(CryptotestEcdsaHashAlg, cryptotest_ecdsa_hash_alg_t, ECDSA_HASH_ALG); + +#define ECDSA_CURVE(_, value) \ + value(_, P256) \ + value(_, P384) +UJSON_SERDE_ENUM(CryptotestEcdsaCurve, cryptotest_ecdsa_curve_t, ECDSA_CURVE); + +#define ECDSA_MESSAGE(field, string) \ + field(input, uint8_t, ECDSA_CMD_MAX_MESSAGE_BYTES) \ + field(input_len, size_t) +UJSON_SERDE_STRUCT(CryptotestEcdsaMessage, cryptotest_ecdsa_message_t, ECDSA_MESSAGE); + +#define ECDSA_SIGNATURE(field, string) \ + field(r, uint8_t, ECDSA_CMD_MAX_SIGNATURE_SCALAR_BYTES) \ + field(r_len, size_t) \ + field(s, uint8_t, ECDSA_CMD_MAX_SIGNATURE_SCALAR_BYTES) \ + field(s_len, size_t) +UJSON_SERDE_STRUCT(CryptotestEcdsaSignature, cryptotest_ecdsa_signature_t, ECDSA_SIGNATURE); + +#define ECDSA_COORDINATE(field, string) \ + field(coordinate, uint8_t, ECDSA_CMD_MAX_COORDINATE_BYTES) \ + field(coordinate_len, size_t) +UJSON_SERDE_STRUCT(CryptotestEcdsaCoordinate, cryptotest_ecdsa_coordinate_t, ECDSA_COORDINATE); + +#define ECDSA_VERIFY_OUTPUT(_, value) \ + value(_, Success) \ + value(_, Failure) +UJSON_SERDE_ENUM(CryptotestEcdsaVerifyOutput, cryptotest_ecdsa_verify_output_t, ECDSA_VERIFY_OUTPUT); + +// clang-format on + +#ifdef __cplusplus +} +#endif +#endif // OPENTITAN_SW_DEVICE_TESTS_CRYPTO_CRYPTOTEST_JSON_ECDSA_COMMANDS_H_