X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/137d3b36ce3d121855364d3a28383ab86fbb9d7b..ae8cd973b817f81c075ab20e84d3239125146f24:/fgoldi.h diff --git a/fgoldi.h b/fgoldi.h deleted file mode 100644 index 1857008..0000000 --- a/fgoldi.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - * fgoldi.h: arithmetic modulo 2^448 - 2^224 - 1 - */ -/* - * This file is Free Software. It has been modified to as part of its - * incorporation into secnet. - * - * Copyright 2017 Mark Wooding - * - * You may redistribute this file and/or modify it under the terms of - * the permissive licence shown below. - * - * You may redistribute secnet as a whole and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3, or (at your option) any - * later version. - * - * This program 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 - * along with this program; if not, see - * https://www.gnu.org/licenses/gpl.html. - */ -/* - * Imported from Catacomb, and lightly modified for Secnet (2017-04-30): - * - * * Use `fake-mLib-bits.h' in place of the real . - * - * * Remove the 16/32-bit implementation, since C99 always has 64-bit - * arithmetic. - * - * The file's original comment headers are preserved below. - */ -/* -*-c-*- - * - * Arithmetic in the Goldilocks field GF(2^448 - 2^224 - 1) - * - * (c) 2017 Straylight/Edgeware - */ - -/*----- Licensing notice --------------------------------------------------* - * - * This file is part of Catacomb. - * - * 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. - */ - -#ifndef CATACOMB_FGOLDI_H -#define CATACOMB_FGOLDI_H - -#ifdef __cplusplus - extern "C" { -#endif - -/*----- Header files ------------------------------------------------------*/ - -#include "fake-mLib-bits.h" - -#ifndef CATACOMB_QFARITH_H -# include "qfarith.h" -#endif - -/*----- Data structures ---------------------------------------------------*/ - -typedef union { - int32 p28[16]; -} fgoldi; - -#if !defined(FGOLDI_IMPL) && defined(HAVE_INT64) -# define FGOLDI_IMPL 28 -#endif - -#ifndef FGOLDI_IMPL -# define FGOLDI_IMPL 12 -#endif - -/*----- Functions provided ------------------------------------------------*/ - -/* --- @fgoldi_load@ --- * - * - * Arguments: @fgoldi *z@ = where to store the result - * @const octet xv[56]@ = source to read - * - * Returns: --- - * - * Use: Reads an element of %$\gf{2^{448} - 2^{224} - 19}$% in - * external representation from @xv@ and stores it in @z@. - * - * External representation is little-endian base-256. Some - * elements have multiple encodings, which are not produced by - * correct software; use of noncanonical encodings is not an - * error, and toleration of them is considered a performance - * feature. - */ - -extern void fgoldi_load(fgoldi */*z*/, const octet /*xv*/[56]); - -/* --- @fgoldi_store@ --- * - * - * Arguments: @octet zv[56]@ = where to write the result - * @const fgoldi *x@ = the field element to write - * - * Returns: --- - * - * Use: Stores a field element in the given octet vector in external - * representation. A canonical encoding is always stored. - */ - -extern void fgoldi_store(octet /*zv*/[56], const fgoldi */*x*/); - -/* --- @fgoldi_set@ --- * - * - * Arguments: @fgoldi *z@ = where to write the result - * @int a@ = a small-ish constant - * - * Returns: --- - * - * Use: Sets @z@ to equal @a@. - */ - -extern void fgoldi_set(fgoldi */*x*/, int /*a*/); - -/* --- @fgoldi_add@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) - * @const fgoldi *x, *y@ = two operands - * - * Returns: --- - * - * Use: Set @z@ to the sum %$x + y$%. - */ - -extern void fgoldi_add(fgoldi */*z*/, - const fgoldi */*x*/, const fgoldi */*y*/); - -/* --- @fgoldi_sub@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) - * @const fgoldi *x, *y@ = two operands - * - * Returns: --- - * - * Use: Set @z@ to the difference %$x - y$%. - */ - -extern void fgoldi_sub(fgoldi */*z*/, - const fgoldi */*x*/, const fgoldi */*y*/); - -/* --- @fgoldi_condswap@ --- * - * - * Arguments: @fgoldi *x, *y@ = two operands - * @uint32 m@ = a mask - * - * Returns: --- - * - * Use: If @m@ is zero, do nothing; if @m@ is all-bits-set, then - * exchange @x@ and @y@. If @m@ has some other value, then - * scramble @x@ and @y@ in an unhelpful way. - */ - -extern void fgoldi_condswap(fgoldi */*x*/, fgoldi */*y*/, uint32 /*m*/); - -/* --- @fgoldi_mulconst@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@) - * @const fgoldi *x@ = an operand - * @long a@ = a small-ish constant; %$|a| < 2^{20}$%. - * - * Returns: --- - * - * Use: Set @z@ to the product %$a x$%. - */ - -extern void fgoldi_mulconst(fgoldi */*z*/, const fgoldi */*x*/, long /*a*/); - -/* --- @fgoldi_mul@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) - * @const fgoldi *x, *y@ = two operands - * - * Returns: --- - * - * Use: Set @z@ to the product %$x y$%. - */ - -extern void fgoldi_mul(fgoldi */*z*/, - const fgoldi */*x*/, const fgoldi */*y*/); - -/* --- @fgoldi_sqr@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) - * @const fgoldi *x@ = an operand - * - * Returns: --- - * - * Use: Set @z@ to the square %$x^2$%. - */ - -extern void fgoldi_sqr(fgoldi */*z*/, const fgoldi */*x*/); - -/* --- @fgoldi_inv@ --- * - * - * Arguments: @fgoldi *z@ = where to put the result (may alias @x@) - * @const fgoldi *x@ = an operand - * - * Returns: --- - * - * Use: Stores in @z@ the multiplicative inverse %$x^{-1}$%. If - * %$x = 0$% then @z@ is set to zero. This is considered a - * feature. - */ - -extern void fgoldi_inv(fgoldi */*z*/, const fgoldi */*x*/); - -/*----- That's all, folks -------------------------------------------------*/ - -#ifdef __cplusplus - } -#endif - -#endif