forked from wolfSSL/wolfssl
Fix wc_ecc_alloc_rs memset logic. Fix error handling in hmac.c for SHA224. Cleanup of the wc_DhGenerateKeyPair_Async function. Added comment about the “BuildTlsFinished” allocation for hash buffer. Fixed issue with example server that caused the benchmark script to fail in throughput mode.
This commit is contained in:
@@ -175,7 +175,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int throughput)
|
|||||||
/* Read data */
|
/* Read data */
|
||||||
while (rx_pos < len) {
|
while (rx_pos < len) {
|
||||||
ret = SSL_read(ssl, &buffer[rx_pos], len - rx_pos);
|
ret = SSL_read(ssl, &buffer[rx_pos], len - rx_pos);
|
||||||
if (ret <= 0) {
|
if (ret < 0) {
|
||||||
err = SSL_get_error(ssl, 0);
|
err = SSL_get_error(ssl, 0);
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
if (err == WC_PENDING_E) {
|
if (err == WC_PENDING_E) {
|
||||||
@@ -1152,7 +1152,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||||||
do {
|
do {
|
||||||
err = 0; /* reset error */
|
err = 0; /* reset error */
|
||||||
ret = SSL_read(ssl, input, sizeof(input)-1);
|
ret = SSL_read(ssl, input, sizeof(input)-1);
|
||||||
if (ret <= 0) {
|
if (ret < 0) {
|
||||||
err = SSL_get_error(ssl, 0);
|
err = SSL_get_error(ssl, 0);
|
||||||
|
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
@@ -399,6 +399,7 @@ int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
|
|||||||
byte* handshake_hash;
|
byte* handshake_hash;
|
||||||
word32 hashSz = HSHASH_SZ;
|
word32 hashSz = HSHASH_SZ;
|
||||||
|
|
||||||
|
/* using allocate here to allow async hardware to use buffer directly */
|
||||||
handshake_hash = (byte*)XMALLOC(hashSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
handshake_hash = (byte*)XMALLOC(hashSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (handshake_hash == NULL)
|
if (handshake_hash == NULL)
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
|
@@ -211,53 +211,53 @@ static int wc_DhGenerateKeyPair_Async(DhKey* key, WC_RNG* rng,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
(void)rng;
|
#if defined(HAVE_INTEL_QA)
|
||||||
|
mp_int x;
|
||||||
#ifdef HAVE_CAVIUM
|
|
||||||
/* TODO: Not implemented - use software for now */
|
|
||||||
|
|
||||||
#elif defined(HAVE_INTEL_QA)
|
|
||||||
{
|
|
||||||
mp_int x;
|
|
||||||
ret = mp_init(&x);
|
|
||||||
if (ret != MP_OKAY)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = GeneratePrivateDh(key, rng, priv, privSz);
|
|
||||||
if (ret == 0)
|
|
||||||
ret = mp_read_unsigned_bin(&x, priv, *privSz);
|
|
||||||
if (ret == MP_OKAY)
|
|
||||||
ret = wc_mp_to_bigint(&x, &x.raw);
|
|
||||||
if (ret == MP_OKAY)
|
|
||||||
ret = wc_mp_to_bigint(&key->p, &key->p.raw);
|
|
||||||
if (ret == MP_OKAY)
|
|
||||||
ret = wc_mp_to_bigint(&key->g, &key->g.raw);
|
|
||||||
if (ret == MP_OKAY)
|
|
||||||
ret = IntelQaDhKeyGen(&key->asyncDev, &key->p.raw, &key->g.raw,
|
|
||||||
&x.raw, pub, pubSz);
|
|
||||||
mp_clear(&x);
|
|
||||||
|
|
||||||
|
ret = mp_init(&x);
|
||||||
|
if (ret != MP_OKAY)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
ret = GeneratePrivateDh(key, rng, priv, privSz);
|
||||||
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
if (ret == 0)
|
||||||
if (testDev->type == ASYNC_TEST_NONE) {
|
ret = mp_read_unsigned_bin(&x, priv, *privSz);
|
||||||
testDev->type = ASYNC_TEST_DH_GEN;
|
if (ret == MP_OKAY)
|
||||||
testDev->dhGen.key = key;
|
ret = wc_mp_to_bigint(&x, &x.raw);
|
||||||
testDev->dhGen.rng = rng;
|
if (ret == MP_OKAY)
|
||||||
testDev->dhGen.priv = priv;
|
ret = wc_mp_to_bigint(&key->p, &key->p.raw);
|
||||||
testDev->dhGen.privSz = privSz;
|
if (ret == MP_OKAY)
|
||||||
testDev->dhGen.pub = pub;
|
ret = wc_mp_to_bigint(&key->g, &key->g.raw);
|
||||||
testDev->dhGen.pubSz = pubSz;
|
if (ret == MP_OKAY)
|
||||||
return WC_PENDING_E;
|
ret = IntelQaDhKeyGen(&key->asyncDev, &key->p.raw, &key->g.raw,
|
||||||
}
|
&x.raw, pub, pubSz);
|
||||||
#endif
|
mp_clear(&x);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#if defined(HAVE_CAVIUM)
|
||||||
|
/* TODO: Not implemented - use software for now */
|
||||||
|
|
||||||
|
#else /* WOLFSSL_ASYNC_CRYPT_TEST */
|
||||||
|
WC_ASYNC_TEST* testDev = &key->asyncDev.test;
|
||||||
|
if (testDev->type == ASYNC_TEST_NONE) {
|
||||||
|
testDev->type = ASYNC_TEST_DH_GEN;
|
||||||
|
testDev->dhGen.key = key;
|
||||||
|
testDev->dhGen.rng = rng;
|
||||||
|
testDev->dhGen.priv = priv;
|
||||||
|
testDev->dhGen.privSz = privSz;
|
||||||
|
testDev->dhGen.pub = pub;
|
||||||
|
testDev->dhGen.pubSz = pubSz;
|
||||||
|
return WC_PENDING_E;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = wc_DhGenerateKeyPair_Sync(key, rng, priv, privSz, pub, pubSz);
|
ret = wc_DhGenerateKeyPair_Sync(key, rng, priv, privSz, pub, pubSz);
|
||||||
|
|
||||||
|
#endif /* HAVE_INTEL_QA */
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_DH */
|
||||||
|
|
||||||
|
|
||||||
/* Check DH Public Key for invalid numbers
|
/* Check DH Public Key for invalid numbers
|
||||||
|
@@ -3185,6 +3185,10 @@ static INLINE int wc_ecc_alloc_rs(ecc_key* key, mp_int** r, mp_int** s)
|
|||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_ASYNC_CRYPT
|
||||||
|
(void)key;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (*r == NULL) {
|
if (*r == NULL) {
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
*r = (mp_int*)XMALLOC(sizeof(mp_int), key->heap, DYNAMIC_TYPE_BIGINT);
|
*r = (mp_int*)XMALLOC(sizeof(mp_int), key->heap, DYNAMIC_TYPE_BIGINT);
|
||||||
@@ -3193,8 +3197,6 @@ static INLINE int wc_ecc_alloc_rs(ecc_key* key, mp_int** r, mp_int** s)
|
|||||||
}
|
}
|
||||||
key->r = *r;
|
key->r = *r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
XMEMSET(*r, 0, sizeof(mp_int));
|
|
||||||
}
|
}
|
||||||
if (*s == NULL) {
|
if (*s == NULL) {
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
@@ -3205,10 +3207,13 @@ static INLINE int wc_ecc_alloc_rs(ecc_key* key, mp_int** r, mp_int** s)
|
|||||||
}
|
}
|
||||||
key->s = *s;
|
key->s = *s;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
XMEMSET(*s, 0, sizeof(mp_int));
|
|
||||||
}
|
}
|
||||||
(void)key;
|
|
||||||
|
/* initialize mp_int */
|
||||||
|
if (*r)
|
||||||
|
XMEMSET(*r, 0, sizeof(mp_int));
|
||||||
|
if (*s)
|
||||||
|
XMEMSET(*s, 0, sizeof(mp_int));
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@@ -322,10 +322,10 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
|||||||
else {
|
else {
|
||||||
ret = wc_Sha224Update(&hmac->hash.sha224, key, length);
|
ret = wc_Sha224Update(&hmac->hash.sha224, key, length);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
ret = wc_Sha224Final(&hmac->hash.sha224, ip);
|
ret = wc_Sha224Final(&hmac->hash.sha224, ip);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
|
|
||||||
length = SHA224_DIGEST_SIZE;
|
length = SHA224_DIGEST_SIZE;
|
||||||
}
|
}
|
||||||
@@ -577,7 +577,6 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
|||||||
return IntelQaHmac(&hmac->asyncDev, hmac->macType,
|
return IntelQaHmac(&hmac->asyncDev, hmac->macType,
|
||||||
hmac->keyRaw, hmac->keyLen, hash, NULL, hashLen);
|
hmac->keyRaw, hmac->keyLen, hash, NULL, hashLen);
|
||||||
#endif
|
#endif
|
||||||
(void)hashLen;
|
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
|
||||||
@@ -627,18 +626,18 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
|||||||
{
|
{
|
||||||
ret = wc_Sha224Final(&hmac->hash.sha224, (byte*)hmac->innerHash);
|
ret = wc_Sha224Final(&hmac->hash.sha224, (byte*)hmac->innerHash);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->opad,
|
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->opad,
|
||||||
SHA224_BLOCK_SIZE);
|
SHA224_BLOCK_SIZE);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->innerHash,
|
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->innerHash,
|
||||||
SHA224_DIGEST_SIZE);
|
SHA224_DIGEST_SIZE);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
ret = wc_Sha224Final(&hmac->hash.sha224, hash);
|
ret = wc_Sha224Final(&hmac->hash.sha224, hash);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* WOLFSSL_SHA224 */
|
#endif /* WOLFSSL_SHA224 */
|
||||||
|
Reference in New Issue
Block a user