/src/libgcrypt/cipher/sntrup761.h
Line | Count | Source (jump to first uncovered line) |
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 | | /* |
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 | 0 | { |
46 | 0 | _gcry_md_hash_buffer (GCRY_MD_SHA512, out, in, inlen); |
47 | 0 | } Unexecuted instantiation: kem.c:crypto_hash_sha512 Unexecuted instantiation: sntrup761.c:crypto_hash_sha512 |
48 | | |
49 | 0 | #define sntrup761_keypair _gcry_sntrup761_keypair |
50 | 0 | #define sntrup761_enc _gcry_sntrup761_enc |
51 | 0 | #define sntrup761_dec _gcry_sntrup761_dec |
52 | | /**** End of the glue code ****/ |
53 | | #else |
54 | | #define SNTRUP761_SECRETKEY_SIZE 1763 |
55 | | #define SNTRUP761_PUBLICKEY_SIZE 1158 |
56 | | #define SNTRUP761_CIPHERTEXT_SIZE 1039 |
57 | | #define SNTRUP761_SIZE 32 |
58 | | #endif |
59 | | |
60 | | typedef void sntrup761_random_func (void *ctx, size_t length, uint8_t *dst); |
61 | | |
62 | | void |
63 | | sntrup761_keypair (uint8_t *pk, uint8_t *sk, |
64 | | void *random_ctx, sntrup761_random_func *random); |
65 | | |
66 | | void |
67 | | sntrup761_enc (uint8_t *c, uint8_t *k, const uint8_t *pk, |
68 | | void *random_ctx, sntrup761_random_func *random); |
69 | | |
70 | | void |
71 | | sntrup761_dec (uint8_t *k, const uint8_t *c, const uint8_t *sk); |
72 | | |
73 | | #endif /* SNTRUP761_H */ |