Skip to content

Commit

Permalink
Merge branch 'jacob-ed'
Browse files Browse the repository at this point in the history
  • Loading branch information
toddouska committed Mar 19, 2015
2 parents 5577555 + 478a8bb commit b54c294
Show file tree
Hide file tree
Showing 16 changed files with 4,532 additions and 504 deletions.
29 changes: 28 additions & 1 deletion configure.ac
Expand Up @@ -643,14 +643,39 @@ AC_ARG_ENABLE([ecc25519],

if test "$ENABLED_ECC25519" = "yes"
then
ENABLED_FEMATH=yes
AM_CFLAGS="$AM_CFLAGS -DHAVE_ECC25519"
fi


AM_CONDITIONAL([BUILD_ECC25519], [test "x$ENABLED_ECC25519" = "xyes"])


# FP ECC, Fixed Point cache ECC
# ED25519
AC_ARG_ENABLE([ed25519],
[AS_HELP_STRING([--enable-ed25519],[Enable ED25519 (default: disabled)])],
[ ENABLED_ED25519=$enableval ],
[ ENABLED_ED25519=no ]
)


if test "$ENABLED_ED25519" = "yes"
then
if test "$ENABLED_SHA512" = "no"
then
AC_MSG_ERROR([cannot enable ed25519 without enabling sha512.])
fi
ENABLED_FEMATH=yes
ENABLED_GEMATH=yes
AM_CFLAGS="$AM_CFLAGS -DHAVE_ED25519"
fi


AM_CONDITIONAL([BUILD_ED25519], [test "x$ENABLED_ED25519" = "xyes"])
AM_CONDITIONAL([BUILD_FEMATH], [test "x$ENABLED_FEMATH" = "xyes"])
AM_CONDITIONAL([BUILD_GEMATH], [test "x$ENABLED_GEMATH" = "xyes"])

# FP ECC, Fixed Point cache ECC
AC_ARG_ENABLE([fpecc],
[ --enable-fpecc Enable Fixed Point cache ECC (default: disabled)],
[ ENABLED_FPECC=$enableval ],
Expand Down Expand Up @@ -1934,6 +1959,8 @@ echo " * RSA: $ENABLED_RSA"
echo " * DSA: $ENABLED_DSA"
echo " * DH: $ENABLED_DH"
echo " * ECC: $ENABLED_ECC"
echo " * CURVE25519: $ENABLED_ECC25519"
echo " * ED25519: $ENABLED_ED25519"
echo " * FPECC: $ENABLED_FPECC"
echo " * ECC_ENCRYPT: $ENABLED_ECC_ENCRYPT"
echo " * ASN: $ENABLED_ASN"
Expand Down
13 changes: 12 additions & 1 deletion src/include.am
Expand Up @@ -169,7 +169,18 @@ endif

if BUILD_ECC25519
src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc25519.c
src_libwolfssl_la_SOURCES += wolfcrypt/src/ecc25519_fe.c
endif

if BUILD_ED25519
src_libwolfssl_la_SOURCES += wolfcrypt/src/ed25519.c
endif

if BUILD_FEMATH
src_libwolfssl_la_SOURCES += wolfcrypt/src/fe_operations.c
endif

if BUILD_GEMATH
src_libwolfssl_la_SOURCES += wolfcrypt/src/ge_operations.c
endif

if BUILD_LIBZ
Expand Down
105 changes: 105 additions & 0 deletions wolfcrypt/benchmark/benchmark.c
Expand Up @@ -60,6 +60,9 @@
#ifdef HAVE_ECC25519
#include <wolfssl/wolfcrypt/ecc25519.h>
#endif
#ifdef HAVE_ED25519
#include <wolfssl/wolfcrypt/ed25519.h>
#endif

#include <wolfssl/wolfcrypt/dh.h>
#ifdef HAVE_CAVIUM
Expand Down Expand Up @@ -143,6 +146,10 @@ void bench_eccKeyAgree(void);
void bench_ecc25519KeyGen(void);
void bench_ecc25519KeyAgree(void);
#endif
#ifdef HAVE_ED25519
void bench_ed25519KeyGen(void);
void bench_ed25519KeySign(void);
#endif
#ifdef HAVE_NTRU
void bench_ntru(void);
void bench_ntruKeyGen(void);
Expand Down Expand Up @@ -354,6 +361,11 @@ int benchmark_test(void *args)
bench_ecc25519KeyAgree();
#endif

#ifdef HAVE_ED25519
bench_ed25519KeyGen();
bench_ed25519KeySign();
#endif

#if defined(HAVE_LOCAL_RNG) && (defined(HAVE_HASHDRBG) || defined(NO_RC4))
wc_FreeRng(&rng);
#endif
Expand Down Expand Up @@ -1704,6 +1716,99 @@ void bench_ecc25519KeyAgree(void)
}
#endif /* HAVE_ECC25519 */

#ifdef HAVE_ED25519
void bench_ed25519KeyGen(void)
{
ed25519_key genKey;
double start, total, each, milliEach;
int i;

/* 256 bit */
start = current_time(1);

for(i = 0; i < genTimes; i++) {
wc_ed25519_init(&genKey);
wc_ed25519_make_key(&rng, 32, &genKey);
wc_ed25519_free(&genKey);
}

total = current_time(0) - start;
each = total / genTimes; /* per second */
milliEach = each * 1000; /* millisconds */
printf("\n");
printf("ED25519 key generation %6.3f milliseconds, avg over %d"
" iterations\n", milliEach, genTimes);
}


void bench_ed25519KeySign(void)
{
ed25519_key genKey, genKey2;
double start, total, each, milliEach;
int i, ret;
byte sig[ED25519_SIG_SIZE];
byte digest[32];
word32 x = 0;

wc_ed25519_init(&genKey);
wc_ed25519_init(&genKey2);

ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &genKey);
if (ret != 0) {
printf("ed25519_make_key failed\n");
return;
}
ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &genKey2);
if (ret != 0) {
printf("ed25519_make_key failed\n");
return;
}

/* make dummy digest */
for (i = 0; i < (int)sizeof(digest); i++)
digest[i] = (byte)i;


start = current_time(1);

for(i = 0; i < agreeTimes; i++) {
x = sizeof(sig);
ret = wc_ed25519_sign_msg(digest, sizeof(digest), sig, &x, &genKey);
if (ret != 0) {
printf("ed25519_sign_hash failed\n");
return;
}
}

total = current_time(0) - start;
each = total / agreeTimes; /* per second */
milliEach = each * 1000; /* millisconds */
printf("ED25519 sign time %6.3f milliseconds, avg over %d"
" iterations\n", milliEach, agreeTimes);

start = current_time(1);

for(i = 0; i < agreeTimes; i++) {
int verify = 0;
ret = wc_ed25519_verify_msg(sig, x, digest, sizeof(digest), &verify,
&genKey);
if (ret != 0 || verify != 1) {
printf("ed25519_verify_hash failed\n");
return;
}
}

total = current_time(0) - start;
each = total / agreeTimes; /* per second */
milliEach = each * 1000; /* millisconds */
printf("ED25519 verify time %6.3f milliseconds, avg over %d"
" iterations\n", milliEach, agreeTimes);

wc_ed25519_free(&genKey2);
wc_ed25519_free(&genKey);
}
#endif /* HAVE_ED25519 */


#ifdef _WIN32

Expand Down
21 changes: 20 additions & 1 deletion wolfcrypt/src/ecc25519.c
Expand Up @@ -81,7 +81,26 @@ static int curve25519(unsigned char* q, unsigned char* n, unsigned char* p)
fe_cswap(x2,x3,swap);
fe_cswap(z2,z3,swap);
swap = b;
#include <wolfssl/wolfcrypt/ecc25519_montgomery.h>

/* montgomery */
fe_sub(tmp0,x3,z3);
fe_sub(tmp1,x2,z2);
fe_add(x2,x2,z2);
fe_add(z2,x3,z3);
fe_mul(z3,tmp0,x2);
fe_mul(z2,z2,tmp1);
fe_sq(tmp0,tmp1);
fe_sq(tmp1,x2);
fe_add(x3,z3,z2);
fe_sub(z2,z3,z2);
fe_mul(x2,tmp1,tmp0);
fe_sub(tmp1,tmp1,tmp0);
fe_sq(z2,z2);
fe_mul121666(z3,tmp1);
fe_sq(x3,x3);
fe_add(tmp0,tmp0,z3);
fe_mul(z3,x1,z2);
fe_mul(z2,tmp1,tmp0);
}
fe_cswap(x2,x3,swap);
fe_cswap(z2,z3,swap);
Expand Down

0 comments on commit b54c294

Please sign in to comment.