3 Copyright (C) 2013 Nikos Mavrogiannopoulos
4 Copyright (C) 2014 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
44 poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t * key)
46 aes128_set_encrypt_key(&ctx->aes, (key));
47 poly1305_set_key(&ctx->pctx, (key+16));
52 poly1305_aes_set_nonce (struct poly1305_aes_ctx *ctx,
53 const uint8_t * nonce)
55 memcpy (ctx->nonce, nonce, POLY1305_AES_NONCE_SIZE);
58 #define COMPRESS(ctx, data) _poly1305_block(&(ctx)->pctx, (data), 1)
61 poly1305_aes_update (struct poly1305_aes_ctx *ctx,
62 size_t length, const uint8_t *data)
64 MD_UPDATE (ctx, length, data, COMPRESS, (void) 0);
68 poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
69 size_t length, uint8_t *digest)
71 union nettle_block16 s;
75 assert (ctx->index < POLY1305_BLOCK_SIZE);
77 ctx->block[ctx->index] = 1;
78 memset (ctx->block + ctx->index + 1,
79 0, POLY1305_BLOCK_SIZE - 1 - ctx->index);
81 _poly1305_block (&ctx->pctx, ctx->block, 0);
83 aes128_encrypt(&ctx->aes, POLY1305_BLOCK_SIZE, s.b, ctx->nonce);
85 poly1305_digest (&ctx->pctx, &s);
86 memcpy (digest, s.b, length);
88 INCREMENT (16, ctx->nonce);