Skip to content

Commit 4e4215a

Browse files
authored
Merge pull request #9904 from julek-wolfssl/fenrir/24
Clean up hpke and rng allocation
2 parents 1744819 + ac333c3 commit 4e4215a

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

src/tls.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13270,13 +13270,9 @@ static int TLSX_ECH_Write(WOLFSSL_ECH* ech, byte msgType, byte* writeBuf,
1327013270
word32 configsLen = 0;
1327113271
void* ephemeralKey = NULL;
1327213272
byte* writeBuf_p = writeBuf;
13273-
#ifdef WOLFSSL_SMALL_STACK
13274-
Hpke* hpke = NULL;
13275-
WC_RNG* rng = NULL;
13276-
#else
13277-
Hpke hpke[1];
13278-
WC_RNG rng[1];
13279-
#endif
13273+
WC_DECLARE_VAR(hpke, Hpke, 1, DYNAMIC_TYPE_TMP_BUFFER);
13274+
WC_DECLARE_VAR(rng, WC_RNG, 1, DYNAMIC_TYPE_RNG);
13275+
1328013276
WOLFSSL_MSG("TLSX_ECH_Write");
1328113277
if (msgType == hello_retry_request) {
1328213278
/* reserve space to write the confirmation to */
@@ -13322,19 +13318,13 @@ static int TLSX_ECH_Write(WOLFSSL_ECH* ech, byte msgType, byte* writeBuf,
1332213318
}
1332313319
writeBuf_p += 2;
1332413320
if (ech->state == ECH_WRITE_GREASE) {
13325-
#ifdef WOLFSSL_SMALL_STACK
13326-
hpke = (Hpke*)XMALLOC(sizeof(Hpke), NULL, DYNAMIC_TYPE_TMP_BUFFER);
13327-
if (hpke == NULL)
13328-
return MEMORY_E;
13329-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
13330-
if (rng == NULL) {
13331-
XFREE(hpke, NULL, DYNAMIC_TYPE_RNG);
13332-
return MEMORY_E;
13333-
}
13334-
#endif
13321+
WC_ALLOC_VAR_EX(hpke, Hpke, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER, ret = MEMORY_E);
13322+
WC_ALLOC_VAR_EX(rng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG, ret = MEMORY_E);
1333513323
/* hpke init */
13336-
ret = wc_HpkeInit(hpke, ech->kemId, ech->cipherSuite.kdfId,
13337-
ech->cipherSuite.aeadId, NULL);
13324+
if (ret == 0) {
13325+
ret = wc_HpkeInit(hpke, ech->kemId, ech->cipherSuite.kdfId,
13326+
ech->cipherSuite.aeadId, NULL);
13327+
}
1333813328
if (ret == 0)
1333913329
rngRet = ret = wc_InitRng(rng);
1334013330
/* create the ephemeralKey */

0 commit comments

Comments
 (0)