mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 12:44:45 +02:00
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 */
|
||||
while (rx_pos < len) {
|
||||
ret = SSL_read(ssl, &buffer[rx_pos], len - rx_pos);
|
||||
if (ret <= 0) {
|
||||
if (ret < 0) {
|
||||
err = SSL_get_error(ssl, 0);
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
if (err == WC_PENDING_E) {
|
||||
@@ -1152,7 +1152,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
do {
|
||||
err = 0; /* reset error */
|
||||
ret = SSL_read(ssl, input, sizeof(input)-1);
|
||||
if (ret <= 0) {
|
||||
if (ret < 0) {
|
||||
err = SSL_get_error(ssl, 0);
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
|
@@ -399,6 +399,7 @@ int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
|
||||
byte* handshake_hash;
|
||||
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);
|
||||
if (handshake_hash == NULL)
|
||||
return MEMORY_E;
|
||||
|
@@ -211,53 +211,53 @@ static int wc_DhGenerateKeyPair_Async(DhKey* key, WC_RNG* rng,
|
||||
{
|
||||
int ret;
|
||||
|
||||
(void)rng;
|
||||
|
||||
#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);
|
||||
#if defined(HAVE_INTEL_QA)
|
||||
mp_int x;
|
||||
|
||||
ret = mp_init(&x);
|
||||
if (ret != MP_OKAY)
|
||||
return ret;
|
||||
}
|
||||
#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 = 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);
|
||||
|
||||
#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);
|
||||
|
||||
#endif /* HAVE_INTEL_QA */
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_DH */
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
#ifndef WOLFSSL_ASYNC_CRYPT
|
||||
(void)key;
|
||||
#endif
|
||||
|
||||
if (*r == NULL) {
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
*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;
|
||||
#endif
|
||||
|
||||
XMEMSET(*r, 0, sizeof(mp_int));
|
||||
}
|
||||
if (*s == NULL) {
|
||||
#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;
|
||||
#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;
|
||||
}
|
||||
|
@@ -322,10 +322,10 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
else {
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, key, length);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, ip);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
|
||||
length = SHA224_DIGEST_SIZE;
|
||||
}
|
||||
@@ -577,7 +577,6 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
return IntelQaHmac(&hmac->asyncDev, hmac->macType,
|
||||
hmac->keyRaw, hmac->keyLen, hash, NULL, hashLen);
|
||||
#endif
|
||||
(void)hashLen;
|
||||
}
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
|
||||
@@ -627,18 +626,18 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
{
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->opad,
|
||||
SHA224_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->innerHash,
|
||||
SHA224_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, hash);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
Reference in New Issue
Block a user