Skip to content

Commit

Permalink
Add safegcd based modular inverse modules
Browse files Browse the repository at this point in the history
Refactored by: Pieter Wuille <pieter@wuille.net>
  • Loading branch information
peterdettman authored and sipa committed Mar 8, 2021
1 parent de0a643 commit 8e415ac
Show file tree
Hide file tree
Showing 5 changed files with 801 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ noinst_HEADERS += src/field_5x52.h
noinst_HEADERS += src/field_5x52_impl.h
noinst_HEADERS += src/field_5x52_int128_impl.h
noinst_HEADERS += src/field_5x52_asm_impl.h
noinst_HEADERS += src/modinv32.h
noinst_HEADERS += src/modinv32_impl.h
noinst_HEADERS += src/modinv64.h
noinst_HEADERS += src/modinv64_impl.h
noinst_HEADERS += src/assumptions.h
noinst_HEADERS += src/util.h
noinst_HEADERS += src/scratch.h
Expand Down
31 changes: 31 additions & 0 deletions src/modinv32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/***********************************************************************
* Copyright (c) 2020 Peter Dettman *
* Distributed under the MIT software license, see the accompanying *
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/

#ifndef SECP256K1_MODINV32_H
#define SECP256K1_MODINV32_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

typedef struct {
int32_t v[9];
} secp256k1_modinv32_signed30;

typedef struct {
/* The modulus in signed30 notation. */
secp256k1_modinv32_signed30 modulus;

/* modulus^{-1} mod 2^30 */
uint32_t modulus_inv30;
} secp256k1_modinv32_modinfo;

static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);
static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);

#endif /* SECP256K1_MODINV32_H */
Loading

0 comments on commit 8e415ac

Please sign in to comment.