forked from wolfSSL/wolfssl
Addressing PR comments
This commit is contained in:
@ -37,26 +37,33 @@ size and a key size of 128, 192, or 256 bits.
|
||||
#include <wolfssl/wolfcrypt/port/aria/aria-crypt.h>
|
||||
|
||||
#ifdef HAVE_ARIA
|
||||
/* return 0 on success or WC_INIT_E on failure */
|
||||
int wc_AriaInitCrypt(wc_Aria* aria, MC_ALGID algo)
|
||||
{
|
||||
|
||||
/* return 0 on success or WC_INIT_E on failure */
|
||||
int wc_AriaInitCrypt(wc_Aria* aria, MC_ALGID algo)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
|
||||
MC_APIMODE gApimode = MC_MODE_KCMV;
|
||||
MC_ALGMODE algMode = MC_ALGMODE_GCM;
|
||||
MC_PADTYPE algPad = MC_PADTYPE_NONE;
|
||||
|
||||
if (aria == NULL) return BAD_FUNC_ARG;
|
||||
if (aria == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (rv == MC_OK) rv = MC_Initialize(NULL);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Initialize(NULL);
|
||||
|
||||
if (rv == MC_OK) rv = wc_AriaFreeCrypt(aria);
|
||||
if (rv == MC_OK)
|
||||
rv = wc_AriaFreeCrypt(aria);
|
||||
|
||||
if (rv == MC_OK) rv = MC_OpenSession(&(aria->hSession));
|
||||
if (rv == MC_OK)
|
||||
rv = MC_OpenSession(&(aria->hSession));
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetApiMode(aria->hSession, gApimode);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetApiMode(aria->hSession, gApimode);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetOption(aria->hSession, algMode, algPad);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetOption(aria->hSession, algMode, algPad);
|
||||
|
||||
if (rv == MC_OK) {
|
||||
aria->algo = algo;
|
||||
@ -69,14 +76,16 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return WC_INIT_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_STATE_E on failure */
|
||||
int wc_AriaFreeCrypt(wc_Aria* aria)
|
||||
{
|
||||
if (aria == NULL) return 0;
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_STATE_E on failure */
|
||||
int wc_AriaFreeCrypt(wc_Aria* aria)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
|
||||
if (aria == NULL)
|
||||
return 0;
|
||||
|
||||
if (aria->hKey != NULL) {
|
||||
if (rv == MC_OK) rv = MC_DestroyObject(aria->hSession, aria->hKey);
|
||||
if (rv == MC_OK) aria->hKey = NULL;
|
||||
@ -91,11 +100,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_STATE_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_FUNC_ARG/PUBLIC_KEY_E on failure */
|
||||
int wc_AriaSetKey(wc_Aria* aria, byte* key)
|
||||
{
|
||||
/* return 0 on success or BAD_FUNC_ARG/PUBLIC_KEY_E on failure */
|
||||
int wc_AriaSetKey(wc_Aria* aria, byte* key)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
MC_UINT keylen;
|
||||
if (aria->algo == MC_ALGID_ARIA_128BITKEY) {
|
||||
@ -110,27 +119,30 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
|
||||
if (aria->hKey != NULL) {
|
||||
if (rv == MC_OK) rv = MC_DestroyObject(aria->hSession, aria->hKey);
|
||||
if (rv == MC_OK) aria->hKey = NULL;
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DestroyObject(aria->hSession, aria->hKey);
|
||||
if (rv == MC_OK)
|
||||
aria->hKey = NULL;
|
||||
}
|
||||
if (rv == MC_OK) rv = MC_CreateObject(aria->hSession, (MC_UCHAR*)key, keylen, &(aria->hKey));
|
||||
if (rv == MC_OK)
|
||||
rv = MC_CreateObject(aria->hSession, (MC_UCHAR*)key, keylen, &(aria->hKey));
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static WARN_UNUSED_RESULT WC_INLINE int CheckAriaGcmIvSize(int ivSz) {
|
||||
static WARN_UNUSED_RESULT WC_INLINE int CheckAriaGcmIvSize(int ivSz) {
|
||||
return (ivSz == GCM_NONCE_MIN_SZ ||
|
||||
ivSz == GCM_NONCE_MID_SZ ||
|
||||
ivSz == GCM_NONCE_MAX_SZ);
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaGcmSetExtIV(wc_Aria* aria, const byte* iv, word32 ivSz)
|
||||
{
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaGcmSetExtIV(wc_Aria* aria, const byte* iv, word32 ivSz)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (aria == NULL || iv == NULL || !CheckAriaGcmIvSize((int)ivSz)) {
|
||||
@ -143,13 +155,13 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaGcmSetIV(wc_Aria* aria, word32 ivSz,
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaGcmSetIV(wc_Aria* aria, word32 ivSz,
|
||||
const byte* ivFixed, word32 ivFixedSz,
|
||||
WC_RNG* rng)
|
||||
{
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (aria == NULL || rng == NULL || !CheckAriaGcmIvSize((int)ivSz) ||
|
||||
@ -172,14 +184,14 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* 'out' buffer is expected to be 'inSz + authTagSz'
|
||||
/* 'out' buffer is expected to be 'inSz + authTagSz'
|
||||
* return 0 on success or BAD_FUNC_ARG/ENCRYPT_ERROR on failure */
|
||||
int wc_AriaEncrypt(wc_Aria* aria, byte* out, byte* in, word32 inSz,
|
||||
int wc_AriaEncrypt(wc_Aria* aria, byte* out, byte* in, word32 inSz,
|
||||
byte* iv, word32 ivSz, byte* aad, word32 aadSz,
|
||||
byte* authTag, word32 authTagSz)
|
||||
{
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
|
||||
MC_ALGPARAM param = {
|
||||
@ -190,10 +202,10 @@ size and a key size of 128, 192, or 256 bits.
|
||||
.nTLen = authTagSz,
|
||||
.nDataLen = inSz
|
||||
};
|
||||
MC_UINT outSz = inSz + authTagSz;
|
||||
MC_ALGORITHM mcAlg = {aria->algo, NULL, 0};
|
||||
mcAlg.pParam = (MC_UCHAR*)¶m;
|
||||
mcAlg.nParam = sizeof(param);
|
||||
MC_UINT outSz = inSz + authTagSz;
|
||||
|
||||
if (authTag == NULL || iv == NULL || authTagSz > ARIA_BLOCK_SIZE ||
|
||||
authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ ||
|
||||
@ -207,25 +219,28 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_EncryptInit(aria->hSession, &mcAlg, aria->hKey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_EncryptInit(aria->hSession, &mcAlg, aria->hKey);
|
||||
|
||||
if (rv == MC_OK) rv = MC_Encrypt(aria->hSession, in, inSz, out, &outSz);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Encrypt(aria->hSession, in, inSz, out, &outSz);
|
||||
|
||||
if (rv == MC_OK) XMEMCPY(authTag, out + inSz, authTagSz);
|
||||
if (rv == MC_OK)
|
||||
XMEMCPY(authTag, out + inSz, authTagSz);
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
return ENCRYPT_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 'in' buffer is expected to be 'inSz + authTagSz'
|
||||
/* 'in' buffer is expected to be 'inSz + authTagSz'
|
||||
* return 0 on success or BAD_FUNC_ARG/ENCRYPT_ERROR on failure */
|
||||
int wc_AriaDecrypt(wc_Aria* aria, byte* out, byte* in, word32 inSz,
|
||||
int wc_AriaDecrypt(wc_Aria* aria, byte* out, byte* in, word32 inSz,
|
||||
byte* iv, word32 ivSz, byte* aad, word32 aadSz,
|
||||
byte* authTag, word32 authTagSz)
|
||||
{
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
|
||||
MC_ALGPARAM param = {
|
||||
@ -236,10 +251,10 @@ size and a key size of 128, 192, or 256 bits.
|
||||
.nTLen = authTagSz,
|
||||
.nDataLen = inSz
|
||||
};
|
||||
MC_UINT outSz = inSz;
|
||||
MC_ALGORITHM mcAlg = {aria->algo, NULL, 0};
|
||||
mcAlg.pParam = (MC_UCHAR*)¶m;
|
||||
mcAlg.nParam = sizeof(param);
|
||||
MC_UINT outSz = inSz;
|
||||
|
||||
if (authTag == NULL || iv == NULL || authTagSz > ARIA_BLOCK_SIZE ||
|
||||
authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ ||
|
||||
@ -253,18 +268,20 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_DecryptInit(aria->hSession, &mcAlg, aria->hKey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DecryptInit(aria->hSession, &mcAlg, aria->hKey);
|
||||
|
||||
if (rv == MC_OK) {
|
||||
XMEMCPY((byte*)in + inSz, authTag, authTagSz);
|
||||
inSz += authTagSz;
|
||||
}
|
||||
if (rv == MC_OK) rv = MC_Decrypt(aria->hSession, in, inSz, out, &outSz);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Decrypt(aria->hSession, in, inSz, out, &outSz);
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
return DECRYPT_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_ARIA */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* aria.c
|
||||
/* aria-cryptocb.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
||||
*
|
||||
@ -37,14 +37,16 @@ size and a key size of 128, 192, or 256 bits.
|
||||
#include <wolfssl/wolfcrypt/asn_public.h>
|
||||
#include <wolfssl/wolfcrypt/port/aria/aria-cryptocb.h>
|
||||
|
||||
int wc_AriaInit(void)
|
||||
{
|
||||
int wc_AriaInit(void)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
static char isInit = 0;
|
||||
|
||||
if (isInit == 0) {
|
||||
if (rv == MC_OK) rv = MC_Initialize(NULL);
|
||||
if (rv == MC_OK) isInit = 1;
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Initialize(NULL);
|
||||
if (rv == MC_OK)
|
||||
isInit = 1;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (rv == MC_OK) {
|
||||
@ -58,11 +60,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return WC_INIT_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or WC_INIT_E on failure */
|
||||
int wc_AriaInitSha(MC_HSESSION* hSession, MC_ALGID algo)
|
||||
{
|
||||
/* return 0 on success or WC_INIT_E on failure */
|
||||
int wc_AriaInitSha(MC_HSESSION* hSession, MC_ALGID algo)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
|
||||
MC_APIMODE gApimode = MC_MODE_KCMV;
|
||||
@ -74,24 +76,28 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = wc_AriaInit();
|
||||
if (rv == MC_OK)
|
||||
rv = wc_AriaInit();
|
||||
|
||||
if (rv == MC_OK) rv = MC_OpenSession(hSession);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_OpenSession(hSession);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetApiMode(*hSession, gApimode);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetApiMode(*hSession, gApimode);
|
||||
|
||||
if (rv == MC_OK) rv = MC_DigestInit(*hSession, &mcAlg);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DigestInit(*hSession, &mcAlg);
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
return WC_INIT_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaShaUpdate(MC_HSESSION hSession, byte* data, word32 len)
|
||||
{
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaShaUpdate(MC_HSESSION hSession, byte* data, word32 len)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
WOLFSSL_ENTER("AriaShaUpdate");
|
||||
|
||||
@ -99,18 +105,19 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_DigestUpdate(hSession, data, len);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DigestUpdate(hSession, data, len);
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaShaFinal(MC_HSESSION hSession, byte* out, word32* len)
|
||||
{
|
||||
/* return 0 on success or BAD_FUNC_ARG on failure */
|
||||
int wc_AriaShaFinal(MC_HSESSION hSession, byte* out, word32* len)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
WOLFSSL_ENTER("AriaShaFinal");
|
||||
|
||||
@ -119,9 +126,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
|
||||
/* Do an extra DigestUpdate noop just in case it is never explicitly called. */
|
||||
if (rv == MC_OK) rv = MC_DigestUpdate(hSession, NULL, 0);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DigestUpdate(hSession, NULL, 0);
|
||||
|
||||
if (rv == MC_OK) rv = MC_DigestFinal(hSession, out, len);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DigestFinal(hSession, out, len);
|
||||
|
||||
if (rv != MC_OK) {
|
||||
WOLFSSL_MSG(MC_GetErrorString(rv));
|
||||
@ -129,11 +138,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
/* WOLFSSL_MSG_EX("Digest len: %d", *len); */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success or BAD_STATE_E on failure */
|
||||
int wc_AriaFree(MC_HSESSION* hSession, MC_HOBJECT *obj1)
|
||||
{
|
||||
/* return 0 on success or BAD_STATE_E on failure */
|
||||
int wc_AriaFree(MC_HSESSION* hSession, MC_HOBJECT *obj1)
|
||||
{
|
||||
MC_RV rv = MC_OK;
|
||||
WOLFSSL_ENTER("AriaFree");
|
||||
|
||||
@ -142,13 +151,17 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
|
||||
if (obj1 != NULL) {
|
||||
if (rv == MC_OK) rv = MC_DestroyObject(*hSession, *obj1);
|
||||
if (rv == MC_OK) *obj1 = NULL;
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DestroyObject(*hSession, *obj1);
|
||||
if (rv == MC_OK)
|
||||
*obj1 = NULL;
|
||||
}
|
||||
|
||||
if (hSession != NULL) {
|
||||
if (rv == MC_OK) rv = MC_CloseSession(*hSession);
|
||||
if (rv == MC_OK) *hSession = NULL;
|
||||
if (rv == MC_OK)
|
||||
rv = MC_CloseSession(*hSession);
|
||||
if (rv == MC_OK)
|
||||
*hSession = NULL;
|
||||
}
|
||||
|
||||
if (rv != MC_OK) {
|
||||
@ -156,10 +169,10 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_STATE_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int wc_AriaSign(byte* in, word32 inSz, byte* out, word32* outSz, ecc_key* key)
|
||||
{
|
||||
int wc_AriaSign(byte* in, word32 inSz, byte* out, word32* outSz, ecc_key* key)
|
||||
{
|
||||
MC_HOBJECT hPrikey = 0;
|
||||
MC_HSESSION hSession = 0;
|
||||
|
||||
@ -177,11 +190,14 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = wc_AriaInit();
|
||||
if (rv == MC_OK)
|
||||
rv = wc_AriaInit();
|
||||
|
||||
if (rv == MC_OK) rv = MC_OpenSession(&hSession);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_OpenSession(&hSession);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetApiMode(hSession, gApimode);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetApiMode(hSession, gApimode);
|
||||
|
||||
if (rv == MC_OK) {
|
||||
int ret = wc_EccPrivateKeyToDerNoCurve(key,keyAsn1,keyAsn1Sz);
|
||||
@ -209,13 +225,16 @@ size and a key size of 128, 192, or 256 bits.
|
||||
rv = MC_ERR_UNSUPPORTED_ALGORITHM;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_CreateObject(hSession, keyAsn1, keyAsn1Sz, &hPrikey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_CreateObject(hSession, keyAsn1, keyAsn1Sz, &hPrikey);
|
||||
WOLFSSL_MSG_EX("AriaSign CreateObject rv=%d",rv);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SignInit(hSession, &mcAlg, hPrikey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SignInit(hSession, &mcAlg, hPrikey);
|
||||
WOLFSSL_MSG_EX("AriaSign SignInit rv=%d",rv);
|
||||
|
||||
if (rv == MC_OK) rv = MC_Sign(hSession, in, inSz, out, outSz);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Sign(hSession, in, inSz, out, outSz);
|
||||
WOLFSSL_MSG_EX("AriaSign Sign rv=%d",rv);
|
||||
|
||||
wc_AriaFree(&hSession, &hPrikey);
|
||||
@ -224,10 +243,10 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_STATE_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int wc_AriaVerify(byte* sig, word32 sigSz, byte* hash, word32 hashSz, int* res, ecc_key* key)
|
||||
{
|
||||
int wc_AriaVerify(byte* sig, word32 sigSz, byte* hash, word32 hashSz, int* res, ecc_key* key)
|
||||
{
|
||||
MC_HOBJECT hPubkey = 0;
|
||||
MC_HSESSION hSession = 0;
|
||||
|
||||
@ -247,11 +266,14 @@ size and a key size of 128, 192, or 256 bits.
|
||||
|
||||
*res = 0; /* Default to invalid signature */
|
||||
|
||||
if (rv == MC_OK) rv = wc_AriaInit();
|
||||
if (rv == MC_OK)
|
||||
rv = wc_AriaInit();
|
||||
|
||||
if (rv == MC_OK) rv = MC_OpenSession(&hSession);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_OpenSession(&hSession);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetApiMode(hSession, gApimode);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetApiMode(hSession, gApimode);
|
||||
|
||||
if (rv == MC_OK) {
|
||||
int ret = wc_EccPublicKeyToDer(key,keyarr,keySz,0);
|
||||
@ -279,13 +301,16 @@ size and a key size of 128, 192, or 256 bits.
|
||||
rv = MC_ERR_UNSUPPORTED_ALGORITHM;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_CreateObject(hSession, keyarr, keySz, &hPubkey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_CreateObject(hSession, keyarr, keySz, &hPubkey);
|
||||
WOLFSSL_MSG_EX("AriaVerify CreateObject rv=%d",rv);
|
||||
|
||||
if (rv == MC_OK) rv = MC_VerifyInit(hSession, &mcAlg, hPubkey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_VerifyInit(hSession, &mcAlg, hPubkey);
|
||||
WOLFSSL_MSG_EX("AriaVerify VerifyInit rv=%d",rv);
|
||||
|
||||
if (rv == MC_OK) rv = MC_Verify(hSession, hash, hashSz, sig, sigSz);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_Verify(hSession, hash, hashSz, sig, sigSz);
|
||||
WOLFSSL_MSG_EX("AriaVerify Verify rv=%d",rv);
|
||||
|
||||
wc_AriaFree(&hSession, &hPubkey);
|
||||
@ -295,10 +320,10 @@ size and a key size of 128, 192, or 256 bits.
|
||||
}
|
||||
*res = 1; /* Valid signature */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int wc_AriaDerive(ecc_key* private_key, ecc_key* public_key, byte* out, word32* outSz)
|
||||
{
|
||||
int wc_AriaDerive(ecc_key* private_key, ecc_key* public_key, byte* out, word32* outSz)
|
||||
{
|
||||
MC_HOBJECT hPrikey = 0;
|
||||
MC_HSESSION hSession = 0;
|
||||
|
||||
@ -318,16 +343,22 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = wc_AriaInit();
|
||||
if (rv == MC_OK)
|
||||
rv = wc_AriaInit();
|
||||
|
||||
if (rv == MC_OK) rv = MC_OpenSession(&hSession);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_OpenSession(&hSession);
|
||||
|
||||
if (rv == MC_OK) rv = MC_SetApiMode(hSession, gApimode);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_SetApiMode(hSession, gApimode);
|
||||
|
||||
if (rv == MC_OK) {
|
||||
int ret = wc_EccPublicKeyToDer(public_key,pubAsn1,pubAsn1Sz,0);
|
||||
if (ret < 0) { rv = ret; }
|
||||
else { pubAsn1Sz = ret; }
|
||||
if (ret < 0) {
|
||||
rv = ret;
|
||||
} else {
|
||||
pubAsn1Sz = ret;
|
||||
}
|
||||
WOLFSSL_MSG_EX("AriaDerive PublicKeyToDer ret=%d",ret);
|
||||
}
|
||||
WOLFSSL_MSG_EX("AriaVerify pubAsn1(%d):",pubAsn1Sz);
|
||||
@ -337,8 +368,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
|
||||
if (rv == MC_OK) {
|
||||
int ret = wc_EccPrivateKeyToDerNoCurve(private_key,privAsn1,privAsn1Sz);
|
||||
if (ret < 0) { rv = ret; }
|
||||
else { privAsn1Sz = ret; }
|
||||
if (ret < 0) {
|
||||
rv = ret;
|
||||
} else {
|
||||
privAsn1Sz = ret;
|
||||
}
|
||||
WOLFSSL_MSG_EX("AriaDerive PrivateKeyToDer ret=%d",ret);
|
||||
}
|
||||
WOLFSSL_MSG_EX("AriaVerify privAsn1(%d):",privAsn1Sz);
|
||||
@ -359,10 +393,12 @@ size and a key size of 128, 192, or 256 bits.
|
||||
rv = MC_ERR_UNSUPPORTED_ALGORITHM;
|
||||
}
|
||||
|
||||
if (rv == MC_OK) rv = MC_CreateObject(hSession, privAsn1, privAsn1Sz, &hPrikey);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_CreateObject(hSession, privAsn1, privAsn1Sz, &hPrikey);
|
||||
WOLFSSL_MSG_EX("AriaDerive CreateObject rv=%d",rv);
|
||||
|
||||
if (rv == MC_OK) rv = MC_DeriveKey(hSession, &mcAlg, hPrikey, out, outSz);
|
||||
if (rv == MC_OK)
|
||||
rv = MC_DeriveKey(hSession, &mcAlg, hPrikey, out, outSz);
|
||||
WOLFSSL_MSG_EX("AriaDerive DeriveKey rv=%d",rv);
|
||||
|
||||
wc_AriaFree(&hSession, &hPrikey);
|
||||
@ -371,11 +407,11 @@ size and a key size of 128, 192, or 256 bits.
|
||||
return BAD_STATE_E;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
static void printOutput(const char* strName, unsigned char* data, unsigned int dataSz)
|
||||
{
|
||||
static void printOutput(const char* strName, unsigned char* data, unsigned int dataSz)
|
||||
{
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
|
||||
WOLFSSL_BUFFER(data,dataSz);
|
||||
@ -399,19 +435,19 @@ static void printOutput(const char* strName, unsigned char* data, unsigned int d
|
||||
(void)dataSz;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
{
|
||||
int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
{
|
||||
int ret = CRYPTOCB_UNAVAILABLE; /* return this to bypass HW and use SW */
|
||||
(void)ctx;
|
||||
|
||||
if (info == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef DEBUG_CRYPTOCB
|
||||
#ifdef DEBUG_CRYPTOCB
|
||||
wc_CryptoCb_InfoString(info);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (info->algo_type == WC_ALGO_TYPE_PK) {
|
||||
if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
|
||||
@ -469,7 +505,8 @@ int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
printOutput((char *)"eccverify.key (after)",
|
||||
(byte *)info->pk.eccverify.key,sizeof(info->pk.eccverify.key));
|
||||
|
||||
if (ret != 0) ret = CRYPTOCB_UNAVAILABLE;
|
||||
if (ret != 0)
|
||||
ret = CRYPTOCB_UNAVAILABLE;
|
||||
/* reset devId */
|
||||
info->pk.eccverify.key->devId = devIdArg;
|
||||
}
|
||||
@ -481,7 +518,8 @@ int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
info->pk.ecdh.private_key, info->pk.ecdh.public_key,
|
||||
info->pk.ecdh.out, info->pk.ecdh.outlen);
|
||||
|
||||
if (ret != 0) ret = CRYPTOCB_UNAVAILABLE;
|
||||
if (ret != 0)
|
||||
ret = CRYPTOCB_UNAVAILABLE;
|
||||
/* reset devId */
|
||||
info->pk.ecdh.private_key->devId = devIdArg;
|
||||
}
|
||||
@ -511,7 +549,8 @@ int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
if ((ret == 0) || (ret == CRYPTOCB_UNAVAILABLE))
|
||||
ret = wc_AriaFree(&(info->hash.sha256->hSession),NULL);
|
||||
}
|
||||
if (ret != 0) ret = CRYPTOCB_UNAVAILABLE;
|
||||
if (ret != 0)
|
||||
ret = CRYPTOCB_UNAVAILABLE;
|
||||
/* reset devId */
|
||||
info->hash.sha256->devId = devIdArg;
|
||||
}
|
||||
@ -546,5 +585,5 @@ int wc_AriaCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif /* WOLF_CRYPTO_CB */
|
||||
|
Reference in New Issue
Block a user