-
Notifications
You must be signed in to change notification settings - Fork 970
fix: reorder wc_curve25519_make_pub/generic to input-before-output #10367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,19 +780,19 @@ int wc_curve25519_size(curve25519_key* key); | |
| \return ECC_BAD_ARG_E If the key sizes are invalid | ||
| \return BAD_FUNC_ARG If any input parameters are NULL | ||
|
|
||
| \param public_size Size of the public key buffer (must be 32) | ||
| \param pub Pointer to buffer to store the public key | ||
| \param private_size Size of the private key (must be 32) | ||
| \param priv Pointer to buffer containing the private key | ||
| \param public_size Size of the public key buffer (must be 32) | ||
| \param pub Pointer to buffer to store the public key | ||
|
|
||
| _Example_ | ||
| \code | ||
| byte priv[CURVE25519_KEYSIZE]; | ||
| byte pub[CURVE25519_KEYSIZE]; | ||
|
|
||
| // initialize priv with private key | ||
| int ret = wc_curve25519_make_pub(sizeof(pub), pub, sizeof(priv), | ||
| priv); | ||
| int ret = wc_curve25519_make_pub(sizeof(priv), priv, sizeof(pub), | ||
| pub); | ||
| if (ret != 0) { | ||
| // error generating public key | ||
| } | ||
|
|
@@ -801,8 +801,8 @@ int wc_curve25519_size(curve25519_key* key); | |
| \sa wc_curve25519_make_key | ||
| \sa wc_curve25519_make_pub_blind | ||
| */ | ||
| int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, | ||
| const byte* priv); | ||
| int wc_curve25519_make_pub(int private_size, const byte* priv, | ||
| int public_size, byte* pub); | ||
|
|
||
| /*! | ||
| \ingroup Curve25519 | ||
|
|
@@ -814,10 +814,10 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, | |
| \return ECC_BAD_ARG_E If the key sizes are invalid | ||
| \return BAD_FUNC_ARG If any input parameters are NULL | ||
|
|
||
| \param public_size Size of the public key buffer (must be 32) | ||
| \param pub Pointer to buffer to store the public key | ||
| \param private_size Size of the private key (must be 32) | ||
| \param priv Pointer to buffer containing the private key | ||
| \param public_size Size of the public key buffer (must be 32) | ||
| \param pub Pointer to buffer to store the public key | ||
| \param rng Pointer to initialized RNG for blinding | ||
|
Comment on lines
813
to
821
|
||
|
|
||
| _Example_ | ||
|
|
@@ -828,8 +828,8 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, | |
|
|
||
| wc_InitRng(&rng); | ||
| // initialize priv with private key | ||
| int ret = wc_curve25519_make_pub_blind(sizeof(pub), pub, | ||
| sizeof(priv), priv, &rng); | ||
| int ret = wc_curve25519_make_pub_blind(sizeof(priv), priv, | ||
| sizeof(pub), pub, &rng); | ||
| if (ret != 0) { | ||
| // error generating public key | ||
| } | ||
|
|
@@ -838,8 +838,8 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, | |
| \sa wc_curve25519_make_pub | ||
| \sa wc_curve25519_generic_blind | ||
| */ | ||
| int wc_curve25519_make_pub_blind(int public_size, byte* pub, | ||
| int private_size, const byte* priv, | ||
| int wc_curve25519_make_pub_blind(int private_size, const byte* priv, | ||
| int public_size, byte* pub, | ||
| WC_RNG* rng); | ||
|
|
||
| /*! | ||
|
|
@@ -853,10 +853,10 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, | |
| \return ECC_BAD_ARG_E If the sizes are invalid | ||
| \return BAD_FUNC_ARG If any input parameters are NULL | ||
|
|
||
| \param public_size Size of the output buffer (must be 32) | ||
| \param pub Pointer to buffer to store the result | ||
| \param private_size Size of the scalar (must be 32) | ||
| \param priv Pointer to buffer containing the scalar | ||
| \param public_size Size of the output buffer (must be 32) | ||
| \param pub Pointer to buffer to store the result | ||
| \param basepoint_size Size of the basepoint (must be 32) | ||
| \param basepoint Pointer to buffer containing the basepoint | ||
|
Comment on lines
852
to
861
|
||
|
|
||
|
|
@@ -867,8 +867,8 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, | |
| byte result[CURVE25519_KEYSIZE]; | ||
|
|
||
| // initialize scalar and basepoint | ||
| int ret = wc_curve25519_generic(sizeof(result), result, | ||
| sizeof(scalar), scalar, | ||
| int ret = wc_curve25519_generic(sizeof(scalar), scalar, | ||
| sizeof(result), result, | ||
| sizeof(basepoint), basepoint); | ||
| if (ret != 0) { | ||
| // error computing result | ||
|
|
@@ -878,9 +878,9 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, | |
| \sa wc_curve25519_shared_secret | ||
| \sa wc_curve25519_generic_blind | ||
| */ | ||
| int wc_curve25519_generic(int public_size, byte* pub, int private_size, | ||
| const byte* priv, int basepoint_size, | ||
| const byte* basepoint); | ||
| int wc_curve25519_generic(int private_size, const byte* priv, | ||
| int public_size, byte* pub, | ||
| int basepoint_size, const byte* basepoint); | ||
|
|
||
| /*! | ||
| \ingroup Curve25519 | ||
|
|
@@ -892,10 +892,10 @@ int wc_curve25519_generic(int public_size, byte* pub, int private_size, | |
| \return ECC_BAD_ARG_E If the sizes are invalid | ||
| \return BAD_FUNC_ARG If any input parameters are NULL | ||
|
|
||
| \param public_size Size of the output buffer (must be 32) | ||
| \param pub Pointer to buffer to store the result | ||
| \param private_size Size of the scalar (must be 32) | ||
| \param priv Pointer to buffer containing the scalar | ||
| \param public_size Size of the output buffer (must be 32) | ||
| \param pub Pointer to buffer to store the result | ||
| \param basepoint_size Size of the basepoint (must be 32) | ||
| \param basepoint Pointer to buffer containing the basepoint | ||
| \param rng Pointer to initialized RNG for blinding | ||
|
Comment on lines
891
to
901
|
||
|
|
@@ -909,17 +909,17 @@ int wc_curve25519_generic(int public_size, byte* pub, int private_size, | |
|
|
||
| wc_InitRng(&rng); | ||
| // initialize scalar and basepoint | ||
| int ret = wc_curve25519_generic_blind(sizeof(result), result, | ||
| sizeof(scalar), scalar, | ||
| int ret = wc_curve25519_generic_blind(sizeof(scalar), scalar, | ||
| sizeof(result), result, | ||
| sizeof(basepoint), basepoint, | ||
| &rng); | ||
| \endcode | ||
|
|
||
| \sa wc_curve25519_generic | ||
| \sa wc_curve25519_make_pub_blind | ||
| */ | ||
| int wc_curve25519_generic_blind(int public_size, byte* pub, | ||
| int private_size, const byte* priv, | ||
| int wc_curve25519_generic_blind(int private_size, const byte* priv, | ||
| int public_size, byte* pub, | ||
| int basepoint_size, const byte* basepoint, | ||
| WC_RNG* rng); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,25 +370,25 @@ int test_wc_curve25519_make_pub(void) | |
| ExpectIntEQ(wc_InitRng(&rng), 0); | ||
| ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0); | ||
|
|
||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out, | ||
| (int)sizeof(key.k), key.k), 0); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), key.k, | ||
| (int)sizeof(out), out), 0); | ||
| /* test bad cases */ | ||
|
Comment on lines
+373
to
375
|
||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k, | ||
| (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k), | ||
| NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out, | ||
| (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL, | ||
| (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| (int)sizeof(out), out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), NULL, | ||
| (int)sizeof(out), out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), key.k, | ||
| (int)sizeof(out) - 1, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), key.k, | ||
| (int)sizeof(out), NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| /* verify clamping test */ | ||
| key.k[0] |= ~248; | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k), | ||
| key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), key.k, | ||
| (int)sizeof(out), out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E)); | ||
| key.k[0] &= 248; | ||
| /* repeat the expected-to-succeed test. */ | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k), | ||
| key.k), 0); | ||
| ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k), key.k, | ||
| (int)sizeof(out), out), 0); | ||
|
|
||
| DoExpectIntEQ(wc_FreeRng(&rng), 0); | ||
| wc_curve25519_free(&key); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -155,22 +155,22 @@ enum { | |||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| WOLFSSL_API | ||||||||||||
| int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, | ||||||||||||
| const byte* priv); | ||||||||||||
| int wc_curve25519_make_pub(int private_size, const byte* priv, | ||||||||||||
| int public_size, byte* pub); | ||||||||||||
| #ifdef WOLFSSL_CURVE25519_BLINDING | ||||||||||||
| WOLFSSL_API | ||||||||||||
| int wc_curve25519_make_pub_blind(int public_size, byte* pub, int private_size, | ||||||||||||
| const byte* priv, WC_RNG* rng); | ||||||||||||
| int wc_curve25519_make_pub_blind(int private_size, const byte* priv, | ||||||||||||
| int public_size, byte* pub, WC_RNG* rng); | ||||||||||||
|
Comment on lines
+162
to
+163
|
||||||||||||
| int wc_curve25519_make_pub_blind(int private_size, const byte* priv, | |
| int public_size, byte* pub, WC_RNG* rng); | |
| int wc_curve25519_make_pub_blind(int public_size, byte* pub, | |
| int private_size, const byte* priv, | |
| WC_RNG* rng); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented return codes say BAD_FUNC_ARG is returned when parameters are NULL, but the implementation returns ECC_BAD_ARG_E for NULL pub/priv in wc_curve25519_make_pub(). Please update the Doxygen \return list to match the actual behavior (or change the implementation, but that would be a behavioral/API change).