Skip to content

Commit 80c1228

Browse files
authored
Merge pull request #9594 from holtrop-wolfssl/rust-curve25519
Rust wrapper: add wolfssl_wolfcrypt::curve25519 module
2 parents bbd3d4f + 8c125df commit 80c1228

File tree

7 files changed

+832
-9
lines changed

7 files changed

+832
-9
lines changed

doc/dox_comments/header_files/curve25519.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
4646
4747
\brief This function computes a shared secret key given a secret private
4848
key and a received public key. It stores the generated secret key in the
49-
buffer out and assigns the variable of the secret key to outlen. Only
49+
buffer out and assigns the length of the secret key to outlen. Only
5050
supports big endian.
5151
5252
\return 0 Returned on successfully computing a shared secret key.
@@ -93,7 +93,7 @@ int wc_curve25519_shared_secret(curve25519_key* private_key,
9393
9494
\brief This function computes a shared secret key given a secret private
9595
key and a received public key. It stores the generated secret key in the
96-
buffer out and assigns the variable of the secret key to outlen. Supports
96+
buffer out and assigns the length of the secret key to outlen. Supports
9797
both big and little endian.
9898
9999
\return 0 Returned on successfully computing a shared secret key.
@@ -361,7 +361,7 @@ int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
361361
\return 0 Returned on successfully exporting the private key from the
362362
curve25519_key structure.
363363
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
364-
\return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
364+
\return ECC_BAD_ARG_E Returned if *outLen is less than wc_curve25519_size().
365365
366366
\param [in] key Pointer to the structure from which to export the key.
367367
\param [out] out Pointer to the buffer in which to store the exported key.
@@ -372,7 +372,7 @@ int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
372372
\code
373373
int ret;
374374
byte priv[32];
375-
int privSz;
375+
word32 privSz;
376376
377377
curve25519_key key;
378378
// initialize and make key
@@ -402,7 +402,7 @@ int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
402402
\return 0 Returned on successfully exporting the private key from the
403403
curve25519_key structure.
404404
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
405-
\return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
405+
\return ECC_BAD_ARG_E Returned if *outLen is less than wc_curve25519_size().
406406
407407
\param [in] key Pointer to the structure from which to export the key.
408408
\param [out] out Pointer to the buffer in which to store the exported key.
@@ -416,7 +416,7 @@ int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
416416
int ret;
417417
418418
byte priv[32];
419-
int privSz;
419+
word32 privSz;
420420
curve25519_key key;
421421
// initialize and make key
422422
ret = wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
@@ -656,7 +656,7 @@ int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
656656
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
657657
pubSz is less than CURVE25519_PUB_KEY_SIZE.
658658
659-
\param [in] key Pointer to the curve448_key structure in from which to
659+
\param [in] key Pointer to the curve25519_key structure in from which to
660660
export the key pair.
661661
\param [out] priv Pointer to the buffer in which to store the private key.
662662
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
@@ -702,7 +702,7 @@ int wc_curve25519_export_key_raw(curve25519_key* key,
702702
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
703703
pubSz is less than CURVE25519_PUB_KEY_SIZE.
704704
705-
\param [in] key Pointer to the curve448_key structure in from which to
705+
\param [in] key Pointer to the curve25519_key structure in from which to
706706
export the key pair.
707707
\param [out] priv Pointer to the buffer in which to store the private key.
708708
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
@@ -725,7 +725,7 @@ int wc_curve25519_export_key_raw(curve25519_key* key,
725725
curve25519_key key;
726726
// initialize and make key
727727
728-
ret = wc_curve25519_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
728+
ret = wc_curve25519_export_key_raw_ex(&key, priv, &privSz, pub, &pubSz,
729729
EC25519_BIG_ENDIAN);
730730
if (ret != 0) {
731731
// error exporting key

wrapper/rust/include.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/headers.h
1414
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/aes.rs
1515
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/blake2.rs
1616
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/cmac.rs
17+
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs
1718
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/dh.rs
1819
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs
1920
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs
@@ -30,6 +31,7 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/sys.rs
3031
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs
3132
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2.rs
3233
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_cmac.rs
34+
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs
3335
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_dh.rs
3436
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs
3537
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_ed25519.rs

wrapper/rust/wolfssl-wolfcrypt/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ fn scan_cfg() -> Result<()> {
133133
/* cmac */
134134
check_cfg(&binding, "wc_InitCmac", "cmac");
135135

136+
/* curve25519 */
137+
check_cfg(&binding, "wc_curve25519_make_pub", "curve25519");
138+
check_cfg(&binding, "wc_curve25519_make_pub_blind", "curve25519_blinding");
139+
136140
/* dh */
137141
check_cfg(&binding, "wc_InitDhKey", "dh");
138142
check_cfg(&binding, "wc_DhGenerateParams", "dh_keygen");

wrapper/rust/wolfssl-wolfcrypt/src/blake2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This module provides a Rust wrapper for the wolfCrypt library's BLAKE2
2323
functionality.
2424
*/
2525

26+
#![cfg(any(blake2b, blake2s))]
27+
2628
use crate::sys;
2729
use std::mem::MaybeUninit;
2830

0 commit comments

Comments
 (0)