poly1305.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_CRYPTO_POLY1305_H
  10. # define OSSL_CRYPTO_POLY1305_H
  11. # pragma once
  12. #include <stddef.h>
  13. #define POLY1305_BLOCK_SIZE 16
  14. #define POLY1305_DIGEST_SIZE 16
  15. #define POLY1305_KEY_SIZE 32
  16. typedef struct poly1305_context POLY1305;
  17. typedef void (*poly1305_blocks_f) (void *ctx, const unsigned char *inp,
  18. size_t len, unsigned int padbit);
  19. typedef void (*poly1305_emit_f) (void *ctx, unsigned char mac[16],
  20. const unsigned int nonce[4]);
  21. struct poly1305_context {
  22. double opaque[24]; /* large enough to hold internal state, declared
  23. * 'double' to ensure at least 64-bit invariant
  24. * alignment across all platforms and
  25. * configurations */
  26. unsigned int nonce[4];
  27. unsigned char data[POLY1305_BLOCK_SIZE];
  28. size_t num;
  29. struct {
  30. poly1305_blocks_f blocks;
  31. poly1305_emit_f emit;
  32. } func;
  33. };
  34. size_t Poly1305_ctx_size(void);
  35. void Poly1305_Init(POLY1305 *ctx, const unsigned char key[32]);
  36. void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len);
  37. void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16]);
  38. #endif /* OSSL_CRYPTO_POLY1305_H */