X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/0bcb8184cfce875a4dde57621139dd44c433f3a5..refs/heads/mdw/xdh:/fgoldi.h diff --git a/fgoldi.h b/fgoldi.h index 1857008..37dc6e2 100644 --- a/fgoldi.h +++ b/fgoldi.h @@ -1,39 +1,3 @@ -/* - * 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) @@ -43,7 +7,26 @@ /*----- Licensing notice --------------------------------------------------* * - * This file is part of Catacomb. + * 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 @@ -82,13 +65,7 @@ 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 + typedef int32 fgoldi_piece; /*----- Functions provided ------------------------------------------------*/ @@ -162,6 +139,52 @@ extern void fgoldi_add(fgoldi */*z*/, extern void fgoldi_sub(fgoldi */*z*/, const fgoldi */*x*/, const fgoldi */*y*/); +/* --- @fgoldi_neg@ --- * + * + * Arguments: @fgoldi *z@ = where to put the result (may alias @x@) + * @const fgoldi *x@ = an operand + * + * Returns: --- + * + * Use: Set @z = -x@. + */ + +extern void fgoldi_neg(fgoldi */*z*/, const fgoldi */*x*/); + +/* --- @fgoldi_pick2@ --- * + * + * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) + * @const fgoldi *x, *y@ = two operands + * @uint32 m@ = a mask + * + * Returns: --- + * + * Use: If @m@ is zero, set @z = y@; if @m@ is all-bits-set, then set + * @z = x@. If @m@ has some other value, then scramble @z@ in + * an unhelpful way. + */ + +extern void fgoldi_pick2(fgoldi */*z*/, + const fgoldi */*x*/, const fgoldi */*y*/, + uint32 /*m*/); + +/* --- @fgoldi_pickn@ --- * + * + * Arguments: @fgoldi *z@ = where to put the result + * @const fgoldi *v@ = a table of entries + * @size_t n@ = the number of entries in @v@ + * @size_t i@ = an index + * + * Returns: --- + * + * Use: If @0 <= i < n < 32@ then set @z = v[i]@. If @n >= 32@ then + * do something unhelpful; otherwise, if @i >= n@ then set @z@ + * to zero. + */ + +extern void fgoldi_pickn(fgoldi */*z*/, + const fgoldi */*v*/, size_t /*n*/, size_t /*i*/); + /* --- @fgoldi_condswap@ --- * * * Arguments: @fgoldi *x, *y@ = two operands @@ -176,6 +199,21 @@ extern void fgoldi_sub(fgoldi */*z*/, extern void fgoldi_condswap(fgoldi */*x*/, fgoldi */*y*/, uint32 /*m*/); +/* --- @fgoldi_condneg@ --- * + * + * Arguments: @fgoldi *z@ = where to put the result (may alias @x@) + * @const fgoldi *x@ = an operand + * @uint32 m@ = a mask + * + * Returns: --- + * + * Use: If @m@ is zero, set @z = x@; if @m@ is all-bits-set, then set + * @z = -x@. If @m@ has some other value then scramble @z@ in + * an unhelpful way. + */ + +extern void fgoldi_condneg(fgoldi */*z*/, const fgoldi */*x*/, uint32 /*m*/); + /* --- @fgoldi_mulconst@ --- * * * Arguments: @fgoldi *z@ = where to put the result (may alias @x@) @@ -228,6 +266,22 @@ extern void fgoldi_sqr(fgoldi */*z*/, const fgoldi */*x*/); extern void fgoldi_inv(fgoldi */*z*/, const fgoldi */*x*/); +/* --- @fgoldi_quosqrt@ --- * + * + * Arguments: @fgoldi *z@ = where to put the result (may alias @x@ or @y@) + * @const fgoldi *x, *y@ = two operands + * + * Returns: Zero if successful, @-1@ if %$x/y$% is not a square. + * + * Use: Stores in @z@ the one of the square roots %$\pm\sqrt{x/y}$%. + * If %$x = y = 0% then the result is zero; if %$y = 0$% but %$x + * \ne 0$% then the operation fails. If you wanted a specific + * square root then you'll have to pick it yourself. + */ + +extern int fgoldi_quosqrt(fgoldi */*z*/, + const fgoldi */*x*/, const fgoldi */*y*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus