3 * The X448 key-agreement algorithm
5 * (c) 2017 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of secnet.
11 * See README for full list of copyright holders.
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.
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.
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.
27 * This file was originally part of Catacomb, but has been automatically
28 * modified for incorporation into secnet: see `import-catacomb-crypto'
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.
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.
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,
47 /*----- Header files ------------------------------------------------------*/
49 #include "fake-mLib-bits.h"
51 #include "montladder.h"
55 /*----- Important constants -----------------------------------------------*/
57 const octet x448_base[56] = { 5, 0, /* ... */ };
61 /*----- Main code ---------------------------------------------------------*/
65 * Arguments: @octet zz[X448_OUTSZ]@ = where to put the result
66 * @const octet k[X448_KEYSZ]@ = pointer to private key
67 * @const octet qx[X448_PUBSZ]@ = pointer to public value
71 * Use: Calculates X448 of @k@ and @qx@.
74 void x448(octet zz[X448_OUTSZ],
75 const octet k[X448_KEYSZ],
76 const octet qx[X448_PUBSZ])
82 /* Load and clamp the key. The low bits are cleared to kill the small
83 * subgroups on the curve and its twist, and a high bit is set to guard
84 * against careless implementations, though this isn't one of those.
86 for (i = 0; i < 14; i++) kw[i] = LOAD32_L(k + 4*i);
87 kw[0] &= 0xfffffffc; kw[13] |= 0x80000000;
89 /* And run the ladder. */
91 #define MULA0(z, x) do { fgoldi_mulconst((z), (x), A0); } while (0)
92 MONT_LADDER(fgoldi, MULA0, kw, 14, 32, &x1, &x1);
94 fgoldi_store(zz, &x1);
97 /*----- That's all, folks -------------------------------------------------*/