mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-07 00:30:51 +02:00
Merge pull request #9721 from dgarske/x25519_nb
Add X25519 non-blocking support and async example improvements
This commit is contained in:
+17
-10
@@ -18467,7 +18467,7 @@ int ConfirmSignature(SignatureCtx* sigCtx,
|
||||
word32 idx = 0;
|
||||
#if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_ASYNC_CRYPT_SW) && \
|
||||
defined(WC_ASYNC_ENABLE_ECC)
|
||||
ecc_nb_ctx_t* nbCtx;
|
||||
ecc_nb_ctx_t* nb_ctx;
|
||||
#endif /* WC_ECC_NONBLOCK && WOLFSSL_ASYNC_CRYPT_SW &&
|
||||
WC_ASYNC_ENABLE_ECC */
|
||||
|
||||
@@ -18485,17 +18485,24 @@ int ConfirmSignature(SignatureCtx* sigCtx,
|
||||
}
|
||||
#if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_ASYNC_CRYPT_SW) && \
|
||||
defined(WC_ASYNC_ENABLE_ECC)
|
||||
nbCtx = (ecc_nb_ctx_t*)XMALLOC(sizeof(ecc_nb_ctx_t),
|
||||
sigCtx->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (nbCtx == NULL) {
|
||||
ERROR_OUT(MEMORY_E, exit_cs);
|
||||
}
|
||||
/* Only set non-blocking context when async device is
|
||||
* active. With INVALID_DEVID there is no async loop to
|
||||
* retry on FP_WOULDBLOCK, so let the WC_ECC_NONBLOCK_ONLY
|
||||
* blocking fallback handle it instead. */
|
||||
if (sigCtx->devId != INVALID_DEVID) {
|
||||
nb_ctx = (ecc_nb_ctx_t*)XMALLOC(sizeof(ecc_nb_ctx_t),
|
||||
sigCtx->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (nb_ctx == NULL) {
|
||||
ERROR_OUT(MEMORY_E, exit_cs);
|
||||
}
|
||||
|
||||
ret = wc_ecc_set_nonblock(sigCtx->key.ecc, nbCtx);
|
||||
if (ret != 0) {
|
||||
goto exit_cs;
|
||||
ret = wc_ecc_set_nonblock(sigCtx->key.ecc, nb_ctx);
|
||||
if (ret != 0) {
|
||||
XFREE(nb_ctx, sigCtx->heap,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
goto exit_cs;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* WC_ECC_NONBLOCK && WOLFSSL_ASYNC_CRYPT_SW &&
|
||||
WC_ASYNC_ENABLE_ECC */
|
||||
ret = wc_EccPublicKeyDecode(key, &idx, sigCtx->key.ecc,
|
||||
|
||||
@@ -268,6 +268,28 @@ static int wolfAsync_DoSw(WC_ASYNC_DEV* asyncDev)
|
||||
break;
|
||||
}
|
||||
#endif /* !NO_DES3 */
|
||||
#ifdef HAVE_CURVE25519
|
||||
case ASYNC_SW_X25519_MAKE:
|
||||
{
|
||||
ret = wc_curve25519_make_key(
|
||||
(WC_RNG*)sw->x25519Make.rng,
|
||||
sw->x25519Make.size,
|
||||
(curve25519_key*)sw->x25519Make.key
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ASYNC_SW_X25519_SHARED_SEC:
|
||||
{
|
||||
ret = wc_curve25519_shared_secret_ex(
|
||||
(curve25519_key*)sw->x25519SharedSec.priv,
|
||||
(curve25519_key*)sw->x25519SharedSec.pub,
|
||||
sw->x25519SharedSec.out,
|
||||
sw->x25519SharedSec.outLen,
|
||||
sw->x25519SharedSec.endian
|
||||
);
|
||||
break;
|
||||
}
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
default:
|
||||
WOLFSSL_MSG("Invalid async crypt SW type!");
|
||||
ret = BAD_FUNC_ARG;
|
||||
|
||||
+277
-74
@@ -22,7 +22,14 @@
|
||||
|
||||
/* Based On Daniel J Bernstein's curve25519 Public Domain ref10 work. */
|
||||
|
||||
#include <wolfssl/wolfcrypt/libwolfssl_sources.h>
|
||||
/*
|
||||
* X25519 configuration macros:
|
||||
*
|
||||
* WC_X25519_NONBLOCK: Enable non-blocking support for key gen and shared
|
||||
* secret. Requires CURVE25519_SMALL. Default: off.
|
||||
*/
|
||||
|
||||
#include <wolfssl/wolfcrypt/libwolfssl_sources.h>
|
||||
|
||||
#ifdef NO_CURVED25519_X64
|
||||
#undef USE_INTEL_SPEEDUP
|
||||
@@ -32,6 +39,8 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/curve25519.h>
|
||||
#include <wolfssl/wolfcrypt/ge_operations.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
@@ -77,7 +86,8 @@ const curve25519_set_type curve25519_sets[] = {
|
||||
|
||||
#if (!defined(WOLFSSL_CURVE25519_USE_ED25519) && \
|
||||
!(defined(CURVED25519_X64) || (defined(WOLFSSL_ARMASM) && \
|
||||
defined(__aarch64__)))) || defined(WOLFSSL_CURVE25519_BLINDING)
|
||||
defined(__aarch64__)))) || defined(WOLFSSL_CURVE25519_BLINDING) || \
|
||||
defined(WC_X25519_NONBLOCK)
|
||||
static const word32 kCurve25519BasePoint[CURVE25519_KEYSIZE/sizeof(word32)] = {
|
||||
#ifdef BIG_ENDIAN_ORDER
|
||||
0x09000000
|
||||
@@ -440,6 +450,85 @@ int wc_curve25519_make_priv(WC_RNG* rng, int keysize, byte* key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
|
||||
static int wc_curve25519_make_pub_nb(curve25519_key* key)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (key == NULL) {
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
else if (key->nb_ctx == NULL) {
|
||||
WOLFSSL_MSG("wc_curve25519_make_pub_nb called with NULL non-blocking "
|
||||
"context.");
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (ret == 0 && key->nb_ctx->state == 0) {
|
||||
/* check clamping */
|
||||
ret = curve25519_priv_clamp_check(key->k);
|
||||
if (ret == 0) {
|
||||
fe_init();
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = curve25519_nb(key->p.point, key->k, (byte*)kCurve25519BasePoint,
|
||||
key->nb_ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int wc_curve25519_make_key_nb(WC_RNG* rng, int keysize,
|
||||
curve25519_key* key)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (key == NULL || rng == NULL) {
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
else if (key->nb_ctx == NULL) {
|
||||
WOLFSSL_MSG("wc_curve25519_make_key_nb called with NULL non-blocking "
|
||||
"context.");
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (ret == 0 && key->nb_ctx->state == 0) {
|
||||
ret = wc_curve25519_make_priv(rng, keysize, key->k);
|
||||
if (ret == 0) {
|
||||
key->privSet = 1;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve25519_make_pub_nb(key);
|
||||
if (ret == 0) {
|
||||
key->pubSet = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_curve25519_set_nonblock(curve25519_key* key, x25519_nb_ctx_t* ctx)
|
||||
{
|
||||
if (key == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
/* If a different context is already set, clear it before replacing.
|
||||
* The caller is responsible for freeing any heap-allocated context. */
|
||||
if (key->nb_ctx != NULL && key->nb_ctx != ctx) {
|
||||
XMEMSET(key->nb_ctx, 0, sizeof(x25519_nb_ctx_t));
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
XMEMSET(ctx, 0, sizeof(x25519_nb_ctx_t));
|
||||
}
|
||||
key->nb_ctx = ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
|
||||
/* generate a new keypair.
|
||||
*
|
||||
* return value is propagated from wc_curve25519_make_private() or
|
||||
@@ -461,26 +550,48 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_X25519) && \
|
||||
defined(WOLFSSL_ASYNC_CRYPT_SW)
|
||||
if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_X25519) {
|
||||
if (wc_AsyncSwInit(&key->asyncDev, ASYNC_SW_X25519_MAKE)) {
|
||||
WC_ASYNC_SW* sw = &key->asyncDev.sw;
|
||||
sw->x25519Make.rng = rng;
|
||||
sw->x25519Make.size = keysize;
|
||||
sw->x25519Make.key = key;
|
||||
return WC_PENDING_E;
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_X25519 &&
|
||||
* WOLFSSL_ASYNC_CRYPT_SW */
|
||||
|
||||
#ifdef WOLFSSL_SE050
|
||||
ret = se050_curve25519_create_key(key, keysize);
|
||||
#else
|
||||
ret = wc_curve25519_make_priv(rng, keysize, key->k);
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
key->pubSet = (ret == 0);
|
||||
#elif defined(WC_X25519_NONBLOCK)
|
||||
if (key->nb_ctx != NULL) {
|
||||
ret = wc_curve25519_make_key_nb(rng, keysize, key);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if !defined(WOLFSSL_SE050)
|
||||
{
|
||||
ret = wc_curve25519_make_priv(rng, keysize, key->k);
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
key->pubSet = (ret == 0);
|
||||
}
|
||||
}
|
||||
#endif /* !WOLFSSL_SE050 */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -494,12 +605,65 @@ int wc_curve25519_shared_secret(curve25519_key* private_key,
|
||||
out, outlen, EC25519_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
|
||||
static int wc_curve25519_shared_secret_nb(curve25519_key* privKey,
|
||||
curve25519_key* pubKey, byte* out, word32* outlen, int endian)
|
||||
{
|
||||
int ret = FP_WOULDBLOCK;
|
||||
|
||||
switch (privKey->nb_ctx->ssState) {
|
||||
case 0:
|
||||
XMEMSET(&privKey->nb_ctx->o, 0, sizeof(privKey->nb_ctx->o));
|
||||
privKey->nb_ctx->ssState = 1;
|
||||
break;
|
||||
case 1:
|
||||
ret = curve25519_nb(privKey->nb_ctx->o.point, privKey->k,
|
||||
pubKey->p.point, privKey->nb_ctx);
|
||||
if (ret == 0) {
|
||||
ret = FP_WOULDBLOCK;
|
||||
privKey->nb_ctx->ssState = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
#ifdef WOLFSSL_ECDHX_SHARED_NOT_ZERO
|
||||
{
|
||||
int i;
|
||||
byte t = 0;
|
||||
|
||||
for (i = 0; i < CURVE25519_KEYSIZE; i++) {
|
||||
t |= privKey->nb_ctx->o.point[i];
|
||||
}
|
||||
if (t == 0) {
|
||||
ret = ECC_OUT_OF_RANGE_E;
|
||||
}
|
||||
else
|
||||
#endif /* WOLFSSL_ECDHX_SHARED_NOT_ZERO */
|
||||
{
|
||||
curve25519_copy_point(out, privKey->nb_ctx->o.point, endian);
|
||||
*outlen = CURVE25519_KEYSIZE;
|
||||
ret = 0;
|
||||
}
|
||||
#ifdef WOLFSSL_ECDHX_SHARED_NOT_ZERO
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != FP_WOULDBLOCK) {
|
||||
XMEMSET(privKey->nb_ctx, 0, sizeof(x25519_nb_ctx_t));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
|
||||
int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
|
||||
curve25519_key* public_key,
|
||||
byte* out, word32* outlen, int endian)
|
||||
{
|
||||
int ret;
|
||||
ECPoint o;
|
||||
int ret = 0;
|
||||
|
||||
/* sanity check */
|
||||
if (private_key == NULL || public_key == NULL ||
|
||||
@@ -531,51 +695,80 @@ int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
|
||||
}
|
||||
#endif
|
||||
|
||||
XMEMSET(&o, 0, sizeof(o));
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
/* input point P on Curve25519 */
|
||||
ret = nxp_ltc_curve25519(&o, private_key->k, &public_key->p,
|
||||
kLTC_Curve25519);
|
||||
#else
|
||||
#ifdef WOLFSSL_SE050
|
||||
if (!private_key->privSet) {
|
||||
/* use NXP SE050: "privSet" is not set */
|
||||
ret = se050_curve25519_shared_secret(private_key, public_key, &o);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_X25519) && \
|
||||
defined(WOLFSSL_ASYNC_CRYPT_SW)
|
||||
if (private_key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_X25519) {
|
||||
if (wc_AsyncSwInit(&private_key->asyncDev,
|
||||
ASYNC_SW_X25519_SHARED_SEC)) {
|
||||
WC_ASYNC_SW* sw = &private_key->asyncDev.sw;
|
||||
sw->x25519SharedSec.priv = private_key;
|
||||
sw->x25519SharedSec.pub = public_key;
|
||||
sw->x25519SharedSec.out = out;
|
||||
sw->x25519SharedSec.outLen = outlen;
|
||||
sw->x25519SharedSec.endian = endian;
|
||||
return WC_PENDING_E;
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_X25519 &&
|
||||
* WOLFSSL_ASYNC_CRYPT_SW */
|
||||
|
||||
if (private_key->nb_ctx != NULL) {
|
||||
ret = wc_curve25519_shared_secret_nb(private_key, public_key, out,
|
||||
outlen, endian);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
{
|
||||
#ifndef WOLFSSL_CURVE25519_BLINDING
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ECPoint o;
|
||||
|
||||
ret = curve25519(o.point, private_key->k, public_key->p.point);
|
||||
XMEMSET(&o, 0, sizeof(o));
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
/* input point P on Curve25519 */
|
||||
ret = nxp_ltc_curve25519(&o, private_key->k, &public_key->p,
|
||||
kLTC_Curve25519);
|
||||
#else
|
||||
ret = curve25519_smul_blind(o.point, private_key->k, public_key->p.point,
|
||||
private_key->rng);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_ECDHX_SHARED_NOT_ZERO
|
||||
if (ret == 0) {
|
||||
int i;
|
||||
byte t = 0;
|
||||
for (i = 0; i < CURVE25519_KEYSIZE; i++) {
|
||||
t |= o.point[i];
|
||||
#ifdef WOLFSSL_SE050
|
||||
if (!private_key->privSet) {
|
||||
/* use NXP SE050: "privSet" is not set */
|
||||
ret = se050_curve25519_shared_secret(private_key, public_key, &o);
|
||||
}
|
||||
if (t == 0) {
|
||||
ret = ECC_OUT_OF_RANGE_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (ret == 0) {
|
||||
curve25519_copy_point(out, o.point, endian);
|
||||
*outlen = CURVE25519_KEYSIZE;
|
||||
}
|
||||
else
|
||||
#endif /* WOLFSSL_SE050 */
|
||||
{
|
||||
#ifndef WOLFSSL_CURVE25519_BLINDING
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
ForceZero(&o, sizeof(o));
|
||||
ret = curve25519(o.point, private_key->k, public_key->p.point);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
#else
|
||||
ret = curve25519_smul_blind(o.point, private_key->k,
|
||||
public_key->p.point, private_key->rng);
|
||||
#endif
|
||||
}
|
||||
#endif /* FREESCALE_LTC_ECC */
|
||||
#ifdef WOLFSSL_ECDHX_SHARED_NOT_ZERO
|
||||
if (ret == 0) {
|
||||
int i;
|
||||
byte t = 0;
|
||||
for (i = 0; i < CURVE25519_KEYSIZE; i++) {
|
||||
t |= o.point[i];
|
||||
}
|
||||
if (t == 0) {
|
||||
ret = ECC_OUT_OF_RANGE_E;
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_ECDHX_SHARED_NOT_ZERO */
|
||||
if (ret == 0) {
|
||||
curve25519_copy_point(out, o.point, endian);
|
||||
*outlen = CURVE25519_KEYSIZE;
|
||||
}
|
||||
|
||||
ForceZero(&o, sizeof(o));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -931,30 +1124,40 @@ int wc_curve25519_delete(curve25519_key* key, curve25519_key** key_p) {
|
||||
|
||||
int wc_curve25519_init_ex(curve25519_key* key, void* heap, int devId)
|
||||
{
|
||||
if (key == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
int ret = 0;
|
||||
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
if (key == NULL) {
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
else {
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
|
||||
/* currently the format for curve25519 */
|
||||
key->dp = &curve25519_sets[0];
|
||||
/* currently the format for curve25519 */
|
||||
key->dp = &curve25519_sets[0];
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
key->devId = devId;
|
||||
#else
|
||||
(void)devId;
|
||||
#endif
|
||||
(void)heap; /* if needed for XMALLOC/XFREE in future */
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
key->devId = devId;
|
||||
#else
|
||||
(void)devId;
|
||||
#endif
|
||||
(void)heap; /* if needed for XMALLOC/XFREE in future */
|
||||
|
||||
#ifndef FREESCALE_LTC_ECC
|
||||
fe_init();
|
||||
#endif
|
||||
#ifndef FREESCALE_LTC_ECC
|
||||
fe_init();
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_CHECK_MEM_ZERO
|
||||
wc_MemZero_Add("wc_curve25519_init_ex key->k", key->k, CURVE25519_KEYSIZE);
|
||||
#endif
|
||||
#ifdef WOLFSSL_CHECK_MEM_ZERO
|
||||
wc_MemZero_Add("wc_curve25519_init_ex key->k", key->k,
|
||||
CURVE25519_KEYSIZE);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_X25519)
|
||||
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_X25519,
|
||||
heap, devId);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_curve25519_init(curve25519_key* key)
|
||||
|
||||
+12
-6
@@ -55,7 +55,7 @@ Possible ECC enable options:
|
||||
* WOLFSSL_ECC_CURVE_STATIC: default off (on for windows)
|
||||
* For the ECC curve parameters `ecc_set_type` use fixed
|
||||
* array for hex string
|
||||
* WC_ECC_NONBLOCK: Enable non-blocking support for sign/verify.
|
||||
* WC_ECC_NONBLOCK: Enable non-blocking support for sign/verify/keygen/secret.
|
||||
* Requires SP with WOLFSSL_SP_NONBLOCK
|
||||
* WC_ECC_NONBLOCK_ONLY Enable the non-blocking function only, no fall-back to
|
||||
* normal blocking API's
|
||||
@@ -15627,12 +15627,18 @@ int wc_ecc_get_key_id(ecc_key* key, word32* keyId)
|
||||
/* Enable ECC support for non-blocking operations */
|
||||
int wc_ecc_set_nonblock(ecc_key *key, ecc_nb_ctx_t* ctx)
|
||||
{
|
||||
if (key) {
|
||||
if (ctx) {
|
||||
XMEMSET(ctx, 0, sizeof(ecc_nb_ctx_t));
|
||||
}
|
||||
key->nb_ctx = ctx;
|
||||
if (key == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
/* If a different context is already set, clear it before replacing.
|
||||
* The caller is responsible for freeing any heap-allocated context. */
|
||||
if (key->nb_ctx != NULL && key->nb_ctx != ctx) {
|
||||
XMEMSET(key->nb_ctx, 0, sizeof(ecc_nb_ctx_t));
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
XMEMSET(ctx, 0, sizeof(ecc_nb_ctx_t));
|
||||
}
|
||||
key->nb_ctx = ctx;
|
||||
return 0;
|
||||
}
|
||||
#endif /* WC_ECC_NONBLOCK */
|
||||
|
||||
@@ -179,6 +179,256 @@ int curve25519(byte *result, const byte *n, const byte *p)
|
||||
fe_normalize(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
|
||||
int fe_inv__distinct_nb(byte *r, const byte *x, fe_inv__distinct_nb_ctx_t* ctx)
|
||||
{
|
||||
int ret = FP_WOULDBLOCK;
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0:
|
||||
fe_mul__distinct(ctx->s, x, x);
|
||||
fe_mul__distinct(r, ctx->s, x);
|
||||
ctx->i = 0;
|
||||
ctx->subState = 0;
|
||||
ctx->state = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (ctx->i < 248) {
|
||||
if (ctx->subState == 0) {
|
||||
fe_mul__distinct(ctx->s, r, r);
|
||||
ctx->subState = 1;
|
||||
}
|
||||
else {
|
||||
fe_mul__distinct(r, ctx->s, x);
|
||||
ctx->subState = 0;
|
||||
++(ctx->i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx->state = 2;
|
||||
ctx->subState = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (ctx->subState) {
|
||||
case 0:
|
||||
fe_mul__distinct(ctx->s, r, r);
|
||||
ctx->subState = 1;
|
||||
break;
|
||||
case 1:
|
||||
fe_mul__distinct(r, ctx->s, ctx->s);
|
||||
ctx->subState = 2;
|
||||
break;
|
||||
case 2:
|
||||
fe_mul__distinct(ctx->s, r, x);
|
||||
ctx->subState = 3;
|
||||
break;
|
||||
case 3:
|
||||
fe_mul__distinct(r, ctx->s, ctx->s);
|
||||
ctx->subState = 4;
|
||||
break;
|
||||
case 4:
|
||||
fe_mul__distinct(ctx->s, r, r);
|
||||
ctx->subState = 5;
|
||||
break;
|
||||
case 5:
|
||||
fe_mul__distinct(r, ctx->s, x);
|
||||
ctx->subState = 6;
|
||||
break;
|
||||
case 6:
|
||||
fe_mul__distinct(ctx->s, r, r);
|
||||
ctx->subState = 7;
|
||||
break;
|
||||
case 7:
|
||||
fe_mul__distinct(r, ctx->s, x);
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
ctx->subState = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
XMEMSET(ctx, 0, sizeof(fe_inv__distinct_nb_ctx_t));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int curve25519_nb(byte *result, const byte *n, const byte *p,
|
||||
struct x25519_nb_ctx_t* ctx)
|
||||
{
|
||||
int ret = FP_WOULDBLOCK;
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0:
|
||||
XMEMSET(ctx->zm, 0, sizeof(ctx->zm));
|
||||
ctx->zm[0] = 1;
|
||||
XMEMSET(ctx->xm1, 0, sizeof(ctx->xm1));
|
||||
ctx->xm1[0] = 1;
|
||||
XMEMSET(ctx->zm1, 0, sizeof(ctx->zm1));
|
||||
lm_copy(ctx->xm, p);
|
||||
ctx->i = 253;
|
||||
ctx->subState = 0;
|
||||
ctx->state = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (ctx->i >= 0) {
|
||||
switch (ctx->subState) {
|
||||
case 0:
|
||||
ctx->bit = (n[ctx->i >> 3] >> (ctx->i & 7)) & 1;
|
||||
/* Diffadd step 1 */
|
||||
lm_add(ctx->a, ctx->xm, ctx->zm);
|
||||
lm_sub(ctx->b, ctx->xm1, ctx->zm1);
|
||||
fe_mul__distinct(ctx->da, ctx->a, ctx->b);
|
||||
ctx->subState = 1;
|
||||
break;
|
||||
case 1:
|
||||
/* Diffadd step 2 */
|
||||
lm_sub(ctx->b, ctx->xm, ctx->zm);
|
||||
lm_add(ctx->a, ctx->xm1, ctx->zm1);
|
||||
fe_mul__distinct(ctx->cb, ctx->a, ctx->b);
|
||||
ctx->subState = 2;
|
||||
break;
|
||||
case 2:
|
||||
/* Diffadd step 3 */
|
||||
lm_add(ctx->a, ctx->da, ctx->cb);
|
||||
fe_mul__distinct(ctx->b, ctx->a, ctx->a);
|
||||
ctx->subState = 3;
|
||||
break;
|
||||
case 3:
|
||||
/* Diffadd step 4 */
|
||||
fe_mul__distinct(ctx->xm1, f25519_one, ctx->b);
|
||||
ctx->subState = 4;
|
||||
break;
|
||||
case 4:
|
||||
/* Diffadd step 5 */
|
||||
lm_sub(ctx->a, ctx->da, ctx->cb);
|
||||
fe_mul__distinct(ctx->b, ctx->a, ctx->a);
|
||||
ctx->subState = 5;
|
||||
break;
|
||||
case 5:
|
||||
/* Diffadd step 6 */
|
||||
fe_mul__distinct(ctx->zm1, p, ctx->b);
|
||||
ctx->subState = 6;
|
||||
break;
|
||||
case 6:
|
||||
/* Double step 1 */
|
||||
fe_mul__distinct(ctx->x1sq, ctx->xm, ctx->xm);
|
||||
ctx->subState = 7;
|
||||
break;
|
||||
case 7:
|
||||
/* Double step 2 */
|
||||
fe_mul__distinct(ctx->z1sq, ctx->zm, ctx->zm);
|
||||
ctx->subState = 8;
|
||||
break;
|
||||
case 8:
|
||||
/* Double step 3 */
|
||||
fe_mul__distinct(ctx->x1z1, ctx->xm, ctx->zm);
|
||||
ctx->subState = 9;
|
||||
break;
|
||||
case 9:
|
||||
/* Double step 4 */
|
||||
lm_sub(ctx->a, ctx->x1sq, ctx->z1sq);
|
||||
fe_mul__distinct(ctx->xm, ctx->a, ctx->a);
|
||||
ctx->subState = 10;
|
||||
break;
|
||||
case 10:
|
||||
/* Double step 5 */
|
||||
fe_mul_c(ctx->a, ctx->x1z1, 486662);
|
||||
lm_add(ctx->a, ctx->x1sq, ctx->a);
|
||||
lm_add(ctx->a, ctx->z1sq, ctx->a);
|
||||
fe_mul__distinct(ctx->x1sq, ctx->x1z1, ctx->a);
|
||||
ctx->subState = 11;
|
||||
break;
|
||||
case 11:
|
||||
fe_mul_c(ctx->zm, ctx->x1sq, 4);
|
||||
ctx->subState = 12;
|
||||
break;
|
||||
case 12:
|
||||
/* Diffadd2 step 1 */
|
||||
lm_add(ctx->a, ctx->xm, ctx->zm);
|
||||
lm_sub(ctx->b, p, f25519_one);
|
||||
fe_mul__distinct(ctx->da, ctx->a, ctx->b);
|
||||
ctx->subState = 13;
|
||||
break;
|
||||
case 13:
|
||||
/* Diffadd2 step 2 */
|
||||
lm_sub(ctx->b, ctx->xm, ctx->zm);
|
||||
lm_add(ctx->a, p, f25519_one);
|
||||
fe_mul__distinct(ctx->cb, ctx->a, ctx->b);
|
||||
ctx->subState = 14;
|
||||
break;
|
||||
case 14:
|
||||
/* Diffadd2 step 3 */
|
||||
lm_add(ctx->a, ctx->da, ctx->cb);
|
||||
fe_mul__distinct(ctx->b, ctx->a, ctx->a);
|
||||
ctx->subState = 15;
|
||||
break;
|
||||
case 15:
|
||||
/* Diffadd2 step 4 */
|
||||
fe_mul__distinct(ctx->xms, ctx->zm1, ctx->b);
|
||||
ctx->subState = 16;
|
||||
break;
|
||||
case 16:
|
||||
/* Diffadd2 step 5 */
|
||||
lm_sub(ctx->a, ctx->da, ctx->cb);
|
||||
fe_mul__distinct(ctx->b, ctx->a, ctx->a);
|
||||
ctx->subState = 17;
|
||||
break;
|
||||
case 17:
|
||||
/* Diffadd2 step 6 */
|
||||
fe_mul__distinct(ctx->zms, ctx->xm1, ctx->b);
|
||||
ctx->subState = 18;
|
||||
break;
|
||||
case 18:
|
||||
/* Select:
|
||||
* bit = 1 --> (P_(2m+1), P_(2m))
|
||||
* bit = 0 --> (P_(2m), P_(2m-1))
|
||||
*/
|
||||
fe_select(ctx->xm1, ctx->xm1, ctx->xm, ctx->bit);
|
||||
fe_select(ctx->zm1, ctx->zm1, ctx->zm, ctx->bit);
|
||||
fe_select(ctx->xm, ctx->xm, ctx->xms, ctx->bit);
|
||||
fe_select(ctx->zm, ctx->zm, ctx->zms, ctx->bit);
|
||||
--(ctx->i);
|
||||
ctx->subState = 0;
|
||||
break;
|
||||
default:
|
||||
ctx->subState = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx->state = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
/* Freeze out of projective coordinates */
|
||||
if (fe_inv__distinct_nb(ctx->zm1, ctx->zm,
|
||||
&ctx->inv_distinct_nb_ctx) == 0) {
|
||||
ctx->state = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
fe_mul__distinct(result, ctx->zm1, ctx->xm);
|
||||
fe_normalize(result);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
XMEMSET(ctx, 0, sizeof(x25519_nb_ctx_t));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
|
||||
#endif /* !FREESCALE_LTC_ECC */
|
||||
#endif /* CURVE25519_SMALL */
|
||||
|
||||
|
||||
+12
-12
@@ -74917,6 +74917,9 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_8_ctx* ctx = (sp_256_proj_point_add_8_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -74924,9 +74927,6 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -92908,6 +92908,9 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_12_ctx* ctx = (sp_384_proj_point_add_12_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -92915,9 +92918,6 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -119987,6 +119987,9 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_17_ctx* ctx = (sp_521_proj_point_add_17_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -119994,9 +119997,6 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -150008,6 +150008,9 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_32_ctx* ctx = (sp_1024_proj_point_add_32_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -150015,9 +150018,6 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+12
-12
@@ -23532,6 +23532,9 @@ static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_4_ctx* ctx = (sp_256_proj_point_add_4_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -23539,9 +23542,6 @@ static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -44108,6 +44108,9 @@ static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_6_ctx* ctx = (sp_384_proj_point_add_6_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -44115,9 +44118,6 @@ static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -72055,6 +72055,9 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_9_ctx* ctx = (sp_521_proj_point_add_9_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -72062,9 +72065,6 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -115721,6 +115721,9 @@ static int sp_1024_proj_point_add_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_16_ctx* ctx = (sp_1024_proj_point_add_16_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -115728,9 +115731,6 @@ static int sp_1024_proj_point_add_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+12
-12
@@ -100369,6 +100369,9 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_8_ctx* ctx = (sp_256_proj_point_add_8_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -100376,9 +100379,6 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -110760,6 +110760,9 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_12_ctx* ctx = (sp_384_proj_point_add_12_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -110767,9 +110770,6 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -123926,6 +123926,9 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_17_ctx* ctx = (sp_521_proj_point_add_17_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -123933,9 +123936,6 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -208389,6 +208389,9 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_32_ctx* ctx = (sp_1024_proj_point_add_32_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -208396,9 +208399,6 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+12
-12
@@ -19982,6 +19982,9 @@ static int sp_256_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_9_ctx* ctx = (sp_256_proj_point_add_9_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -19989,9 +19992,6 @@ static int sp_256_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -26983,6 +26983,9 @@ static int sp_384_proj_point_add_15_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_15_ctx* ctx = (sp_384_proj_point_add_15_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_15_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -26990,9 +26993,6 @@ static int sp_384_proj_point_add_15_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_15_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -34228,6 +34228,9 @@ static int sp_521_proj_point_add_21_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_21_ctx* ctx = (sp_521_proj_point_add_21_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_21_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -34235,9 +34238,6 @@ static int sp_521_proj_point_add_21_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_21_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -42594,6 +42594,9 @@ static int sp_1024_proj_point_add_42_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_42_ctx* ctx = (sp_1024_proj_point_add_42_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_42_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -42601,9 +42604,6 @@ static int sp_1024_proj_point_add_42_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_42_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+12
-12
@@ -20599,6 +20599,9 @@ static int sp_256_proj_point_add_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_5_ctx* ctx = (sp_256_proj_point_add_5_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -20606,9 +20609,6 @@ static int sp_256_proj_point_add_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -27087,6 +27087,9 @@ static int sp_384_proj_point_add_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_7_ctx* ctx = (sp_384_proj_point_add_7_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -27094,9 +27097,6 @@ static int sp_384_proj_point_add_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -34191,6 +34191,9 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_9_ctx* ctx = (sp_521_proj_point_add_9_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -34198,9 +34201,6 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -41643,6 +41643,9 @@ static int sp_1024_proj_point_add_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_18_ctx* ctx = (sp_1024_proj_point_add_18_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_18_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -41650,9 +41653,6 @@ static int sp_1024_proj_point_add_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_18_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+12
-12
@@ -36307,6 +36307,9 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_8_ctx* ctx = (sp_256_proj_point_add_8_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -36314,9 +36317,6 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -46218,6 +46218,9 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_12_ctx* ctx = (sp_384_proj_point_add_12_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -46225,9 +46228,6 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -58009,6 +58009,9 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_17_ctx* ctx = (sp_521_proj_point_add_17_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -58016,9 +58019,6 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -72548,6 +72548,9 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_32_ctx* ctx = (sp_1024_proj_point_add_32_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -72555,9 +72558,6 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+24
-24
@@ -8505,6 +8505,9 @@ static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_4_ctx* ctx = (sp_256_proj_point_add_4_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -8512,9 +8515,6 @@ static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -9606,6 +9606,9 @@ static int sp_256_proj_point_add_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_proj_point_add_avx2_4_ctx* ctx = (sp_256_proj_point_add_avx2_4_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_avx2_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_256* a = p;
|
||||
@@ -9613,9 +9616,6 @@ static int sp_256_proj_point_add_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_avx2_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -27196,6 +27196,9 @@ static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_6_ctx* ctx = (sp_384_proj_point_add_6_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -27203,9 +27206,6 @@ static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -28350,6 +28350,9 @@ static int sp_384_proj_point_add_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_proj_point_add_avx2_6_ctx* ctx = (sp_384_proj_point_add_avx2_6_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_avx2_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_384* a = p;
|
||||
@@ -28357,9 +28360,6 @@ static int sp_384_proj_point_add_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_avx2_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -51673,6 +51673,9 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_9_ctx* ctx = (sp_521_proj_point_add_9_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -51680,9 +51683,6 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -52804,6 +52804,9 @@ static int sp_521_proj_point_add_avx2_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_521_proj_point_add_avx2_9_ctx* ctx = (sp_521_proj_point_add_avx2_9_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_avx2_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_521* a = p;
|
||||
@@ -52811,9 +52814,6 @@ static int sp_521_proj_point_add_avx2_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_avx2_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -92503,6 +92503,9 @@ static int sp_1024_proj_point_add_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_16_ctx* ctx = (sp_1024_proj_point_add_16_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -92510,9 +92513,6 @@ static int sp_1024_proj_point_add_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
@@ -93604,6 +93604,9 @@ static int sp_1024_proj_point_add_avx2_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_1024_proj_point_add_avx2_16_ctx* ctx = (sp_1024_proj_point_add_avx2_16_ctx*)sp_ctx->data;
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_avx2_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
/* Ensure only the first point is the same as the result. */
|
||||
if (q == r) {
|
||||
const sp_point_1024* a = p;
|
||||
@@ -93611,9 +93614,6 @@ static int sp_1024_proj_point_add_avx2_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024
|
||||
q = a;
|
||||
}
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_avx2_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
switch (ctx->state) {
|
||||
case 0: /* INIT */
|
||||
ctx->t6 = t;
|
||||
|
||||
+184
-4
@@ -38247,7 +38247,12 @@ static wc_test_ret_t curve25519_overflow_test(WC_RNG* rng)
|
||||
/* test against known test vector */
|
||||
XMEMSET(shared, 0, sizeof(shared));
|
||||
y = sizeof(shared);
|
||||
if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
|
||||
ret = wc_curve25519_shared_secret(&userA, &userA, shared, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userA.asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ret = WC_TEST_RET_ENC_I(i); break;
|
||||
}
|
||||
|
||||
@@ -38625,6 +38630,131 @@ static wc_test_ret_t curve255519_der_test(void)
|
||||
}
|
||||
#endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
|
||||
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
/* build and test with:
|
||||
* ./configure --enable-curve25519=nonblock CFLAGS="-DWOLFSSL_DEBUG_NONBLOCK"
|
||||
* make
|
||||
* ./wolfcrypt/test/testwolfcrypt
|
||||
*/
|
||||
static int x25519_nonblock_test(WC_RNG* rng)
|
||||
{
|
||||
int ret = 0;
|
||||
x25519_nb_ctx_t nb_ctx;
|
||||
curve25519_key userA;
|
||||
curve25519_key userB;
|
||||
#ifdef HAVE_CURVE25519_SHARED_SECRET
|
||||
byte sharedA[32];
|
||||
byte sharedB[32];
|
||||
word32 x;
|
||||
word32 y;
|
||||
#endif
|
||||
int count;
|
||||
|
||||
XMEMSET(&nb_ctx, 0, sizeof(nb_ctx));
|
||||
|
||||
ret = wc_curve25519_init(&userA);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_init 1 %d\n", ret);
|
||||
return -10722;
|
||||
}
|
||||
ret = wc_curve25519_set_nonblock(&userA, &nb_ctx);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_set_nonblock 1 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
return -10723;
|
||||
}
|
||||
count = 0;
|
||||
do {
|
||||
ret = wc_curve25519_make_key(rng, 32, &userA);
|
||||
count++;
|
||||
} while (ret == FP_WOULDBLOCK);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_make_key_nb 1 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
return -10724;
|
||||
}
|
||||
#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
|
||||
/* CURVE25519 non-block key gen: 5335 times */
|
||||
printf("CURVE25519 non-block key gen: %d times\n", count);
|
||||
#endif
|
||||
|
||||
ret = wc_curve25519_init(&userB);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_init 2 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
return -10724;
|
||||
}
|
||||
ret = wc_curve25519_set_nonblock(&userB, &nb_ctx);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_set_nonblock 2 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10725;
|
||||
}
|
||||
count = 0;
|
||||
do {
|
||||
ret = wc_curve25519_make_key(rng, 32, &userB);
|
||||
count++;
|
||||
} while (ret == FP_WOULDBLOCK);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_make_key_nb 2 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10726;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CURVE25519_SHARED_SECRET
|
||||
x = sizeof(sharedA);
|
||||
do {
|
||||
ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x);
|
||||
} while (ret == FP_WOULDBLOCK);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_shared_secret_nb 1 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10727;
|
||||
}
|
||||
|
||||
y = sizeof(sharedB);
|
||||
count = 0;
|
||||
do {
|
||||
ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y);
|
||||
count++;
|
||||
}
|
||||
while (ret == FP_WOULDBLOCK);
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_shared_secret_nb 2 %d\n", ret);
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10728;
|
||||
}
|
||||
#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
|
||||
/* CURVE25519 non-block shared secret: 5337 times */
|
||||
printf("CURVE25519 non-block shared secret: %d times\n", count);
|
||||
#endif
|
||||
|
||||
/* compare shared secret keys to test they are the same */
|
||||
if (y != x) {
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10729;
|
||||
}
|
||||
|
||||
if (XMEMCMP(sharedA, sharedB, x) != 0) {
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
return -10730;
|
||||
}
|
||||
#endif /* HAVE_CURVE25519_SHARED_SECRET */
|
||||
|
||||
wc_curve25519_free(&userA);
|
||||
wc_curve25519_free(&userB);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
|
||||
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
{
|
||||
WC_RNG rng;
|
||||
@@ -38726,23 +38856,41 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
|
||||
/* make curve25519 keys */
|
||||
ret = wc_curve25519_make_key(&rng, 32, userA);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
ret = wc_curve25519_make_key(&rng, 32, userB);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
#ifdef HAVE_CURVE25519_SHARED_SECRET
|
||||
/* find shared secret key */
|
||||
x = sizeof(sharedA);
|
||||
if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
|
||||
ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_shared_secret 1 failed\n");
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
}
|
||||
|
||||
y = sizeof(sharedB);
|
||||
if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
|
||||
ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
printf("wc_curve25519_shared_secret 2 failed\n");
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
}
|
||||
@@ -38774,7 +38922,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
/* test shared key after importing a public key */
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
y = sizeof(sharedB);
|
||||
if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
|
||||
ret = wc_curve25519_shared_secret(userB, pubKey, sharedB, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
|
||||
}
|
||||
|
||||
@@ -38796,6 +38949,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
y = sizeof(sharedB);
|
||||
ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
@@ -38806,6 +38963,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
XMEMSET(sharedB, 0, sizeof(sharedB));
|
||||
y = sizeof(sharedB);
|
||||
ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
@@ -38825,16 +38986,28 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
#endif
|
||||
|
||||
ret = wc_curve25519_make_key(&rng, 32, userB);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
x = sizeof(sharedA);
|
||||
ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
y = sizeof(sharedB);
|
||||
ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
|
||||
ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
|
||||
|
||||
@@ -38860,6 +39033,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
|
||||
goto cleanup;
|
||||
#endif
|
||||
|
||||
#ifdef WC_X25519_NONBLOCK
|
||||
ret = x25519_nonblock_test(&rng);
|
||||
if (ret != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* WC_X25519_NONBLOCK */
|
||||
|
||||
cleanup:
|
||||
|
||||
/* clean up keys when done */
|
||||
|
||||
Reference in New Issue
Block a user