Skip to content

Instantly share code, notes, and snippets.

@cygnusv
Created February 3, 2017 09:41
Show Gist options
  • Save cygnusv/a1710ed5c1e74ac77ea0643266f0a15f to your computer and use it in GitHub Desktop.
Save cygnusv/a1710ed5c1e74ac77ea0643266f0a15f to your computer and use it in GitHub Desktop.
diff -u old/big.cpp new/big.cpp
--- old/big.cpp 2016-10-28 03:19:34.000000000 +0200
+++ new/big.cpp 2017-02-03 09:50:04.000000000 +0100
@@ -104,6 +104,19 @@
Big operator>>(const Big& b, int i)
{Big ms; sftbit(b.fn,-i,ms.fn); return ms;}
+BOOL operator<=(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)<=0) return TRUE; else return FALSE;}
+BOOL operator>=(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)>=0) return TRUE; else return FALSE;}
+BOOL operator==(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
+BOOL operator!=(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
+BOOL operator<(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)<0) return TRUE; else return FALSE;}
+BOOL operator>(const Big& b1,const Big& b2)
+ {if (mr_compare(b1.fn,b2.fn)>0) return TRUE; else return FALSE;}
+
#ifndef MR_FP
Big land(const Big& x,const Big& y)
{Big z; mr_and(x.fn,y.fn,z.fn); return z;}
@@ -174,7 +187,7 @@
#endif
-Big luc(const Big& b1,const Big& b2,const Big& b3,Big *b4)
+Big luc(const Big& b1,const Big& b2,const Big& b3,Big *b4=NULL)
{Big z; if (b4!=NULL) lucas(b1.fn,b2.fn,b3.fn,b4->fn,z.fn);
else lucas(b1.fn,b2.fn,b3.fn,z.fn,z.fn);
return z;}
@@ -328,7 +341,7 @@
// Note new parameter of window_size. Default to 5, but reduce to 4 (or even 3) to save RAM
-int window(const Big& x,int i,int *nbs,int *nzs,int window_size)
+int window(const Big& x,int i,int *nbs,int *nzs,int window_size=5)
{ /* returns sliding window value, max. of 5 bits, *
* starting at i-th bit of big x. nbs is number of bits *
* processed, nzs is the number of additional trailing *
@@ -340,7 +353,7 @@
return mr_window(x.fn,i,nbs,nzs,window_size);
}
-int naf_window(const Big& x,const Big& x3,int i,int *nbs,int *nzs,int store)
+int naf_window(const Big& x,const Big& x3,int i,int *nbs,int *nzs,int store=11)
{ /* returns sliding window value, max of 5 bits *
* starting at i-th bit of x. nbs is number of bits *
* processed. nzs is number of additional trailing *
diff -u old/big.h new/big.h
--- old/big.h 2016-10-28 03:19:34.000000000 +0200
+++ new/big.h 2017-02-03 09:49:58.000000000 +0100
@@ -285,21 +285,21 @@
friend Big operator<<(const Big&, int);
friend Big operator>>(const Big&, int);
- friend BOOL operator<=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)<=0) return TRUE; else return FALSE;}
- friend BOOL operator>=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)>=0) return TRUE; else return FALSE;}
- friend BOOL operator==(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
- friend BOOL operator<(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)<0) return TRUE; else return FALSE;}
- friend BOOL operator>(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)>0) return TRUE; else return FALSE;}
+ friend BOOL operator<=(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)<=0) return TRUE; else return FALSE;}
+ friend BOOL operator>=(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)>=0) return TRUE; else return FALSE;}
+ friend BOOL operator==(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
+ friend BOOL operator!=(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
+ friend BOOL operator<(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)<0) return TRUE; else return FALSE;}
+ friend BOOL operator>(const Big& b1,const Big& b2);
+ // {if (mr_compare(b1.fn,b2.fn)>0) return TRUE; else return FALSE;}
friend Big from_binary(int,char *);
- friend int to_binary(const Big&,int,char *,BOOL justify=FALSE);
+ friend int to_binary(const Big&,int,char *,BOOL justify);
friend Big modmult(const Big&,const Big&,const Big&);
friend Big mad(const Big&,const Big&,const Big&,const Big&,Big&);
friend Big norm(const Big&);
@@ -321,7 +321,7 @@
// x^m.y^k mod n
friend Big pow(int,Big *,Big *,Big); // x[0]^m[0].x[1].m[1]... mod n
- friend Big luc(const Big& ,const Big&, const Big&, Big *b4=NULL);
+ friend Big luc(const Big& ,const Big&, const Big&, Big *b4);
friend Big moddiv(const Big&,const Big&,const Big&);
friend Big inverse(const Big&, const Big&);
friend void multi_inverse(int,Big*,const Big&,Big *);
@@ -353,8 +353,8 @@
friend void modulo(const Big&);
friend BOOL modulo(int,int,int,int,BOOL);
friend Big get_modulus(void);
- friend int window(const Big&,int,int*,int*,int window_size=5);
- friend int naf_window(const Big&,const Big&,int,int*,int*,int store=11);
+ friend int window(const Big&,int,int*,int*,int window_size);
+ friend int naf_window(const Big&,const Big&,int,int*,int*,int store);
friend void jsf(const Big&,const Big&,Big&,Big&,Big&,Big&);
/* Montgomery stuff */
@@ -420,7 +420,7 @@
extern Big rand(int,int);
extern Big strong_rand(csprng *,int,int);
extern Big from_binary(int,char *);
-extern int to_binary(const Big&,int,char *,BOOL);
+extern int to_binary(const Big&,int,char *,BOOL justify=FALSE);
using namespace std;
diff -u old/zzn.cpp new/zzn.cpp
--- old/zzn.cpp 2016-10-28 03:19:34.000000000 +0200
+++ new/zzn.cpp 2017-02-03 09:58:27.000000000 +0100
@@ -167,10 +167,10 @@
ZZn powl(const ZZn& x,const Big& k)
{
- return luc(2*x,k)/2;
+ return luc(2*x,k,NULL)/2;
}
-ZZn luc( const ZZn& b1, const Big& b2, ZZn *b3)
+ZZn luc( const ZZn& b1, const Big& b2, ZZn *b3=NULL)
{ZZn z; if (b3!=NULL) nres_lucas(b1.fn,b2.getbig(),b3->fn,z.fn);
else nres_lucas(b1.fn,b2.getbig(),z.fn,z.fn);
return z;}
diff -u old/zzn.h new/zzn.h
--- old/zzn.h 2016-10-28 03:19:34.000000000 +0200
+++ new/zzn.h 2017-02-03 09:52:37.000000000 +0100
@@ -183,7 +183,7 @@
friend ZZn getB(void); // get B parameter of elliptic curve
friend ZZn sqrt(const ZZn&); // only works if modulus is prime
- friend ZZn luc( const ZZn&, const Big&, ZZn* b3=NULL);
+ friend ZZn luc( const ZZn&, const Big&, ZZn* b3);
big getzzn(void) const;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment