diff --git a/doc/dox_comments/header_files/curve25519.h b/doc/dox_comments/header_files/curve25519.h index 3c9b68f39a..5c4f675dde 100644 --- a/doc/dox_comments/header_files/curve25519.h +++ b/doc/dox_comments/header_files/curve25519.h @@ -780,10 +780,10 @@ 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 @@ -791,8 +791,8 @@ int wc_curve25519_size(curve25519_key* key); 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 _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 @@ -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 @@ -909,8 +909,8 @@ 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 @@ -918,8 +918,8 @@ int wc_curve25519_generic(int public_size, byte* pub, int private_size, \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); diff --git a/tests/api/test_curve25519.c b/tests/api/test_curve25519.c index 36cf643f2c..fa03b35602 100644 --- a/tests/api/test_curve25519.c +++ b/tests/api/test_curve25519.c @@ -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 */ 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); diff --git a/wolfcrypt/src/curve25519.c b/wolfcrypt/src/curve25519.c index f8ca74255c..3fd526e678 100644 --- a/wolfcrypt/src/curve25519.c +++ b/wolfcrypt/src/curve25519.c @@ -137,8 +137,8 @@ static WC_INLINE void curve25519_copy_point(byte* out, const byte* point, * return value is propagated from curve25519() (0 on success), or * ECC_BAD_ARG_E, and the byte vectors are little endian. */ -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) { int ret; #ifdef FREESCALE_LTC_ECC @@ -204,8 +204,8 @@ int wc_curve25519_make_pub(int public_size, byte* pub, int private_size, ret = wc_InitRng(&rng); if (ret == 0) { - ret = wc_curve25519_make_pub_blind(public_size, pub, private_size, - priv, &rng); + ret = wc_curve25519_make_pub_blind(private_size, priv, public_size, + pub, &rng); wc_FreeRng(&rng); } @@ -283,8 +283,8 @@ static int curve25519_smul_blind(byte* rp, const byte* n, const byte* p, } #endif -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) { int ret; #ifdef FREESCALE_LTC_ECC @@ -333,8 +333,8 @@ int wc_curve25519_make_pub_blind(int public_size, byte* pub, int private_size, * return value is propagated from curve25519() (0 on success), * and the byte vectors are little endian. */ -int wc_curve25519_generic(int public_size, byte* pub, - int private_size, const byte* priv, +int wc_curve25519_generic(int private_size, const byte* priv, + int public_size, byte* pub, int basepoint_size, const byte* basepoint) { #ifdef FREESCALE_LTC_ECC @@ -373,7 +373,7 @@ int wc_curve25519_generic(int public_size, byte* pub, ret = wc_InitRng(&rng); if (ret == 0) { - ret = wc_curve25519_generic_blind(public_size, pub, private_size, priv, + ret = wc_curve25519_generic_blind(private_size, priv, public_size, pub, basepoint_size, basepoint, &rng); wc_FreeRng(&rng); @@ -391,8 +391,8 @@ int wc_curve25519_generic(int public_size, byte* pub, * return value is propagated from curve25519() (0 on success), * and the byte vectors are little endian. */ -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) { @@ -579,14 +579,14 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key) if (ret == 0) { key->privSet = 1; #ifdef WOLFSSL_CURVE25519_BLINDING - ret = wc_curve25519_make_pub_blind((int)sizeof(key->p.point), - key->p.point, (int)sizeof(key->k), key->k, rng); + ret = wc_curve25519_make_pub_blind((int)sizeof(key->k), + key->k, (int)sizeof(key->p.point), key->p.point, rng); if (ret == 0) { ret = wc_curve25519_set_rng(key, rng); } #else - ret = wc_curve25519_make_pub((int)sizeof(key->p.point), - key->p.point, (int)sizeof(key->k), key->k); + ret = wc_curve25519_make_pub((int)sizeof(key->k), + key->k, (int)sizeof(key->p.point), key->p.point); #endif key->pubSet = (ret == 0); } @@ -805,12 +805,12 @@ int wc_curve25519_export_public_ex(curve25519_key* key, byte* out, /* calculate public if missing */ if (!key->pubSet) { #ifdef WOLFSSL_CURVE25519_BLINDING - ret = wc_curve25519_make_pub_blind((int)sizeof(key->p.point), - key->p.point, (int)sizeof(key->k), - key->k, key->rng); + ret = wc_curve25519_make_pub_blind((int)sizeof(key->k), + key->k, (int)sizeof(key->p.point), + key->p.point, key->rng); #else - ret = wc_curve25519_make_pub((int)sizeof(key->p.point), key->p.point, - (int)sizeof(key->k), key->k); + ret = wc_curve25519_make_pub((int)sizeof(key->k), key->k, + (int)sizeof(key->p.point), key->p.point); #endif key->pubSet = (ret == 0); } diff --git a/wolfssl/wolfcrypt/curve25519.h b/wolfssl/wolfcrypt/curve25519.h index 6497840341..256556f6eb 100644 --- a/wolfssl/wolfcrypt/curve25519.h +++ b/wolfssl/wolfcrypt/curve25519.h @@ -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); #endif WOLFSSL_API -int wc_curve25519_generic(int public_size, byte* pub, - int private_size, const byte* priv, +int wc_curve25519_generic(int private_size, const byte* priv, + int public_size, byte* pub, int basepoint_size, const byte* basepoint); #ifdef WOLFSSL_CURVE25519_BLINDING WOLFSSL_API -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); #endif diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs b/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs index ef3c3ca8bd..a629211a84 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs @@ -330,8 +330,8 @@ impl Curve25519Key { let private_size = crate::buffer_len_to_i32(private.len())?; let public_size = crate::buffer_len_to_i32(public.len())?; let rc = unsafe { - sys::wc_curve25519_make_pub(public_size, public.as_mut_ptr(), - private_size, private.as_ptr()) + sys::wc_curve25519_make_pub(private_size, private.as_ptr(), + public_size, public.as_mut_ptr()) }; if rc != 0 { return Err(rc); @@ -357,8 +357,8 @@ impl Curve25519Key { let private_size = crate::buffer_len_to_i32(private.len())?; let public_size = crate::buffer_len_to_i32(public.len())?; let rc = unsafe { - sys::wc_curve25519_make_pub_blind(public_size, public.as_mut_ptr(), - private_size, private.as_ptr(), &mut rng.wc_rng) + sys::wc_curve25519_make_pub_blind(private_size, private.as_ptr(), + public_size, public.as_mut_ptr(), &mut rng.wc_rng) }; if rc != 0 { return Err(rc); @@ -384,8 +384,8 @@ impl Curve25519Key { let public_size = crate::buffer_len_to_i32(public.len())?; let basepoint_size = crate::buffer_len_to_i32(basepoint.len())?; let rc = unsafe { - sys::wc_curve25519_generic(public_size, public.as_mut_ptr(), - private_size, private.as_ptr(), basepoint_size, basepoint.as_ptr()) + sys::wc_curve25519_generic(private_size, private.as_ptr(), + public_size, public.as_mut_ptr(), basepoint_size, basepoint.as_ptr()) }; if rc != 0 { return Err(rc); @@ -413,8 +413,8 @@ impl Curve25519Key { let public_size = crate::buffer_len_to_i32(public.len())?; let basepoint_size = crate::buffer_len_to_i32(basepoint.len())?; let rc = unsafe { - sys::wc_curve25519_generic_blind(public_size, public.as_mut_ptr(), - private_size, private.as_ptr(), basepoint_size, basepoint.as_ptr(), + sys::wc_curve25519_generic_blind(private_size, private.as_ptr(), + public_size, public.as_mut_ptr(), basepoint_size, basepoint.as_ptr(), &mut rng.wc_rng) }; if rc != 0 {