Skip to content

Commit 21fcc77

Browse files
committed
- Added logs when outputing a digest indicating which algo is being used;
- Fixed memory leak in wolfssl_pk_generate_keys_dh;
1 parent f397d34 commit 21fcc77

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

wolfssl-gnutls-wrapper/src/wolfssl.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3101,69 +3101,79 @@ static int wolfssl_digest_output(void *_ctx, void *digest, size_t digestsize)
31013101

31023102
/* Finalize the digest and get the result. */
31033103
if (ctx->algorithm == GNUTLS_DIG_MD5) {
3104+
WGW_LOG("Outputting Md5");
31043105
/* Make sure the output buffer is large enough. */
31053106
if (digestsize < WC_MD5_DIGEST_SIZE) {
31063107
WGW_ERROR("digestsize too small for MD5 output");
31073108
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31083109
}
31093110
ret = wc_Md5Final(&ctx->obj.md5, (byte*)digest);
31103111
} else if (ctx->algorithm == GNUTLS_DIG_SHA1) {
3112+
WGW_LOG("Outputting Sha1");
31113113
/* Make sure the output buffer is large enough. */
31123114
if (digestsize < WC_SHA_DIGEST_SIZE) {
31133115
WGW_ERROR("digestsize too small for SHA-1 output");
31143116
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31153117
}
31163118
ret = wc_ShaFinal(&ctx->obj.sha, (byte*)digest);
31173119
} else if (ctx->algorithm == GNUTLS_DIG_SHA224) {
3120+
WGW_LOG("Outputting Sha224");
31183121
/* Make sure the output buffer is large enough. */
31193122
if (digestsize < WC_SHA224_DIGEST_SIZE) {
31203123
WGW_ERROR("digestsize too small for SHA-224 output");
31213124
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31223125
}
31233126
ret = wc_Sha224Final(&ctx->obj.sha224, (byte*)digest);
31243127
} else if (ctx->algorithm == GNUTLS_DIG_SHA256) {
3128+
WGW_LOG("Outputting Sha256");
31253129
/* Make sure the output buffer is large enough. */
31263130
if (digestsize < WC_SHA256_DIGEST_SIZE) {
31273131
WGW_ERROR("digestsize too small for SHA-256 output");
31283132
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31293133
}
31303134
ret = wc_Sha256Final(&ctx->obj.sha256, (byte*)digest);
31313135
} else if (ctx->algorithm == GNUTLS_DIG_SHA384) {
3136+
WGW_LOG("Outputting Sha384");
31323137
/* Make sure the output buffer is large enough. */
31333138
if (digestsize < WC_SHA384_DIGEST_SIZE) {
31343139
WGW_ERROR("digestsize too small for SHA-384 output");
31353140
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31363141
}
31373142
ret = wc_Sha384Final(&ctx->obj.sha384, (byte*)digest);
31383143
} else if (ctx->algorithm == GNUTLS_DIG_SHA512) {
3144+
WGW_LOG("Outputting Sha512");
31393145
/* Make sure the output buffer is large enough. */
31403146
if (digestsize < WC_SHA512_DIGEST_SIZE) {
31413147
WGW_ERROR("digestsize too small for SHA-512 output");
31423148
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31433149
}
31443150
ret = wc_Sha512Final(&ctx->obj.sha512, (byte*)digest);
31453151
} else if (ctx->algorithm == GNUTLS_DIG_SHA3_224) {
3152+
WGW_LOG("Outputting Sha3 224");
31463153
/* Make sure the output buffer is large enough. */
31473154
if (digestsize < WC_SHA3_224_DIGEST_SIZE) {
31483155
WGW_ERROR("digestsize too small for SHA3-224 output");
31493156
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31503157
}
31513158
ret = wc_Sha3_224_Final(&ctx->obj.sha3, (byte*)digest);
31523159
} else if (ctx->algorithm == GNUTLS_DIG_SHA3_256) {
3160+
WGW_LOG("Outputting Sha3 256");
31533161
/* Make sure the output buffer is large enough. */
31543162
if (digestsize < WC_SHA3_256_DIGEST_SIZE) {
31553163
WGW_ERROR("digestsize too small for SHA3-256 output");
31563164
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31573165
}
31583166
ret = wc_Sha3_256_Final(&ctx->obj.sha3, (byte*)digest);
31593167
} else if (ctx->algorithm == GNUTLS_DIG_SHA3_384) {
3168+
WGW_LOG("Outputting Sha3 384");
31603169
/* Make sure the output buffer is large enough. */
31613170
if (digestsize < WC_SHA3_384_DIGEST_SIZE) {
31623171
WGW_ERROR("digestsize too small for SHA3-384 output");
31633172
return GNUTLS_E_SHORT_MEMORY_BUFFER;
31643173
}
31653174
ret = wc_Sha3_384_Final(&ctx->obj.sha3, (byte*)digest);
31663175
} else if (ctx->algorithm == GNUTLS_DIG_SHA3_512) {
3176+
WGW_LOG("Outputting Sha3 512");
31673177
/* Make sure the output buffer is large enough. */
31683178
if (digestsize < WC_SHA3_512_DIGEST_SIZE) {
31693179
WGW_ERROR("digestsize too small for SHA3-512 output");
@@ -5439,11 +5449,11 @@ static int wolfssl_pk_generate_keys_dh(unsigned int bits,
54395449

54405450
wc_FreeRng(&rng);
54415451
wc_FreeDhKey(&dh);
5452+
54425453
if (ret != 0) {
54435454
WGW_WOLFSSL_ERROR("wc_DhGenerateKeyPair", ret);
54445455
gnutls_free(pub);
54455456
gnutls_free(priv);
5446-
wc_FreeDhKey(&dh);
54475457
return ret;
54485458
}
54495459

@@ -5456,6 +5466,9 @@ static int wolfssl_pk_generate_keys_dh(unsigned int bits,
54565466
params->params_nr++;
54575467
}
54585468

5469+
gnutls_free(pub);
5470+
gnutls_free(priv);
5471+
54595472
return ret;
54605473
}
54615474

0 commit comments

Comments
 (0)