Skip to content

Commit 868c5a8

Browse files
committed
OCBv3: fix handling of empty plaintext
1 parent bc0c18f commit 868c5a8

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/encauth/ocb3/ocb3_decrypt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ int ocb3_decrypt(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen,
3030
unsigned char *pt_b, *ct_b;
3131

3232
LTC_ARGCHK(ocb != NULL);
33-
LTC_ARGCHK(pt != NULL);
34-
LTC_ARGCHK(ct != NULL);
33+
if (ct == NULL) LTC_ARGCHK(ctlen == 0);
34+
if (ctlen == 0) LTC_ARGCHK(ct == NULL);
35+
else LTC_ARGCHK(pt != NULL);
36+
3537
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
3638
return err;
3739
}

src/encauth/ocb3/ocb3_decrypt_last.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ct
3030
int err, x, full_blocks, full_blocks_len, last_block_len;
3131

3232
LTC_ARGCHK(ocb != NULL);
33-
LTC_ARGCHK(ct != NULL);
34-
LTC_ARGCHK(pt != NULL);
33+
if (ct == NULL) LTC_ARGCHK(ctlen == 0);
34+
if (ctlen == 0) LTC_ARGCHK(ct == NULL);
35+
else LTC_ARGCHK(pt != NULL);
36+
3537
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
3638
goto LBL_ERR;
3739
}

src/encauth/ocb3/ocb3_encrypt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ int ocb3_encrypt(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen,
3030
unsigned char *pt_b, *ct_b;
3131

3232
LTC_ARGCHK(ocb != NULL);
33-
LTC_ARGCHK(pt != NULL);
34-
LTC_ARGCHK(ct != NULL);
33+
if (pt == NULL) LTC_ARGCHK(ptlen == 0);
34+
if (ptlen == 0) LTC_ARGCHK(pt == NULL);
35+
else LTC_ARGCHK(ct != NULL);
36+
3537
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
3638
return err;
3739
}

src/encauth/ocb3/ocb3_encrypt_last.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
3030
int err, x, full_blocks, full_blocks_len, last_block_len;
3131

3232
LTC_ARGCHK(ocb != NULL);
33-
LTC_ARGCHK(pt != NULL);
33+
if (pt == NULL) LTC_ARGCHK(ptlen == 0);
34+
if (ptlen == 0) LTC_ARGCHK(pt == NULL);
35+
else LTC_ARGCHK(ct != NULL);
36+
3437
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
3538
goto LBL_ERR;
3639
}

src/encauth/ocb3/ocb3_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ int ocb3_test(void)
219219
key, sizeof(key),
220220
nonce, sizeof(nonce),
221221
tests[x].aadlen != 0 ? tests[x].aad : NULL, tests[x].aadlen,
222-
tests[x].pt, tests[x].ptlen,
223-
outct, outtag, &len)) != CRYPT_OK) {
222+
tests[x].ptlen != 0 ? tests[x].pt : NULL, tests[x].ptlen,
223+
tests[x].ptlen != 0 ? outct : NULL, outtag, &len)) != CRYPT_OK) {
224224
return err;
225225
}
226226

@@ -233,8 +233,8 @@ int ocb3_test(void)
233233
key, sizeof(key),
234234
nonce, sizeof(nonce),
235235
tests[x].aadlen != 0 ? tests[x].aad : NULL, tests[x].aadlen,
236-
outct, tests[x].ptlen,
237-
outct, tests[x].tag, len, &res)) != CRYPT_OK) {
236+
tests[x].ptlen != 0 ? outct : NULL, tests[x].ptlen,
237+
tests[x].ptlen != 0 ? outct : NULL, tests[x].tag, len, &res)) != CRYPT_OK) {
238238
return err;
239239
}
240240
if ((res != 1) || compare_testvector(outct, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "OCB3", x)) {

0 commit comments

Comments
 (0)