| 1 |
/* sntrup761.h - Streamlined NTRU Prime sntrup761 key-encapsulation method |
| 2 |
* Copyright (C) 2023 Simon Josefsson <[email protected]> |
| 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 |
/* |
| 25 |
* Derived from public domain source, written by (in alphabetical order): |
| 26 |
* - Daniel J. Bernstein |
| 27 |
* - Chitchanok Chuengsatiansup |
| 28 |
* - Tanja Lange |
| 29 |
* - Christine van Vredendaal |
| 30 |
*/ |
| 31 |
|
| 32 |
#ifndef SNTRUP761_H |
| 33 |
#define SNTRUP761_H |
| 34 |
|
| 35 |
#include <string.h> |
| 36 |
#include <stdint.h> |
| 37 |
|
| 38 |
#ifdef _GCRYPT_IN_LIBGCRYPT |
| 39 |
/**** Start of the glue code to libgcrypt ****/ |
| 40 |
#include "gcrypt-int.h" |
| 41 |
|
| 42 |
static inline void |
| 43 |
crypto_hash_sha512 (unsigned char *out, |
| 44 |
const unsigned char *in, size_t inlen) |
| 45 |
{ |
| 46 |
_gcry_md_hash_buffer (GCRY_MD_SHA512, out, in, inlen); |
| 47 |
} |
| 48 |
|
| 49 |
#define SNTRUP761_KEYPAIR_STACK_BURN (26 * 1024) |
| 50 |
#define SNTRUP761_ENC_STACK_BURN (23 * 1024) |
| 51 |
#define SNTRUP761_DEC_STACK_BURN (34 * 1024) |
| 52 |
|
| 53 |
#define sntrup761_keypair _gcry_sntrup761_keypair |
| 54 |
#define sntrup761_enc _gcry_sntrup761_enc |
| 55 |
#define sntrup761_dec _gcry_sntrup761_dec |
| 56 |
/**** End of the glue code ****/ |
| 57 |
#else |
| 58 |
#define SNTRUP761_SECRETKEY_SIZE 1763 |
| 59 |
#define SNTRUP761_PUBLICKEY_SIZE 1158 |
| 60 |
#define SNTRUP761_CIPHERTEXT_SIZE 1039 |
| 61 |
#define SNTRUP761_SIZE 32 |
| 62 |
#endif |
| 63 |
|
| 64 |
typedef void sntrup761_random_func (void *ctx, size_t length, uint8_t *dst); |
| 65 |
|
| 66 |
void |
| 67 |
sntrup761_keypair (uint8_t *pk, uint8_t *sk, |
| 68 |
void *random_ctx, sntrup761_random_func *random); |
| 69 |
|
| 70 |
void |
| 71 |
sntrup761_enc (uint8_t *c, uint8_t *k, const uint8_t *pk, |
| 72 |
void *random_ctx, sntrup761_random_func *random); |
| 73 |
|
| 74 |
void |
| 75 |
sntrup761_dec (uint8_t *k, const uint8_t *c, const uint8_t *sk); |
| 76 |
|
| 77 |
#endif /* SNTRUP761_H */ |