2026-01-14 Niels Möller <nisse@lysator.liu.se>
+ * ocb.h (struct ocb_ctx): New field tag_length, storing the size
+ passed to ocb_set_nonce.
+ * ocb.c (ocb_set_nonce): Store tag length in context.
+ (ocb_digest): Delete length argument. Size of digest was stored in
+ the context by ocb_set_nonce. Updated all callers.
+ * ocb-aes128.c (ocb_aes128_digest): Deleted length argument.
+ * non-nettle.c (ocb_aes128_t96_digest): Deleted.
+
* nettle.texinfo (CCM): Update CCM documentation.
* ccm.h (CCM_MIN_DIGEST_SIZE): New constant.
static void
ocb_aes128_digest_wrapper (struct ocb_aes128_ctx *ctx, uint8_t *digest)
{
- ocb_aes128_digest (&ctx->ocb, &ctx->key, OCB_DIGEST_SIZE, digest);
+ ocb_aes128_digest (&ctx->ocb, &ctx->key, digest);
}
const struct nettle_aead
12, OCB_NONCE_SIZE, nonce);
}
-static void
-ocb_aes128_t96_digest (struct ocb_aes128_ctx *ctx, uint8_t *digest)
-{
- ocb_aes128_digest (&ctx->ocb, &ctx->key, 12, digest);
-}
-
const struct nettle_aead
nettle_ocb_aes128_t96 =
{ "ocb_aes128", sizeof(struct ocb_aes128_ctx),
(nettle_hash_update_func *) ocb_aes128_update_wrapper,
(nettle_crypt_func *) ocb_aes128_encrypt_wrapper,
(nettle_crypt_func *) ocb_aes128_decrypt_wrapper,
- (nettle_hash_digest_func *) ocb_aes128_t96_digest,
+ (nettle_hash_digest_func *) ocb_aes128_digest_wrapper,
};
assert (tag_length > 0);
assert (tag_length <= 16);
+ ctx->tag_length = tag_length;
+
/* Bit size, or zero for tag_length == 16 */
top.b[0] = (tag_length & 15) << 4;
memset (top.b + 1, 0, 15 - nonce_length);
void
ocb_digest (const struct ocb_ctx *ctx, const struct ocb_key *key,
const void *cipher, nettle_cipher_func *f,
- size_t length, uint8_t *digest)
+ uint8_t *digest)
{
union nettle_block16 block;
- assert (length <= OCB_DIGEST_SIZE);
block16_xor3 (&block, &key->L[1],
(ctx->message_count > 0) ? &ctx->offset : &ctx->initial);
block16_xor (&block, &ctx->checksum);
f (cipher, OCB_BLOCK_SIZE, block.b, block.b);
- memxor3 (digest, block.b, ctx->sum.b, length);
+ assert (ctx->tag_length <= OCB_BLOCK_SIZE);
+ memxor3 (digest, block.b, ctx->sum.b, ctx->tag_length);
}
void
ocb_set_nonce (&ctx, cipher, f, tlength, nlength, nonce);
ocb_update (&ctx, key, cipher, f, alength, adata);
ocb_encrypt (&ctx, key, cipher, f, clength - tlength, dst, src);
- ocb_digest (&ctx, key, cipher, f, tlength, dst + clength - tlength);
+ ocb_digest (&ctx, key, cipher, f, dst + clength - tlength);
}
int
ocb_update (&ctx, key, encrypt_ctx, encrypt, alength, adata);
ocb_decrypt (&ctx, key, encrypt_ctx, encrypt, decrypt_ctx, decrypt,
mlength, dst, src);
- ocb_digest (&ctx, key, encrypt_ctx, encrypt, tlength, digest.b);
+ ocb_digest (&ctx, key, encrypt_ctx, encrypt, digest.b);
return memeql_sec(digest.b, src + mlength, tlength);
}
union nettle_block16 sum;
/* Authentication for the message */
union nettle_block16 checksum;
+ unsigned short tag_length;
/* Count of processed blocks. */
uint32_t data_count;
uint64_t message_count;
void
ocb_digest (const struct ocb_ctx *ctx, const struct ocb_key *key,
const void *cipher, nettle_cipher_func *f,
- size_t length, uint8_t *digest);
+ uint8_t *digest);
void
void
ocb_aes128_digest(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
- size_t length, uint8_t *digest);
+ uint8_t *digest);
void
ocb_aes128_encrypt_message (const struct ocb_aes128_encrypt_key *key,