Skip to content

Commit 13d91e7

Browse files
committed
Merge pull request #327 from libtom/fix/ccm_segfault
Fix ccm_memory() cleaning user-supplied key (cherry picked from commit 85ac227)
1 parent 368dc60 commit 13d91e7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/encauth/ccm/ccm_memory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ int ccm_memory(int cipher,
333333

334334
if (skey != uskey) {
335335
cipher_descriptor[cipher].done(skey);
336+
#ifdef LTC_CLEAN_STACK
337+
zeromem(skey, sizeof(*skey));
338+
#endif
336339
}
337340

338341
if (direction == CCM_ENCRYPT) {
@@ -380,7 +383,6 @@ int ccm_memory(int cipher,
380383
fastMask = 0;
381384
#endif
382385
mask = 0;
383-
zeromem(skey, sizeof(*skey));
384386
zeromem(PAD, sizeof(PAD));
385387
zeromem(CTRPAD, sizeof(CTRPAD));
386388
if (pt_work != NULL) {

src/encauth/ccm/ccm_test.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ int ccm_test(void)
145145
tag, &taglen, 0)) != CRYPT_OK) {
146146
return err;
147147
}
148+
/* run a second time to make sure skey is not touched */
149+
if ((err = ccm_memory(idx,
150+
tests[x].key, 16,
151+
&skey,
152+
tests[x].nonce, tests[x].noncelen,
153+
tests[x].header, tests[x].headerlen,
154+
(unsigned char*)tests[x].pt, tests[x].ptlen,
155+
buf,
156+
tag, &taglen, 0)) != CRYPT_OK) {
157+
return err;
158+
}
148159
} else {
149160
if ((err = ccm_init(&ccm, idx, tests[x].key, 16, tests[x].ptlen, tests[x].taglen, tests[x].headerlen)) != CRYPT_OK) {
150161
return err;

0 commit comments

Comments
 (0)