chacha20poly1305.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /*
  3. * Copyright (C) 2015-2019 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
  4. */
  5. #ifndef __CHACHA20POLY1305_H
  6. #define __CHACHA20POLY1305_H
  7. #include <linux/types.h>
  8. #include <linux/scatterlist.h>
  9. enum chacha20poly1305_lengths {
  10. XCHACHA20POLY1305_NONCE_SIZE = 24,
  11. CHACHA20POLY1305_KEY_SIZE = 32,
  12. CHACHA20POLY1305_AUTHTAG_SIZE = 16
  13. };
  14. void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
  15. const u8 *ad, const size_t ad_len,
  16. const u64 nonce,
  17. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  18. bool __must_check
  19. chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
  20. const u8 *ad, const size_t ad_len, const u64 nonce,
  21. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  22. void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
  23. const u8 *ad, const size_t ad_len,
  24. const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
  25. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  26. bool __must_check xchacha20poly1305_decrypt(
  27. u8 *dst, const u8 *src, const size_t src_len, const u8 *ad,
  28. const size_t ad_len, const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
  29. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  30. bool chacha20poly1305_encrypt_sg_inplace(struct scatterlist *src, size_t src_len,
  31. const u8 *ad, const size_t ad_len,
  32. const u64 nonce,
  33. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  34. bool chacha20poly1305_decrypt_sg_inplace(struct scatterlist *src, size_t src_len,
  35. const u8 *ad, const size_t ad_len,
  36. const u64 nonce,
  37. const u8 key[CHACHA20POLY1305_KEY_SIZE]);
  38. bool chacha20poly1305_selftest(void);
  39. #endif /* __CHACHA20POLY1305_H */