sntrup761.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* sntrup761.h - Streamlined NTRU Prime sntrup761 key-encapsulation method
  2. * Copyright (C) 2023 Simon Josefsson <simon@josefsson.org>
  3. *
  4. * This file is part of Libgcrypt.
  5. *
  6. * Libgcrypt is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * Libgcrypt is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, see <https://www.gnu.org/licenses/>.
  18. * SPDX-License-Identifier: LGPL-2.1-or-later
  19. *
  20. * For a description of the algorithm, see:
  21. * https://ntruprime.cr.yp.to/
  22. */
  23. /*
  24. * Derived from public domain source, written by (in alphabetical order):
  25. * - Daniel J. Bernstein
  26. * - Chitchanok Chuengsatiansup
  27. * - Tanja Lange
  28. * - Christine van Vredendaal
  29. */
  30. #ifndef SNTRUP761_H
  31. #define SNTRUP761_H
  32. #include <string.h>
  33. #include <stdint.h>
  34. #ifdef _GCRYPT_IN_LIBGCRYPT
  35. /**** Start of the glue code to libgcrypt ****/
  36. #include "gcrypt-int.h"
  37. static inline void
  38. crypto_hash_sha512 (unsigned char *out,
  39. const unsigned char *in, size_t inlen)
  40. {
  41. _gcry_md_hash_buffer (GCRY_MD_SHA512, out, in, inlen);
  42. }
  43. #define sntrup761_keypair _gcry_sntrup761_keypair
  44. #define sntrup761_enc _gcry_sntrup761_enc
  45. #define sntrup761_dec _gcry_sntrup761_dec
  46. /**** End of the glue code ****/
  47. #else
  48. #define SNTRUP761_SECRETKEY_SIZE 1763
  49. #define SNTRUP761_PUBLICKEY_SIZE 1158
  50. #define SNTRUP761_CIPHERTEXT_SIZE 1039
  51. #define SNTRUP761_SIZE 32
  52. #endif
  53. typedef void sntrup761_random_func (void *ctx, size_t length, uint8_t *dst);
  54. void
  55. sntrup761_keypair (uint8_t *pk, uint8_t *sk,
  56. void *random_ctx, sntrup761_random_func *random);
  57. void
  58. sntrup761_enc (uint8_t *c, uint8_t *k, const uint8_t *pk,
  59. void *random_ctx, sntrup761_random_func *random);
  60. void
  61. sntrup761_dec (uint8_t *k, const uint8_t *c, const uint8_t *sk);
  62. #endif /* SNTRUP761_H */