summaryrefslogtreecommitdiff
path: root/sys/include/mp.h
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-12-16 21:18:20 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2015-12-16 21:18:20 +0100
commitefd3ac8a2328d1baf55c296a00807052473d549e (patch)
tree3e0851312267fee156a3cfb67aea5b4faebbfb76 /sys/include/mp.h
parentb6f04b77e3d11699d664d0ca7d0ba991f9599acc (diff)
libmp: add mpfield() function for fast field arithmetic
instead of testing for special field primes each time in mpmod(), make it explicit with a mpfiled() function that tests a modulus N to be of some special form that can be reduced more efficiently with some precalculation, and replaces N with a Mfield* when it can. the Mfield*'s are recognized by mpmod() as they have the MPfield flag set and provide a function pointer that executes the fast reduction.
Diffstat (limited to 'sys/include/mp.h')
-rw-r--r--sys/include/mp.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/include/mp.h b/sys/include/mp.h
index 31e4ef3d8..f883712de 100644
--- a/sys/include/mp.h
+++ b/sys/include/mp.h
@@ -8,7 +8,6 @@
* mpdigit must be an atomic type. mpdigit is defined
* in the architecture specific u.h
*/
-
typedef struct mpint mpint;
struct mpint
@@ -25,6 +24,7 @@ enum
MPstatic= 0x01, /* static constant */
MPnorm= 0x02, /* normalization status */
MPtimesafe= 0x04, /* request time invariant computation */
+ MPfield= 0x08, /* this mpint is a field modulus */
Dbytes= sizeof(mpdigit), /* bytes per digit */
Dbits= Dbytes*8 /* bits per digit */
@@ -165,5 +165,18 @@ void crtout(CRTpre*, CRTres*, mpint*); /* convert residues to mpint */
void crtprefree(CRTpre*);
void crtresfree(CRTres*);
+/* fast field arithmetic */
+typedef struct Mfield Mfield;
+
+struct Mfield
+{
+ mpint;
+ int (*reduce)(Mfield*, mpint*, mpint*);
+};
+
+mpint *mpfield(mpint*);
+
+Mfield *gmfield(mpint*);
+Mfield *cnfield(mpint*);
#pragma varargck type "B" mpint*