X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/ae8cd973b817f81c075ab20e84d3239125146f24..8a7654a695e8ecdc8c14dced445839a7a7e6a8ca:/x448.c diff --git a/x448.c b/x448.c new file mode 100644 index 0000000..332ff7b --- /dev/null +++ b/x448.c @@ -0,0 +1,97 @@ +/* -*-c-*- + * + * The X448 key-agreement algorithm + * + * (c) 2017 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version d of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + * + * This file was originally part of Catacomb, but has been automatically + * modified for incorporation into secnet: see `import-catacomb-crypto' + * for details. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Header files ------------------------------------------------------*/ + +#include "fake-mLib-bits.h" + +#include "montladder.h" +#include "fgoldi.h" +#include "x448.h" + +/*----- Important constants -----------------------------------------------*/ + +const octet x448_base[56] = { 5, 0, /* ... */ }; + +#define A0 39081 + +/*----- Main code ---------------------------------------------------------*/ + +/* --- @x448@ --- * + * + * Arguments: @octet zz[X448_OUTSZ]@ = where to put the result + * @const octet k[X448_KEYSZ]@ = pointer to private key + * @const octet qx[X448_PUBSZ]@ = pointer to public value + * + * Returns: --- + * + * Use: Calculates X448 of @k@ and @qx@. + */ + +void x448(octet zz[X448_OUTSZ], + const octet k[X448_KEYSZ], + const octet qx[X448_PUBSZ]) +{ + uint32 kw[14]; + fgoldi x1; + unsigned i; + + /* Load and clamp the key. The low bits are cleared to kill the small + * subgroups on the curve and its twist, and a high bit is set to guard + * against careless implementations, though this isn't one of those. + */ + for (i = 0; i < 14; i++) kw[i] = LOAD32_L(k + 4*i); + kw[0] &= 0xfffffffc; kw[13] |= 0x80000000; + + /* And run the ladder. */ + fgoldi_load(&x1, qx); +#define MULA0(z, x) do { fgoldi_mulconst((z), (x), A0); } while (0) + MONT_LADDER(fgoldi, MULA0, kw, 14, 32, &x1, &x1); +#undef MULA0 + fgoldi_store(zz, &x1); +} + +/*----- That's all, folks -------------------------------------------------*/