norx.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * cifra - embedded cryptography library
  3. * Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
  4. *
  5. * To the extent possible under law, the author(s) have dedicated all
  6. * copyright and related and neighboring rights to this software to the
  7. * public domain worldwide. This software is distributed without any
  8. * warranty.
  9. *
  10. * You should have received a copy of the CC0 Public Domain Dedication
  11. * along with this software. If not, see
  12. * <http://creativecommons.org/publicdomain/zero/1.0/>.
  13. */
  14. #ifndef NORX_H
  15. #define NORX_H
  16. #include <stdint.h>
  17. #include <stddef.h>
  18. /**
  19. * The NORX AEAD cipher
  20. * ====================
  21. * This is an implementation of NORX32-4-1 with a one-shot
  22. * interface. NORX is a CAESAR candidate with a core similar
  23. * to ChaCha20 and a sponge structure like Keccak.
  24. *
  25. * This is NORX v2.0. It is not compatible with earlier
  26. * versions.
  27. *
  28. * NORX32 uses a 128-bit key. Each encryption requires a
  29. * 64-bit nonce. An encryption processes one sequence of
  30. * additional data ('header'), followed by encryption of
  31. * the plaintext, followed by processing a second sequence
  32. * of additional data ('trailer'). It outputs a 128-bit
  33. * tag.
  34. */
  35. /* .. c:function:: $DECL
  36. * NORX32-4-1 one-shot encryption interface.
  37. *
  38. * :param key: key material.
  39. * :param nonce: per-message nonce.
  40. * :param header: header buffer.
  41. * :param nheader: number of header bytes.
  42. * :param plaintext: plaintext bytes to be encrypted.
  43. * :param nbytes: number of plaintext/ciphertext bytes.
  44. * :param trailer: trailer buffer.
  45. * :param ntrailer: number of trailer bytes.
  46. * :param ciphertext: ciphertext output buffer, nbytes in length.
  47. * :param tag: authentication tag output buffer.
  48. */
  49. void cf_norx32_encrypt(const uint8_t key[16],
  50. const uint8_t nonce[8],
  51. const uint8_t *header, size_t nheader,
  52. const uint8_t *plaintext, size_t nbytes,
  53. const uint8_t *trailer, size_t ntrailer,
  54. uint8_t *ciphertext,
  55. uint8_t tag[16]);
  56. /* .. c:function:: $DECL
  57. * NORX32-4-1 one-shot decryption interface.
  58. *
  59. * :return: 0 on success, non-zero on error. Plaintext is zeroed on error.
  60. *
  61. * :param key: key material.
  62. * :param nonce: per-message nonce.
  63. * :param header: header buffer.
  64. * :param nheader: number of header bytes.
  65. * :param ciphertext: ciphertext bytes to be decrypted.
  66. * :param nbytes: number of plaintext/ciphertext bytes.
  67. * :param trailer: trailer buffer.
  68. * :param ntrailer: number of trailer bytes.
  69. * :param plaintext: plaintext output buffer, nbytes in length.
  70. * :param tag: authentication tag output buffer.
  71. */
  72. int cf_norx32_decrypt(const uint8_t key[16],
  73. const uint8_t nonce[8],
  74. const uint8_t *header, size_t nheader,
  75. const uint8_t *ciphertext, size_t nbytes,
  76. const uint8_t *trailer, size_t ntrailer,
  77. const uint8_t tag[16],
  78. uint8_t *plaintext);
  79. #endif