This commit is contained in:
Frank Denis
2014-06-19 18:45:56 -07:00
parent b0f798aa66
commit 3ae2cb5c26
3 changed files with 45 additions and 40 deletions
@@ -14,49 +14,49 @@
static void
poly1305_update(poly1305_context *ctx, const unsigned char *m,
unsigned long long bytes) {
poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx;
unsigned long long i;
poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx;
unsigned long long i;
/* handle leftover */
if (st->leftover) {
unsigned long long want = (poly1305_block_size - st->leftover);
if (want > bytes)
want = bytes;
for (i = 0; i < want; i++)
st->buffer[st->leftover + i] = m[i];
bytes -= want;
m += want;
st->leftover += want;
if (st->leftover < poly1305_block_size)
return;
poly1305_blocks(st, st->buffer, poly1305_block_size);
st->leftover = 0;
}
/* handle leftover */
if (st->leftover) {
unsigned long long want = (poly1305_block_size - st->leftover);
if (want > bytes)
want = bytes;
for (i = 0; i < want; i++)
st->buffer[st->leftover + i] = m[i];
bytes -= want;
m += want;
st->leftover += want;
if (st->leftover < poly1305_block_size)
return;
poly1305_blocks(st, st->buffer, poly1305_block_size);
st->leftover = 0;
}
/* process full blocks */
if (bytes >= poly1305_block_size) {
unsigned long long want = (bytes & ~(poly1305_block_size - 1));
poly1305_blocks(st, m, want);
m += want;
bytes -= want;
}
/* process full blocks */
if (bytes >= poly1305_block_size) {
unsigned long long want = (bytes & ~(poly1305_block_size - 1));
poly1305_blocks(st, m, want);
m += want;
bytes -= want;
}
/* store leftover */
if (bytes) {
for (i = 0; i < bytes; i++)
st->buffer[st->leftover + i] = m[i];
st->leftover += bytes;
}
/* store leftover */
if (bytes) {
for (i = 0; i < bytes; i++)
st->buffer[st->leftover + i] = m[i];
st->leftover += bytes;
}
}
int
crypto_onetimeauth(unsigned char *out, const unsigned char *m,
unsigned long long inlen, const unsigned char *key)
{
poly1305_context ctx;
poly1305_init(&ctx, key);
poly1305_update(&ctx, m, inlen);
poly1305_finish(&ctx, out);
poly1305_context ctx;
poly1305_init(&ctx, key);
poly1305_update(&ctx, m, inlen);
poly1305_finish(&ctx, out);
return 0;
}
@@ -4,8 +4,8 @@
#include <stddef.h>
typedef struct poly1305_context {
unsigned long long aligner;
unsigned char opaque[136];
unsigned long long aligner;
unsigned char opaque[136];
} poly1305_context;
#endif /* POLY1305_DONNA_H */
@@ -2,9 +2,14 @@
#include "crypto_onetimeauth_poly1305_donna.h"
#include "crypto_verify_16.h"
int crypto_onetimeauth_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
int
crypto_onetimeauth_verify(const unsigned char *h,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k)
{
unsigned char correct[16];
crypto_onetimeauth(correct,in,inlen,k);
return crypto_verify_16(h,correct);
unsigned char correct[16];
crypto_onetimeauth(correct,in,inlen,k);
return crypto_verify_16(h,correct);
}