From 325221707c5ee0eed9f45eff443f056187ce19b4 Mon Sep 17 00:00:00 2001 From: Brett Nicholas <7547222+bigbrett@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:02:21 -0600 Subject: [PATCH] address review feedback --- doc/dox_comments/header_files/asn_public.h | 86 +++++++++++++++++++++- wolfcrypt/src/asn.c | 8 +- wolfcrypt/test/test.c | 3 +- 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/doc/dox_comments/header_files/asn_public.h b/doc/dox_comments/header_files/asn_public.h index c3dfaa4911..3b9cc72826 100644 --- a/doc/dox_comments/header_files/asn_public.h +++ b/doc/dox_comments/header_files/asn_public.h @@ -1578,6 +1578,21 @@ int wc_EccPublicKeyToDer_ex(ecc_key* key, byte* output, index is set to last position parsed of input buffer. \param key Pointer to curve25519_key structure to store decoded key \param inSz Size of input DER buffer + + \sa wc_Curve25519KeyDecode + \sa wc_Curve25519PublicKeyDecode + + _Example_ + \code + byte der[] = { // DER encoded key }; + word32 idx = 0; + curve25519_key key; + wc_curve25519_init(&key); + + if (wc_Curve25519PrivateKeyDecode(der, &idx, &key, sizeof(der)) != 0) { + // Error decoding private key + } + \endcode */ int wc_Curve25519PrivateKeyDecode(const byte* input, word32* inOutIdx, curve25519_key* key, word32 inSz); @@ -1602,6 +1617,20 @@ int wc_Curve25519PrivateKeyDecode(const byte* input, word32* inOutIdx, index is set to last position parsed of input buffer. \param key Pointer to curve25519_key structure to store decoded key \param inSz Size of input DER buffer + + \sa wc_Curve25519KeyDecode + \sa wc_Curve25519PrivateKeyDecode + + _Example_ + \code + byte der[] = { // DER encoded key }; + word32 idx = 0; + curve25519_key key; + wc_curve25519_init(&key); + if (wc_Curve25519PublicKeyDecode(der, &idx, &key, sizeof(der)) != 0) { + // Error decoding public key + } + \endcode */ int wc_Curve25519PublicKeyDecode(const byte* input, word32* inOutIdx, curve25519_key* key, word32 inSz); @@ -1626,6 +1655,20 @@ int wc_Curve25519PublicKeyDecode(const byte* input, word32* inOutIdx, index is set to last position parsed of input buffer. \param key Pointer to curve25519_key structure to store decoded key \param inSz Size of input DER buffer + + \sa wc_Curve25519PrivateKeyDecode + \sa wc_Curve25519PublicKeyDecode + + _Example_ + \code + byte der[] = { // DER encoded key }; + word32 idx = 0; + curve25519_key key; + wc_curve25519_init(&key); + if (wc_Curve25519KeyDecode(der, &idx, &key, sizeof(der)) != 0) { + // Error decoding key + } + \endcode */ int wc_Curve25519KeyDecode(const byte* input, word32* inOutIdx, curve25519_key* key, word32 inSz); @@ -1645,6 +1688,19 @@ int wc_Curve25519KeyDecode(const byte* input, word32* inOutIdx, encode \param output Buffer to hold DER encoding \param inLen Size of output buffer + + \sa wc_Curve25519KeyToDer + \sa wc_Curve25519PublicKeyToDer + + _Example_ + \code + curve25519_key key; + wc_curve25519_init(&key); + ... + int derSz = 128; // Some appropriate size for output DER + byte der[derSz]; + wc_Curve25519PrivateKeyToDer(&key, der, derSz); + \endcode */ int wc_Curve25519PrivateKeyToDer(curve25519_key* key, byte* output, word32 inLen); @@ -1664,7 +1720,20 @@ int wc_Curve25519PrivateKeyToDer(curve25519_key* key, byte* output, encode \param output Buffer to hold DER encoding \param inLen Size of output buffer - \param withAlg Whether to include algorithm identifier + \param withAlg Whether to include algorithm identifier in the DER encoding + + \sa wc_Curve25519KeyToDer + \sa wc_Curve25519PrivateKeyToDer + + _Example_ + \code + curve25519_key key; + wc_curve25519_init(&key); + ... + int derSz = 128; // Some appropriate size for output DER + byte der[derSz]; + wc_Curve25519PublicKeyToDer(&key, der, derSz, 1); + \endcode */ int wc_Curve25519PublicKeyToDer(curve25519_key* key, byte* output, word32 inLen, int withAlg); @@ -1683,7 +1752,20 @@ int wc_Curve25519PublicKeyToDer(curve25519_key* key, byte* output, word32 inLen, \param key Pointer to curve25519_key structure containing key to encode \param output Buffer to hold DER encoding \param inLen Size of output buffer - \param withAlg Whether to include algorithm identifier + \param withAlg Whether to include algorithm identifier in the DER encoding + + \sa wc_Curve25519PrivateKeyToDer + \sa wc_Curve25519PublicKeyToDer + + _Example_ + \code + curve25519_key key; + wc_curve25519_init(&key); + ... + int derSz = 128; // Some appropriate size for output DER + byte der[derSz]; + wc_Curve25519KeyToDer(&key, der, derSz, 1); + \endcode */ int wc_Curve25519KeyToDer(curve25519_key* key, byte* output, word32 inLen, int withAlg); diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 737f8bd41d..7b54d51dab 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -35670,9 +35670,9 @@ int wc_Curve25519KeyDecode(const byte* input, word32* inOutIdx, { int ret; byte privKey[CURVE25519_KEYSIZE]; - byte pubKey[CURVE25519_KEYSIZE]; + byte pubKey[CURVE25519_PUB_KEY_SIZE]; word32 privKeyLen = CURVE25519_KEYSIZE; - word32 pubKeyLen = CURVE25519_KEYSIZE; + word32 pubKeyLen = CURVE25519_PUB_KEY_SIZE; /* sanity check */ if (input == NULL || inOutIdx == NULL || key == NULL || inSz == 0) { @@ -35925,9 +35925,9 @@ int wc_Curve25519KeyToDer(curve25519_key* key, byte* output, word32 inLen, int w { int ret; byte privKey[CURVE25519_KEYSIZE]; - byte pubKey[CURVE25519_KEYSIZE]; + byte pubKey[CURVE25519_PUB_KEY_SIZE]; word32 privKeyLen = CURVE25519_KEYSIZE; - word32 pubKeyLen = CURVE25519_KEYSIZE; + word32 pubKeyLen = CURVE25519_PUB_KEY_SIZE; if (key == NULL) { return BAD_FUNC_ARG; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 234cbf235a..fa8f484054 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -35098,8 +35098,7 @@ static wc_test_ret_t curve255519_der_test(void) ret = WC_TEST_RET_ENC_NC; } - /* Test decode/encode of a key file containing both public and private - * fields */ + /* Test decode/encode key data containing both public and private fields */ if (ret == 0) { XMEMSET(&key, 0 , sizeof(key));