forked from wolfSSL/wolfssl
Improve the build message to not always allocate the IV (16 byte) (use fixed buffer if <= 16 bytes).
This commit is contained in:
@ -18116,8 +18116,10 @@ int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes)
|
|||||||
void FreeBuildMsgArgs(WOLFSSL* ssl, BuildMsgArgs* args)
|
void FreeBuildMsgArgs(WOLFSSL* ssl, BuildMsgArgs* args)
|
||||||
{
|
{
|
||||||
if (args) {
|
if (args) {
|
||||||
if (ssl && args->iv)
|
/* only free the IV if it was dynamically allocated */
|
||||||
|
if (ssl && args->iv && (args->iv != args->staticIvBuffer)) {
|
||||||
XFREE(args->iv, ssl->heap, DYNAMIC_TYPE_SALT);
|
XFREE(args->iv, ssl->heap, DYNAMIC_TYPE_SALT);
|
||||||
|
}
|
||||||
XMEMSET(args, 0, sizeof(BuildMsgArgs));
|
XMEMSET(args, 0, sizeof(BuildMsgArgs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18312,9 +18314,16 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args->ivSz > 0) {
|
if (args->ivSz > 0) {
|
||||||
args->iv = (byte*)XMALLOC(args->ivSz, ssl->heap, DYNAMIC_TYPE_SALT);
|
if (args->ivSz > sizeof(args->staticIvBuffer)) {
|
||||||
if (args->iv == NULL)
|
args->iv = (byte*)XMALLOC(args->ivSz, ssl->heap,
|
||||||
ERROR_OUT(MEMORY_E, exit_buildmsg);
|
DYNAMIC_TYPE_SALT);
|
||||||
|
if (args->iv == NULL) {
|
||||||
|
ERROR_OUT(MEMORY_E, exit_buildmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
args->iv = args->staticIvBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
ret = wc_RNG_GenerateBlock(ssl->rng, args->iv, args->ivSz);
|
ret = wc_RNG_GenerateBlock(ssl->rng, args->iv, args->ivSz);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
|
@ -4183,6 +4183,7 @@ typedef struct BuildMsgArgs {
|
|||||||
word16 size;
|
word16 size;
|
||||||
word32 ivSz; /* TLSv1.1 IV */
|
word32 ivSz; /* TLSv1.1 IV */
|
||||||
byte* iv;
|
byte* iv;
|
||||||
|
ALIGN16 byte staticIvBuffer[MAX_IV_SZ];
|
||||||
} BuildMsgArgs;
|
} BuildMsgArgs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user