X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fchacha-poly1305%2Fchacha-poly1305.c;h=77d531add2ab6a291a52557bb9e85720c88d01dc;hb=2f2bda4d1953617b945f1222e008cb53edee162a;hp=b5dab4e4f9afac9aa9b249d687416b61a2930cf9;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/chacha-poly1305/chacha-poly1305.c b/src/chacha-poly1305/chacha-poly1305.c index b5dab4e4..77d531ad 100644 --- a/src/chacha-poly1305/chacha-poly1305.c +++ b/src/chacha-poly1305/chacha-poly1305.c @@ -1,6 +1,4 @@ #include "../system.h" - -#include "../cipher.h" #include "../xalloc.h" #include "chacha.h" @@ -12,15 +10,14 @@ struct chacha_poly1305_ctx { }; chacha_poly1305_ctx_t *chacha_poly1305_init(void) { - chacha_poly1305_ctx_t *ctx = xzalloc(sizeof(*ctx)); - return ctx; + return xzalloc(sizeof(chacha_poly1305_ctx_t)); } void chacha_poly1305_exit(chacha_poly1305_ctx_t *ctx) { - free(ctx); + xzfree(ctx, sizeof(chacha_poly1305_ctx_t)); } -bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *key) { +bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const uint8_t *key) { chacha_keysetup(&ctx->main_ctx, key, 256); chacha_keysetup(&ctx->header_ctx, key + 32, 256); return true; @@ -39,10 +36,11 @@ static void put_u64(void *vp, uint64_t v) { p[7] = (uint8_t) v & 0xff; } -bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) { +bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *voutdata, size_t *outlen) { uint8_t seqbuf[8]; const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */ uint8_t poly_key[POLY1305_KEYLEN]; + uint8_t *outdata = voutdata; /* * Run ChaCha20 once to generate the Poly1305 key. The IV is the @@ -66,10 +64,11 @@ bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const v return true; } -bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) { +bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *vindata, size_t inlen, void *outdata, size_t *outlen) { uint8_t seqbuf[8]; const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */ uint8_t expected_tag[POLY1305_TAGLEN], poly_key[POLY1305_KEYLEN]; + const uint8_t *indata = vindata; /* * Run ChaCha20 once to generate the Poly1305 key. The IV is the