forked from wolfSSL/wolfssl
Fix line length issues. Add debug msg in test to show number of non-blocking iterations.
``` $ ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" --enable-debug && make $ ./wolfcrypt/test/testwolfcrypt ... ECC non-block sign: 18063 times ECC non-block verify: 35759 times ECC test passed! ```
This commit is contained in:
@@ -4917,11 +4917,13 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
|
|||||||
if (ecc_sets[key->idx].id == ECC_SECP256R1) {
|
if (ecc_sets[key->idx].id == ECC_SECP256R1) {
|
||||||
#ifdef WC_ECC_NONBLOCK
|
#ifdef WC_ECC_NONBLOCK
|
||||||
if (key->nb_ctx) {
|
if (key->nb_ctx) {
|
||||||
return sp_ecc_sign_256_nb(&key->nb_ctx->sp_ctx, in, inlen, rng, &key->k, r, s, sign_k, key->heap);
|
return sp_ecc_sign_256_nb(&key->nb_ctx->sp_ctx, in, inlen, rng,
|
||||||
|
&key->k, r, s, sign_k, key->heap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef WC_ECC_NONBLOCK_ONLY
|
#ifndef WC_ECC_NONBLOCK_ONLY
|
||||||
return sp_ecc_sign_256(in, inlen, rng, &key->k, r, s, sign_k, key->heap);
|
return sp_ecc_sign_256(in, inlen, rng, &key->k, r, s, sign_k,
|
||||||
|
key->heap);
|
||||||
#else
|
#else
|
||||||
return NOT_COMPILED_IN;
|
return NOT_COMPILED_IN;
|
||||||
#endif
|
#endif
|
||||||
@@ -4931,11 +4933,13 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
|
|||||||
if (ecc_sets[key->idx].id == ECC_SECP384R1) {
|
if (ecc_sets[key->idx].id == ECC_SECP384R1) {
|
||||||
#ifdef WC_ECC_NONBLOCK
|
#ifdef WC_ECC_NONBLOCK
|
||||||
if (key->nb_ctx) {
|
if (key->nb_ctx) {
|
||||||
return sp_ecc_sign_384_nb(&key->nb_ctx->sp_ctx, in, inlen, rng, &key->k, r, s, sign_k, key->heap);
|
return sp_ecc_sign_384_nb(&key->nb_ctx->sp_ctx, in, inlen, rng,
|
||||||
|
&key->k, r, s, sign_k, key->heap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef WC_ECC_NONBLOCK_ONLY
|
#ifndef WC_ECC_NONBLOCK_ONLY
|
||||||
return sp_ecc_sign_384(in, inlen, rng, &key->k, r, s, sign_k, key->heap);
|
return sp_ecc_sign_384(in, inlen, rng, &key->k, r, s, sign_k,
|
||||||
|
key->heap);
|
||||||
#else
|
#else
|
||||||
return NOT_COMPILED_IN;
|
return NOT_COMPILED_IN;
|
||||||
#endif
|
#endif
|
||||||
@@ -5985,12 +5989,12 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
|||||||
|
|
||||||
#if defined(WOLFSSL_DSP) && !defined(FREESCALE_LTC_ECC)
|
#if defined(WOLFSSL_DSP) && !defined(FREESCALE_LTC_ECC)
|
||||||
if (key->handle != -1) {
|
if (key->handle != -1) {
|
||||||
return sp_dsp_ecc_verify_256(key->handle, hash, hashlen, key->pubkey.x, key->pubkey.y,
|
return sp_dsp_ecc_verify_256(key->handle, hash, hashlen, key->pubkey.x,
|
||||||
key->pubkey.z, r, s, res, key->heap);
|
key->pubkey.y, key->pubkey.z, r, s, res, key->heap);
|
||||||
}
|
}
|
||||||
if (wolfSSL_GetHandleCbSet() == 1) {
|
if (wolfSSL_GetHandleCbSet() == 1) {
|
||||||
return sp_dsp_ecc_verify_256(0, hash, hashlen, key->pubkey.x, key->pubkey.y,
|
return sp_dsp_ecc_verify_256(0, hash, hashlen, key->pubkey.x,
|
||||||
key->pubkey.z, r, s, res, key->heap);
|
key->pubkey.y, key->pubkey.z, r, s, res, key->heap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -6002,7 +6006,8 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_HAVE_SP_ECC)) && !defined(FREESCALE_LTC_ECC)
|
#if (defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_HAVE_SP_ECC)) && \
|
||||||
|
!defined(FREESCALE_LTC_ECC)
|
||||||
if (key->idx != ECC_CUSTOM_IDX
|
if (key->idx != ECC_CUSTOM_IDX
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
|
||||||
&& key->asyncDev.marker != WOLFSSL_ASYNC_MARKER_ECC
|
&& key->asyncDev.marker != WOLFSSL_ASYNC_MARKER_ECC
|
||||||
@@ -6013,7 +6018,8 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
|||||||
#ifdef WC_ECC_NONBLOCK
|
#ifdef WC_ECC_NONBLOCK
|
||||||
if (key->nb_ctx) {
|
if (key->nb_ctx) {
|
||||||
return sp_ecc_verify_256_nb(&key->nb_ctx->sp_ctx, hash, hashlen,
|
return sp_ecc_verify_256_nb(&key->nb_ctx->sp_ctx, hash, hashlen,
|
||||||
key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res, key->heap);
|
key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res,
|
||||||
|
key->heap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef WC_ECC_NONBLOCK_ONLY
|
#ifndef WC_ECC_NONBLOCK_ONLY
|
||||||
@@ -6029,7 +6035,8 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
|||||||
#ifdef WC_ECC_NONBLOCK
|
#ifdef WC_ECC_NONBLOCK
|
||||||
if (key->nb_ctx) {
|
if (key->nb_ctx) {
|
||||||
return sp_ecc_verify_384_nb(&key->nb_ctx->sp_ctx, hash, hashlen,
|
return sp_ecc_verify_384_nb(&key->nb_ctx->sp_ctx, hash, hashlen,
|
||||||
key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res, key->heap);
|
key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res,
|
||||||
|
key->heap);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef WC_ECC_NONBLOCK_ONLY
|
#ifndef WC_ECC_NONBLOCK_ONLY
|
||||||
|
@@ -20273,7 +20273,7 @@ static int crypto_ecc_verify(const uint8_t *key, uint32_t keySz,
|
|||||||
const uint8_t *hash, uint32_t hashSz, const uint8_t *sig, uint32_t sigSz,
|
const uint8_t *hash, uint32_t hashSz, const uint8_t *sig, uint32_t sigSz,
|
||||||
uint32_t curveSz, int curveId)
|
uint32_t curveSz, int curveId)
|
||||||
{
|
{
|
||||||
int ret, verify_res = 0;
|
int ret, verify_res = 0, count = 0;
|
||||||
mp_int r, s;
|
mp_int r, s;
|
||||||
ecc_key ecc;
|
ecc_key ecc;
|
||||||
ecc_nb_ctx_t nb_ctx;
|
ecc_nb_ctx_t nb_ctx;
|
||||||
@@ -20340,9 +20340,13 @@ static int crypto_ecc_verify(const uint8_t *key, uint32_t keySz,
|
|||||||
&verify_res, /* verification result 1=success */
|
&verify_res, /* verification result 1=success */
|
||||||
&ecc
|
&ecc
|
||||||
);
|
);
|
||||||
|
count++;
|
||||||
|
|
||||||
/* TODO: Real-time work can be called here */
|
/* TODO: Real-time work can be called here */
|
||||||
} while (ret == FP_WOULDBLOCK);
|
} while (ret == FP_WOULDBLOCK);
|
||||||
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
printf("ECC non-block verify: %d times\n", count);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check verify result */
|
/* check verify result */
|
||||||
@@ -20354,6 +20358,8 @@ static int crypto_ecc_verify(const uint8_t *key, uint32_t keySz,
|
|||||||
mp_clear(&s);
|
mp_clear(&s);
|
||||||
wc_ecc_free(&ecc);
|
wc_ecc_free(&ecc);
|
||||||
|
|
||||||
|
(void)count;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20362,7 +20368,7 @@ static int crypto_ecc_sign(const uint8_t *key, uint32_t keySz,
|
|||||||
const uint8_t *hash, uint32_t hashSz, uint8_t *sig, uint32_t* sigSz,
|
const uint8_t *hash, uint32_t hashSz, uint8_t *sig, uint32_t* sigSz,
|
||||||
uint32_t curveSz, int curveId, WC_RNG* rng)
|
uint32_t curveSz, int curveId, WC_RNG* rng)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret, count = 0;
|
||||||
mp_int r, s;
|
mp_int r, s;
|
||||||
ecc_key ecc;
|
ecc_key ecc;
|
||||||
ecc_nb_ctx_t nb_ctx;
|
ecc_nb_ctx_t nb_ctx;
|
||||||
@@ -20418,9 +20424,14 @@ static int crypto_ecc_sign(const uint8_t *key, uint32_t keySz,
|
|||||||
rng, &ecc, /* random and key context */
|
rng, &ecc, /* random and key context */
|
||||||
&r, &s /* r/s as mp_int */
|
&r, &s /* r/s as mp_int */
|
||||||
);
|
);
|
||||||
|
count++;
|
||||||
|
|
||||||
/* TODO: Real-time work can be called here */
|
/* TODO: Real-time work can be called here */
|
||||||
} while (ret == FP_WOULDBLOCK);
|
} while (ret == FP_WOULDBLOCK);
|
||||||
|
|
||||||
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
printf("ECC non-block sign: %d times\n", count);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
@@ -20433,6 +20444,8 @@ static int crypto_ecc_sign(const uint8_t *key, uint32_t keySz,
|
|||||||
mp_clear(&s);
|
mp_clear(&s);
|
||||||
wc_ecc_free(&ecc);
|
wc_ecc_free(&ecc);
|
||||||
|
|
||||||
|
(void)count;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user