mirror of https://github.com/wolfSSL/wolfssl
rename ecc25519 to curve25519, less confusing with ed25519 now in play too
This commit is contained in:
parent
fe303c97c6
commit
8f6d7a1ce7
20
configure.ac
20
configure.ac
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
#
|
||||
|
||||
AC_INIT([wolfssl],[3.4.3],[https://github.com/wolfssl/wolfssl/issues],[wolfssl],[http://www.wolfssl.com])
|
||||
AC_INIT([wolfssl],[3.4.4],[https://github.com/wolfssl/wolfssl/issues],[wolfssl],[http://www.wolfssl.com])
|
||||
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
|
||||
|
@ -634,21 +634,21 @@ then
|
|||
fi
|
||||
|
||||
|
||||
# ECC25519
|
||||
AC_ARG_ENABLE([ecc25519],
|
||||
[AS_HELP_STRING([--enable-ecc25519],[Enable ECC25519 (default: disabled)])],
|
||||
[ ENABLED_ECC25519=$enableval ],
|
||||
[ ENABLED_ECC25519=no ]
|
||||
# CURVE25519
|
||||
AC_ARG_ENABLE([curve25519],
|
||||
[AS_HELP_STRING([--enable-curve25519],[Enable Curve25519 (default: disabled)])],
|
||||
[ ENABLED_CURVE25519=$enableval ],
|
||||
[ ENABLED_CURVE25519=no ]
|
||||
)
|
||||
|
||||
if test "$ENABLED_ECC25519" = "yes"
|
||||
if test "$ENABLED_CURVE25519" = "yes"
|
||||
then
|
||||
ENABLED_FEMATH=yes
|
||||
AM_CFLAGS="$AM_CFLAGS -DHAVE_ECC25519"
|
||||
AM_CFLAGS="$AM_CFLAGS -DHAVE_CURVE25519"
|
||||
fi
|
||||
|
||||
|
||||
AM_CONDITIONAL([BUILD_ECC25519], [test "x$ENABLED_ECC25519" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_CURVE25519], [test "x$ENABLED_CURVE25519" = "xyes"])
|
||||
|
||||
|
||||
# ED25519
|
||||
|
@ -1959,7 +1959,7 @@ echo " * RSA: $ENABLED_RSA"
|
|||
echo " * DSA: $ENABLED_DSA"
|
||||
echo " * DH: $ENABLED_DH"
|
||||
echo " * ECC: $ENABLED_ECC"
|
||||
echo " * CURVE25519: $ENABLED_ECC25519"
|
||||
echo " * CURVE25519: $ENABLED_CURVE25519"
|
||||
echo " * ED25519: $ENABLED_ED25519"
|
||||
echo " * FPECC: $ENABLED_FPECC"
|
||||
echo " * ECC_ENCRYPT: $ENABLED_ECC_ENCRYPT"
|
||||
|
|
|
@ -167,8 +167,8 @@ if BUILD_ECC
|
|||
src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc.c
|
||||
endif
|
||||
|
||||
if BUILD_ECC25519
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc25519.c
|
||||
if BUILD_CURVE25519
|
||||
src_libwolfssl_la_SOURCES += wolfcrypt/src/curve25519.c
|
||||
endif
|
||||
|
||||
if BUILD_ED25519
|
||||
|
|
|
@ -5,6 +5,6 @@ includedir=${prefix}/include
|
|||
|
||||
Name: wolfssl
|
||||
Description: wolfssl C library.
|
||||
Version: 3.4.3
|
||||
Version: 3.4.4
|
||||
Libs: -L${libdir} -lwolfssl
|
||||
Cflags: -I${includedir}
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
#ifdef HAVE_ECC
|
||||
#include <wolfssl/wolfcrypt/ecc.h>
|
||||
#endif
|
||||
#ifdef HAVE_ECC25519
|
||||
#include <wolfssl/wolfcrypt/ecc25519.h>
|
||||
#ifdef HAVE_CURVE25519
|
||||
#include <wolfssl/wolfcrypt/curve25519.h>
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
#include <wolfssl/wolfcrypt/ed25519.h>
|
||||
|
@ -142,9 +142,9 @@ void bench_dh(void);
|
|||
void bench_eccKeyGen(void);
|
||||
void bench_eccKeyAgree(void);
|
||||
#endif
|
||||
#ifdef HAVE_ECC25519
|
||||
void bench_ecc25519KeyGen(void);
|
||||
void bench_ecc25519KeyAgree(void);
|
||||
#ifdef HAVE_CURVE25519
|
||||
void bench_curve25519KeyGen(void);
|
||||
void bench_curve25519KeyAgree(void);
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
void bench_ed25519KeyGen(void);
|
||||
|
@ -356,9 +356,9 @@ int benchmark_test(void *args)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
bench_ecc25519KeyGen();
|
||||
bench_ecc25519KeyAgree();
|
||||
#ifdef HAVE_CURVE25519
|
||||
bench_curve25519KeyGen();
|
||||
bench_curve25519KeyAgree();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
|
@ -1647,10 +1647,10 @@ void bench_eccKeyAgree(void)
|
|||
}
|
||||
#endif /* HAVE_ECC */
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
void bench_ecc25519KeyGen(void)
|
||||
#ifdef HAVE_CURVE25519
|
||||
void bench_curve25519KeyGen(void)
|
||||
{
|
||||
ecc25519_key genKey;
|
||||
curve25519_key genKey;
|
||||
double start, total, each, milliEach;
|
||||
int i;
|
||||
|
||||
|
@ -1658,38 +1658,38 @@ void bench_ecc25519KeyGen(void)
|
|||
start = current_time(1);
|
||||
|
||||
for(i = 0; i < genTimes; i++) {
|
||||
wc_ecc25519_make_key(&rng, 32, &genKey);
|
||||
wc_ecc25519_free(&genKey);
|
||||
wc_curve25519_make_key(&rng, 32, &genKey);
|
||||
wc_curve25519_free(&genKey);
|
||||
}
|
||||
|
||||
total = current_time(0) - start;
|
||||
each = total / genTimes; /* per second */
|
||||
milliEach = each * 1000; /* millisconds */
|
||||
printf("\n");
|
||||
printf("ECC25519 256 key generation %6.3f milliseconds, avg over %d"
|
||||
printf("CURVE25519 256 key generation %6.3f milliseconds, avg over %d"
|
||||
" iterations\n", milliEach, genTimes);
|
||||
}
|
||||
|
||||
|
||||
void bench_ecc25519KeyAgree(void)
|
||||
void bench_curve25519KeyAgree(void)
|
||||
{
|
||||
ecc25519_key genKey, genKey2;
|
||||
curve25519_key genKey, genKey2;
|
||||
double start, total, each, milliEach;
|
||||
int i, ret;
|
||||
byte shared[1024];
|
||||
word32 x = 0;
|
||||
|
||||
wc_ecc25519_init(&genKey);
|
||||
wc_ecc25519_init(&genKey2);
|
||||
wc_curve25519_init(&genKey);
|
||||
wc_curve25519_init(&genKey2);
|
||||
|
||||
ret = wc_ecc25519_make_key(&rng, 32, &genKey);
|
||||
ret = wc_curve25519_make_key(&rng, 32, &genKey);
|
||||
if (ret != 0) {
|
||||
printf("ecc25519_make_key failed\n");
|
||||
printf("curve25519_make_key failed\n");
|
||||
return;
|
||||
}
|
||||
ret = wc_ecc25519_make_key(&rng, 32, &genKey2);
|
||||
ret = wc_curve25519_make_key(&rng, 32, &genKey2);
|
||||
if (ret != 0) {
|
||||
printf("ecc25519_make_key failed\n");
|
||||
printf("curve25519_make_key failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1698,9 +1698,9 @@ void bench_ecc25519KeyAgree(void)
|
|||
|
||||
for(i = 0; i < agreeTimes; i++) {
|
||||
x = sizeof(shared);
|
||||
ret = wc_ecc25519_shared_secret(&genKey, &genKey2, shared, &x);
|
||||
ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
|
||||
if (ret != 0) {
|
||||
printf("ecc25519_shared_secret failed\n");
|
||||
printf("curve25519_shared_secret failed\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1708,13 +1708,13 @@ void bench_ecc25519KeyAgree(void)
|
|||
total = current_time(0) - start;
|
||||
each = total / agreeTimes; /* per second */
|
||||
milliEach = each * 1000; /* millisconds */
|
||||
printf("ECC25519 key agreement %6.3f milliseconds, avg over %d"
|
||||
printf("CURVE25519 key agreement %6.3f milliseconds, avg over %d"
|
||||
" iterations\n", milliEach, agreeTimes);
|
||||
|
||||
wc_ecc25519_free(&genKey2);
|
||||
wc_ecc25519_free(&genKey);
|
||||
wc_curve25519_free(&genKey2);
|
||||
wc_curve25519_free(&genKey);
|
||||
}
|
||||
#endif /* HAVE_ECC25519 */
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
void bench_ed25519KeyGen(void)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* ecc25519.c
|
||||
/* curve25519.c
|
||||
*
|
||||
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||
*
|
||||
|
@ -28,9 +28,9 @@
|
|||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
#ifdef HAVE_CURVE25519
|
||||
|
||||
#include <wolfssl/wolfcrypt/ecc25519.h>
|
||||
#include <wolfssl/wolfcrypt/curve25519.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
|
@ -38,7 +38,7 @@
|
|||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
const ecc25519_set_type ecc25519_sets[] = {
|
||||
const curve25519_set_type curve25519_sets[] = {
|
||||
{
|
||||
32,
|
||||
"CURVE25519",
|
||||
|
@ -113,11 +113,11 @@ static int curve25519(unsigned char* q, unsigned char* n, unsigned char* p)
|
|||
}
|
||||
|
||||
|
||||
int wc_ecc25519_make_key(RNG* rng, int keysize, ecc25519_key* key)
|
||||
int wc_curve25519_make_key(RNG* rng, int keysize, curve25519_key* key)
|
||||
{
|
||||
unsigned char basepoint[ECC25519_KEYSIZE] = {9};
|
||||
unsigned char n[ECC25519_KEYSIZE];
|
||||
unsigned char p[ECC25519_KEYSIZE];
|
||||
unsigned char basepoint[CURVE25519_KEYSIZE] = {9};
|
||||
unsigned char n[CURVE25519_KEYSIZE];
|
||||
unsigned char p[CURVE25519_KEYSIZE];
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
|
@ -125,7 +125,7 @@ int wc_ecc25519_make_key(RNG* rng, int keysize, ecc25519_key* key)
|
|||
return ECC_BAD_ARG_E;
|
||||
|
||||
/* currently only a key size of 32 bytes is used */
|
||||
if (keysize != ECC25519_KEYSIZE)
|
||||
if (keysize != CURVE25519_KEYSIZE)
|
||||
return ECC_BAD_ARG_E;
|
||||
|
||||
/* get random number from RNG */
|
||||
|
@ -155,12 +155,13 @@ int wc_ecc25519_make_key(RNG* rng, int keysize, ecc25519_key* key)
|
|||
}
|
||||
|
||||
|
||||
int wc_ecc25519_shared_secret(ecc25519_key* private_key, ecc25519_key* public_key,
|
||||
byte* out, word32* outlen)
|
||||
int wc_curve25519_shared_secret(curve25519_key* private_key,
|
||||
curve25519_key* public_key,
|
||||
byte* out, word32* outlen)
|
||||
{
|
||||
unsigned char k[ECC25519_KEYSIZE];
|
||||
unsigned char p[ECC25519_KEYSIZE];
|
||||
unsigned char o[ECC25519_KEYSIZE];
|
||||
unsigned char k[CURVE25519_KEYSIZE];
|
||||
unsigned char p[CURVE25519_KEYSIZE];
|
||||
unsigned char o[CURVE25519_KEYSIZE];
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
|
@ -175,18 +176,18 @@ int wc_ecc25519_shared_secret(ecc25519_key* private_key, ecc25519_key* public_ke
|
|||
|
||||
XMEMSET(p, 0, sizeof(p));
|
||||
XMEMSET(k, 0, sizeof(k));
|
||||
XMEMSET(out, 0, ECC25519_KEYSIZE);
|
||||
XMEMSET(out, 0, CURVE25519_KEYSIZE);
|
||||
|
||||
for (i = 0; i < ECC25519_KEYSIZE; ++i) {
|
||||
p[i] = public_key->p.point [ECC25519_KEYSIZE - i - 1];
|
||||
k[i] = private_key->k.point[ECC25519_KEYSIZE - i - 1];
|
||||
for (i = 0; i < CURVE25519_KEYSIZE; ++i) {
|
||||
p[i] = public_key->p.point [CURVE25519_KEYSIZE - i - 1];
|
||||
k[i] = private_key->k.point[CURVE25519_KEYSIZE - i - 1];
|
||||
}
|
||||
|
||||
ret = curve25519(o , k, p);
|
||||
*outlen = ECC25519_KEYSIZE;
|
||||
*outlen = CURVE25519_KEYSIZE;
|
||||
|
||||
for (i = 0; i < ECC25519_KEYSIZE; ++i) {
|
||||
out[i] = o[ECC25519_KEYSIZE - i -1];
|
||||
for (i = 0; i < CURVE25519_KEYSIZE; ++i) {
|
||||
out[i] = o[CURVE25519_KEYSIZE - i -1];
|
||||
}
|
||||
|
||||
ForceZero(p, sizeof(p));
|
||||
|
@ -198,7 +199,7 @@ int wc_ecc25519_shared_secret(ecc25519_key* private_key, ecc25519_key* public_ke
|
|||
|
||||
|
||||
/* curve25519 uses a serialized string for key representation */
|
||||
int wc_ecc25519_export_public(ecc25519_key* key, byte* out, word32* outLen)
|
||||
int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen)
|
||||
{
|
||||
word32 keySz;
|
||||
|
||||
|
@ -206,7 +207,7 @@ int wc_ecc25519_export_public(ecc25519_key* key, byte* out, word32* outLen)
|
|||
return BAD_FUNC_ARG;
|
||||
|
||||
/* check size of outgoing key */
|
||||
keySz = wc_ecc25519_size(key);
|
||||
keySz = wc_curve25519_size(key);
|
||||
|
||||
/* copy in public key */
|
||||
XMEMCPY(out, key->p.point, keySz);
|
||||
|
@ -217,7 +218,8 @@ int wc_ecc25519_export_public(ecc25519_key* key, byte* out, word32* outLen)
|
|||
|
||||
/* import curve25519 public key
|
||||
return 0 on success */
|
||||
int wc_ecc25519_import_public(const byte* in, word32 inLen, ecc25519_key* key)
|
||||
int wc_curve25519_import_public(const byte* in, word32 inLen,
|
||||
curve25519_key* key)
|
||||
{
|
||||
word32 keySz;
|
||||
|
||||
|
@ -226,13 +228,13 @@ int wc_ecc25519_import_public(const byte* in, word32 inLen, ecc25519_key* key)
|
|||
return ECC_BAD_ARG_E;
|
||||
|
||||
/* check size of incoming keys */
|
||||
keySz = wc_ecc25519_size(key);
|
||||
keySz = wc_curve25519_size(key);
|
||||
if (inLen != keySz)
|
||||
return ECC_BAD_ARG_E;
|
||||
|
||||
XMEMCPY(key->p.point, in, inLen);
|
||||
|
||||
key->dp = &ecc25519_sets[0];
|
||||
key->dp = &curve25519_sets[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -240,7 +242,8 @@ int wc_ecc25519_import_public(const byte* in, word32 inLen, ecc25519_key* key)
|
|||
|
||||
/* export curve25519 private key only raw, outLen is in/out size
|
||||
return 0 on success */
|
||||
int wc_ecc25519_export_private_raw(ecc25519_key* key, byte* out, word32* outLen)
|
||||
int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
|
||||
word32* outLen)
|
||||
{
|
||||
word32 keySz;
|
||||
|
||||
|
@ -248,7 +251,7 @@ int wc_ecc25519_export_private_raw(ecc25519_key* key, byte* out, word32* outLen)
|
|||
if (key == NULL || out == NULL || outLen == NULL)
|
||||
return ECC_BAD_ARG_E;
|
||||
|
||||
keySz = wc_ecc25519_size(key);
|
||||
keySz = wc_curve25519_size(key);
|
||||
*outLen = keySz;
|
||||
XMEMSET(out, 0, keySz);
|
||||
XMEMCPY(out, key->k.point, keySz);
|
||||
|
@ -259,8 +262,8 @@ int wc_ecc25519_export_private_raw(ecc25519_key* key, byte* out, word32* outLen)
|
|||
|
||||
/* curve25519 private key import.
|
||||
Public key to match private key needs to be imported too */
|
||||
int wc_ecc25519_import_private_raw(const byte* priv, word32 privSz,
|
||||
const byte* pub, word32 pubSz, ecc25519_key* key)
|
||||
int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
|
||||
const byte* pub, word32 pubSz, curve25519_key* key)
|
||||
{
|
||||
int ret = 0;
|
||||
word32 keySz;
|
||||
|
@ -270,7 +273,7 @@ int wc_ecc25519_import_private_raw(const byte* priv, word32 privSz,
|
|||
return ECC_BAD_ARG_E;
|
||||
|
||||
/* check size of incoming keys */
|
||||
keySz = wc_ecc25519_size(key);
|
||||
keySz = wc_curve25519_size(key);
|
||||
if (privSz != keySz || pubSz != keySz)
|
||||
return ECC_BAD_ARG_E;
|
||||
|
||||
|
@ -281,7 +284,7 @@ int wc_ecc25519_import_private_raw(const byte* priv, word32 privSz,
|
|||
}
|
||||
|
||||
|
||||
int wc_ecc25519_init(ecc25519_key* key)
|
||||
int wc_curve25519_init(curve25519_key* key)
|
||||
{
|
||||
word32 keySz;
|
||||
|
||||
|
@ -289,7 +292,7 @@ int wc_ecc25519_init(ecc25519_key* key)
|
|||
return ECC_BAD_ARG_E;
|
||||
|
||||
/* currently the format for curve25519 */
|
||||
key->dp = &ecc25519_sets[0];
|
||||
key->dp = &curve25519_sets[0];
|
||||
keySz = key->dp->size;
|
||||
|
||||
XMEMSET(key->k.point, 0, keySz);
|
||||
|
@ -300,7 +303,7 @@ int wc_ecc25519_init(ecc25519_key* key)
|
|||
|
||||
|
||||
/* Clean the memory of a key */
|
||||
void wc_ecc25519_free(ecc25519_key* key)
|
||||
void wc_curve25519_free(curve25519_key* key)
|
||||
{
|
||||
if (key == NULL)
|
||||
return;
|
||||
|
@ -312,12 +315,12 @@ void wc_ecc25519_free(ecc25519_key* key)
|
|||
|
||||
|
||||
/* get key size */
|
||||
int wc_ecc25519_size(ecc25519_key* key)
|
||||
int wc_curve25519_size(curve25519_key* key)
|
||||
{
|
||||
if (key == NULL) return 0;
|
||||
|
||||
return key->dp->size;
|
||||
}
|
||||
|
||||
#endif /*HAVE_ECC25519*/
|
||||
#endif /*HAVE_CURVE25519*/
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#if defined(HAVE_ED25519) || defined(HAVE_ECC25519)
|
||||
#if defined(HAVE_ED25519) || defined(HAVE_CURVE25519)
|
||||
|
||||
#include <wolfssl/wolfcrypt/fe_operations.h>
|
||||
#include <stdint.h>
|
||||
|
@ -1332,5 +1332,5 @@ void fe_cmov(fe f,const fe g,unsigned int b)
|
|||
f[8] = f8 ^ x8;
|
||||
f[9] = f9 ^ x9;
|
||||
}
|
||||
#endif /* HAVE ED25519 or ECC25519 */
|
||||
#endif /* HAVE ED25519 or CURVE25519 */
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@
|
|||
#ifdef HAVE_ECC
|
||||
#include <wolfssl/wolfcrypt/ecc.h>
|
||||
#endif
|
||||
#ifdef HAVE_ECC25519
|
||||
#include <wolfssl/wolfcrypt/ecc25519.h>
|
||||
#ifdef HAVE_CURVE25519
|
||||
#include <wolfssl/wolfcrypt/curve25519.h>
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
#include <wolfssl/wolfcrypt/ed25519.h>
|
||||
|
@ -191,8 +191,8 @@ int pbkdf2_test(void);
|
|||
int ecc_encrypt_test(void);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_ECC25519
|
||||
int ecc25519_test(void);
|
||||
#ifdef HAVE_CURVE25519
|
||||
int curve25519_test(void);
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
int ed25519_test(void);
|
||||
|
@ -523,11 +523,11 @@ int wolfcrypt_test(void* args)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
if ( (ret = ecc25519_test()) != 0)
|
||||
return err_sys("ECC25519 test failed!\n", ret);
|
||||
#ifdef HAVE_CURVE25519
|
||||
if ( (ret = curve25519_test()) != 0)
|
||||
return err_sys("CURVE25519 test failed!\n", ret);
|
||||
else
|
||||
printf( "ECC25519 test passed!\n");
|
||||
printf( "CURVE25519 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
|
@ -5209,16 +5209,16 @@ int ecc_encrypt_test(void)
|
|||
#endif /* HAVE_ECC */
|
||||
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
#ifdef HAVE_CURVE25519
|
||||
|
||||
int ecc25519_test(void)
|
||||
int curve25519_test(void)
|
||||
{
|
||||
RNG rng;
|
||||
byte sharedA[1024];
|
||||
byte sharedB[1024];
|
||||
word32 x, y;
|
||||
byte exportBuf[1024];
|
||||
ecc25519_key userA, userB, pubKey;
|
||||
curve25519_key userA, userB, pubKey;
|
||||
|
||||
/* test vectors from
|
||||
https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
|
||||
|
@ -5267,22 +5267,22 @@ int ecc25519_test(void)
|
|||
if (wc_InitRng(&rng) != 0)
|
||||
return -1001;
|
||||
|
||||
wc_ecc25519_init(&userA);
|
||||
wc_ecc25519_init(&userB);
|
||||
wc_ecc25519_init(&pubKey);
|
||||
wc_curve25519_init(&userA);
|
||||
wc_curve25519_init(&userB);
|
||||
wc_curve25519_init(&pubKey);
|
||||
|
||||
/* make curve25519 keys */
|
||||
if (wc_ecc25519_make_key(&rng, 32, &userA) != 0)
|
||||
if (wc_curve25519_make_key(&rng, 32, &userA) != 0)
|
||||
return -1002;
|
||||
|
||||
if (wc_ecc25519_make_key(&rng, 32, &userB) != 0)
|
||||
if (wc_curve25519_make_key(&rng, 32, &userB) != 0)
|
||||
return -1003;
|
||||
|
||||
/* find shared secret key */
|
||||
if (wc_ecc25519_shared_secret(&userA, &userB, sharedA, &x) != 0)
|
||||
if (wc_curve25519_shared_secret(&userA, &userB, sharedA, &x) != 0)
|
||||
return -1004;
|
||||
|
||||
if (wc_ecc25519_shared_secret(&userB, &userA, sharedB, &y) != 0)
|
||||
if (wc_curve25519_shared_secret(&userB, &userA, sharedB, &y) != 0)
|
||||
return -1005;
|
||||
|
||||
/* compare shared secret keys to test they are the same */
|
||||
|
@ -5293,32 +5293,32 @@ int ecc25519_test(void)
|
|||
return -1007;
|
||||
|
||||
/* export a public key and import it for another user */
|
||||
if (wc_ecc25519_export_public(&userA, exportBuf, &x) != 0)
|
||||
if (wc_curve25519_export_public(&userA, exportBuf, &x) != 0)
|
||||
return -1008;
|
||||
|
||||
if (wc_ecc25519_import_public(exportBuf, x, &pubKey) != 0)
|
||||
if (wc_curve25519_import_public(exportBuf, x, &pubKey) != 0)
|
||||
return -1009;
|
||||
|
||||
/* test shared key after importing a public key */
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
if (wc_ecc25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0)
|
||||
if (wc_curve25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0)
|
||||
return -1010;
|
||||
|
||||
if (XMEMCMP(sharedA, sharedB, y))
|
||||
return -1011;
|
||||
|
||||
/* import RFC test vectors and compare shared key */
|
||||
if (wc_ecc25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA)
|
||||
if (wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA)
|
||||
!= 0)
|
||||
return -1012;
|
||||
|
||||
if (wc_ecc25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB)
|
||||
if (wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB)
|
||||
!= 0)
|
||||
return -1013;
|
||||
|
||||
/* test against known test vector */
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
if (wc_ecc25519_shared_secret(&userA, &userB, sharedB, &y) != 0)
|
||||
if (wc_curve25519_shared_secret(&userA, &userB, sharedB, &y) != 0)
|
||||
return -1014;
|
||||
|
||||
if (XMEMCMP(ss, sharedB, y))
|
||||
|
@ -5326,22 +5326,22 @@ int ecc25519_test(void)
|
|||
|
||||
/* test swaping roles of keys and generating same shared key */
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
if (wc_ecc25519_shared_secret(&userB, &userA, sharedB, &y) != 0)
|
||||
if (wc_curve25519_shared_secret(&userB, &userA, sharedB, &y) != 0)
|
||||
return -1016;
|
||||
|
||||
if (XMEMCMP(ss, sharedB, y))
|
||||
return -1017;
|
||||
|
||||
/* clean up keys when done */
|
||||
wc_ecc25519_free(&pubKey);
|
||||
wc_ecc25519_free(&userB);
|
||||
wc_ecc25519_free(&userA);
|
||||
wc_curve25519_free(&pubKey);
|
||||
wc_curve25519_free(&userB);
|
||||
wc_curve25519_free(&userA);
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_ECC25519 */
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LIBWOLFSSL_VERSION_STRING "3.4.3"
|
||||
#define LIBWOLFSSL_VERSION_HEX 0x03004003
|
||||
#define LIBWOLFSSL_VERSION_STRING "3.4.4"
|
||||
#define LIBWOLFSSL_VERSION_HEX 0x03004004
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* ecc25519.h
|
||||
/* curve25519.h
|
||||
*
|
||||
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||
*
|
||||
|
@ -19,12 +19,12 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef WOLF_CRYPT_ECC25519_H
|
||||
#define WOLF_CRYPT_ECC25519_H
|
||||
#ifndef WOLF_CRYPT_CURVE25519_H
|
||||
#define WOLF_CRYPT_CURVE25519_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
#ifdef HAVE_ECC25519
|
||||
#ifdef HAVE_CURVE25519
|
||||
|
||||
#include <wolfssl/wolfcrypt/fe_operations.h>
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
|
@ -33,67 +33,70 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ECC25519_KEYSIZE 32
|
||||
#define CURVE25519_KEYSIZE 32
|
||||
|
||||
/* ECC set type */
|
||||
/* curve25519 set type */
|
||||
typedef struct {
|
||||
int size; /* The size of the curve in octets */
|
||||
const char* name; /* name of this curve */
|
||||
} ecc25519_set_type;
|
||||
} curve25519_set_type;
|
||||
|
||||
|
||||
/* ECC point */
|
||||
typedef struct {
|
||||
byte point[ECC25519_KEYSIZE];
|
||||
byte point[CURVE25519_KEYSIZE];
|
||||
}ECPoint;
|
||||
|
||||
/* An ECC25519 Key */
|
||||
/* A CURVE25519 Key */
|
||||
typedef struct {
|
||||
int idx; /* Index into the ecc_sets[] for the parameters of
|
||||
this curve if -1, this key is using user supplied
|
||||
curve in dp */
|
||||
const ecc25519_set_type* dp; /* domain parameters, either points to
|
||||
const curve25519_set_type* dp; /* domain parameters, either points to
|
||||
curves (idx >= 0) or user supplied */
|
||||
ECPoint p; /* public key */
|
||||
ECPoint k; /* private key */
|
||||
} ecc25519_key;
|
||||
} curve25519_key;
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_make_key(RNG* rng, int keysize, ecc25519_key* key);
|
||||
int wc_curve25519_make_key(RNG* rng, int keysize, curve25519_key* key);
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_shared_secret(ecc25519_key* private_key, ecc25519_key* public_key,
|
||||
byte* out, word32* outlen);
|
||||
int wc_curve25519_shared_secret(curve25519_key* private_key,
|
||||
curve25519_key* public_key,
|
||||
byte* out, word32* outlen);
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_init(ecc25519_key* key);
|
||||
int wc_curve25519_init(curve25519_key* key);
|
||||
|
||||
WOLFSSL_API
|
||||
void wc_ecc25519_free(ecc25519_key* key);
|
||||
void wc_curve25519_free(curve25519_key* key);
|
||||
|
||||
|
||||
/* raw key helpers */
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_import_private_raw(const byte* priv, word32 privSz,
|
||||
const byte* pub, word32 pubSz, ecc25519_key* key);
|
||||
int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
|
||||
const byte* pub, word32 pubSz, curve25519_key* key);
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_export_private_raw(ecc25519_key* key, byte* out, word32* outLen);
|
||||
int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
|
||||
word32* outLen);
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_import_public(const byte* in, word32 inLen, ecc25519_key* key);
|
||||
int wc_curve25519_import_public(const byte* in, word32 inLen,
|
||||
curve25519_key* key);
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_export_public(ecc25519_key* key, byte* out, word32* outLen);
|
||||
int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
|
||||
|
||||
|
||||
/* size helper */
|
||||
WOLFSSL_API
|
||||
int wc_ecc25519_size(ecc25519_key* key);
|
||||
int wc_curve25519_size(curve25519_key* key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_ECC25519 */
|
||||
#endif /* WOLF_CRYPT_ECC25519_H */
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
#endif /* WOLF_CRYPT_CURVE25519_H */
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#if defined(HAVE_ECC25519) || defined(HAVE_ED25519)
|
||||
#if defined(HAVE_CURVE25519) || defined(HAVE_ED25519)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -62,6 +62,6 @@ WOLFSSL_LOCAL void fe_pow22523(fe,const fe);
|
|||
WOLFSSL_LOCAL uint64_t load_3(const unsigned char *in);
|
||||
WOLFSSL_LOCAL uint64_t load_4(const unsigned char *in);
|
||||
|
||||
#endif /* HAVE_ECC25519 or HAVE_ED25519 */
|
||||
#endif /* HAVE_CURVE25519 or HAVE_ED25519 */
|
||||
#endif /* WOLF_CRYPT_FE_OPERATIONS_H */
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ nobase_include_HEADERS+= \
|
|||
wolfssl/wolfcrypt/dh.h \
|
||||
wolfssl/wolfcrypt/dsa.h \
|
||||
wolfssl/wolfcrypt/ecc.h \
|
||||
wolfssl/wolfcrypt/ecc25519.h \
|
||||
wolfssl/wolfcrypt/curve25519.h \
|
||||
wolfssl/wolfcrypt/ed25519.h \
|
||||
wolfssl/wolfcrypt/fe_operations.h \
|
||||
wolfssl/wolfcrypt/ge_operations.h \
|
||||
|
|
Loading…
Reference in New Issue