aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generated by cgit v1.2.3 (git 2.25.1) at 2025-04-06 06:10:01 +0000 const uint8_t * const der, const size_t der_len);
+extern hal_error_t hal_ecdsa_private_key_from_der(hal_ecdsa_key_t **key,
+ void *keybuf, const size_t keybuf_len,
+ const uint8_t * const der, const size_t der_len);
extern hal_error_t hal_ecdsa_key_to_ecpoint(const hal_ecdsa_key_t * const key,
uint8_t *der, size_t *der_len, const size_t der_max);
diff --git a/rpc_pkey.c b/rpc_pkey.c
index d286497..d9ee53c 100644
--- a/rpc_pkey.c
+++ b/rpc_pkey.c
@@ -296,7 +296,7 @@ static hal_error_t generate_rsa(const hal_rpc_client_handle_t client,
uint8_t der[hal_rsa_key_to_der_len(key)];
size_t der_len;
- if ((err = hal_rsa_key_to_der(key, der, &der_len, sizeof(der))) == HAL_OK)
+ if ((err = hal_rsa_private_key_to_der(key, der, &der_len, sizeof(der))) == HAL_OK)
err = hal_ks_store(HAL_KEY_TYPE_RSA_PRIVATE, HAL_CURVE_NONE, flags,
name, name_len, der, der_len, &slot->ks_hint);
@@ -347,7 +347,7 @@ static hal_error_t generate_ec(const hal_rpc_client_handle_t client,
uint8_t der[hal_ecdsa_key_to_der_len(key)];
size_t der_len;
- if ((err = hal_ecdsa_key_to_der(key, der, &der_len, sizeof(der))) == HAL_OK)
+ if ((err = hal_ecdsa_private_key_to_der(key, der, &der_len, sizeof(der))) == HAL_OK)
err = hal_ks_store(HAL_KEY_TYPE_EC_PRIVATE, curve, flags,
name, name_len, der, der_len, &slot->ks_hint);
@@ -486,7 +486,7 @@ static hal_error_t sign_rsa(uint8_t *keybuf, const size_t keybuf_len,
assert(signature != NULL && signature_len != NULL);
assert((hash.handle == hal_rpc_hash_handle_none.handle) != (input == NULL || input_len == 0));
- if ((err = hal_rsa_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK ||
+ if ((err = hal_rsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK ||
(err = hal_rsa_key_get_modulus(key, NULL, signature_len, 0)) != HAL_OK)
return err;
@@ -518,7 +518,7 @@ static hal_error_t sign_ecdsa(uint8_t *keybuf, const size_t keybuf_len,
assert(signature != NULL && signature_len != NULL);
assert((hash.handle == hal_rpc_hash_handle_none.handle) != (input == NULL || input_len == 0));
- if ((err = hal_ecdsa_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
+ if ((err = hal_ecdsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
return err;
if (input == NULL) {
@@ -607,7 +607,7 @@ static hal_error_t verify_rsa(uint8_t *keybuf, const size_t keybuf_len,
assert(signature != NULL && signature_len > 0);
assert((hash.handle == hal_rpc_hash_handle_none.handle) != (input == NULL || input_len == 0));
- if ((err = hal_rsa_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
+ if ((err = hal_rsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
return err;
if (input == NULL) {
@@ -643,7 +643,7 @@ static hal_error_t verify_ecdsa(uint8_t *keybuf, const size_t keybuf_len,
assert(signature != NULL && signature_len > 0);
assert((hash.handle == hal_rpc_hash_handle_none.handle) != (input == NULL || input_len == 0));
- if ((err = hal_ecdsa_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
+ if ((err = hal_ecdsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
return err;
if (input == NULL) {
diff --git a/rsa.c b/rsa.c
index a901b24..e6d70db 100644
--- a/rsa.c
+++ b/rsa.c
@@ -687,8 +687,8 @@ hal_error_t hal_rsa_key_gen(const hal_core_t *core,
_(key->dQ); \
_(key->u);
-hal_error_t hal_rsa_key_to_der(const hal_rsa_key_t * const key,
- uint8_t *der, size_t *der_len, const size_t der_max)
+hal_error_t hal_rsa_private_key_to_der(const hal_rsa_key_t * const key,
+ uint8_t *der, size_t *der_len, const size_t der_max)
{
hal_error_t err = HAL_OK;
@@ -736,12 +736,12 @@ hal_error_t hal_rsa_key_to_der(const hal_rsa_key_t * const key,
size_t hal_rsa_key_to_der_len(const hal_rsa_key_t * const key)
{
size_t len = 0;
- return hal_rsa_key_to_der(key, NULL, &len, 0) == HAL_OK ? len : 0;
+ return hal_rsa_private_key_to_der(key, NULL, &len, 0) == HAL_OK ? len : 0;
}
-hal_error_t hal_rsa_key_from_der(hal_rsa_key_t **key_,
- void *keybuf, const size_t keybuf_len,
- const uint8_t *der, const size_t der_len)
+hal_error_t hal_rsa_private_key_from_der(hal_rsa_key_t **key_,
+ void *keybuf, const size_t keybuf_len,
+ const uint8_t *der, const size_t der_len)
{
if (key_ == NULL || keybuf == NULL || keybuf_len < sizeof(hal_rsa_key_t) || der == NULL)
return HAL_ERROR_BAD_ARGUMENTS;
diff --git a/tests/test-ecdsa.c b/tests/test-ecdsa.c
index 98b3d70..d88aeb2 100644
--- a/tests/test-ecdsa.c
+++ b/tests/test-ecdsa.c
@@ -133,14 +133,14 @@ static int test_against_static_vectors(const ecdsa_tc_t * const tc)
uint8_t keyder[tc->key_len];
size_t keyder_len;
- if ((err = hal_ecdsa_key_to_der(key1, keyder, &keyder_len, sizeof(keyder))) != HAL_OK)
- return printf("hal_ecdsa_key_to_der() failed: %s\n", hal_error_string(err)), 0;
+ if ((err = hal_ecdsa_private_key_to_der(key1, keyder, &keyder_len, sizeof(keyder))) != HAL_OK)
+ return printf("hal_ecdsa_private_key_to_der() failed: %s\n", hal_error_string(err)), 0;
uint8_t keybuf2[hal_ecdsa_key_t_size];
hal_ecdsa_key_t *key2 = NULL;
- if ((err = hal_ecdsa_key_from_der(&key2, keybuf2, sizeof(keybuf2), keyder, keyder_len)) != HAL_OK)
- return printf("hal_ecdsa_key_from_der() failed: %s\n", hal_error_string(err)), 0;
+ if ((err = hal_ecdsa_private_key_from_der(&key2, keybuf2, sizeof(keybuf2), keyder, keyder_len)) != HAL_OK)
+ return printf("hal_ecdsa_private_key_from_der() failed: %s\n", hal_error_string(err)), 0;
if (memcmp(key1, key2, hal_ecdsa_key_t_size) != 0)
return printf("Private key mismatch after read/write cycle\n"), 0;
diff --git a/tests/test-rsa.c b/tests/test-rsa.c
index e7e831e..2872250 100644
--- a/tests/test-rsa.c
+++ b/tests/test-rsa.c
@@ -148,19 +148,19 @@ static int test_gen(const hal_core_t *core,
size_t der_len = 0;
- if ((err = hal_rsa_key_to_der(key1, NULL, &der_len, 0)) != HAL_OK) {
+ if ((err = hal_rsa_private_key_to_der(key1, NULL, &der_len, 0)) != HAL_OK) {
printf("Getting DER length of RSA key failed: %s\n", hal_error_string(err));
return 0;
}
uint8_t der[der_len];
- if ((err = hal_rsa_key_to_der(key1, der, &der_len, sizeof(der))) != HAL_OK) {
+ if ((err = hal_rsa_private_key_to_der(key1, der, &der_len, sizeof(der))) != HAL_OK) {
printf("Converting RSA key to DER failed: %s\n", hal_error_string(err));
return 0;
}
- if ((err = hal_rsa_key_from_der(&key2, keybuf2, sizeof(keybuf2), der, sizeof(der))) != HAL_OK) {
+ if ((err = hal_rsa_private_key_from_der(&key2, keybuf2, sizeof(keybuf2), der, sizeof(der))) != HAL_OK) {
printf("Converting RSA key back from DER failed: %s\n", hal_error_string(err));
return 0;
}