Skip to content

Commit ac333c3

Browse files
committed
Clean up hpke and rng allocation
1 parent 8093875 commit ac333c3

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
@@ -13269,13 +13269,9 @@ static int TLSX_ECH_Write(WOLFSSL_ECH* ech, byte msgType, byte* writeBuf,
1326913269
word32 configsLen = 0;
1327013270
void* ephemeralKey = NULL;
1327113271
byte* writeBuf_p = writeBuf;
13272-
#ifdef WOLFSSL_SMALL_STACK
13273-
Hpke* hpke = NULL;
13274-
WC_RNG* rng = NULL;
13275-
#else
13276-
Hpke hpke[1];
13277-
WC_RNG rng[1];
13278-
#endif
13272+
WC_DECLARE_VAR(hpke, Hpke, 1, DYNAMIC_TYPE_TMP_BUFFER);
13273+
WC_DECLARE_VAR(rng, WC_RNG, 1, DYNAMIC_TYPE_RNG);
13274+
1327913275
WOLFSSL_MSG("TLSX_ECH_Write");
1328013276
if (msgType == hello_retry_request) {
1328113277
/* reserve space to write the confirmation to */
@@ -13321,19 +13317,13 @@ static int TLSX_ECH_Write(WOLFSSL_ECH* ech, byte msgType, byte* writeBuf,
1332113317
}
1332213318
writeBuf_p += 2;
1332313319
if (ech->state == ECH_WRITE_GREASE) {
13324-
#ifdef WOLFSSL_SMALL_STACK
13325-
hpke = (Hpke*)XMALLOC(sizeof(Hpke), NULL, DYNAMIC_TYPE_TMP_BUFFER);
13326-
if (hpke == NULL)
13327-
return MEMORY_E;
13328-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
13329-
if (rng == NULL) {
13330-
XFREE(hpke, NULL, DYNAMIC_TYPE_RNG);
13331-
return MEMORY_E;
13332-
}
13333-
#endif
13320+
WC_ALLOC_VAR_EX(hpke, Hpke, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER, ret = MEMORY_E);
13321+
WC_ALLOC_VAR_EX(rng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG, ret = MEMORY_E);
1333413322
/* hpke init */
13335-
ret = wc_HpkeInit(hpke, ech->kemId, ech->cipherSuite.kdfId,
13336-
ech->cipherSuite.aeadId, NULL);
13323+
if (ret == 0) {
13324+
ret = wc_HpkeInit(hpke, ech->kemId, ech->cipherSuite.kdfId,
13325+
ech->cipherSuite.aeadId, NULL);
13326+
}
1333713327
if (ret == 0)
1333813328
rngRet = ret = wc_InitRng(rng);
1333913329
/* create the ephemeralKey */

0 commit comments

Comments
 (0)