You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by br...@apache.org on 2019/01/15 15:19:09 UTC
[04/51] [partial] incubator-milagro-crypto git commit: update code
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/big.h
----------------------------------------------------------------------
diff --git a/version3/cpp/big.h b/version3/cpp/big.h
deleted file mode 100644
index 1f4f451..0000000
--- a/version3/cpp/big.h
+++ /dev/null
@@ -1,595 +0,0 @@
-#ifndef BIG_XXX_H
-#define BIG_XXX_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include "arch.h"
-#include "amcl.h"
-#include "config_big_XXX.h"
-
-using namespace amcl;
-
-
-//#define UNWOUND
-
-#define BIGBITS_XXX (8*MODBYTES_XXX)
-#define NLEN_XXX (1+((8*MODBYTES_XXX-1)/BASEBITS_XXX))
-#define DNLEN_XXX 2*NLEN_XXX
-#define BMASK_XXX (((chunk)1<<BASEBITS_XXX)-1) /**< Mask = 2^BASEBITS-1 */
-#define NEXCESS_XXX (1<<(CHUNK-BASEBITS_XXX-1)) /**< 2^(CHUNK-BASEBITS-1) - digit cannot be multiplied by more than this before normalisation */
-
-#define HBITS_XXX (BASEBITS_XXX/2) /**< Number of bits in number base divided by 2 */
-#define HMASK_XXX (((chunk)1<<HBITS_XXX)-1) /**< Mask = 2^HBITS-1 */
-
-//#define DEBUG_NORM
-
-#ifdef DEBUG_NORM /* Add an extra location to track chunk extension */
-#define MPV_XXX NLEN_XXX
-#define MNV_XXX (NLEN_XXX+1)
-#define DMPV_XXX DNLEN_XXX
-#define DMNV_XXX (DNLEN_XXX+1)
-
-#endif
-
-namespace XXX {
-
-#ifdef DEBUG_NORM
-typedef chunk BIG[NLEN_XXX+2]; /**< Define type BIG as array of chunks */
-typedef chunk DBIG[DNLEN_XXX+2]; /**< Define type DBIG as array of chunks */
-#else
-typedef chunk BIG[NLEN_XXX]; /**< Define type BIG as array of chunks */
-typedef chunk DBIG[DNLEN_XXX]; /**< Define type DBIG as array of chunks */
-#endif
-
-/* BIG number prototypes */
-
-/** @brief Tests for BIG equal to zero
- *
- @param x a BIG number
- @return 1 if zero, else returns 0
- */
-extern int BIG_iszilch(BIG x);
-/** @brief Tests for BIG equal to one
- *
- @param x a BIG number
- @return 1 if one, else returns 0
- */
-extern int BIG_isunity(BIG x);
-/** @brief Tests for DBIG equal to zero
- *
- @param x a DBIG number
- @return 1 if zero, else returns 0
- */
-extern int BIG_diszilch(DBIG x);
-/** @brief Outputs a BIG number to the console
- *
- @param x a BIG number
- */
-extern void BIG_output(BIG x);
-/** @brief Outputs a BIG number to the console in raw form (for debugging)
- *
- @param x a BIG number
- */
-extern void BIG_rawoutput(BIG x);
-/** @brief Conditional constant time swap of two BIG numbers
- *
- Conditionally swaps parameters in constant time (without branching)
- @param x a BIG number
- @param y another BIG number
- @param s swap takes place if not equal to 0
- */
-extern void BIG_cswap(BIG x,BIG y,int s);
-/** @brief Conditional copy of BIG number
- *
- Conditionally copies second parameter to the first (without branching)
- @param x a BIG number
- @param y another BIG number
- @param s copy takes place if not equal to 0
- */
-extern void BIG_cmove(BIG x,BIG y,int s);
-/** @brief Conditional copy of DBIG number
- *
- Conditionally copies second parameter to the first (without branching)
- @param x a DBIG number
- @param y another DBIG number
- @param s copy takes place if not equal to 0
- */
-extern void BIG_dcmove(BIG x,BIG y,int s);
-/** @brief Convert from BIG number to byte array
- *
- @param a byte array
- @param x BIG number
- */
-extern void BIG_toBytes(char *a,BIG x);
-/** @brief Convert to BIG number from byte array
- *
- @param x BIG number
- @param a byte array
- */
-extern void BIG_fromBytes(BIG x,char *a);
-/** @brief Convert to BIG number from byte array of given length
- *
- @param x BIG number
- @param a byte array
- @param s byte array length
- */
-extern void BIG_fromBytesLen(BIG x,char *a,int s);
-/**@brief Convert to DBIG number from byte array of given length
- *
- @param x DBIG number
- @param a byte array
- @param s byte array length
- */
-extern void BIG_dfromBytesLen(DBIG x,char *a,int s);
-/** @brief Outputs a DBIG number to the console
- *
- @param x a DBIG number
- */
-extern void BIG_doutput(DBIG x);
-
-/** @brief Outputs a DBIG number to the console
- *
- @param x a DBIG number
- */
-extern void BIG_drawoutput(DBIG x);
-
-/** @brief Copy BIG from Read-Only Memory to a BIG
- *
- @param x BIG number
- @param y BIG number in ROM
- */
-extern void BIG_rcopy(BIG x,const BIG y);
-/** @brief Copy BIG to another BIG
- *
- @param x BIG number
- @param y BIG number to be copied
- */
-extern void BIG_copy(BIG x,BIG y);
-/** @brief Copy DBIG to another DBIG
- *
- @param x DBIG number
- @param y DBIG number to be copied
- */
-extern void BIG_dcopy(DBIG x,DBIG y);
-/** @brief Copy BIG to upper half of DBIG
- *
- @param x DBIG number
- @param y BIG number to be copied
- */
-extern void BIG_dsucopy(DBIG x,BIG y);
-/** @brief Copy BIG to lower half of DBIG
- *
- @param x DBIG number
- @param y BIG number to be copied
- */
-extern void BIG_dscopy(DBIG x,BIG y);
-/** @brief Copy lower half of DBIG to a BIG
- *
- @param x BIG number
- @param y DBIG number to be copied
- */
-extern void BIG_sdcopy(BIG x,DBIG y);
-/** @brief Copy upper half of DBIG to a BIG
- *
- @param x BIG number
- @param y DBIG number to be copied
- */
-extern void BIG_sducopy(BIG x,DBIG y);
-/** @brief Set BIG to zero
- *
- @param x BIG number to be set to zero
- */
-extern void BIG_zero(BIG x);
-/** @brief Set DBIG to zero
- *
- @param x DBIG number to be set to zero
- */
-extern void BIG_dzero(DBIG x);
-/** @brief Set BIG to one (unity)
- *
- @param x BIG number to be set to one.
- */
-extern void BIG_one(BIG x);
-/** @brief Set BIG to inverse mod 2^256
- *
- @param x BIG number to be inverted
- */
-extern void BIG_invmod2m(BIG x);
-/** @brief Set BIG to sum of two BIGs - output not normalised
- *
- @param x BIG number, sum of other two
- @param y BIG number
- @param z BIG number
- */
-extern void BIG_add(BIG x,BIG y,BIG z);
-
-/** @brief Set BIG to logical or of two BIGs - output normalised
- *
- @param x BIG number, or of other two
- @param y BIG number
- @param z BIG number
- */
-extern void BIG_or(BIG x,BIG y,BIG z);
-
-/** @brief Increment BIG by a small integer - output not normalised
- *
- @param x BIG number to be incremented
- @param i integer
- */
-extern void BIG_inc(BIG x,int i);
-/** @brief Set BIG to difference of two BIGs
- *
- @param x BIG number, difference of other two - output not normalised
- @param y BIG number
- @param z BIG number
- */
-extern void BIG_sub(BIG x,BIG y,BIG z);
-/** @brief Decrement BIG by a small integer - output not normalised
- *
- @param x BIG number to be decremented
- @param i integer
- */
-extern void BIG_dec(BIG x,int i);
-/** @brief Set DBIG to sum of two DBIGs
- *
- @param x DBIG number, sum of other two - output not normalised
- @param y DBIG number
- @param z DBIG number
- */
-extern void BIG_dadd(DBIG x,DBIG y,DBIG z);
-/** @brief Set DBIG to difference of two DBIGs
- *
- @param x DBIG number, difference of other two - output not normalised
- @param y DBIG number
- @param z DBIG number
- */
-extern void BIG_dsub(DBIG x,DBIG y,DBIG z);
-/** @brief Multiply BIG by a small integer - output not normalised
- *
- @param x BIG number, product of other two
- @param y BIG number
- @param i small integer
- */
-extern void BIG_imul(BIG x,BIG y,int i);
-/** @brief Multiply BIG by not-so-small small integer - output normalised
- *
- @param x BIG number, product of other two
- @param y BIG number
- @param i small integer
- @return Overflowing bits
- */
-extern chunk BIG_pmul(BIG x,BIG y,int i);
-/** @brief Divide BIG by 3 - output normalised
- *
- @param x BIG number
- @return Remainder
- */
-extern int BIG_div3(BIG x);
-/** @brief Multiply BIG by even bigger small integer resulting in a DBIG - output normalised
- *
- @param x DBIG number, product of other two
- @param y BIG number
- @param i small integer
- */
-extern void BIG_pxmul(DBIG x,BIG y,int i);
-/** @brief Multiply BIG by another BIG resulting in DBIG - inputs normalised and output normalised
- *
- @param x DBIG number, product of other two
- @param y BIG number
- @param z BIG number
- */
-extern void BIG_mul(DBIG x,BIG y,BIG z);
-/** @brief Multiply BIG by another BIG resulting in another BIG - inputs normalised and output normalised
- *
- Note that the product must fit into a BIG, and x must be distinct from y and z
- @param x BIG number, product of other two
- @param y BIG number
- @param z BIG number
- */
-extern void BIG_smul(BIG x,BIG y,BIG z);
-/** @brief Square BIG resulting in a DBIG - input normalised and output normalised
- *
- @param x DBIG number, square of a BIG
- @param y BIG number to be squared
- */
-extern void BIG_sqr(DBIG x,BIG y);
-
-/** @brief Montgomery reduction of a DBIG to a BIG - input normalised and output normalised
- *
- @param a BIG number, reduction of a BIG
- @param md BIG number, the modulus
- @param MC the Montgomery Constant
- @param d DBIG number to be reduced
- */
-extern void BIG_monty(BIG a,BIG md,chunk MC,DBIG d);
-
-/** @brief Shifts a BIG left by any number of bits - input must be normalised, output normalised
- *
- @param x BIG number to be shifted
- @param s Number of bits to shift
- */
-extern void BIG_shl(BIG x,int s);
-/** @brief Fast shifts a BIG left by a small number of bits - input must be normalised, output will be normalised
- *
- The number of bits to be shifted must be less than BASEBITS
- @param x BIG number to be shifted
- @param s Number of bits to shift
- @return Overflow bits
- */
-extern int BIG_fshl(BIG x,int s);
-/** @brief Shifts a DBIG left by any number of bits - input must be normalised, output normalised
- *
- @param x DBIG number to be shifted
- @param s Number of bits to shift
- */
-extern void BIG_dshl(DBIG x,int s);
-/** @brief Shifts a BIG right by any number of bits - input must be normalised, output normalised
- *
- @param x BIG number to be shifted
- @param s Number of bits to shift
- */
-extern void BIG_shr(BIG x,int s);
-
-
-/** @brief Fast time-critical combined shift by 1 bit, subtract and normalise
- *
- @param r BIG number normalised output
- @param a BIG number to be subtracted from
- @param m BIG number to be shifted and subtracted
- @return sign of r
- */
-extern int BIG_ssn(BIG r,BIG a, BIG m);
-
-/** @brief Fast shifts a BIG right by a small number of bits - input must be normalised, output will be normalised
- *
- The number of bits to be shifted must be less than BASEBITS
- @param x BIG number to be shifted
- @param s Number of bits to shift
- @return Shifted out bits
- */
-extern int BIG_fshr(BIG x,int s);
-/** @brief Shifts a DBIG right by any number of bits - input must be normalised, output normalised
- *
- @param x DBIG number to be shifted
- @param s Number of bits to shift
- */
-extern void BIG_dshr(DBIG x,int s);
-/** @brief Splits a DBIG into two BIGs - input must be normalised, outputs normalised
- *
- Internal function. The value of s must be approximately in the middle of the DBIG.
- Typically used to extract z mod 2^MODBITS and z/2^MODBITS
- @param x BIG number, top half of z
- @param y BIG number, bottom half of z
- @param z DBIG number to be split in two.
- @param s Bit position at which to split
- @return carry-out from top half
- */
-extern chunk BIG_split(BIG x,BIG y,DBIG z,int s);
-/** @brief Normalizes a BIG number - output normalised
- *
- All digits of the input BIG are reduced mod 2^BASEBITS
- @param x BIG number to be normalised
- */
-extern chunk BIG_norm(BIG x);
-/** @brief Normalizes a DBIG number - output normalised
- *
- All digits of the input DBIG are reduced mod 2^BASEBITS
- @param x DBIG number to be normalised
- */
-extern void BIG_dnorm(DBIG x);
-/** @brief Compares two BIG numbers. Inputs must be normalised externally
- *
- @param x first BIG number to be compared
- @param y second BIG number to be compared
- @return -1 is x<y, 0 if x=y, 1 if x>y
- */
-extern int BIG_comp(BIG x,BIG y);
-/** @brief Compares two DBIG numbers. Inputs must be normalised externally
- *
- @param x first DBIG number to be compared
- @param y second DBIG number to be compared
- @return -1 is x<y, 0 if x=y, 1 if x>y
- */
-extern int BIG_dcomp(DBIG x,DBIG y);
-/** @brief Calculate number of bits in a BIG - output normalised
- *
- @param x BIG number
- @return Number of bits in x
- */
-extern int BIG_nbits(BIG x);
-/** @brief Calculate number of bits in a DBIG - output normalised
- *
- @param x DBIG number
- @return Number of bits in x
- */
-extern int BIG_dnbits(DBIG x);
-/** @brief Reduce x mod n - input and output normalised
- *
- Slow but rarely used
- @param x BIG number to be reduced mod n
- @param n The modulus
- */
-extern void BIG_mod(BIG x,BIG n);
-/** @brief Divide x by n - output normalised
- *
- Slow but rarely used
- @param x BIG number to be divided by n
- @param n The Divisor
- */
-extern void BIG_sdiv(BIG x,BIG n);
-/** @brief x=y mod n - output normalised
- *
- Slow but rarely used. y is destroyed.
- @param x BIG number, on exit = y mod n
- @param y DBIG number
- @param n Modulus
- */
-extern void BIG_dmod(BIG x,DBIG y,BIG n);
-/** @brief x=y/n - output normalised
- *
- Slow but rarely used. y is destroyed.
- @param x BIG number, on exit = y/n
- @param y DBIG number
- @param n Modulus
- */
-extern void BIG_ddiv(BIG x,DBIG y,BIG n);
-/** @brief return parity of BIG, that is the least significant bit
- *
- @param x BIG number
- @return 0 or 1
- */
-extern int BIG_parity(BIG x);
-/** @brief return i-th of BIG
- *
- @param x BIG number
- @param i the bit of x to be returned
- @return 0 or 1
- */
-extern int BIG_bit(BIG x,int i);
-/** @brief return least significant bits of a BIG
- *
- @param x BIG number
- @param n number of bits to return. Assumed to be less than BASEBITS.
- @return least significant n bits as an integer
- */
-extern int BIG_lastbits(BIG x,int n);
-/** @brief Create a random BIG from a random number generator
- *
- Assumes that the random number generator has been suitably initialised
- @param x BIG number, on exit a random number
- @param r A pointer to a Cryptographically Secure Random Number Generator
- */
-extern void BIG_random(BIG x,csprng *r);
-/** @brief Create an unbiased random BIG from a random number generator, reduced with respect to a modulus
- *
- Assumes that the random number generator has been suitably initialised
- @param x BIG number, on exit a random number
- @param n The modulus
- @param r A pointer to a Cryptographically Secure Random Number Generator
- */
-extern void BIG_randomnum(BIG x,BIG n,csprng *r);
-/** brief return NAF (Non-Adjacent-Form) value as +/- 1, 3 or 5, inputs must be normalised
- *
- Given x and 3*x extracts NAF value from given bit position, and returns number of bits processed, and number of trailing zeros detected if any
- param x BIG number
- param x3 BIG number, three times x
- param i bit position
- param nbs pointer to integer returning number of bits processed
- param nzs pointer to integer returning number of trailing 0s
- return + or - 1, 3 or 5
-*/
-
-/** @brief Calculate x=y*z mod n
- *
- Slow method for modular multiplication
- @param x BIG number, on exit = y*z mod n
- @param y BIG number
- @param z BIG number
- @param n The BIG Modulus
- */
-extern void BIG_modmul(BIG x,BIG y,BIG z,BIG n);
-/** @brief Calculate x=y/z mod n
- *
- Slow method for modular division
- @param x BIG number, on exit = y/z mod n
- @param y BIG number
- @param z BIG number
- @param n The BIG Modulus
- */
-extern void BIG_moddiv(BIG x,BIG y,BIG z,BIG n);
-/** @brief Calculate x=y^2 mod n
- *
- Slow method for modular squaring
- @param x BIG number, on exit = y^2 mod n
- @param y BIG number
- @param n The BIG Modulus
- */
-extern void BIG_modsqr(BIG x,BIG y,BIG n);
-/** @brief Calculate x=-y mod n
- *
- Modular negation
- @param x BIG number, on exit = -y mod n
- @param y BIG number
- @param n The BIG Modulus
- */
-extern void BIG_modneg(BIG x,BIG y,BIG n);
-/** @brief Calculate jacobi Symbol (x/y)
- *
- @param x BIG number
- @param y BIG number
- @return Jacobi symbol, -1,0 or 1
- */
-extern int BIG_jacobi(BIG x,BIG y);
-/** @brief Calculate x=1/y mod n
- *
- Modular Inversion - This is slow. Uses binary method.
- @param x BIG number, on exit = 1/y mod n
- @param y BIG number
- @param n The BIG Modulus
- */
-extern void BIG_invmodp(BIG x,BIG y,BIG n);
-/** @brief Calculate x=x mod 2^m
- *
- Truncation
- @param x BIG number, on reduced mod 2^m
- @param m new truncated size
-*/
-extern void BIG_mod2m(BIG x,int m);
-
-/** @brief Calculates a*b+c+*d
- *
- Calculate partial product of a.b, add in carry c, and add total to d
- @param a multiplier
- @param b multiplicand
- @param c carry
- @param d pointer to accumulated bottom half of result
- @return top half of result
- */
-
-#ifdef dchunk
-
-/* Method required to calculate x*y+c+r, bottom half in r, top half returned */
-inline chunk muladd(chunk x,chunk y,chunk c,chunk *r)
-{
- dchunk prod=(dchunk)x*y+c+*r;
- *r=(chunk)prod&BMASK_XXX;
- return (chunk)(prod>>BASEBITS_XXX);
-}
-
-#else
-
-/* No integer type available that can store double the wordlength */
-/* accumulate partial products */
-
-inline chunk muladd(chunk x,chunk y,chunk c,chunk *r)
-{
- chunk x0,x1,y0,y1;
- chunk bot,top,mid,carry;
- x0=x&HMASK;
- x1=(x>>HBITS_XXX);
- y0=y&HMASK_XXX;
- y1=(y>>HBITS_XXX);
- bot=x0*y0;
- top=x1*y1;
- mid=x0*y1+x1*y0;
- x0=mid&HMASK_XXX;
- x1=(mid>>HBITS_XXX);
- bot+=x0<<HBITS_XXX;
- bot+=*r;
- bot+=c;
-
- top+=x1;
- carry=bot>>BASEBITS_XXX;
- bot&=BMASK_XXX;
- top+=carry;
-
- *r=bot;
- return top;
-}
-
-#endif
-
-}
-
-#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config16.py
----------------------------------------------------------------------
diff --git a/version3/cpp/config16.py b/version3/cpp/config16.py
deleted file mode 100644
index d22a76a..0000000
--- a/version3/cpp/config16.py
+++ /dev/null
@@ -1,370 +0,0 @@
-import os
-import sys
-
-deltext=""
-if sys.platform.startswith("linux") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("darwin") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("win") :
- deltext="del"
- copytext="copy"
-
-def replace(namefile,oldtext,newtext):
- f = open(namefile,'r')
- filedata = f.read()
- f.close()
-
- newdata = filedata.replace(oldtext,newtext)
-
- f = open(namefile,'w')
- f.write(newdata)
- f.close()
-
-
-def rsaset(tb,tff,nb,base,ml) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_ff_"+tff+".h"
- os.system(copytext+" config_ff.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"@ML@",ml)
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ff_"+tff+".cpp"
- fnameh="ff_"+tff+".h"
-
- os.system(copytext+" ff.cpp "+fnamec)
- os.system(copytext+" ff.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="rsa_"+tff+".cpp"
- fnameh="rsa_"+tff+".h"
-
- os.system(copytext+" rsa.cpp "+fnamec)
- os.system(copytext+" rsa.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-def curveset(tb,tf,tc,nb,base,nbt,m8,mt,ct,pf,stw,sx,cs) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_field_"+tf+".h"
- os.system(copytext+" config_field.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"@NBT@",nbt)
- replace(fnameh,"@M8@",m8)
- replace(fnameh,"@MT@",mt)
-
- ib=int(base)
- inb=int(nb)
- inbt=int(nbt)
- sh=ib*(1+((8*inb-1)//ib))-inbt
-
- if sh > 6 :
- sh=6
- replace(fnameh,"@SH@",str(sh))
-
- fnameh="config_curve_"+tc+".h"
- os.system(copytext+" config_curve.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"@CT@",ct)
- replace(fnameh,"@PF@",pf)
-
- replace(fnameh,"@ST@",stw)
- replace(fnameh,"@SX@",sx)
- replace(fnameh,"@CS@",cs)
-
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp_"+tf+".cpp"
- fnameh="fp_"+tf+".h"
-
- os.system(copytext+" fp.cpp "+fnamec)
- os.system(copytext+" fp.h "+fnameh)
-
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_field_"+tf+".cpp")
-
- fnamec="ecp_"+tc+".cpp"
- fnameh="ecp_"+tc+".h"
-
- os.system(copytext+" ecp.cpp "+fnamec)
- os.system(copytext+" ecp.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecdh_"+tc+".cpp"
- fnameh="ecdh_"+tc+".h"
-
- os.system(copytext+" ecdh.cpp "+fnamec)
- os.system(copytext+" ecdh.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_curve_"+tc+".cpp")
-
- if pf != "NOT" :
- fnamec="fp2_"+tf+".cpp"
- fnameh="fp2_"+tf+".h"
-
- os.system(copytext+" fp2.cpp "+fnamec)
- os.system(copytext+" fp2.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp4_"+tf+".cpp"
- fnameh="fp4_"+tf+".h"
-
- os.system(copytext+" fp4.cpp "+fnamec)
- os.system(copytext+" fp4.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp12_"+tf+".cpp"
- fnameh="fp12_"+tf+".h"
-
- os.system(copytext+" fp12.cpp "+fnamec)
- os.system(copytext+" fp12.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecp2_"+tc+".cpp"
- fnameh="ecp2_"+tc+".h"
-
- os.system(copytext+" ecp2.cpp "+fnamec)
- os.system(copytext+" ecp2.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="pair_"+tc+".cpp"
- fnameh="pair_"+tc+".h"
-
- os.system(copytext+" pair.cpp "+fnamec)
- os.system(copytext+" pair.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin_"+tc+".cpp"
- fnameh="mpin_"+tc+".h"
-
- os.system(copytext+" mpin.cpp "+fnamec)
- os.system(copytext+" mpin.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-replace("arch.h","@WL@","16")
-print("Elliptic Curves")
-print("1. ED25519")
-print("2. NUMS256E")
-
-print("Pairing-Friendly Elliptic Curves")
-print("3. BN254")
-print("4. BN254CX")
-
-print("RSA")
-print("5. RSA2048")
-
-
-selection=[]
-ptr=0
-max=6
-
-curve_selected=False
-pfcurve_selected=False
-rsa_selected=False
-
-while ptr<max:
- x=int(input("Choose a Scheme to support - 0 to finish: "))
- if x == 0:
- break
-# print("Choice= ",x)
- already=False
- for i in range(0,ptr):
- if x==selection[i]:
- already=True
- break
- if already:
- continue
-
- selection.append(x)
- ptr=ptr+1
-
-# curveset(big,field,curve,big_length_bytes,bits_in_base,modulus_bits,modulus_mod_8,modulus_type,curve_type,pairing_friendly)
-# for each curve give names for big, field and curve. In many cases the latter two will be the same.
-# Typically "big" is the size in bits, always a multiple of 8, "field" describes the modulus, and "curve" is the common name for the elliptic curve
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 16 bit architectures, as n where the base is 2^n (note that these must be fixed for the same "big" name, if is ever re-used for another curve)
-# modulus_bits is the bit length of the modulus, typically the same or slightly smaller than "big"
-# modulus_mod_8 is the remainder when the modulus is divided by 8
-# modulus_type is NOT_SPECIAL, or PSEUDO_MERSENNE, or MONTGOMERY_Friendly, or GENERALISED_MERSENNE (supported for GOLDILOCKS only)
-# curve_type is WEIERSTRASS, EDWARDS or MONTGOMERY
-# pairing_friendly is BN, BLS or NOT (if not pairing friendly)
-# if pairing friendly. M or D type twist, and sign of the family parameter x
-
-
- if x==1:
- curveset("256","F25519","ED25519","32","13","255","5","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
- if x==2:
- curveset("256","F256PME","NUMS256E","32","13","256","3","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
-
-
- if x==3:
- curveset("256","BN254","BN254","32","13","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==4:
- curveset("256","BN254CX","BN254CX","32","13","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
-
-# rsaset(big,ring,big_length_bytes,bits_in_base,multiplier)
-# for each choice give distinct names for "big" and "ring".
-# Typically "big" is the length in bits of the underlying big number type
-# "ring" is the RSA modulus size = "big" times 2^m
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 16 bit architectures, as n where the base is 2^n
-# multiplier is 2^m (see above)
-
-# There are choices here, different ways of getting the same result, but some faster than others
- if x==5:
- #256 is slower but may allow reuse of 256-bit BIGs used for elliptic curve
- #512 is faster.. but best is 1024
- rsaset("256","RSA2048","32","13","8")
- rsa_selected=True
-
-
-os.system(deltext+" big.*")
-os.system(deltext+" fp.*")
-os.system(deltext+" ecp.*")
-os.system(deltext+" ecdh.*")
-os.system(deltext+" ff.*")
-os.system(deltext+" rsa.*")
-os.system(deltext+" config_big.h")
-os.system(deltext+" config_field.h")
-os.system(deltext+" config_curve.h")
-os.system(deltext+" config_ff.h")
-os.system(deltext+" fp2.*")
-os.system(deltext+" fp4.*")
-os.system(deltext+" fp12.*")
-os.system(deltext+" ecp2.*")
-os.system(deltext+" pair.*")
-os.system(deltext+" mpin.*")
-
-# create library
-os.system("g++ -O3 -c randapi.cpp")
-if curve_selected :
- os.system("g++ -O3 -c ecdh_support.cpp")
-if rsa_selected :
- os.system("g++ -O3 -c rsa_support.cpp")
-if pfcurve_selected :
- os.system("g++ -O3 -c pbc_support.cpp")
-
-os.system("g++ -O3 -c hash.cpp")
-os.system("g++ -O3 -c rand.cpp")
-os.system("g++ -O3 -c oct.cpp")
-os.system("g++ -O3 -c aes.cpp")
-os.system("g++ -O3 -c gcm.cpp")
-os.system("g++ -O3 -c newhope.cpp")
-
-if sys.platform.startswith("win") :
- os.system("for %i in (*.o) do @echo %~nxi >> f.list")
- os.system("ar rc amcl.a @f.list")
- os.system(deltext+" f.list")
-
-else :
- os.system("ar rc amcl.a *.o")
-
-os.system(deltext+" *.o")
-
-
-#print("Your section was ")
-#for i in range(0,ptr):
-# print (selection[i])
-
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config32.py
----------------------------------------------------------------------
diff --git a/version3/cpp/config32.py b/version3/cpp/config32.py
deleted file mode 100644
index b2ab9b0..0000000
--- a/version3/cpp/config32.py
+++ /dev/null
@@ -1,641 +0,0 @@
-import os
-import sys
-
-deltext=""
-if sys.platform.startswith("linux") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("darwin") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("win") :
- deltext="del"
- copytext="copy"
-
-def replace(namefile,oldtext,newtext):
- f = open(namefile,'r')
- filedata = f.read()
- f.close()
-
- newdata = filedata.replace(oldtext,newtext)
-
- f = open(namefile,'w')
- f.write(newdata)
- f.close()
-
-
-def rsaset(tb,tff,nb,base,ml) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_ff_"+tff+".h"
- os.system(copytext+" config_ff.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"@ML@",ml)
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ff_"+tff+".cpp"
- fnameh="ff_"+tff+".h"
-
- os.system(copytext+" ff.cpp "+fnamec)
- os.system(copytext+" ff.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="rsa_"+tff+".cpp"
- fnameh="rsa_"+tff+".h"
-
- os.system(copytext+" rsa.cpp "+fnamec)
- os.system(copytext+" rsa.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-def curveset(tb,tf,tc,nb,base,nbt,m8,mt,ct,pf,stw,sx,cs) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_field_"+tf+".h"
- os.system(copytext+" config_field.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"@NBT@",nbt)
- replace(fnameh,"@M8@",m8)
- replace(fnameh,"@MT@",mt)
-
- ib=int(base)
- inb=int(nb)
- inbt=int(nbt)
- sh=ib*(1+((8*inb-1)//ib))-inbt
-
- if sh > 14 :
- sh=14
- replace(fnameh,"@SH@",str(sh))
-
- fnameh="config_curve_"+tc+".h"
- os.system(copytext+" config_curve.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"@CT@",ct)
- replace(fnameh,"@PF@",pf)
-
- replace(fnameh,"@ST@",stw)
- replace(fnameh,"@SX@",sx)
- replace(fnameh,"@CS@",cs)
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp_"+tf+".cpp"
- fnameh="fp_"+tf+".h"
-
- os.system(copytext+" fp.cpp "+fnamec)
- os.system(copytext+" fp.h "+fnameh)
-
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_field_"+tf+".cpp")
-
- fnamec="ecp_"+tc+".cpp"
- fnameh="ecp_"+tc+".h"
-
- os.system(copytext+" ecp.cpp "+fnamec)
- os.system(copytext+" ecp.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecdh_"+tc+".cpp"
- fnameh="ecdh_"+tc+".h"
-
- os.system(copytext+" ecdh.cpp "+fnamec)
- os.system(copytext+" ecdh.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_curve_"+tc+".cpp")
-
- if pf != "NOT" :
- fnamec="fp2_"+tf+".cpp"
- fnameh="fp2_"+tf+".h"
-
- os.system(copytext+" fp2.cpp "+fnamec)
- os.system(copytext+" fp2.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp4_"+tf+".cpp"
- fnameh="fp4_"+tf+".h"
-
- os.system(copytext+" fp4.cpp "+fnamec)
- os.system(copytext+" fp4.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "128" :
- fnamec="fp12_"+tf+".cpp"
- fnameh="fp12_"+tf+".h"
-
- os.system(copytext+" fp12.cpp "+fnamec)
- os.system(copytext+" fp12.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecp2_"+tc+".cpp"
- fnameh="ecp2_"+tc+".h"
-
- os.system(copytext+" ecp2.cpp "+fnamec)
- os.system(copytext+" ecp2.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="pair_"+tc+".cpp"
- fnameh="pair_"+tc+".h"
-
- os.system(copytext+" pair.cpp "+fnamec)
- os.system(copytext+" pair.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin_"+tc+".cpp"
- fnameh="mpin_"+tc+".h"
-
- os.system(copytext+" mpin.cpp "+fnamec)
- os.system(copytext+" mpin.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "192" :
- fnamec="fp8_"+tf+".cpp"
- fnameh="fp8_"+tf+".h"
-
- os.system(copytext+" fp8.cpp "+fnamec)
- os.system(copytext+" fp8.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp24_"+tf+".cpp"
- fnameh="fp24_"+tf+".h"
-
- os.system(copytext+" fp24.cpp "+fnamec)
- os.system(copytext+" fp24.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecp4_"+tc+".cpp"
- fnameh="ecp4_"+tc+".h"
-
- os.system(copytext+" ecp4.cpp "+fnamec)
- os.system(copytext+" ecp4.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="pair192_"+tc+".cpp"
- fnameh="pair192_"+tc+".h"
-
- os.system(copytext+" pair192.cpp "+fnamec)
- os.system(copytext+" pair192.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin192_"+tc+".cpp"
- fnameh="mpin192_"+tc+".h"
-
- os.system(copytext+" mpin192.cpp "+fnamec)
- os.system(copytext+" mpin192.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "256" :
-
- fnamec="fp8_"+tf+".cpp"
- fnameh="fp8_"+tf+".h"
-
- os.system(copytext+" fp8.cpp "+fnamec)
- os.system(copytext+" fp8.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="ecp8_"+tc+".cpp"
- fnameh="ecp8_"+tc+".h"
-
- os.system(copytext+" ecp8.cpp "+fnamec)
- os.system(copytext+" ecp8.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp16_"+tf+".cpp"
- fnameh="fp16_"+tf+".h"
-
- os.system(copytext+" fp16.cpp "+fnamec)
- os.system(copytext+" fp16.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp48_"+tf+".cpp"
- fnameh="fp48_"+tf+".h"
-
- os.system(copytext+" fp48.cpp "+fnamec)
- os.system(copytext+" fp48.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="pair256_"+tc+".cpp"
- fnameh="pair256_"+tc+".h"
-
- os.system(copytext+" pair256.cpp "+fnamec)
- os.system(copytext+" pair256.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin256_"+tc+".cpp"
- fnameh="mpin256_"+tc+".h"
-
- os.system(copytext+" mpin256.cpp "+fnamec)
- os.system(copytext+" mpin256.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-replace("arch.h","@WL@","32")
-print("Elliptic Curves")
-print("1. ED25519")
-print("2. C25519")
-print("3. NIST256")
-print("4. BRAINPOOL")
-print("5. ANSSI")
-print("6. HIFIVE")
-print("7. GOLDILOCKS")
-print("8. NIST384")
-print("9. C41417")
-print("10. NIST521\n")
-print("11. NUMS256W")
-print("12. NUMS256E")
-print("13. NUMS384W")
-print("14. NUMS384E")
-print("15. NUMS512W")
-print("16. NUMS512E")
-print("17. SECP256K1\n")
-
-print("Pairing-Friendly Elliptic Curves")
-print("18. BN254")
-print("19. BN254CX")
-print("20. BLS383")
-print("21. BLS381")
-print("22. FP256BN")
-print("23. FP512BN")
-print("24. BLS461\n")
-print("25. BLS24")
-print("26. BLS48\n")
-
-print("RSA")
-print("27. RSA2048")
-print("28. RSA3072")
-print("29. RSA4096")
-
-selection=[]
-ptr=0
-max=30
-
-
-curve_selected=False
-pfcurve_selected=False
-rsa_selected=False
-
-while ptr<max:
- x=int(input("Choose a Scheme to support - 0 to finish: "))
- if x == 0:
- break
-# print("Choice= ",x)
- already=False
- for i in range(0,ptr):
- if x==selection[i]:
- already=True
- break
- if already:
- continue
-
- selection.append(x)
- ptr=ptr+1
-
-# curveset(big,field,curve,big_length_bytes,bits_in_base,modulus_bits,modulus_mod_8,modulus_type,curve_type,pairing_friendly,sextic twist,sign of x,curve security)
-# for each curve give names for big, field and curve. In many cases the latter two will be the same.
-# Typically "big" is the size in bits, always a multiple of 8, "field" describes the modulus, and "curve" is the common name for the elliptic curve
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 32 bit architecture, as n where the base is 2^n (note that these must be fixed for the same "big" name, if is ever re-used for another curve)
-# modulus_bits is the bit length of the modulus, typically the same or slightly smaller than "big"
-# modulus_mod_8 is the remainder when the modulus is divided by 8
-# modulus_type is NOT_SPECIAL, or PSEUDO_MERSENNE, or MONTGOMERY_Friendly, or GENERALISED_MERSENNE (supported for GOLDILOCKS only)
-# curve_type is WEIERSTRASS, EDWARDS or MONTGOMERY
-# pairing_friendly is BN, BLS or NOT (if not pairing friendly)
-# if pairing friendly. M or D type twist, and sign of the family parameter x
-# curve security is AES equiavlent, rounded up.
-
- if x==1:
- curveset("256","F25519","ED25519","32","29","255","5","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
- if x==2:
- curveset("256","F25519","C25519","32","29","255","5","PSEUDO_MERSENNE","MONTGOMERY","NOT","","","128")
- curve_selected=True
- if x==3:
- curveset("256","NIST256","NIST256","32","28","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==4:
- curveset("256","BRAINPOOL","BRAINPOOL","32","28","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==5:
- curveset("256","ANSSI","ANSSI","32","28","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
-
- if x==6:
- curveset("336","HIFIVE","HIFIVE","42","29","336","5","PSEUDO_MERSENNE","EDWARDS","NOT","","","192")
- curve_selected=True
- if x==7:
- curveset("448","GOLDILOCKS","GOLDILOCKS","56","29","448","7","GENERALISED_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
- if x==8:
- curveset("384","NIST384","NIST384","48","29","384","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","192")
- curve_selected=True
- if x==9:
- curveset("416","C41417","C41417","52","29","414","7","PSEUDO_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
- if x==10:
- curveset("528","NIST521","NIST521","66","28","521","7","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","256")
- curve_selected=True
-
- if x==11:
- curveset("256","F256PMW","NUMS256W","32","28","256","3","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==12:
- curveset("256","F256PME","NUMS256E","32","29","256","3","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
- if x==13:
- curveset("384","F384PM","NUMS384W","48","29","384","3","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","192")
- curve_selected=True
- if x==14:
- curveset("384","F384PM","NUMS384E","48","29","384","3","PSEUDO_MERSENNE","EDWARDS","NOT","","","192")
- curve_selected=True
- if x==15:
- curveset("512","F512PM","NUMS512W","64","29","512","7","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","256")
- curve_selected=True
- if x==16:
- curveset("512","F512PM","NUMS512E","64","29","512","7","PSEUDO_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
-
- if x==17:
- curveset("256","SECP256K1","SECP256K1","32","28","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
-
- if x==18:
- curveset("256","BN254","BN254","32","28","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==19:
- curveset("256","BN254CX","BN254CX","32","28","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==20:
- curveset("384","BLS383","BLS383","48","29","383","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","128")
- pfcurve_selected=True
-
- if x==21:
- curveset("384","BLS381","BLS381","48","29","381","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
-
-
- if x==22:
- curveset("256","FP256BN","FP256BN","32","28","256","3","NOT_SPECIAL","WEIERSTRASS","BN","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==23:
- curveset("512","FP512BN","FP512BN","64","29","512","3","NOT_SPECIAL","WEIERSTRASS","BN","M_TYPE","POSITIVEX","128")
- pfcurve_selected=True
-# https://eprint.iacr.org/2017/334.pdf
- if x==24:
- curveset("464","BLS461","BLS461","58","28","461","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
-
- if x==25:
- curveset("480","BLS24","BLS24","60","29","479","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","192")
- pfcurve_selected=True
-
-
- if x==26:
- curveset("560","BLS48","BLS48","70","29","556","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","256")
- pfcurve_selected=True
-
-
-# rsaset(big,ring,big_length_bytes,bit_bits_in_base,multiplier)
-# for each choice give distinct names for "big" and "ring".
-# Typically "big" is the length in bits of the underlying big number type
-# "ring" is the RSA modulus size = "big" times 2^m
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 32 bit architectures, as n where the base is 2^n
-# multiplier is 2^m (see above)
-
-# There are choices here, different ways of getting the same result, but some faster than others
- if x==27:
- #256 is slower but may allow reuse of 256-bit BIGs used for elliptic curve
- #512 is faster.. but best is 1024
- rsaset("1024","RSA2048","128","28","2")
- #rsaset("512","RSA2048","64","29","4")
- #rsaset("256","RSA2048","32","29","8")
- rsa_selected=True
- if x==28:
- rsaset("384","RSA3072","48","28","8")
- rsa_selected=True
- if x==29:
- #rsaset("256","RSA4096","32","29","16")
- rsaset("512","RSA4096","64","29","8")
- rsa_selected=True
-
-
-os.system(deltext+" big.*")
-os.system(deltext+" fp.*")
-os.system(deltext+" ecp.*")
-os.system(deltext+" ecdh.*")
-os.system(deltext+" ff.*")
-os.system(deltext+" rsa.*")
-os.system(deltext+" config_big.h")
-os.system(deltext+" config_field.h")
-os.system(deltext+" config_curve.h")
-os.system(deltext+" config_ff.h")
-os.system(deltext+" fp2.*")
-os.system(deltext+" fp4.*")
-os.system(deltext+" fp8.*")
-os.system(deltext+" fp16.*")
-
-os.system(deltext+" fp12.*")
-os.system(deltext+" fp24.*")
-os.system(deltext+" fp48.*")
-
-os.system(deltext+" ecp2.*")
-os.system(deltext+" ecp4.*")
-os.system(deltext+" ecp8.*")
-
-os.system(deltext+" pair.*")
-os.system(deltext+" mpin.*")
-
-os.system(deltext+" pair192.*")
-os.system(deltext+" mpin192.*")
-
-os.system(deltext+" pair256.*")
-os.system(deltext+" mpin256.*")
-
-# create library
-os.system("g++ -O3 -c randapi.cpp")
-if curve_selected :
- os.system("g++ -O3 -c ecdh_support.cpp")
-if rsa_selected :
- os.system("g++ -O3 -c rsa_support.cpp")
-if pfcurve_selected :
- os.system("g++ -O3 -c pbc_support.cpp")
-
-os.system("g++ -O3 -c hash.cpp")
-os.system("g++ -O3 -c rand.cpp")
-os.system("g++ -O3 -c oct.cpp")
-os.system("g++ -O3 -c aes.cpp")
-os.system("g++ -O3 -c gcm.cpp")
-os.system("g++ -O3 -c newhope.cpp")
-
-if sys.platform.startswith("win") :
- os.system("for %i in (*.o) do @echo %~nxi >> f.list")
- os.system("ar rc amcl.a @f.list")
- os.system(deltext+" f.list")
-
-else :
- os.system("ar rc amcl.a *.o")
-
-os.system(deltext+" *.o")
-
-
-#print("Your section was ")
-#for i in range(0,ptr):
-# print (selection[i])
-
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config64.py
----------------------------------------------------------------------
diff --git a/version3/cpp/config64.py b/version3/cpp/config64.py
deleted file mode 100644
index faa6a90..0000000
--- a/version3/cpp/config64.py
+++ /dev/null
@@ -1,641 +0,0 @@
-import os
-import sys
-
-deltext=""
-if sys.platform.startswith("linux") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("darwin") :
- deltext="rm"
- copytext="cp"
-if sys.platform.startswith("win") :
- deltext="del"
- copytext="copy"
-
-def replace(namefile,oldtext,newtext):
- f = open(namefile,'r')
- filedata = f.read()
- f.close()
-
- newdata = filedata.replace(oldtext,newtext)
-
- f = open(namefile,'w')
- f.write(newdata)
- f.close()
-
-
-def rsaset(tb,tff,nb,base,ml) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_ff_"+tff+".h"
- os.system(copytext+" config_ff.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"@ML@",ml)
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ff_"+tff+".cpp"
- fnameh="ff_"+tff+".h"
-
- os.system(copytext+" ff.cpp "+fnamec)
- os.system(copytext+" ff.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="rsa_"+tff+".cpp"
- fnameh="rsa_"+tff+".h"
-
- os.system(copytext+" rsa.cpp "+fnamec)
- os.system(copytext+" rsa.h "+fnameh)
-
- replace(fnamec,"WWW",tff)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"WWW",tff)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-def curveset(tb,tf,tc,nb,base,nbt,m8,mt,ct,pf,stw,sx,cs) :
- bd="B"+tb+"_"+base
- fnameh="config_big_"+bd+".h"
- os.system(copytext+" config_big.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"@NB@",nb)
- replace(fnameh,"@BASE@",base)
-
- fnameh="config_field_"+tf+".h"
- os.system(copytext+" config_field.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"@NBT@",nbt)
- replace(fnameh,"@M8@",m8)
- replace(fnameh,"@MT@",mt)
-
- ib=int(base)
- inb=int(nb)
- inbt=int(nbt)
- sh=ib*(1+((8*inb-1)//ib))-inbt
-
- if sh > 30 :
- sh=30
- replace(fnameh,"@SH@",str(sh))
-
- fnameh="config_curve_"+tc+".h"
- os.system(copytext+" config_curve.h "+fnameh)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"@CT@",ct)
- replace(fnameh,"@PF@",pf)
-
- replace(fnameh,"@ST@",stw)
- replace(fnameh,"@SX@",sx)
- replace(fnameh,"@CS@",cs)
-
-
- fnamec="big_"+bd+".cpp"
- fnameh="big_"+bd+".h"
-
- os.system(copytext+" big.cpp "+fnamec)
- os.system(copytext+" big.h "+fnameh)
-
- replace(fnamec,"XXX",bd)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp_"+tf+".cpp"
- fnameh="fp_"+tf+".h"
-
- os.system(copytext+" fp.cpp "+fnamec)
- os.system(copytext+" fp.h "+fnameh)
-
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_field_"+tf+".cpp")
-
- fnamec="ecp_"+tc+".cpp"
- fnameh="ecp_"+tc+".h"
-
- os.system(copytext+" ecp.cpp "+fnamec)
- os.system(copytext+" ecp.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecdh_"+tc+".cpp"
- fnameh="ecdh_"+tc+".h"
-
- os.system(copytext+" ecdh.cpp "+fnamec)
- os.system(copytext+" ecdh.h "+fnameh)
-
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- os.system("g++ -O3 -c rom_curve_"+tc+".cpp")
-
- if pf != "NOT" :
- fnamec="fp2_"+tf+".cpp"
- fnameh="fp2_"+tf+".h"
-
- os.system(copytext+" fp2.cpp "+fnamec)
- os.system(copytext+" fp2.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="fp4_"+tf+".cpp"
- fnameh="fp4_"+tf+".h"
-
- os.system(copytext+" fp4.cpp "+fnamec)
- os.system(copytext+" fp4.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "128" :
- fnamec="fp12_"+tf+".cpp"
- fnameh="fp12_"+tf+".h"
-
- os.system(copytext+" fp12.cpp "+fnamec)
- os.system(copytext+" fp12.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecp2_"+tc+".cpp"
- fnameh="ecp2_"+tc+".h"
-
- os.system(copytext+" ecp2.cpp "+fnamec)
- os.system(copytext+" ecp2.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="pair_"+tc+".cpp"
- fnameh="pair_"+tc+".h"
-
- os.system(copytext+" pair.cpp "+fnamec)
- os.system(copytext+" pair.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin_"+tc+".cpp"
- fnameh="mpin_"+tc+".h"
-
- os.system(copytext+" mpin.cpp "+fnamec)
- os.system(copytext+" mpin.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "192" :
- fnamec="fp8_"+tf+".cpp"
- fnameh="fp8_"+tf+".h"
-
- os.system(copytext+" fp8.cpp "+fnamec)
- os.system(copytext+" fp8.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp24_"+tf+".cpp"
- fnameh="fp24_"+tf+".h"
-
- os.system(copytext+" fp24.cpp "+fnamec)
- os.system(copytext+" fp24.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="ecp4_"+tc+".cpp"
- fnameh="ecp4_"+tc+".h"
-
- os.system(copytext+" ecp4.cpp "+fnamec)
- os.system(copytext+" ecp4.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="pair192_"+tc+".cpp"
- fnameh="pair192_"+tc+".h"
-
- os.system(copytext+" pair192.cpp "+fnamec)
- os.system(copytext+" pair192.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin192_"+tc+".cpp"
- fnameh="mpin192_"+tc+".h"
-
- os.system(copytext+" mpin192.cpp "+fnamec)
- os.system(copytext+" mpin192.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- if cs == "256" :
-
- fnamec="fp8_"+tf+".cpp"
- fnameh="fp8_"+tf+".h"
-
- os.system(copytext+" fp8.cpp "+fnamec)
- os.system(copytext+" fp8.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="ecp8_"+tc+".cpp"
- fnameh="ecp8_"+tc+".h"
-
- os.system(copytext+" ecp8.cpp "+fnamec)
- os.system(copytext+" ecp8.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp16_"+tf+".cpp"
- fnameh="fp16_"+tf+".h"
-
- os.system(copytext+" fp16.cpp "+fnamec)
- os.system(copytext+" fp16.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnamec,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="fp48_"+tf+".cpp"
- fnameh="fp48_"+tf+".h"
-
- os.system(copytext+" fp48.cpp "+fnamec)
- os.system(copytext+" fp48.h "+fnameh)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-
- fnamec="pair256_"+tc+".cpp"
- fnameh="pair256_"+tc+".h"
-
- os.system(copytext+" pair256.cpp "+fnamec)
- os.system(copytext+" pair256.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
- fnamec="mpin256_"+tc+".cpp"
- fnameh="mpin256_"+tc+".h"
-
- os.system(copytext+" mpin256.cpp "+fnamec)
- os.system(copytext+" mpin256.h "+fnameh)
- replace(fnamec,"ZZZ",tc)
- replace(fnamec,"YYY",tf)
- replace(fnamec,"XXX",bd)
- replace(fnameh,"ZZZ",tc)
- replace(fnameh,"YYY",tf)
- replace(fnameh,"XXX",bd)
- os.system("g++ -O3 -c "+fnamec)
-
-replace("arch.h","@WL@","64")
-print("Elliptic Curves")
-print("1. ED25519")
-print("2. C25519")
-print("3. NIST256")
-print("4. BRAINPOOL")
-print("5. ANSSI")
-print("6. HIFIVE")
-print("7. GOLDILOCKS")
-print("8. NIST384")
-print("9. C41417")
-print("10. NIST521\n")
-print("11. NUMS256W")
-print("12. NUMS256E")
-print("13. NUMS384W")
-print("14. NUMS384E")
-print("15. NUMS512W")
-print("16. NUMS512E")
-print("17. SECP256K1\n")
-
-print("Pairing-Friendly Elliptic Curves")
-print("18. BN254")
-print("19. BN254CX")
-print("20. BLS383")
-print("21. BLS381")
-print("22. FP256BN")
-print("23. FP512BN")
-print("24. BLS461\n")
-print("25. BLS24")
-print("26. BLS48\n")
-
-print("RSA")
-print("27. RSA2048")
-print("28. RSA3072")
-print("29. RSA4096")
-
-selection=[]
-ptr=0
-max=30
-
-curve_selected=False
-pfcurve_selected=False
-rsa_selected=False
-
-while ptr<max:
- x=int(input("Choose a Scheme to support - 0 to finish: "))
- if x == 0:
- break
-# print("Choice= ",x)
- already=False
- for i in range(0,ptr):
- if x==selection[i]:
- already=True
- break
- if already:
- continue
-
- selection.append(x)
- ptr=ptr+1
-
-# curveset(big,field,curve,big_length_bytes,bits_in_base,modulus_bits,modulus_mod_8,modulus_type,curve_type,pairing_friendly,sextic twist,sign of x,curve security)
-# for each curve give names for big, field and curve. In many cases the latter two will be the same.
-# Typically "big" is the size in bits, always a multiple of 8, "field" describes the modulus, and "curve" is the common name for the elliptic curve
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 64 bit architectures, as n where the base is 2^n (note that these must be fixed for the same "big" name, if is ever re-used for another curve)
-# modulus_bits is the bit length of the modulus, typically the same or slightly smaller than "big"
-# modulus_mod_8 is the remainder when the modulus is divided by 8
-# modulus_type is NOT_SPECIAL, or PSEUDO_MERSENNE, or MONTGOMERY_Friendly, or GENERALISED_MERSENNE (supported for GOLDILOCKS only)
-# curve_type is WEIERSTRASS, EDWARDS or MONTGOMERY
-# pairing_friendly is BN, BLS or NOT (if not pairing friendly)
-# if pairing friendly. M or D type twist, and sign of the family parameter x
-# curve security is AES equiavlent, rounded up.
-
-
- if x==1:
- curveset("256","F25519","ED25519","32","56","255","5","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
- if x==2:
- curveset("256","F25519","C25519","32","56","255","5","PSEUDO_MERSENNE","MONTGOMERY","NOT","","","128")
- curve_selected=True
- if x==3:
- curveset("256","NIST256","NIST256","32","56","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==4:
- curveset("256","BRAINPOOL","BRAINPOOL","32","56","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==5:
- curveset("256","ANSSI","ANSSI","32","56","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
-
- if x==6:
- curveset("336","HIFIVE","HIFIVE","42","60","336","5","PSEUDO_MERSENNE","EDWARDS","NOT","","","192")
- curve_selected=True
- if x==7:
- curveset("448","GOLDILOCKS","GOLDILOCKS","56","58","448","7","GENERALISED_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
- if x==8:
- curveset("384","NIST384","NIST384","48","56","384","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","192")
- curve_selected=True
- if x==9:
- curveset("416","C41417","C41417","52","60","414","7","PSEUDO_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
- if x==10:
- curveset("528","NIST521","NIST521","66","60","521","7","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","256")
- curve_selected=True
-
- if x==11:
- curveset("256","F256PMW","NUMS256W","32","56","256","3","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","128")
- curve_selected=True
- if x==12:
- curveset("256","F256PME","NUMS256E","32","56","256","3","PSEUDO_MERSENNE","EDWARDS","NOT","","","128")
- curve_selected=True
- if x==13:
- curveset("384","F384PM","NUMS384W","48","56","384","3","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","192")
- curve_selected=True
- if x==14:
- curveset("384","F384PM","NUMS384E","48","56","384","3","PSEUDO_MERSENNE","EDWARDS","NOT","","","192")
- curve_selected=True
- if x==15:
- curveset("512","F512PM","NUMS512W","64","56","512","7","PSEUDO_MERSENNE","WEIERSTRASS","NOT","","","256")
- curve_selected=True
- if x==16:
- curveset("512","F512PM","NUMS512E","64","56","512","7","PSEUDO_MERSENNE","EDWARDS","NOT","","","256")
- curve_selected=True
-
- if x==17:
- curveset("256","SECP256K1","SECP256K1","32","56","256","7","NOT_SPECIAL","WEIERSTRASS","NOT","","","128")
- curve_selected=True
-
- if x==18:
- curveset("256","BN254","BN254","32","56","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==19:
- curveset("256","BN254CX","BN254CX","32","56","254","3","NOT_SPECIAL","WEIERSTRASS","BN","D_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==20:
- curveset("384","BLS383","BLS383","48","58","383","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","128")
- pfcurve_selected=True
-
- if x==21:
- curveset("384","BLS381","BLS381","48","58","381","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
-
- if x==22:
- curveset("256","FP256BN","FP256BN","32","56","256","3","NOT_SPECIAL","WEIERSTRASS","BN","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
- if x==23:
- curveset("512","FP512BN","FP512BN","64","60","512","3","NOT_SPECIAL","WEIERSTRASS","BN","M_TYPE","POSITIVEX","128")
- pfcurve_selected=True
-# https://eprint.iacr.org/2017/334.pdf
- if x==24:
- curveset("464","BLS461","BLS461","58","60","461","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","NEGATIVEX","128")
- pfcurve_selected=True
-
- if x==25:
- curveset("480","BLS24","BLS24","60","56","479","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","192")
- pfcurve_selected=True
-
- if x==26:
- curveset("560","BLS48","BLS48","70","58","556","3","NOT_SPECIAL","WEIERSTRASS","BLS","M_TYPE","POSITIVEX","256")
- pfcurve_selected=True
-
-
-# rsaset(big,ring,big_length_bytes,bits_in_base,multiplier)
-# for each choice give distinct names for "big" and "ring".
-# Typically "big" is the length in bits of the underlying big number type
-# "ring" is the RSA modulus size = "big" times 2^m
-# big_length_bytes is "big" divided by 8
-# Next give the number base used for 64 bit architectures, as n where the base is 2^n
-# multiplier is 2^m (see above)
-
-# There are choices here, different ways of getting the same result, but some faster than others
- if x==27:
- #256 is slower but may allow reuse of 256-bit BIGs used for elliptic curve
- #512 is faster.. but best is 1024
- rsaset("1024","RSA2048","128","58","2")
- #rsaset("512","RSA2048","64","60","4")
- #rsaset("256","RSA2048","32","56","8")
- rsa_selected=True
- if x==28:
- rsaset("384","RSA3072","48","56","8")
- rsa_selected=True
- if x==29:
- #rsaset("256","RSA4096","32","56","16")
- rsaset("512","RSA4096","64","60","8")
- rsa_selected=True
-
-
-os.system(deltext+" big.*")
-os.system(deltext+" fp.*")
-os.system(deltext+" ecp.*")
-os.system(deltext+" ecdh.*")
-os.system(deltext+" ff.*")
-os.system(deltext+" rsa.*")
-os.system(deltext+" config_big.h")
-os.system(deltext+" config_field.h")
-os.system(deltext+" config_curve.h")
-os.system(deltext+" config_ff.h")
-os.system(deltext+" fp2.*")
-os.system(deltext+" fp4.*")
-os.system(deltext+" fp8.*")
-os.system(deltext+" fp16.*")
-
-os.system(deltext+" fp12.*")
-os.system(deltext+" fp24.*")
-os.system(deltext+" fp48.*")
-
-os.system(deltext+" ecp2.*")
-os.system(deltext+" ecp4.*")
-os.system(deltext+" ecp8.*")
-
-os.system(deltext+" pair.*")
-os.system(deltext+" mpin.*")
-
-os.system(deltext+" pair192.*")
-os.system(deltext+" mpin192.*")
-
-os.system(deltext+" pair256.*")
-os.system(deltext+" mpin256.*")
-
-
-# create library
-os.system("g++ -O3 -c randapi.cpp")
-if curve_selected :
- os.system("g++ -O3 -c ecdh_support.cpp")
-if rsa_selected :
- os.system("g++ -O3 -c rsa_support.cpp")
-if pfcurve_selected :
- os.system("g++ -O3 -c pbc_support.cpp")
-
-os.system("g++ -O3 -c hash.cpp")
-os.system("g++ -O3 -c rand.cpp")
-os.system("g++ -O3 -c oct.cpp")
-os.system("g++ -O3 -c aes.cpp")
-os.system("g++ -O3 -c gcm.cpp")
-os.system("g++ -O3 -c newhope.cpp")
-
-if sys.platform.startswith("win") :
- os.system("for %i in (*.o) do @echo %~nxi >> f.list")
- os.system("ar rc amcl.a @f.list")
- os.system(deltext+" f.list")
-
-else :
- os.system("ar rc amcl.a *.o")
-
-os.system(deltext+" *.o")
-
-
-#print("Your section was ")
-#for i in range(0,ptr):
-# print (selection[i])
-
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config_big.h
----------------------------------------------------------------------
diff --git a/version3/cpp/config_big.h b/version3/cpp/config_big.h
deleted file mode 100644
index 6d12010..0000000
--- a/version3/cpp/config_big.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef CONFIG_BIG_XXX_H
-#define CONFIG_BIG_XXX_H
-
-#include"amcl.h"
-
-// BIG stuff
-
-#define MODBYTES_XXX @NB@
-#define BASEBITS_XXX @BASE@
-
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config_curve.h
----------------------------------------------------------------------
diff --git a/version3/cpp/config_curve.h b/version3/cpp/config_curve.h
deleted file mode 100644
index 4f905d5..0000000
--- a/version3/cpp/config_curve.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef CONFIG_CURVE_ZZZ_H
-#define CONFIG_CURVE_ZZZ_H
-
-#include"amcl.h"
-#include"config_field_YYY.h"
-
-// ECP stuff
-
-#define CURVETYPE_ZZZ @CT@
-#define PAIRING_FRIENDLY_ZZZ @PF@
-#define CURVE_SECURITY_ZZZ @CS@
-
-#if PAIRING_FRIENDLY_ZZZ != NOT
-#define USE_GLV_ZZZ /**< Note this method is patented (GLV), so maybe you want to comment this out */
-#define USE_GS_G2_ZZZ /**< Well we didn't patent it :) But may be covered by GLV patent :( */
-#define USE_GS_GT_ZZZ /**< Not patented, so probably safe to always use this */
-
-#define POSITIVEX 0
-#define NEGATIVEX 1
-
-#define SEXTIC_TWIST_ZZZ @ST@
-#define SIGN_OF_X_ZZZ @SX@
-
-#endif
-
-
-#if CURVE_SECURITY_ZZZ == 128
-#define AESKEY_ZZZ 16 /**< Symmetric Key size - 128 bits */
-#define HASH_TYPE_ZZZ SHA256 /**< Hash type */
-#endif
-
-#if CURVE_SECURITY_ZZZ == 192
-#define AESKEY_ZZZ 24 /**< Symmetric Key size - 192 bits */
-#define HASH_TYPE_ZZZ SHA384 /**< Hash type */
-#endif
-
-#if CURVE_SECURITY_ZZZ == 256
-#define AESKEY_ZZZ 32 /**< Symmetric Key size - 256 bits */
-#define HASH_TYPE_ZZZ SHA512 /**< Hash type */
-#endif
-
-
-
-namespace ZZZ_BIG=XXX;
-namespace ZZZ_FP=YYY;
-
-#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config_ff.h
----------------------------------------------------------------------
diff --git a/version3/cpp/config_ff.h b/version3/cpp/config_ff.h
deleted file mode 100644
index 33cb95a..0000000
--- a/version3/cpp/config_ff.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef CONFIG_RSA_WWW_H
-#define CONFIG_RSA_WWW_H
-
-#include "amcl.h"
-#include "config_big_XXX.h"
-
-// FF stuff
-
-#define FFLEN_WWW @ML@ /**< 2^n multiplier of BIGBITS to specify supported Finite Field size, e.g 2048=256*2^3 where BIGBITS=256 */
-
-namespace WWW_BIG=XXX;
-
-#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/config_field.h
----------------------------------------------------------------------
diff --git a/version3/cpp/config_field.h b/version3/cpp/config_field.h
deleted file mode 100644
index ab86941..0000000
--- a/version3/cpp/config_field.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef CONFIG_FIELD_YYY_H
-#define CONFIG_FIELD_YYY_H
-
-#include"amcl.h"
-#include "config_big_XXX.h"
-
-// FP stuff
-
-#define MBITS_YYY @NBT@
-#define MOD8_YYY @M8@
-#define MODTYPE_YYY @MT@
-#define MAXXES_YYY @SH@
-
-
-#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/ecdh.cpp
----------------------------------------------------------------------
diff --git a/version3/cpp/ecdh.cpp b/version3/cpp/ecdh.cpp
deleted file mode 100644
index d088b4d..0000000
--- a/version3/cpp/ecdh.cpp
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-/* ECDH/ECIES/ECDSA Functions - see main program below */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include "ecdh_ZZZ.h"
-
-using namespace XXX;
-using namespace YYY;
-
-/* Calculate a public/private EC GF(p) key pair. W=S.G mod EC(p),
- * where S is the secret key and W is the public key
- * and G is fixed generator.
- * If RNG is NULL then the private key is provided externally in S
- * otherwise it is generated randomly internally */
-int ZZZ::ECP_KEY_PAIR_GENERATE(csprng *RNG,octet* S,octet *W)
-{
- BIG r,gx,gy,s;
- ECP G;
- int res=0;
-
- ECP_generator(&G);
-
- BIG_rcopy(r,CURVE_Order);
- if (RNG!=NULL)
- {
- BIG_randomnum(s,r,RNG);
- }
- else
- {
- BIG_fromBytes(s,S->val);
- BIG_mod(s,r);
- }
-
-#ifdef AES_S
- BIG_mod2m(s,2*AES_S);
-// BIG_toBytes(S->val,s);
-#endif
-
- S->len=EGS_ZZZ;
- BIG_toBytes(S->val,s);
-
-
- ECP_mul(&G,s);
-
- ECP_toOctet(W,&G,false); // To use point compression on public keys, change to true
-
-/*
-
-#if CURVETYPE_ZZZ!=MONTGOMERY
- ECP_get(gx,gy,&G);
-#else
- ECP_get(gx,&G);
-
-#endif
-
-
-
-#if CURVETYPE_ZZZ!=MONTGOMERY
- W->len=2*EFS_ZZZ+1;
- W->val[0]=4;
- BIG_toBytes(&(W->val[1]),gx);
- BIG_toBytes(&(W->val[EFS_ZZZ+1]),gy);
-#else
- W->len=EFS_ZZZ+1;
- W->val[0]=2;
- BIG_toBytes(&(W->val[1]),gx);
-#endif
-*/
-
- return res;
-}
-
-/* Validate public key */
-int ZZZ::ECP_PUBLIC_KEY_VALIDATE(octet *W)
-{
- BIG q,r,wx,k;
- ECP WP;
- int valid,nb;
- int res=0;
-
- BIG_rcopy(q,Modulus);
- BIG_rcopy(r,CURVE_Order);
-
- valid=ECP_fromOctet(&WP,W);
- if (!valid) res=ECDH_INVALID_PUBLIC_KEY;
-
-/*
- BIG_fromBytes(wx,&(W->val[1]));
- if (BIG_comp(wx,q)>=0) res=ECDH_INVALID_PUBLIC_KEY;
-#if CURVETYPE_ZZZ!=MONTGOMERY
- BIG wy;
- BIG_fromBytes(wy,&(W->val[EFS_ZZZ+1]));
- if (BIG_comp(wy,q)>=0) res=ECDH_INVALID_PUBLIC_KEY;
-#endif
-*/
- if (res==0)
- {
-
-//#if CURVETYPE_ZZZ!=MONTGOMERY
-// valid=ECP_set(&WP,wx,wy);
-//#else
-// valid=ECP_set(&WP,wx);
-//#endif
-// if (!valid || ECP_isinf(&WP)) res=ECDH_INVALID_PUBLIC_KEY;
-// if (res==0 )
-// {/* Check point is not in wrong group */
- nb=BIG_nbits(q);
- BIG_one(k);
- BIG_shl(k,(nb+4)/2);
- BIG_add(k,q,k);
- BIG_sdiv(k,r); /* get co-factor */
-
- while (BIG_parity(k)==0)
- {
- ECP_dbl(&WP);
- BIG_fshr(k,1);
- }
-
- if (!BIG_isunity(k)) ECP_mul(&WP,k);
- if (ECP_isinf(&WP)) res=ECDH_INVALID_PUBLIC_KEY;
-// }
- }
-
- return res;
-}
-
-/* IEEE-1363 Diffie-Hellman online calculation Z=S.WD */
-int ZZZ::ECP_SVDP_DH(octet *S,octet *WD,octet *Z)
-{
- BIG r,s,wx;
- int valid;
- ECP W;
- int res=0;
-
- BIG_fromBytes(s,S->val);
-
- valid=ECP_fromOctet(&W,WD);
-/*
- BIG_fromBytes(wx,&(WD->val[1]));
-#if CURVETYPE_ZZZ!=MONTGOMERY
- BIG wy;
- BIG_fromBytes(wy,&(WD->val[EFS_ZZZ+1]));
- valid=ECP_set(&W,wx,wy);
-#else
- valid=ECP_set(&W,wx);
-#endif
-*/
- if (!valid) res=ECDH_ERROR;
- if (res==0)
- {
- BIG_rcopy(r,CURVE_Order);
- BIG_mod(s,r);
-
- ECP_mul(&W,s);
- if (ECP_isinf(&W)) res=ECDH_ERROR;
- else
- {
-#if CURVETYPE_ZZZ!=MONTGOMERY
- ECP_get(wx,wx,&W);
-#else
- ECP_get(wx,&W);
-#endif
- Z->len=MODBYTES_XXX;
- BIG_toBytes(Z->val,wx);
- }
- }
- return res;
-}
-
-#if CURVETYPE_ZZZ!=MONTGOMERY
-
-/* IEEE ECDSA Signature, C and D are signature on F using private key S */
-int ZZZ::ECP_SP_DSA(int sha,csprng *RNG,octet *K,octet *S,octet *F,octet *C,octet *D)
-{
- char h[128];
- octet H= {0,sizeof(h),h};
-
- BIG r,s,f,c,d,u,vx,w;
- ECP G,V;
-
- ehashit(sha,F,-1,NULL,&H,sha);
-
- ECP_generator(&G);
-
- BIG_rcopy(r,CURVE_Order);
-
- BIG_fromBytes(s,S->val);
-
- int hlen=H.len;
- if (H.len>MODBYTES_XXX) hlen=MODBYTES_XXX;
- BIG_fromBytesLen(f,H.val,hlen);
-
-
- if (RNG!=NULL)
- {
-
- do
- {
-
- BIG_randomnum(u,r,RNG);
- BIG_randomnum(w,r,RNG); /* side channel masking */
-
-#ifdef AES_S
- BIG_mod2m(u,2*AES_S);
-#endif
- ECP_copy(&V,&G);
- ECP_mul(&V,u);
-
- ECP_get(vx,vx,&V);
-
- BIG_copy(c,vx);
- BIG_mod(c,r);
- if (BIG_iszilch(c)) continue;
-
- BIG_modmul(u,u,w,r);
-
-
- BIG_invmodp(u,u,r);
- BIG_modmul(d,s,c,r);
-
- BIG_add(d,f,d);
-
- BIG_modmul(d,d,w,r);
-
- BIG_modmul(d,u,d,r);
-
- }
- while (BIG_iszilch(d));
- }
- else
- {
- BIG_fromBytes(u,K->val);
- BIG_mod(u,r);
-
-#ifdef AES_S
- BIG_mod2m(u,2*AES_S);
-#endif
- ECP_copy(&V,&G);
- ECP_mul(&V,u);
-
- ECP_get(vx,vx,&V);
-
- BIG_copy(c,vx);
- BIG_mod(c,r);
- if (BIG_iszilch(c)) return ECDH_ERROR;
-
- BIG_invmodp(u,u,r);
- BIG_modmul(d,s,c,r);
-
- BIG_add(d,f,d);
-
- BIG_modmul(d,u,d,r);
- if (BIG_iszilch(d)) return ECDH_ERROR;
-
- }
-
- C->len=D->len=EGS_ZZZ;
-
- BIG_toBytes(C->val,c);
- BIG_toBytes(D->val,d);
-
- return 0;
-}
-
-/* IEEE1363 ECDSA Signature Verification. Signature C and D on F is verified using public key W */
-int ZZZ::ECP_VP_DSA(int sha,octet *W,octet *F, octet *C,octet *D)
-{
- char h[128];
- octet H= {0,sizeof(h),h};
-
- BIG r,wx,wy,f,c,d,h2;
- int res=0;
- ECP G,WP;
- int valid;
-
- ehashit(sha,F,-1,NULL,&H,sha);
-
- ECP_generator(&G);
-
- BIG_rcopy(r,CURVE_Order);
-
- OCT_shl(C,C->len-MODBYTES_XXX);
- OCT_shl(D,D->len-MODBYTES_XXX);
-
- BIG_fromBytes(c,C->val);
- BIG_fromBytes(d,D->val);
-
- int hlen=H.len;
- if (hlen>MODBYTES_XXX) hlen=MODBYTES_XXX;
-
- BIG_fromBytesLen(f,H.val,hlen);
-
- //BIG_fromBytes(f,H.val);
-
- if (BIG_iszilch(c) || BIG_comp(c,r)>=0 || BIG_iszilch(d) || BIG_comp(d,r)>=0)
- res=ECDH_INVALID;
-
- if (res==0)
- {
- BIG_invmodp(d,d,r);
- BIG_modmul(f,f,d,r);
- BIG_modmul(h2,c,d,r);
-
- valid=ECP_fromOctet(&WP,W);
-/*
- BIG_fromBytes(wx,&(W->val[1]));
- BIG_fromBytes(wy,&(W->val[EFS_ZZZ+1]));
-
- valid=ECP_set(&WP,wx,wy);
-*/
- if (!valid) res=ECDH_ERROR;
- else
- {
- ECP_mul2(&WP,&G,h2,f);
-
- if (ECP_isinf(&WP)) res=ECDH_INVALID;
- else
- {
- ECP_get(d,d,&WP);
- BIG_mod(d,r);
- if (BIG_comp(d,c)!=0) res=ECDH_INVALID;
- }
- }
- }
-
- return res;
-}
-
-/* IEEE1363 ECIES encryption. Encryption of plaintext M uses public key W and produces ciphertext V,C,T */
-void ZZZ::ECP_ECIES_ENCRYPT(int sha,octet *P1,octet *P2,csprng *RNG,octet *W,octet *M,int tlen,octet *V,octet *C,octet *T)
-{
-
- int i,len;
- char z[EFS_ZZZ],vz[3*EFS_ZZZ+1],k[2*AESKEY_ZZZ],k1[AESKEY_ZZZ],k2[AESKEY_ZZZ],l2[8],u[EFS_ZZZ];
- octet Z= {0,sizeof(z),z};
- octet VZ= {0,sizeof(vz),vz};
- octet K= {0,sizeof(k),k};
- octet K1= {0,sizeof(k1),k1};
- octet K2= {0,sizeof(k2),k2};
- octet L2= {0,sizeof(l2),l2};
- octet U= {0,sizeof(u),u};
-
- if (ECP_KEY_PAIR_GENERATE(RNG,&U,V)!=0) return;
- if (ECP_SVDP_DH(&U,W,&Z)!=0) return;
-
- OCT_copy(&VZ,V);
- OCT_joctet(&VZ,&Z);
-
- KDF2(sha,&VZ,P1,2*AESKEY_ZZZ,&K);
-
- K1.len=K2.len=AESKEY_ZZZ;
- for (i=0; i<AESKEY_ZZZ; i++)
- {
- K1.val[i]=K.val[i];
- K2.val[i]=K.val[AESKEY_ZZZ+i];
- }
-
- AES_CBC_IV0_ENCRYPT(&K1,M,C);
-
- OCT_jint(&L2,P2->len,8);
-
- len=C->len;
- OCT_joctet(C,P2);
- OCT_joctet(C,&L2);
- HMAC(sha,C,&K2,tlen,T);
- C->len=len;
-}
-
-/* IEEE1363 ECIES decryption. Decryption of ciphertext V,C,T using private key U outputs plaintext M */
-int ZZZ::ECP_ECIES_DECRYPT(int sha,octet *P1,octet *P2,octet *V,octet *C,octet *T,octet *U,octet *M)
-{
-
- int i,len;
- char z[EFS_ZZZ],vz[3*EFS_ZZZ+1],k[2*AESKEY_ZZZ],k1[AESKEY_ZZZ],k2[AESKEY_ZZZ],l2[8],tag[32];
- octet Z= {0,sizeof(z),z};
- octet VZ= {0,sizeof(vz),vz};
- octet K= {0,sizeof(k),k};
- octet K1= {0,sizeof(k1),k1};
- octet K2= {0,sizeof(k2),k2};
- octet L2= {0,sizeof(l2),l2};
- octet TAG= {0,sizeof(tag),tag};
-
- if (ECP_SVDP_DH(U,V,&Z)!=0) return 0;
-
- OCT_copy(&VZ,V);
- OCT_joctet(&VZ,&Z);
-
- KDF2(sha,&VZ,P1,2*AESKEY_ZZZ,&K);
-
- K1.len=K2.len=AESKEY_ZZZ;
- for (i=0; i<AESKEY_ZZZ; i++)
- {
- K1.val[i]=K.val[i];
- K2.val[i]=K.val[AESKEY_ZZZ+i];
- }
-
- if (!AES_CBC_IV0_DECRYPT(&K1,C,M)) return 0;
-
- OCT_jint(&L2,P2->len,8);
-
- len=C->len;
- OCT_joctet(C,P2);
- OCT_joctet(C,&L2);
- HMAC(sha,C,&K2,T->len,&TAG);
- C->len=len;
-
- if (!OCT_ncomp(T,&TAG,T->len)) return 0;
-
- return 1;
-
-}
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/1add7560/version3/cpp/ecdh.h
----------------------------------------------------------------------
diff --git a/version3/cpp/ecdh.h b/version3/cpp/ecdh.h
deleted file mode 100644
index f1f1873..0000000
--- a/version3/cpp/ecdh.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-/**
- * @file ecdh.h
- * @author Mike Scott and Kealan McCusker
- * @date 2nd June 2015
- * @brief ECDH Header file for implementation of standard EC protocols
- *
- * declares functions
- *
- */
-
-#ifndef ECDH_ZZZ_H
-#define ECDH_ZZZ_H
-
-#include "ecp_ZZZ.h"
-#include "ecdh_support.h"
-
-using namespace amcl;
-
-
-/*** START OF USER CONFIGURABLE SECTION - ***/
-
-/*** START OF USER CONFIGURABLE SECTION - ***/
-
-
-/*** END OF USER CONFIGURABLE SECTION ***/
-
-#define EGS_ZZZ MODBYTES_XXX /**< ECC Group Size in bytes */
-#define EFS_ZZZ MODBYTES_XXX /**< ECC Field Size in bytes */
-
-#define ECDH_OK 0 /**< Function completed without error */
-/*#define ECDH_DOMAIN_ERROR -1*/
-#define ECDH_INVALID_PUBLIC_KEY -2 /**< Public Key is Invalid */
-#define ECDH_ERROR -3 /**< ECDH Internal Error */
-#define ECDH_INVALID -4 /**< ECDH Internal Error */
-/*#define ECDH_DOMAIN_NOT_FOUND -5
-#define ECDH_OUT_OF_MEMORY -6
-#define ECDH_DIV_BY_ZERO -7
-#define ECDH_BAD_ASSUMPTION -8*/
-
-
-namespace ZZZ {
-
-/* ECDH primitives */
-/** @brief Generate an ECC public/private key pair
- *
- @param R is a pointer to a cryptographically secure random number generator
- @param s the private key, an output internally randomly generated if R!=NULL, otherwise must be provided as an input
- @param W the output public key, which is s.G, where G is a fixed generator
- @return 0 or an error code
- */
-extern int ECP_KEY_PAIR_GENERATE(csprng *R,octet *s,octet *W);
-/** @brief Validate an ECC public key
- *
- @param W the input public key to be validated
- @return 0 if public key is OK, or an error code
- */
-extern int ECP_PUBLIC_KEY_VALIDATE(octet *W);
-
-/* ECDH primitives */
-
-/** @brief Generate Diffie-Hellman shared key
- *
- IEEE-1363 Diffie-Hellman shared secret calculation
- @param s is the input private key,
- @param W the input public key of the other party
- @param K the output shared key, in fact the x-coordinate of s.W
- @return 0 or an error code
- */
-extern int ECP_SVDP_DH(octet *s,octet *W,octet *K);
-/*extern int ECPSVDP_DHC(octet *,octet *,int,octet *);*/
-
-/*#if CURVETYPE!=MONTGOMERY */
-/* ECIES functions */
-/*#if CURVETYPE!=MONTGOMERY */
-/* ECIES functions */
-/** @brief ECIES Encryption
- *
- IEEE-1363 ECIES Encryption
- @param h is the hash type
- @param P1 input Key Derivation parameters
- @param P2 input Encoding parameters
- @param R is a pointer to a cryptographically secure random number generator
- @param W the input public key of the recieving party
- @param M is the plaintext message to be encrypted
- @param len the length of the HMAC tag
- @param V component of the output ciphertext
- @param C the output ciphertext
- @param T the output HMAC tag, part of the ciphertext
- */
-extern void ECP_ECIES_ENCRYPT(int h,octet *P1,octet *P2,csprng *R,octet *W,octet *M,int len,octet *V,octet *C,octet *T);
-/** @brief ECIES Decryption
- *
- IEEE-1363 ECIES Decryption
- @param h is the hash type
- @param P1 input Key Derivation parameters
- @param P2 input Encoding parameters
- @param V component of the input ciphertext
- @param C the input ciphertext
- @param T the input HMAC tag, part of the ciphertext
- @param U the input private key for decryption
- @param M the output plaintext message
- @return 1 if successful, else 0
- */
-extern int ECP_ECIES_DECRYPT(int h,octet *P1,octet *P2,octet *V,octet *C,octet *T,octet *U,octet *M);
-
-/* ECDSA functions */
-/** @brief ECDSA Signature
- *
- IEEE-1363 ECDSA Signature
- @param h is the hash type
- @param R is a pointer to a cryptographically secure random number generator
- @param k Ephemeral key. This value is used when R=NULL
- @param s the input private signing key
- @param M the input message to be signed
- @param c component of the output signature
- @param d component of the output signature
-
- */
-extern int ECP_SP_DSA(int h,csprng *R,octet *k,octet *s,octet *M,octet *c,octet *d);
-/** @brief ECDSA Signature Verification
- *
- IEEE-1363 ECDSA Signature Verification
- @param h is the hash type
- @param W the input public key
- @param M the input message
- @param c component of the input signature
- @param d component of the input signature
- @return 0 or an error code
- */
-extern int ECP_VP_DSA(int h,octet *W,octet *M,octet *c,octet *d);
-/*#endif*/
-}
-
-#endif
-