mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Fixes to WOLFSSL_ATECC508A
support to enable use of wc_ecc_export_x963_ex
and wc_ecc_import_x963_ex
. These changes are experimental (builds, but not tested).
This commit is contained in:
@@ -1292,6 +1292,16 @@ int wc_ecc_set_curve(ecc_key* key, int keysize, int curve_id)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ALT_ECC_SIZE
|
||||||
|
static void alt_fp_init(fp_int* a)
|
||||||
|
{
|
||||||
|
a->size = FP_SIZE_ECC;
|
||||||
|
fp_zero(a);
|
||||||
|
}
|
||||||
|
#endif /* ALT_ECC_SIZE */
|
||||||
|
|
||||||
|
|
||||||
#ifndef WOLFSSL_ATECC508A
|
#ifndef WOLFSSL_ATECC508A
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2326,17 +2336,7 @@ int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
|
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* !WOLFSSL_ATECC508A */
|
||||||
#ifdef ALT_ECC_SIZE
|
|
||||||
|
|
||||||
static void alt_fp_init(fp_int* a)
|
|
||||||
{
|
|
||||||
a->size = FP_SIZE_ECC;
|
|
||||||
fp_zero(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* ALT_ECC_SIZE */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use a heap hint when creating new ecc_point
|
* use a heap hint when creating new ecc_point
|
||||||
@@ -2454,8 +2454,6 @@ int wc_ecc_cmp_point(ecc_point* a, ecc_point *b)
|
|||||||
return MP_EQ;
|
return MP_EQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !WOLFSSL_ATECC508A */
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns whether an ECC idx is valid or not
|
/** Returns whether an ECC idx is valid or not
|
||||||
n The idx number to check
|
n The idx number to check
|
||||||
@@ -2710,7 +2708,7 @@ int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
err = atcatls_ecdh(private_key->slot, public_key->pubkey, out);
|
err = atcatls_ecdh(private_key->slot, public_key->pubkey_raw, out);
|
||||||
if (err != ATCA_SUCCESS) {
|
if (err != ATCA_SUCCESS) {
|
||||||
err = BAD_COND_E;
|
err = BAD_COND_E;
|
||||||
}
|
}
|
||||||
@@ -3190,10 +3188,16 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
|
|||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
key->type = ECC_PRIVATEKEY;
|
key->type = ECC_PRIVATEKEY;
|
||||||
err = atcatls_create_key(key->slot, key->pubkey);
|
err = atcatls_create_key(key->slot, key->pubkey_raw);
|
||||||
if (err != ATCA_SUCCESS)
|
if (err != ATCA_SUCCESS) {
|
||||||
err = BAD_COND_E;
|
err = BAD_COND_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* populate key->pubkey */
|
||||||
|
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw, 32);
|
||||||
|
if (err = MP_OKAY)
|
||||||
|
err = mp_read_unsigned_bin(key->pubkey.y, key->pubkey_raw + 32, 32);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef WOLFSSL_HAVE_SP_ECC
|
#ifdef WOLFSSL_HAVE_SP_ECC
|
||||||
@@ -4176,7 +4180,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = atcatls_verify(hash, sigRS, key->pubkey, (bool*)res);
|
err = atcatls_verify(hash, sigRS, key->pubkey_raw, (bool*)res);
|
||||||
if (err != ATCA_SUCCESS) {
|
if (err != ATCA_SUCCESS) {
|
||||||
return BAD_COND_E;
|
return BAD_COND_E;
|
||||||
}
|
}
|
||||||
@@ -4426,6 +4430,11 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ATECC508A
|
||||||
|
/* populate key->pubkey_raw */
|
||||||
|
XMEMCPY(key->pubkey_raw, (byte*)in+1, PUB_KEY_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* read data */
|
/* read data */
|
||||||
if (err == MP_OKAY)
|
if (err == MP_OKAY)
|
||||||
err = mp_read_unsigned_bin(point->x, (byte*)in+1, (inLen-1)>>1);
|
err = mp_read_unsigned_bin(point->x, (byte*)in+1, (inLen-1)>>1);
|
||||||
@@ -4587,14 +4596,12 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
|
|||||||
{
|
{
|
||||||
int ret = MP_OKAY;
|
int ret = MP_OKAY;
|
||||||
word32 numlen;
|
word32 numlen;
|
||||||
#ifndef WOLFSSL_ATECC508A
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
byte* buf;
|
byte* buf;
|
||||||
#else
|
#else
|
||||||
byte buf[ECC_BUFSIZE];
|
byte buf[ECC_BUFSIZE];
|
||||||
#endif
|
#endif
|
||||||
word32 pubxlen, pubylen;
|
word32 pubxlen, pubylen;
|
||||||
#endif /* WOLFSSL_ATECC508A */
|
|
||||||
|
|
||||||
/* return length needed only */
|
/* return length needed only */
|
||||||
if (key != NULL && out == NULL && outLen != NULL) {
|
if (key != NULL && out == NULL && outLen != NULL) {
|
||||||
@@ -4620,12 +4627,6 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
|
|||||||
return BUFFER_E;
|
return BUFFER_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
|
||||||
/* TODO: Implement equiv call to ATECC508A */
|
|
||||||
ret = BAD_COND_E;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* verify public key length is less than key size */
|
/* verify public key length is less than key size */
|
||||||
pubxlen = mp_unsigned_bin_size(key->pubkey.x);
|
pubxlen = mp_unsigned_bin_size(key->pubkey.x);
|
||||||
pubylen = mp_unsigned_bin_size(key->pubkey.y);
|
pubylen = mp_unsigned_bin_size(key->pubkey.y);
|
||||||
@@ -4663,7 +4664,6 @@ done:
|
|||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
XFREE(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
|
XFREE(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
|
||||||
#endif
|
#endif
|
||||||
#endif /* WOLFSSL_ATECC508A */
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -4994,9 +4994,7 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
|||||||
int curve_id)
|
int curve_id)
|
||||||
{
|
{
|
||||||
int err = MP_OKAY;
|
int err = MP_OKAY;
|
||||||
#ifndef WOLFSSL_ATECC508A
|
|
||||||
int compressed = 0;
|
int compressed = 0;
|
||||||
#endif /* !WOLFSSL_ATECC508A */
|
|
||||||
|
|
||||||
if (in == NULL || key == NULL)
|
if (in == NULL || key == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
@@ -5009,12 +5007,6 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
|||||||
/* make sure required variables are reset */
|
/* make sure required variables are reset */
|
||||||
wc_ecc_reset(key);
|
wc_ecc_reset(key);
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
|
||||||
/* TODO: Implement equiv call to ATECC508A */
|
|
||||||
err = BAD_COND_E;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* init key */
|
/* init key */
|
||||||
#ifdef ALT_ECC_SIZE
|
#ifdef ALT_ECC_SIZE
|
||||||
key->pubkey.x = (mp_int*)&key->pubkey.xyz[0];
|
key->pubkey.x = (mp_int*)&key->pubkey.xyz[0];
|
||||||
@@ -5139,7 +5131,6 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
|||||||
mp_clear(key->pubkey.z);
|
mp_clear(key->pubkey.z);
|
||||||
mp_clear(&key->k);
|
mp_clear(&key->k);
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_ATECC508A */
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -5253,12 +5244,6 @@ static int wc_ecc_export_raw(ecc_key* key, byte* qx, word32* qxLen,
|
|||||||
#endif /* WOLFSSL_ATECC508A */
|
#endif /* WOLFSSL_ATECC508A */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
|
||||||
/* TODO: Implement equiv call to ATECC508A */
|
|
||||||
return BAD_COND_E;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* public x component */
|
/* public x component */
|
||||||
err = mp_to_unsigned_bin(key->pubkey.x, qx +
|
err = mp_to_unsigned_bin(key->pubkey.x, qx +
|
||||||
(numLen - mp_unsigned_bin_size(key->pubkey.x)));
|
(numLen - mp_unsigned_bin_size(key->pubkey.x)));
|
||||||
@@ -5272,7 +5257,6 @@ static int wc_ecc_export_raw(ecc_key* key, byte* qx, word32* qxLen,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* WOLFSSL_ATECC508A */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -285,12 +285,11 @@ struct ecc_key {
|
|||||||
const ecc_set_type* dp; /* domain parameters, either points to NIST
|
const ecc_set_type* dp; /* domain parameters, either points to NIST
|
||||||
curves (idx >= 0) or user supplied */
|
curves (idx >= 0) or user supplied */
|
||||||
void* heap; /* heap hint */
|
void* heap; /* heap hint */
|
||||||
#ifdef WOLFSSL_ATECC508A
|
|
||||||
int slot; /* Key Slot Number (-1 unknown) */
|
|
||||||
byte pubkey[PUB_KEY_SIZE];
|
|
||||||
#else
|
|
||||||
ecc_point pubkey; /* public key */
|
ecc_point pubkey; /* public key */
|
||||||
mp_int k; /* private key */
|
mp_int k; /* private key */
|
||||||
|
#ifdef WOLFSSL_ATECC508A
|
||||||
|
int slot; /* Key Slot Number (-1 unknown) */
|
||||||
|
byte pubkey_raw[PUB_KEY_SIZE];
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
mp_int* r; /* sign/verify temps */
|
mp_int* r; /* sign/verify temps */
|
||||||
@@ -409,7 +408,6 @@ int wc_ecc_get_curve_id_from_params(int fieldSize,
|
|||||||
const byte* Bf, word32 BfSz, const byte* order, word32 orderSz,
|
const byte* Bf, word32 BfSz, const byte* order, word32 orderSz,
|
||||||
const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
|
const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
|
||||||
|
|
||||||
#ifndef WOLFSSL_ATECC508A
|
|
||||||
|
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
ecc_point* wc_ecc_new_point(void);
|
ecc_point* wc_ecc_new_point(void);
|
||||||
@@ -425,6 +423,8 @@ WOLFSSL_API
|
|||||||
int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
|
int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_point_is_at_infinity(ecc_point *p);
|
int wc_ecc_point_is_at_infinity(ecc_point *p);
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_ATECC508A
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
|
int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
|
||||||
mp_int* a, mp_int* modulus, int map);
|
mp_int* a, mp_int* modulus, int map);
|
||||||
|
Reference in New Issue
Block a user