mirror of https://github.com/wolfSSL/wolfssl.git
Added ED25519 and Curve25519 crypto callback support.
parent
9c24731e3c
commit
15d761a0c2
|
@ -344,6 +344,155 @@ int wc_CryptoCb_EccCheckPrivKey(ecc_key* key, const byte* pubKey,
|
|||
}
|
||||
#endif /* HAVE_ECC */
|
||||
|
||||
#ifdef HAVE_CURVE25519
|
||||
int wc_CryptoCb_Curve25519Gen(WC_RNG* rng, int keySize,
|
||||
curve25519_key* key)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_CURVE25519_KEYGEN;
|
||||
cryptoInfo.pk.curve25519kg.rng = rng;
|
||||
cryptoInfo.pk.curve25519kg.size = keySize;
|
||||
cryptoInfo.pk.curve25519kg.key = key;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return wc_CryptoCb_TranslateErrorCode(ret);
|
||||
}
|
||||
|
||||
int wc_CryptoCb_Curve25519(curve25519_key* private_key,
|
||||
curve25519_key* public_key, byte* out, word32* outlen, int endian)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (private_key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(private_key->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_CURVE25519;
|
||||
cryptoInfo.pk.curve25519.private_key = private_key;
|
||||
cryptoInfo.pk.curve25519.public_key = public_key;
|
||||
cryptoInfo.pk.curve25519.out = out;
|
||||
cryptoInfo.pk.curve25519.outlen = outlen;
|
||||
cryptoInfo.pk.curve25519.endian = endian;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return wc_CryptoCb_TranslateErrorCode(ret);
|
||||
}
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
int wc_CryptoCb_Ed25519Gen(WC_RNG* rng, int keySize,
|
||||
ed25519_key* key)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ED25519_KEYGEN;
|
||||
cryptoInfo.pk.ed25519kg.rng = rng;
|
||||
cryptoInfo.pk.ed25519kg.size = keySize;
|
||||
cryptoInfo.pk.ed25519kg.key = key;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return wc_CryptoCb_TranslateErrorCode(ret);
|
||||
}
|
||||
|
||||
int wc_CryptoCb_Ed25519Sign(const byte* in, word32 inLen, byte* out,
|
||||
word32 *outLen, ed25519_key* key, byte type,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ED25519_SIGN;
|
||||
cryptoInfo.pk.ed25519sign.in = in;
|
||||
cryptoInfo.pk.ed25519sign.inLen = inLen;
|
||||
cryptoInfo.pk.ed25519sign.out = out;
|
||||
cryptoInfo.pk.ed25519sign.outLen = outLen;
|
||||
cryptoInfo.pk.ed25519sign.key = key;
|
||||
cryptoInfo.pk.ed25519sign.type = type;
|
||||
cryptoInfo.pk.ed25519sign.context = context;
|
||||
cryptoInfo.pk.ed25519sign.contextLen = contextLen;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return wc_CryptoCb_TranslateErrorCode(ret);
|
||||
}
|
||||
|
||||
int wc_CryptoCb_Ed25519Verify(const byte* sig, word32 sigLen,
|
||||
const byte* msg, word32 msgLen, int* res, ed25519_key* key, byte type,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ED25519_VERIFY;
|
||||
cryptoInfo.pk.ed25519verify.sig = sig;
|
||||
cryptoInfo.pk.ed25519verify.sigLen = sigLen;
|
||||
cryptoInfo.pk.ed25519verify.msg = msg;
|
||||
cryptoInfo.pk.ed25519verify.msgLen = msgLen;
|
||||
cryptoInfo.pk.ed25519verify.res = res;
|
||||
cryptoInfo.pk.ed25519verify.key = key;
|
||||
cryptoInfo.pk.ed25519verify.type = type;
|
||||
cryptoInfo.pk.ed25519verify.context = context;
|
||||
cryptoInfo.pk.ed25519verify.contextLen = contextLen;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return wc_CryptoCb_TranslateErrorCode(ret);
|
||||
}
|
||||
#endif /* HAVE_ED25519 */
|
||||
|
||||
#ifndef NO_AES
|
||||
#ifdef HAVE_AESGCM
|
||||
int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
|
||||
|
|
|
@ -44,6 +44,10 @@
|
|||
#include <wolfssl/wolfcrypt/port/nxp/ksdk_port.h>
|
||||
#endif
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
#endif
|
||||
|
||||
const curve25519_set_type curve25519_sets[] = {
|
||||
{
|
||||
CURVE25519_KEYSIZE,
|
||||
|
@ -190,6 +194,15 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
|
|||
if (key == NULL || rng == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (key->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Curve25519Gen(rng, keysize, key);
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = wc_curve25519_make_priv(rng, keysize, key->k.point);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
@ -211,22 +224,34 @@ int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
|
|||
curve25519_key* public_key,
|
||||
byte* out, word32* outlen, int endian)
|
||||
{
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
ECPoint o = {{0}};
|
||||
#else
|
||||
unsigned char o[CURVE25519_KEYSIZE];
|
||||
#endif
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
ECPoint o = {{0}};
|
||||
#else
|
||||
unsigned char o[CURVE25519_KEYSIZE];
|
||||
#endif
|
||||
int ret = 0;
|
||||
|
||||
/* sanity check */
|
||||
if (private_key == NULL || public_key == NULL ||
|
||||
out == NULL || outlen == NULL || *outlen < CURVE25519_KEYSIZE)
|
||||
out == NULL || outlen == NULL || *outlen < CURVE25519_KEYSIZE) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
/* avoid implementation fingerprinting */
|
||||
if (public_key->p.point[CURVE25519_KEYSIZE-1] > 0x7F)
|
||||
return ECC_BAD_ARG_E;
|
||||
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (private_key->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Curve25519(private_key, public_key, out, outlen,
|
||||
endian);
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
/* input point P on Curve25519 */
|
||||
ret = nxp_ltc_curve25519(&o, private_key->k.point, &public_key->p,
|
||||
|
@ -576,8 +601,7 @@ int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
|
|||
|
||||
#endif /* HAVE_CURVE25519_KEY_IMPORT */
|
||||
|
||||
|
||||
int wc_curve25519_init(curve25519_key* key)
|
||||
int wc_curve25519_init_ex(curve25519_key* key, void* heap, int devId)
|
||||
{
|
||||
if (key == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
@ -587,6 +611,13 @@ int wc_curve25519_init(curve25519_key* key)
|
|||
/* 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 */
|
||||
|
||||
#ifndef FREESCALE_LTC_ECC
|
||||
fe_init();
|
||||
#endif
|
||||
|
@ -594,6 +625,10 @@ int wc_curve25519_init(curve25519_key* key)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wc_curve25519_init(curve25519_key* key)
|
||||
{
|
||||
return wc_curve25519_init_ex(key, NULL, INVALID_DEVID);
|
||||
}
|
||||
|
||||
/* Clean the memory of a key */
|
||||
void wc_curve25519_free(curve25519_key* key)
|
||||
|
|
|
@ -45,6 +45,10 @@
|
|||
#include <wolfssl/wolfcrypt/port/nxp/ksdk_port.h>
|
||||
#endif
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ED25519_SIGN) || defined(HAVE_ED25519_VERIFY)
|
||||
#define ED25519CTX_SIZE 32
|
||||
|
||||
|
@ -102,6 +106,15 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key)
|
|||
if (keySz != ED25519_KEY_SIZE)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (key->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Ed25519Gen(rng, keySz, key);
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = wc_RNG_GenerateBlock(rng, key->k, ED25519_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
@ -134,7 +147,7 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key)
|
|||
contextLen length of extra signing data
|
||||
return 0 on success
|
||||
*/
|
||||
static int ed25519_sign_msg(const byte* in, word32 inLen, byte* out,
|
||||
int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out,
|
||||
word32 *outLen, ed25519_key* key, byte type,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
|
@ -154,6 +167,17 @@ static int ed25519_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
(context == NULL && contextLen != 0)) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (key->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Ed25519Sign(in, inLen, out, outLen, key, type,
|
||||
context, contextLen);
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!key->pubKeySet)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
|
@ -263,7 +287,8 @@ static int ed25519_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
int wc_ed25519_sign_msg(const byte* in, word32 inLen, byte* out,
|
||||
word32 *outLen, ed25519_key* key)
|
||||
{
|
||||
return ed25519_sign_msg(in, inLen, out, outLen, key, (byte)Ed25519, NULL, 0);
|
||||
return wc_ed25519_sign_msg_ex(in, inLen, out, outLen, key, (byte)Ed25519,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -281,8 +306,8 @@ int wc_ed25519ctx_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
word32 *outLen, ed25519_key* key,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
return ed25519_sign_msg(in, inLen, out, outLen, key, Ed25519ctx, context,
|
||||
contextLen);
|
||||
return wc_ed25519_sign_msg_ex(in, inLen, out, outLen, key, Ed25519ctx,
|
||||
context, contextLen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -300,8 +325,8 @@ int wc_ed25519ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
|
|||
word32 *outLen, ed25519_key* key,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
return ed25519_sign_msg(hash, hashLen, out, outLen, key, Ed25519ph, context,
|
||||
contextLen);
|
||||
return wc_ed25519_sign_msg_ex(hash, hashLen, out, outLen, key, Ed25519ph,
|
||||
context, contextLen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -326,8 +351,8 @@ int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
return wc_ed25519ph_sign_hash(hash, sizeof(hash), out, outLen, key, context,
|
||||
contextLen);
|
||||
return wc_ed25519_sign_msg_ex(hash, sizeof(hash), out, outLen, key,
|
||||
Ed25519ph, context, contextLen);
|
||||
}
|
||||
#endif /* HAVE_ED25519_SIGN */
|
||||
|
||||
|
@ -342,7 +367,7 @@ int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
key Ed25519 public key
|
||||
return 0 and res of 1 on success
|
||||
*/
|
||||
static int ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
||||
int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
|
||||
word32 msgLen, int* res, ed25519_key* key,
|
||||
byte type, const byte* context, byte contextLen)
|
||||
{
|
||||
|
@ -368,6 +393,16 @@ static int ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||
if (sigLen != ED25519_SIG_SIZE || (sig[ED25519_SIG_SIZE-1] & 224))
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (key->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Ed25519Verify(sig, sigLen, msg, msgLen, res, key,
|
||||
type, context, contextLen);
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* uncompress A (public key), test if valid, and negate it */
|
||||
#ifndef FREESCALE_LTC_ECC
|
||||
if (ge_frombytes_negate_vartime(&A, key->p) != 0)
|
||||
|
@ -439,8 +474,8 @@ static int ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||
int wc_ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
||||
word32 msgLen, int* res, ed25519_key* key)
|
||||
{
|
||||
return ed25519_verify_msg(sig, sigLen, msg, msgLen, res, key, (byte)Ed25519,
|
||||
NULL, 0);
|
||||
return wc_ed25519_verify_msg_ex(sig, sigLen, msg, msgLen, res, key,
|
||||
(byte)Ed25519, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -458,8 +493,8 @@ int wc_ed25519ctx_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||
word32 msgLen, int* res, ed25519_key* key,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
return ed25519_verify_msg(sig, sigLen, msg, msgLen, res, key, Ed25519ctx,
|
||||
context, contextLen);
|
||||
return wc_ed25519_verify_msg_ex(sig, sigLen, msg, msgLen, res, key,
|
||||
Ed25519ctx, context, contextLen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -477,8 +512,8 @@ int wc_ed25519ph_verify_hash(const byte* sig, word32 sigLen, const byte* hash,
|
|||
word32 hashLen, int* res, ed25519_key* key,
|
||||
const byte* context, byte contextLen)
|
||||
{
|
||||
return ed25519_verify_msg(sig, sigLen, hash, hashLen, res, key, Ed25519ph,
|
||||
context, contextLen);
|
||||
return wc_ed25519_verify_msg_ex(sig, sigLen, hash, hashLen, res, key,
|
||||
Ed25519ph, context, contextLen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -503,19 +538,25 @@ int wc_ed25519ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
return wc_ed25519ph_verify_hash(sig, sigLen, hash, sizeof(hash), res, key,
|
||||
context, contextLen);
|
||||
return wc_ed25519_verify_msg_ex(sig, sigLen, hash, sizeof(hash), res, key,
|
||||
Ed25519ph, context, contextLen);
|
||||
}
|
||||
#endif /* HAVE_ED25519_VERIFY */
|
||||
|
||||
|
||||
/* initialize information and memory for key */
|
||||
int wc_ed25519_init(ed25519_key* key)
|
||||
int wc_ed25519_init_ex(ed25519_key* key, void* heap, int devId)
|
||||
{
|
||||
if (key == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
XMEMSET(key, 0, sizeof(ed25519_key));
|
||||
#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();
|
||||
|
@ -524,6 +565,10 @@ int wc_ed25519_init(ed25519_key* key)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wc_ed25519_init(ed25519_key* key)
|
||||
{
|
||||
return wc_ed25519_init_ex(key, NULL, INVALID_DEVID);
|
||||
}
|
||||
|
||||
/* clear memory of key */
|
||||
void wc_ed25519_free(ed25519_key* key)
|
||||
|
|
|
@ -36853,6 +36853,69 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
|||
info->pk.ecdh.private_key->devId = devIdArg;
|
||||
}
|
||||
#endif /* HAVE_ECC */
|
||||
#ifdef HAVE_CURVE25519
|
||||
if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
|
||||
/* set devId to invalid, so software is used */
|
||||
info->pk.curve25519kg.key->devId = INVALID_DEVID;
|
||||
|
||||
ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
|
||||
info->pk.curve25519kg.size, info->pk.curve25519kg.key);
|
||||
|
||||
/* reset devId */
|
||||
info->pk.curve25519kg.key->devId = devIdArg;
|
||||
}
|
||||
else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
|
||||
/* set devId to invalid, so software is used */
|
||||
info->pk.curve25519.private_key->devId = INVALID_DEVID;
|
||||
|
||||
ret = wc_curve25519_shared_secret_ex(
|
||||
info->pk.curve25519.private_key, info->pk.curve25519.public_key,
|
||||
info->pk.curve25519.out, info->pk.curve25519.outlen,
|
||||
info->pk.curve25519.endian);
|
||||
|
||||
/* reset devId */
|
||||
info->pk.curve25519.private_key->devId = devIdArg;
|
||||
}
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
#ifdef HAVE_ED25519
|
||||
if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
|
||||
/* set devId to invalid, so software is used */
|
||||
info->pk.ed25519kg.key->devId = INVALID_DEVID;
|
||||
|
||||
ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
|
||||
info->pk.ed25519kg.size, info->pk.ed25519kg.key);
|
||||
|
||||
/* reset devId */
|
||||
info->pk.ed25519kg.key->devId = devIdArg;
|
||||
}
|
||||
else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
|
||||
/* set devId to invalid, so software is used */
|
||||
info->pk.ed25519sign.key->devId = INVALID_DEVID;
|
||||
|
||||
ret = wc_ed25519_sign_msg_ex(
|
||||
info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
|
||||
info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
|
||||
info->pk.ed25519sign.key, info->pk.ed25519sign.type,
|
||||
info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
|
||||
|
||||
/* reset devId */
|
||||
info->pk.ed25519sign.key->devId = devIdArg;
|
||||
}
|
||||
else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
|
||||
/* set devId to invalid, so software is used */
|
||||
info->pk.ed25519verify.key->devId = INVALID_DEVID;
|
||||
|
||||
ret = wc_ed25519_verify_msg_ex(
|
||||
info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
|
||||
info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
|
||||
info->pk.ed25519verify.res, info->pk.ed25519verify.key,
|
||||
info->pk.ed25519verify.type, info->pk.ed25519verify.context,
|
||||
info->pk.ed25519verify.contextLen);
|
||||
|
||||
/* reset devId */
|
||||
info->pk.ed25519verify.key->devId = devIdArg;
|
||||
}
|
||||
#endif /* HAVE_ED25519 */
|
||||
}
|
||||
else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
|
||||
#if !defined(NO_AES) || !defined(NO_DES3)
|
||||
|
@ -37122,6 +37185,14 @@ WOLFSSL_TEST_SUBROUTINE int cryptocb_test(void)
|
|||
if (ret == 0)
|
||||
ret = ecc_test();
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
if (ret == 0)
|
||||
ret = ed25519_test();
|
||||
#endif
|
||||
#ifdef HAVE_CURVE25519
|
||||
if (ret == 0)
|
||||
ret = curve25519_test();
|
||||
#endif
|
||||
#ifndef NO_AES
|
||||
#ifdef HAVE_AESGCM
|
||||
if (ret == 0)
|
||||
|
|
|
@ -140,13 +140,47 @@ typedef struct wc_CryptoInfo {
|
|||
#endif
|
||||
#ifdef HAVE_CURVE25519
|
||||
struct {
|
||||
WC_RNG* rng;
|
||||
int size;
|
||||
curve25519_key* key;
|
||||
int curveId;
|
||||
} curve25519kg;
|
||||
struct {
|
||||
curve25519_key* private_key;
|
||||
curve25519_key* public_key;
|
||||
byte* out;
|
||||
word32* outlen;
|
||||
int endian;
|
||||
} curve25519;
|
||||
#endif
|
||||
#ifdef HAVE_ED25519
|
||||
struct {
|
||||
WC_RNG* rng;
|
||||
int size;
|
||||
ed25519_key* key;
|
||||
} ed25519;
|
||||
int curveId;
|
||||
} ed25519kg;
|
||||
struct {
|
||||
const byte* in;
|
||||
word32 inLen;
|
||||
byte* out;
|
||||
word32* outLen;
|
||||
ed25519_key* key;
|
||||
byte type;
|
||||
const byte* context;
|
||||
byte contextLen;
|
||||
} ed25519sign;
|
||||
struct {
|
||||
const byte* sig;
|
||||
word32 sigLen;
|
||||
const byte* msg;
|
||||
word32 msgLen;
|
||||
int* res;
|
||||
ed25519_key* key;
|
||||
byte type;
|
||||
const byte* context;
|
||||
byte contextLen;
|
||||
} ed25519verify;
|
||||
#endif
|
||||
};
|
||||
} pk;
|
||||
|
@ -303,6 +337,25 @@ WOLFSSL_LOCAL int wc_CryptoCb_EccCheckPrivKey(ecc_key* key, const byte* pubKey,
|
|||
word32 pubKeySz);
|
||||
#endif /* HAVE_ECC */
|
||||
|
||||
#ifdef HAVE_CURVE25519
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_Curve25519Gen(WC_RNG* rng, int keySize,
|
||||
curve25519_key* key);
|
||||
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_Curve25519(curve25519_key* private_key,
|
||||
curve25519_key* public_key, byte* out, word32* outlen, int endian);
|
||||
#endif /* HAVE_CURVE25519 */
|
||||
|
||||
#ifdef HAVE_ED25519
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_Ed25519Gen(WC_RNG* rng, int keySize,
|
||||
ed25519_key* key);
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_Ed25519Sign(const byte* in, word32 inLen,
|
||||
byte* out, word32 *outLen, ed25519_key* key, byte type, const byte* context,
|
||||
byte contextLen);
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_Ed25519Verify(const byte* sig, word32 sigLen,
|
||||
const byte* msg, word32 msgLen, int* res, ed25519_key* key, byte type,
|
||||
const byte* context, byte contextLen);
|
||||
#endif /* HAVE_ED25519 */
|
||||
|
||||
#ifndef NO_AES
|
||||
#ifdef HAVE_AESGCM
|
||||
WOLFSSL_LOCAL int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
|
||||
|
|
|
@ -79,6 +79,9 @@ typedef struct curve25519_key {
|
|||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
WC_ASYNC_DEV asyncDev;
|
||||
#endif
|
||||
#if defined(WOLF_CRYPTO_CB)
|
||||
int devId;
|
||||
#endif
|
||||
} curve25519_key;
|
||||
|
||||
enum {
|
||||
|
@ -113,6 +116,8 @@ int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
|
|||
|
||||
WOLFSSL_API
|
||||
int wc_curve25519_init(curve25519_key* key);
|
||||
WOLFSSL_API
|
||||
int wc_curve25519_init_ex(curve25519_key* key, void* heap, int devId);
|
||||
|
||||
WOLFSSL_API
|
||||
void wc_curve25519_free(curve25519_key* key);
|
||||
|
|
|
@ -87,6 +87,9 @@ struct ed25519_key {
|
|||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
WC_ASYNC_DEV asyncDev;
|
||||
#endif
|
||||
#if defined(WOLF_CRYPTO_CB)
|
||||
int devId;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@ -111,6 +114,10 @@ int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out,
|
|||
word32 *outLen, ed25519_key* key, const byte* context,
|
||||
byte contextLen);
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out,
|
||||
word32 *outLen, ed25519_key* key, byte type,
|
||||
const byte* context, byte contextLen);
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
||||
word32 msgLen, int* stat, ed25519_key* key);
|
||||
WOLFSSL_API
|
||||
|
@ -126,8 +133,15 @@ int wc_ed25519ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||
word32 msgLen, int* stat, ed25519_key* key,
|
||||
const byte* context, byte contextLen);
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
|
||||
word32 msgLen, int* res, ed25519_key* key,
|
||||
byte type, const byte* context, byte contextLen);
|
||||
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_init(ed25519_key* key);
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_init_ex(ed25519_key* key, void* heap, int devId);
|
||||
WOLFSSL_API
|
||||
void wc_ed25519_free(ed25519_key* key);
|
||||
WOLFSSL_API
|
||||
int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
|
||||
|
|
|
@ -883,7 +883,7 @@ decouple library dependencies with standard string, memory and so on.
|
|||
WC_PK_TYPE_ECDH = 3,
|
||||
WC_PK_TYPE_ECDSA_SIGN = 4,
|
||||
WC_PK_TYPE_ECDSA_VERIFY = 5,
|
||||
WC_PK_TYPE_ED25519 = 6,
|
||||
WC_PK_TYPE_ED25519_SIGN = 6,
|
||||
WC_PK_TYPE_CURVE25519 = 7,
|
||||
WC_PK_TYPE_RSA_KEYGEN = 8,
|
||||
WC_PK_TYPE_EC_KEYGEN = 9,
|
||||
|
@ -891,7 +891,10 @@ decouple library dependencies with standard string, memory and so on.
|
|||
WC_PK_TYPE_EC_CHECK_PRIV_KEY = 11,
|
||||
WC_PK_TYPE_ED448 = 12,
|
||||
WC_PK_TYPE_CURVE448 = 13,
|
||||
WC_PK_TYPE_MAX = WC_PK_TYPE_CURVE448
|
||||
WC_PK_TYPE_ED25519_VERIFY = 14,
|
||||
WC_PK_TYPE_ED25519_KEYGEN = 15,
|
||||
WC_PK_TYPE_CURVE25519_KEYGEN = 16,
|
||||
WC_PK_TYPE_MAX = WC_PK_TYPE_CURVE25519_KEYGEN
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue