Commit 91d0c1b5 authored by Niels Möller's avatar Niels Möller

ccm_decrypt_message: length argument is cleartext (dst) length

Also updated related functions.
parent c8e472cb
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
......
......@@ -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);
}
......@@ -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);
}
......@@ -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);
}
......@@ -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);
}
......@@ -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
}
......
......@@ -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");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment