You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sa...@apache.org on 2020/02/04 10:42:22 UTC
[incubator-milagro-crypto-c] branch add-multiple-exponent-api
updated (6b8acfa -> 86c33c6)
This is an automated email from the ASF dual-hosted git repository.
sandreoli pushed a change to branch add-multiple-exponent-api
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git.
from 6b8acfa Add support for non constant time multiple exponentiation
new 32ac3e7 add constant time triple exponent
new d87a7b8 Format code
new 86c33c6 Use tailored primes in ff test
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/ff.h.in | 16 ++++++++++-
include/paillier.h | 2 +-
python/bls_ZZZ.py.in | 7 ++---
python/mpin_ZZZ.py.in | 2 +-
python/wcc_ZZZ.py.in | 2 +-
src/ff.c.in | 58 +++++++++++++++++++++++++++++++++++++++
test/test_ff_consistency_WWW.c.in | 23 ++++++++++++----
7 files changed, 97 insertions(+), 13 deletions(-)
[incubator-milagro-crypto-c] 01/03: add constant time triple
exponent
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sandreoli pushed a commit to branch add-multiple-exponent-api
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git
commit 32ac3e7fbf23be73b7965c47e043250477d09cf0
Author: Samuele Andreoli <sa...@yahoo.it>
AuthorDate: Tue Feb 4 10:18:34 2020 +0000
add constant time triple exponent
---
include/ff.h.in | 16 ++++++++++-
src/ff.c.in | 58 +++++++++++++++++++++++++++++++++++++++
test/test_ff_consistency_WWW.c.in | 10 +++++++
3 files changed, 83 insertions(+), 1 deletion(-)
diff --git a/include/ff.h.in b/include/ff.h.in
index 7096162..0bcf458 100644
--- a/include/ff.h.in
+++ b/include/ff.h.in
@@ -253,7 +253,7 @@ extern void FF_WWW_skpow(BIG_XXX *r,BIG_XXX *x,BIG_XXX * e,BIG_XXX *p,int n, int
@param n size of FF in BIGs
*/
extern void FF_WWW_skspow(BIG_XXX *r,BIG_XXX *x,BIG_XXX e,BIG_XXX *p,int n);
-/** @brief Calculate r=x^e.y^f mod p for big e and f, side channel resistant
+/** @brief Calculate r=x^e.y^f mod p for FF e and f, side channel resistant
*
@param r FF instance, on exit = x^e.y^f mod p
@param x FF instance
@@ -265,6 +265,20 @@ extern void FF_WWW_skspow(BIG_XXX *r,BIG_XXX *x,BIG_XXX e,BIG_XXX *p,int n);
@param en size of the exponent in BIGs
*/
extern void FF_WWW_skpow2(BIG_XXX *r,BIG_XXX *x, BIG_XXX *e, BIG_XXX *y, BIG_XXX *f, BIG_XXX *p, int n, int en);
+/** @brief Calculate r=x^e.y^f.z^g mod p for FF e, f and g, side channel resistant
+ *
+ @param r FF instance, on exit = x^e.y^f.z^g mod p
+ @param x FF instance
+ @param e FF exponent
+ @param y FF instance
+ @param f FF exponent
+ @param z FF instance
+ @param g FF exponent
+ @param p FF modulus
+ @param n size of FF in BIGs
+ @param en size of the exponent in BIGs
+ */
+extern void FF_WWW_skpow3(BIG_XXX *r,BIG_XXX *x, BIG_XXX *e, BIG_XXX *y, BIG_XXX *f, BIG_XXX *z, BIG_XXX *g, BIG_XXX *p, int n, int en);
/** @brief Calculate r=x^e mod p
*
For very short integer exponent
diff --git a/src/ff.c.in b/src/ff.c.in
index 2ce8da1..3f83bc2 100644
--- a/src/ff.c.in
+++ b/src/ff.c.in
@@ -866,6 +866,64 @@ void FF_WWW_skpow2(BIG_XXX r[],BIG_XXX x[], BIG_XXX e[], BIG_XXX y[], BIG_XXX f[
FF_WWW_redc(r,p,ND,n);
}
+/* r=x^e*y^f mod p - side channel resistant */
+void FF_WWW_skpow3(BIG_XXX r[],BIG_XXX x[], BIG_XXX e[], BIG_XXX y[], BIG_XXX f[], BIG_XXX z[], BIG_XXX g[], BIG_XXX p[], int n, int en)
+{
+ int i,b;
+#ifndef C99
+ BIG_XXX xn[FFLEN_WWW],yn[FFLEN_WWW],zn[FFLEN_WWW],xy[FFLEN_WWW],xz[FFLEN_WWW],yz[FFLEN_WWW],xyz[FFLEN_WWW],w[FFLEN_WWW],ND[FFLEN_WWW];
+#else
+ BIG_XXX xn[n],yn[n],zn[n],xy[n],xz[n],yz[n],xyz[n],w[n],ND[n];
+#endif
+
+ FF_WWW_invmod2m(ND, p, n);
+
+ FF_WWW_copy(xn, x, n);
+ FF_WWW_copy(yn, y, n);
+ FF_WWW_copy(zn, z, n);
+ FF_WWW_nres(xn, p, n);
+ FF_WWW_nres(yn, p, n);
+ FF_WWW_nres(zn, p, n);
+ FF_WWW_modmul(xy, xn, yn, p, ND, n);
+ FF_WWW_modmul(xz, xn, zn, p, ND, n);
+ FF_WWW_modmul(yz, yn, zn, p, ND, n);
+ FF_WWW_modmul(xyz, xy, zn, p, ND, n);
+ FF_WWW_one(w, n);
+ FF_WWW_one(r, n);
+ FF_WWW_nres(w, p, n);
+ FF_WWW_nres(r, p, n);
+
+ for (i=8*MODBYTES_XXX*en-1; i>=0; i--)
+ {
+ b = BIG_XXX_bit(g[i/BIGBITS_XXX],i%BIGBITS_XXX);
+ b <<= 1;
+ b = b | BIG_XXX_bit(f[i/BIGBITS_XXX],i%BIGBITS_XXX);
+ b <<= 1;
+ b = b | BIG_XXX_bit(e[i/BIGBITS_XXX],i%BIGBITS_XXX);
+
+ FF_WWW_cswap(w, xn, b == 0x01, n);
+ FF_WWW_cswap(w, yn, b == 0x02, n);
+ FF_WWW_cswap(w, zn, b == 0x04, n);
+ FF_WWW_cswap(w, xy, b == 0x03, n);
+ FF_WWW_cswap(w, xz, b == 0x05, n);
+ FF_WWW_cswap(w, yz, b == 0x06, n);
+ FF_WWW_cswap(w, xyz, b == 0x07, n);
+
+ FF_WWW_modsqr(r, r, p, ND, n);
+ FF_WWW_modmul(r, w, r, p, ND, n);
+
+ FF_WWW_cswap(w, xn, b == 0x01, n);
+ FF_WWW_cswap(w, yn, b == 0x02, n);
+ FF_WWW_cswap(w, zn, b == 0x04, n);
+ FF_WWW_cswap(w, xy, b == 0x03, n);
+ FF_WWW_cswap(w, xz, b == 0x05, n);
+ FF_WWW_cswap(w, yz, b == 0x06, n);
+ FF_WWW_cswap(w, xyz, b == 0x07, n);
+ }
+
+ FF_WWW_redc(r, p, ND, n);
+}
+
/* raise to an integer power - right-to-left method */
void FF_WWW_power(BIG_XXX r[],BIG_XXX x[],int e,BIG_XXX p[],int n)
{
diff --git a/test/test_ff_consistency_WWW.c.in b/test/test_ff_consistency_WWW.c.in
index 56fa552..f077a5d 100644
--- a/test/test_ff_consistency_WWW.c.in
+++ b/test/test_ff_consistency_WWW.c.in
@@ -324,6 +324,16 @@ int main()
exit(EXIT_FAILURE);
}
+ // Test triple exponent for secret key
+ FF_WWW_zero(N, HFLEN_WWW);
+ FF_WWW_skpow3(N, A, E, B, F, C, G, P, HFLEN_WWW, HFLEN_WWW);
+
+ if(FF_WWW_comp(N, L, HFLEN_WWW))
+ {
+ printf("ERROR testing pow3");
+ exit(EXIT_FAILURE);
+ }
+
// Test quadruple exponent
FF_WWW_pow(N, D, H, P, HFLEN_WWW);
FF_WWW_mul(Q, L, N, HFLEN_WWW);
[incubator-milagro-crypto-c] 02/03: Format code
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sandreoli pushed a commit to branch add-multiple-exponent-api
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git
commit d87a7b8d1742d5418f0c3574b25cc954e49e67b4
Author: Samuele Andreoli <sa...@yahoo.it>
AuthorDate: Tue Feb 4 10:19:04 2020 +0000
Format code
---
include/paillier.h | 2 +-
python/bls_ZZZ.py.in | 7 +++----
python/mpin_ZZZ.py.in | 2 +-
python/wcc_ZZZ.py.in | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/include/paillier.h b/include/paillier.h
index a5928dc..794ef6e 100644
--- a/include/paillier.h
+++ b/include/paillier.h
@@ -186,5 +186,5 @@ void PAILLIER_PK_toOctet(octet *PK, PAILLIER_public_key *PUB);
#ifdef __cplusplus
}
#endif
-
+
#endif
diff --git a/python/bls_ZZZ.py.in b/python/bls_ZZZ.py.in
index cf5e6d7..adf8ce9 100755
--- a/python/bls_ZZZ.py.in
+++ b/python/bls_ZZZ.py.in
@@ -28,10 +28,10 @@ This module use cffi to access the c functions in the BLS library.
There is also an example usage program in this file.
"""
+
import cffi
import platform
import os
-
ffi = cffi.FFI()
ffi.cdef("""
typedef struct {
@@ -252,7 +252,7 @@ def sign(message, sk):
Raises:
"""
- m, m_val = make_octet(None, message)
+ m, m_val = make_octet(None, message)
sk1, sk1_val = make_octet(None, sk)
signature1, signature1_val = make_octet(G1LEN)
error_code = libamcl_bls_ZZZ.BLS_ZZZ_SIGN(signature1, m, sk1)
@@ -284,7 +284,7 @@ def verify(signature, message, pk):
Raises:
"""
- m, m_val = make_octet(None, message)
+ m, m_val = make_octet(None, message)
pk1, pk1_val = make_octet(None, pk)
signature1, signature1_val = make_octet(None, signature)
error_code = libamcl_bls_ZZZ.BLS_ZZZ_VERIFY(signature1, m, pk1)
@@ -362,7 +362,6 @@ def add_G2(R1, R2):
return error_code, R
-
if __name__ == "__main__":
# Print hex values
DEBUG = False
diff --git a/python/mpin_ZZZ.py.in b/python/mpin_ZZZ.py.in
index 6e84805..094e1ef 100644
--- a/python/mpin_ZZZ.py.in
+++ b/python/mpin_ZZZ.py.in
@@ -28,10 +28,10 @@ This module use cffi to access the c functions in the mpin library.
There is also an example usage program in this file.
"""
+
import cffi
import platform
import os
-
ffi = cffi.FFI()
ffi.cdef("""
typedef struct {
diff --git a/python/wcc_ZZZ.py.in b/python/wcc_ZZZ.py.in
index d899eea..734dcf0 100644
--- a/python/wcc_ZZZ.py.in
+++ b/python/wcc_ZZZ.py.in
@@ -28,9 +28,9 @@ This module use cffi to access the c functions in the WCC library.
There is also an example usage program in this file.
"""
+
import cffi
import platform
-
ffi = cffi.FFI()
ffi.cdef("""
typedef struct {
[incubator-milagro-crypto-c] 03/03: Use tailored primes in ff test
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sandreoli pushed a commit to branch add-multiple-exponent-api
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git
commit 86c33c63d34fd3b9024a5e5c32934d4103805b9c
Author: Samuele Andreoli <sa...@yahoo.it>
AuthorDate: Tue Feb 4 10:41:59 2020 +0000
Use tailored primes in ff test
---
test/test_ff_consistency_WWW.c.in | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/test/test_ff_consistency_WWW.c.in b/test/test_ff_consistency_WWW.c.in
index f077a5d..53b0b4d 100644
--- a/test/test_ff_consistency_WWW.c.in
+++ b/test/test_ff_consistency_WWW.c.in
@@ -34,8 +34,16 @@
#define FS_WWW MODBYTES_XXX*FFLEN_WWW
#define HFS_WWW MODBYTES_XXX*HFLEN_WWW
+#if WWW == 2048
char *Phex = "cc44dc413faedf280f429f57881d48047e6041b16774b3074e81c6d2b2753269e61db41fb6a1bddc43f4257c49724f1d2678df0fc4d05032d228037c6580ed4b35001f1c01d788c1a5e2dfd3f676b25646d7df23d62bff478c5875327ca47b0145153fb316ad2289687fbc6fc113dca2d592e9761dd0d60577a1551c1cd37c29";
char *Qhex = "f68a619af0db4e19ed9c32569b25650e4cd9d9b3949bad18ce58c77770413e823c92dea3eb0a0a41425b2a0ba4e329c42d89bba26548ec3544a9798c887a0e1bb419e73374202505ada6b63c63ba9af2b10ab7c80efe4bf752cb951e6c8a763d6fa6430c23547f2e671303bc3e9591f45696f25c2da64939ff2346f636581e0d";
+#elif WWW == 3072
+char *Phex = "e80f3579282159380cd9a7923b90d5565795bc46a3ef5fcaec8769886a6e59499db17e8eb9163f714bf481d100c7ed66e2ec6f45389d74146ed02e7c9e0bfadb0e9625c3eaf55ce460c812ef04cb83213dc136212c88c16afc43d1b1dc53f5326804b853b60165c913740f127e7649778993852d3b46517ce75eed668976fdd9b8bb4b548a9012465b60aa5215c9fff7b4b3d270e0892add878d5fc97124b66094b358e68ced76a1d75db07804b7b0986eef123175f30a6e7530aa14c0c3cd41";
+char *Qhex = "e01b5c4cc562898d5dda3a71699b9bbde49d89f25868f6806a484c660cacfac59c2d42550960245c509dbfdec01dc980d2c50f3074fc188291ef4e4345850875eb150b7eb1d9d1f4354dd462ffaca772900b5c915ad4e17ec286343913bf3650b34c32fe240305f61c4c57ae3012027d987a84a33087990365f5ac7d1c6ea53e62af477e3fbda86b22c1c80ebcece950627b981052a7e7ca0789eee7b14df7c174660799e583d8d5284cb97821fbb02d00be90fad65e6a9d231b1fac04ef69b9";
+#else
+char *Phex = "e94f422c81696ed652102bb6dfa96e2977f6b0e16188b89319f00c2aad1e5d9617fe5d5126ce31e8a6f957caa56102f4863452bf901d53d8595c3fa4dc6ca6bfb76ec4ebed2f46e508bb6501a35cda8fde7caec29b3dd09b540a24019fc6bb1d28975a0946f01b226bd81d1a2c8d92287b22a4bb55c894caa4a7b35071b4e261b5cf3d10706eb4ca3dfe75181c356aa8bfc3d4ce03dda4a58149d9a6489e06b79db9390ea97e6e498047518ab32e5151ecb644342ec750da99f08fab040f7a02506d5b603b69ee3efdb403a90361a9ff307e6c55b20759ef0907d03aa8190813a522a340accc1a2f520098f2b56c8f [...]
+char *Qhex = "ec0a7fd563b3e58212e3ce6437a07df1294c8cb44ed3f66af0e5145db048db2e02de30e08e3c9ee8ecc6335ed8d4ba2bbbd699fbcd599f0db98e1433a071a7e331fba574926ca61131f35cf7b7b770a5fd7ccd2ac60054ddfc79fe9b587c28bf2ab3350aef850bc74b9508af2bc291c13823369d38c79a1b86539d52d3d4bf4a1ffe07274cef610660ea936bce4c9eaab4334b5e28a61703860fec1898c83d97439be945c8e782430a13428d3fe5d6ebc9d03baf027c4c1822a092c58120fc2180ad61d568c124401ab2ff12148a1a434d2832d971a113d5577fda4245e139a971336b10b5d83f1a74511a89cca229 [...]
+#endif
int main()
{
@@ -293,11 +301,6 @@ int main()
FF_WWW_random(G, &RNG, HFLEN_WWW);
FF_WWW_random(H, &RNG, HFLEN_WWW);
-#if WWW == 4096
- // P is too small for dmod if using ff_4096
- FF_WWW_copy(P, N, HFLEN_WWW);
-#endif
-
FF_WWW_pow(L, A, E, P, HFLEN_WWW);
FF_WWW_pow(N, B, F, P, HFLEN_WWW);
FF_WWW_mul(Q, L, N, HFLEN_WWW);