cipher_chacha20_poly1305.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2019-2020 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. /* Dispatch functions for chacha20_poly1305 cipher */
  10. #include "include/crypto/poly1305.h"
  11. #include "cipher_chacha20.h"
  12. #define NO_TLS_PAYLOAD_LENGTH ((size_t)-1)
  13. #define CHACHA20_POLY1305_IVLEN 12
  14. typedef struct {
  15. PROV_CIPHER_CTX base; /* must be first */
  16. PROV_CHACHA20_CTX chacha;
  17. POLY1305 poly1305;
  18. unsigned int nonce[12 / 4];
  19. unsigned char tag[POLY1305_BLOCK_SIZE];
  20. unsigned char tls_aad[POLY1305_BLOCK_SIZE];
  21. struct { uint64_t aad, text; } len;
  22. unsigned int aad : 1;
  23. unsigned int mac_inited : 1;
  24. size_t tag_len, nonce_len;
  25. size_t tls_payload_length;
  26. size_t tls_aad_pad_sz;
  27. } PROV_CHACHA20_POLY1305_CTX;
  28. typedef struct prov_cipher_hw_chacha_aead_st {
  29. PROV_CIPHER_HW base; /* must be first */
  30. int (*aead_cipher)(PROV_CIPHER_CTX *dat, unsigned char *out, size_t *outl,
  31. const unsigned char *in, size_t len);
  32. int (*initiv)(PROV_CIPHER_CTX *ctx);
  33. int (*tls_init)(PROV_CIPHER_CTX *ctx, unsigned char *aad, size_t alen);
  34. int (*tls_iv_set_fixed)(PROV_CIPHER_CTX *ctx, unsigned char *fixed,
  35. size_t flen);
  36. } PROV_CIPHER_HW_CHACHA20_POLY1305;
  37. const PROV_CIPHER_HW *ossl_prov_cipher_hw_chacha20_poly1305(size_t keybits);