Skip to content

Commit 890c1a8

Browse files
committed
fix - CCM invalid tag len
1 parent 93c676c commit 890c1a8

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

src/encauth/ccm/ccm_init.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ int ccm_init(ccm_state *ccm, int cipher,
2929

3030
LTC_ARGCHK(ccm != NULL);
3131
LTC_ARGCHK(key != NULL);
32-
LTC_ARGCHK(taglen != 0);
3332

3433
XMEMSET(ccm, 0, sizeof(ccm_state));
3534

@@ -41,17 +40,11 @@ int ccm_init(ccm_state *ccm, int cipher,
4140
return CRYPT_INVALID_CIPHER;
4241
}
4342

44-
/* make sure the taglen is even and <= 16 */
45-
ccm->taglen = taglen;
46-
ccm->taglen &= ~1;
47-
if (ccm->taglen > 16) {
48-
ccm->taglen = 16;
49-
}
50-
51-
/* can't use < 4 */
52-
if (ccm->taglen < 4) {
43+
/* make sure the taglen is valid */
44+
if (taglen < 4 || taglen > 16 || (taglen % 2) == 1) {
5345
return CRYPT_INVALID_ARG;
5446
}
47+
ccm->taglen = taglen;
5548

5649
/* schedule key */
5750
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &ccm->K)) != CRYPT_OK) {

src/encauth/ccm/ccm_memory.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,8 @@ int ccm_memory(int cipher,
8080
return CRYPT_INVALID_CIPHER;
8181
}
8282

83-
/* make sure the taglen is even and <= 16 */
84-
*taglen &= ~1;
85-
if (*taglen > 16) {
86-
*taglen = 16;
87-
}
88-
89-
/* can't use < 4 */
90-
if (*taglen < 4) {
83+
/* make sure the taglen is valid */
84+
if (*taglen < 4 || *taglen > 16 || (*taglen % 2) == 1) {
9185
return CRYPT_INVALID_ARG;
9286
}
9387

src/encauth/ccm/ccm_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ int ccm_test(void)
269269
err = ccm_memory(idx, key, sizeof(key), NULL, iv, sizeof(iv), NULL, 0,
270270
pt, sizeof(ct), ct, invalid_tag, &taglen, CCM_DECRYPT);
271271
if (err == CRYPT_OK) {
272-
fprintf(stderr, "XXX-FIXME ccm_memory should reject invalid tag\n");
273-
/* return CRYPT_FAIL_TESTVECTOR; */
272+
return CRYPT_FAIL_TESTVECTOR; /* should fail */
274273
}
275274
}
276275

0 commit comments

Comments
 (0)