diff --git a/ChangeLog b/ChangeLog index 12ddbc7001a19f658ce9a24fada83b6a3e8c798f..2a43a3cb684c82ccbd8840b40ac1057256b893df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2014-04-25 Niels Möller <nisse@lysator.liu.se> + + * testsuite/ccm-test.c (test_cipher_ccm): And tests. + + * ccm.c (ccm_decrypt_message): Change length argument, should now + be clear text (dst) length. + * ccm-aes128.c (ccm_aes128_decrypt_message): Likewise. + * ccm-aes192.c (ccm_aes192_decrypt_message): Likewise. + * ccm-aes256.c (ccm_aes256_decrypt_message): Likewise. + * ccm.h: Updated prototypes. + 2014-04-22 Niels Möller <nisse@lysator.liu.se> * nettle.texinfo (Recommended hash functions): Document additional diff --git a/ccm-aes128.c b/ccm-aes128.c index c47249ea8ae32257bbfd44a0971d0cf8046ce96d..74ae51f4c7eac491ec1f532f8776b15e8dc8ab4e 100644 --- a/ccm-aes128.c +++ b/ccm-aes128.c @@ -105,10 +105,10 @@ ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src) + size_t mlength, uint8_t *dst, const uint8_t *src) { return ccm_decrypt_message(&ctx->cipher, (nettle_cipher_func *) aes128_encrypt, nlength, nonce, alength, adata, - tlength, clength, dst, src); + tlength, mlength, dst, src); } diff --git a/ccm-aes192.c b/ccm-aes192.c index 01d406a0d87f1da1f43ce83862df103c5d035277..6b6ebed94abf2a69b9a650e3fae07c9eca4ccbfc 100644 --- a/ccm-aes192.c +++ b/ccm-aes192.c @@ -105,10 +105,10 @@ ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src) + size_t mlength, uint8_t *dst, const uint8_t *src) { return ccm_decrypt_message(&ctx->cipher, (nettle_cipher_func *) aes192_encrypt, nlength, nonce, alength, adata, - tlength, clength, dst, src); + tlength, mlength, dst, src); } diff --git a/ccm-aes256.c b/ccm-aes256.c index 9a58ceabee7cb25bec145a42ba2f1df414ac2185..211c411b3200f066d748f444e4995e78637adbb4 100644 --- a/ccm-aes256.c +++ b/ccm-aes256.c @@ -106,9 +106,9 @@ ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src) + size_t mlength, uint8_t *dst, const uint8_t *src) { return ccm_decrypt_message(&ctx->cipher, (nettle_cipher_func *) aes256_encrypt, nlength, nonce, alength, adata, - tlength, clength, dst, src); + tlength, mlength, dst, src); } diff --git a/ccm.c b/ccm.c index 496559145ff8cec06da6db2c2fc242a730db5569..00f3f26e4ad51c38305382eff4e5257acbd06380 100644 --- a/ccm.c +++ b/ccm.c @@ -250,14 +250,13 @@ int ccm_decrypt_message(const void *cipher, nettle_cipher_func *f, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src) + size_t mlength, uint8_t *dst, const uint8_t *src) { struct ccm_ctx ctx; uint8_t tag[CCM_BLOCK_SIZE]; - assert(clength >= tlength); - ccm_set_nonce(&ctx, cipher, f, nlength, nonce, alength, clength-tlength, tlength); + ccm_set_nonce(&ctx, cipher, f, nlength, nonce, alength, mlength, tlength); ccm_update(&ctx, cipher, f, alength, adata); - ccm_decrypt(&ctx, cipher, f, clength-tlength, dst, src); + ccm_decrypt(&ctx, cipher, f, mlength, dst, src); ccm_digest(&ctx, cipher, f, tlength, tag); - return (memcmp(tag, src + (clength-tlength), tlength) == 0); + return (memcmp(tag, src + mlength, tlength) == 0); } diff --git a/ccm.h b/ccm.h index b215360d8555775797b04e4a2d888973fc9203e7..9827e45db9dfc7d9dab11cd9112a1bfe3f080be7 100644 --- a/ccm.h +++ b/ccm.h @@ -150,7 +150,7 @@ ccm_decrypt_message(const void *cipher, nettle_cipher_func *f, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src); + size_t mlength, uint8_t *dst, const uint8_t *src); /* CCM Mode with AES-128 */ struct ccm_aes128_ctx { @@ -194,7 +194,7 @@ ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src); + size_t mlength, uint8_t *dst, const uint8_t *src); struct ccm_aes192_ctx { struct ccm_ctx ccm; @@ -238,7 +238,7 @@ ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src); + size_t mlength, uint8_t *dst, const uint8_t *src); /* CCM Mode with AES-256 */ struct ccm_aes256_ctx { @@ -282,7 +282,7 @@ ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx, size_t nlength, const uint8_t *nonce, size_t alength, const uint8_t *adata, size_t tlength, - size_t clength, uint8_t *dst, const uint8_t *src); + size_t mlength, uint8_t *dst, const uint8_t *src); #ifdef __cplusplus } diff --git a/testsuite/ccm-test.c b/testsuite/ccm-test.c index 9a7161b9c9108ca2c107b6bc60644c6beff8c099..4176cc7fbcbf450522a6b8e9bd6355f239a13f25 100644 --- a/testsuite/ccm-test.c +++ b/testsuite/ccm-test.c @@ -156,10 +156,12 @@ test_cipher_ccm(const struct nettle_cipher *cipher, memset(de_digest, 0, sizeof(de_digest)); ccm_encrypt_message(ctx, cipher->encrypt, nonce->length, nonce->data, - authdata->length, authdata->data, tlength, ciphertext->length, en_data, cleartext->data); + authdata->length, authdata->data, tlength, + ciphertext->length, en_data, cleartext->data); ret = ccm_decrypt_message(ctx, cipher->encrypt, nonce->length, nonce->data, - authdata->length, authdata->data, tlength, ciphertext->length, de_data, ciphertext->data); + authdata->length, authdata->data, tlength, + cleartext->length, de_data, ciphertext->data); if (ret != 1) fprintf(stderr, "ccm_decrypt_message failed to validate message\n"); test_compare_results("CCM_MSG", authdata, @@ -169,13 +171,15 @@ test_cipher_ccm(const struct nettle_cipher *cipher, if (tlength) { en_data[0] ^= 1; ret = ccm_decrypt_message(ctx, cipher->encrypt, nonce->length, nonce->data, - authdata->length, authdata->data, tlength, ciphertext->length, de_data, en_data); + authdata->length, authdata->data, tlength, + cleartext->length, de_data, en_data); if (ret != 0) fprintf(stderr, "ccm_decrypt_message failed to detect corrupted message\n"); } /* Ensure we can detect corrupted adata. */ if (tlength && authdata->length) { ret = ccm_decrypt_message(ctx, cipher->encrypt, nonce->length, nonce->data, - authdata->length-1, authdata->data, tlength, ciphertext->length, de_data, ciphertext->data); + authdata->length-1, authdata->data, tlength, + cleartext->length, de_data, ciphertext->data); if (ret != 0) fprintf(stderr, "ccm_decrypt_message failed to detect corrupted message\n"); } }