summaryrefslogtreecommitdiffstats
path: root/crypto/ec/curve448
diff options
context:
space:
mode:
authorJames Muir <muir.james.a@gmail.com>2022-10-15 22:23:39 -0400
committerHugo Landau <hlandau@openssl.org>2023-01-13 07:09:09 +0000
commit836080a89a1f5e45dac4e0df76b9270587f65d5b (patch)
tree72abd378cbb77d89d85c3d1dcb14c7e92d0653a0 /crypto/ec/curve448
parent9fa553247874728cee8ca0ece9aaed476eb0f303 (diff)
Support all five EdDSA instances from RFC 8032
Fixes #6277 Description: Make each of the five EdDSA instances defined in RFC 8032 -- Ed25519, Ed25519ctx, Ed25519ph, Ed448, Ed448ph -- available via the EVP APIs. The desired EdDSA instance is specified via an OSSL_PARAM. All instances, except for Ed25519, allow context strings as input. Context strings are passed via an OSSL_PARAM. For Ed25519ctx, the context string must be nonempty. Ed25519, Ed25519ctx, Ed448 are PureEdDSA instances, which means that the full message (not a digest) must be passed to sign and verify operations. Ed25519ph, Ed448ph are HashEdDSA instances, which means that the input message is hashed before sign and verify. Testing: All 21 test vectors from RFC 8032 have been added to evppkey_ecx.txt (thanks to Shane Lontis for showing how to do that). Those 21 test vectors are exercised by evp_test.c and cover all five instances. Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/19705)
Diffstat (limited to 'crypto/ec/curve448')
-rw-r--r--crypto/ec/curve448/curve448_local.h11
-rw-r--r--crypto/ec/curve448/eddsa.c50
2 files changed, 14 insertions, 47 deletions
diff --git a/crypto/ec/curve448/curve448_local.h b/crypto/ec/curve448/curve448_local.h
index 3410f091a6..f118d851ee 100644
--- a/crypto/ec/curve448/curve448_local.h
+++ b/crypto/ec/curve448/curve448_local.h
@@ -10,15 +10,4 @@
# define OSSL_CRYPTO_EC_CURVE448_LOCAL_H
# include "curve448utils.h"
-int
-ossl_ed448ph_sign(OSSL_LIB_CTX *ctx, uint8_t *out_sig, const uint8_t hash[64],
- const uint8_t public_key[57], const uint8_t private_key[57],
- const uint8_t *context, size_t context_len, const char *propq);
-
-int
-ossl_ed448ph_verify(OSSL_LIB_CTX *ctx, const uint8_t hash[64],
- const uint8_t signature[114], const uint8_t public_key[57],
- const uint8_t *context, size_t context_len,
- const char *propq);
-
#endif /* OSSL_CRYPTO_EC_CURVE448_LOCAL_H */
diff --git a/crypto/ec/curve448/eddsa.c b/crypto/ec/curve448/eddsa.c
index 6648692ff3..cbef27d9bb 100644
--- a/crypto/ec/curve448/eddsa.c
+++ b/crypto/ec/curve448/eddsa.c
@@ -61,12 +61,8 @@ static c448_error_t hash_init_with_dom(OSSL_LIB_CTX *ctx, EVP_MD_CTX *hashctx,
size_t context_len,
const char *propq)
{
-#ifdef CHARSET_EBCDIC
- const char dom_s[] = {0x53, 0x69, 0x67, 0x45,
- 0x64, 0x34, 0x34, 0x38, 0x00};
-#else
- const char dom_s[] = "SigEd448";
-#endif
+ /* ASCII: "SigEd448", in hex for EBCDIC compatibility */
+ const char dom_s[] = "\x53\x69\x67\x45\x64\x34\x34\x38";
uint8_t dom[2];
EVP_MD *shake256 = NULL;
@@ -82,7 +78,7 @@ static c448_error_t hash_init_with_dom(OSSL_LIB_CTX *ctx, EVP_MD_CTX *hashctx,
return C448_FAILURE;
if (!EVP_DigestInit_ex(hashctx, shake256, NULL)
- || !EVP_DigestUpdate(hashctx, dom_s, strlen(dom_s))
+ || !EVP_DigestUpdate(hashctx, dom_s, sizeof(dom_s)-1)
|| !EVP_DigestUpdate(hashctx, dom, sizeof(dom))
|| !EVP_DigestUpdate(hashctx, context, context_len)) {
EVP_MD_free(shake256);
@@ -373,48 +369,30 @@ ossl_c448_ed448_verify_prehash(
}
int
-ossl_ed448_sign(OSSL_LIB_CTX *ctx, uint8_t *out_sig, const uint8_t *message,
- size_t message_len, const uint8_t public_key[57],
- const uint8_t private_key[57], const uint8_t *context,
- size_t context_len, const char *propq)
+ossl_ed448_sign(OSSL_LIB_CTX *ctx, uint8_t *out_sig,
+ const uint8_t *message, size_t message_len,
+ const uint8_t public_key[57], const uint8_t private_key[57],
+ const uint8_t *context, size_t context_len,
+ const uint8_t phflag, const char *propq)
{
return ossl_c448_ed448_sign(ctx, out_sig, private_key, public_key, message,
- message_len, 0, context, context_len,
+ message_len, phflag, context, context_len,
propq) == C448_SUCCESS;
}
int
-ossl_ed448_verify(OSSL_LIB_CTX *ctx, const uint8_t *message, size_t message_len,
+ossl_ed448_verify(OSSL_LIB_CTX *ctx,
+ const uint8_t *message, size_t message_len,
const uint8_t signature[114], const uint8_t public_key[57],
- const uint8_t *context, size_t context_len, const char *propq)
+ const uint8_t *context, size_t context_len,
+ const uint8_t phflag, const char *propq)
{
return ossl_c448_ed448_verify(ctx, signature, public_key, message,
- message_len, 0, context, (uint8_t)context_len,
+ message_len, phflag, context, (uint8_t)context_len,
propq) == C448_SUCCESS;
}
int
-ossl_ed448ph_sign(OSSL_LIB_CTX *ctx, uint8_t *out_sig, const uint8_t hash[64],
- const uint8_t public_key[57], const uint8_t private_key[57],
- const uint8_t *context, size_t context_len, const char *propq)
-{
- return ossl_c448_ed448_sign_prehash(ctx, out_sig, private_key, public_key,
- hash, context, context_len,
- propq) == C448_SUCCESS;
-}
-
-int
-ossl_ed448ph_verify(OSSL_LIB_CTX *ctx, const uint8_t hash[64],
- const uint8_t signature[114], const uint8_t public_key[57],
- const uint8_t *context, size_t context_len,
- const char *propq)
-{
- return ossl_c448_ed448_verify_prehash(ctx, signature, public_key, hash,
- context, (uint8_t)context_len,
- propq) == C448_SUCCESS;
-}
-
-int
ossl_ed448_public_from_private(OSSL_LIB_CTX *ctx, uint8_t out_public_key[57],
const uint8_t private_key[57], const char *propq)
{