summaryrefslogtreecommitdiff
path: root/poly1305-aes.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2014-01-20 14:14:40 +0100
committerNiels Möller <nisse@lysator.liu.se>2014-01-20 14:14:40 +0100
commit5d6be1bc102de591c56e673853de68eedf9df683 (patch)
treef5ff4153850845512f8a1f2e0954d43fc8d9a19c /poly1305-aes.c
parent51473db79c03fbb51e0adfe054606d6ca450e310 (diff)
downloadnettle-5d6be1bc102de591c56e673853de68eedf9df683.tar.gz
Move block buffer from poly1305_ctx to poly1305_aes_ctx. Simplify poly1305_digest.poly1305
Diffstat (limited to 'poly1305-aes.c')
-rw-r--r--poly1305-aes.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/poly1305-aes.c b/poly1305-aes.c
index 8a7d9d13..e4a6f748 100644
--- a/poly1305-aes.c
+++ b/poly1305-aes.c
@@ -23,6 +23,7 @@
#include "config.h"
#endif
+#include <assert.h>
#include <string.h>
#include "poly1305.h"
@@ -33,7 +34,7 @@ poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t * key)
{
aes128_set_encrypt_key(&ctx->aes, (key));
poly1305_set_key(&ctx->pctx, (key+16));
- ctx->pctx.index = 0;
+ ctx->index = 0;
}
void
@@ -43,13 +44,35 @@ poly1305_aes_set_nonce (struct poly1305_aes_ctx *ctx,
memcpy (ctx->nonce, nonce, POLY1305_AES_NONCE_SIZE);
}
+#define COMPRESS(ctx, data) _poly1305_block(&(ctx)->pctx, (data), 1)
+
+void
+poly1305_aes_update (struct poly1305_aes_ctx *ctx, size_t length, const uint8_t *data)
+{
+ MD_UPDATE (ctx, length, data, COMPRESS, (void) 0);
+}
+
void
poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
- size_t length, uint8_t * digest)
+ size_t length, uint8_t *digest)
{
uint8_t s[POLY1305_BLOCK_SIZE];
+ /* final bytes */
+ if (ctx->index > 0)
+ {
+ assert (ctx->index < POLY1305_BLOCK_SIZE);
+
+ ctx->block[ctx->index] = 1;
+ memset (ctx->block + ctx->index + 1,
+ 0, POLY1305_BLOCK_SIZE - 1 - ctx->index);
+
+ _poly1305_block (&ctx->pctx, ctx->block, 0);
+ }
aes128_encrypt(&ctx->aes, POLY1305_BLOCK_SIZE, s, ctx->nonce);
- poly1305_digest (&ctx->pctx, length, digest, s);
+
+ poly1305_digest (&ctx->pctx, s);
+ memcpy (digest, s, length);
+
INCREMENT (16, ctx->nonce);
- ctx->pctx.index = 0;
+ ctx->index = 0;
}