Commit | Line | Data |
---|---|---|
8a7654a6 MW |
1 | /* -*-c-*- |
2 | * | |
3 | * The X25519 key-agreement algorithm | |
4 | * | |
5 | * (c) 2017 Straylight/Edgeware | |
6 | */ | |
7 | ||
8 | /*----- Licensing notice --------------------------------------------------* | |
9 | * | |
10 | * This file is part of secnet. | |
11 | * See README for full list of copyright holders. | |
12 | * | |
13 | * secnet is free software; you can redistribute it and/or modify it | |
14 | * under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version d of the License, or | |
16 | * (at your option) any later version. | |
17 | * | |
18 | * secnet is distributed in the hope that it will be useful, but | |
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | * General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * version 3 along with secnet; if not, see | |
25 | * https://www.gnu.org/licenses/gpl.html. | |
26 | * | |
27 | * This file was originally part of Catacomb, but has been automatically | |
28 | * modified for incorporation into secnet: see `import-catacomb-crypto' | |
29 | * for details. | |
30 | * | |
31 | * Catacomb is free software; you can redistribute it and/or modify | |
32 | * it under the terms of the GNU Library General Public License as | |
33 | * published by the Free Software Foundation; either version 2 of the | |
34 | * License, or (at your option) any later version. | |
35 | * | |
36 | * Catacomb is distributed in the hope that it will be useful, | |
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
39 | * GNU Library General Public License for more details. | |
40 | * | |
41 | * You should have received a copy of the GNU Library General Public | |
42 | * License along with Catacomb; if not, write to the Free | |
43 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
44 | * MA 02111-1307, USA. | |
45 | */ | |
46 | ||
47 | #ifndef CATACOMB_X25519_H | |
48 | #define CATACOMB_X25519_H | |
49 | ||
50 | #ifdef __cplusplus | |
51 | extern "C" { | |
52 | #endif | |
53 | ||
54 | /*----- Notes on the X25519 key-agreement algorithm -----------------------* | |
55 | * | |
56 | * This is X25519, as described in Daniel J. Bernstein, `Curve25519: new | |
57 | * Diffie--Hellman speed records', PKC 2006, | |
58 | * https://cr.yp.to/ecdh/curve25519-20060209.pdf | |
59 | * | |
60 | * Since then, the name `Curve25519' has shifted somewhat, to refer to the | |
61 | * specific elliptic curve used, and the x-coordinate Diffie--Hellman | |
62 | * operation is now named `X25519'. | |
63 | */ | |
64 | ||
65 | /*----- Header files ------------------------------------------------------*/ | |
66 | ||
67 | #include "fake-mLib-bits.h" | |
68 | ||
69 | /*----- Important constants -----------------------------------------------*/ | |
70 | ||
71 | #define X25519_KEYSZ 32u | |
72 | #define X25519_PUBSZ 32u | |
73 | #define X25519_OUTSZ 32u | |
74 | ||
75 | extern const octet x25519_base[32]; | |
76 | ||
77 | /*----- Functions provided ------------------------------------------------*/ | |
78 | ||
79 | /* --- @x25519@ --- * | |
80 | * | |
81 | * Arguments: @octet zz[X25519_OUTSZ]@ = where to put the result | |
82 | * @const octet k[X25519_KEYSZ]@ = pointer to private key | |
83 | * @const octet qx[X25519_PUBSZ]@ = pointer to public value | |
84 | * | |
85 | * Returns: --- | |
86 | * | |
87 | * Use: Calculates X25519 of @k@ and @qx@. | |
88 | * | |
89 | * Note that there is disagreement over whether the most | |
90 | * significant bit of @qx@ (i.e., the value @qx[31]&0x80@) | |
91 | * should be ignored or counted towards the represented value. | |
92 | * Historically implementations respected the bit; later | |
93 | * convention seems to be to ignore it. This implementation | |
94 | * honours the bit: a caller who wants to ignore the bit can | |
95 | * easily clear it, while caller who wants to respect it has a | |
96 | * difficult job if this function ignores it. | |
97 | */ | |
98 | ||
99 | extern void x25519(octet /*zz*/[X25519_OUTSZ], | |
100 | const octet /*k*/[X25519_KEYSZ], | |
101 | const octet /*qx*/[X25519_PUBSZ]); | |
102 | ||
103 | /*----- That's all, folks -------------------------------------------------*/ | |
104 | ||
105 | #ifdef __cplusplus | |
106 | } | |
107 | #endif | |
108 | ||
109 | #endif |