You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by km...@apache.org on 2019/06/25 14:08:49 UTC

[incubator-milagro-crypto-js] branch issue7 created (now 6071f37)

This is an automated email from the ASF dual-hosted git repository.

kmccusker pushed a change to branch issue7
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-js.git.


      at 6071f37  BLS signature and public key aggregation

This branch includes the following new commits:

     new 6071f37  BLS signature and public key aggregation

The 1 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.



[incubator-milagro-crypto-js] 01/01: BLS signature and public key aggregation

Posted by km...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kmccusker pushed a commit to branch issue7
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-js.git

commit 6071f374640c8e3ae6d6586e9cbde8d7123feb56
Author: Kealan McCusker <ke...@gmail.com>
AuthorDate: Tue Jun 25 15:08:25 2019 +0100

    BLS signature and public key aggregation
---
 examples/node/example_BLS_BLS383.js           | 96 +++++++++++++++++++++++++++
 examples/node/example_DVS_BLS383.js           |  2 +-
 examples/node/example_MPIN_BLS383.js          |  2 +-
 examples/node/example_MPIN_FULL_BLS383.js     |  2 +-
 examples/node/example_MPIN_ONE_PASS_BLS383.js |  2 +-
 src/bls.js                                    | 35 +++++++++-
 src/bls192.js                                 | 33 +++++++++
 src/bls256.js                                 | 34 ++++++++++
 test.test                                     |  0
 9 files changed, 201 insertions(+), 5 deletions(-)

diff --git a/examples/node/example_BLS_BLS383.js b/examples/node/example_BLS_BLS383.js
new file mode 100644
index 0000000..83e1d2c
--- /dev/null
+++ b/examples/node/example_BLS_BLS383.js
@@ -0,0 +1,96 @@
+/* Test BLS - test driver and function exerciser for BLS API Functions */
+
+var CTX = require("../../index");
+var ctx = new CTX('BLS383');
+
+var i,res;
+
+var BGS=ctx.BLS.BGS;
+var BFS=ctx.BLS.BFS;
+
+/* Group 1 Size */
+var G1S=BFS+1;
+/* Group 2 Size */
+var G2S=4*BFS; 
+
+var raw=[];
+var rng=new ctx.RAND();
+rng.clean();
+
+for (i=0;i<100;i++) raw[i]=i;
+rng.seed(100,raw);
+
+var message="test message";
+
+// User 1
+var sk1=[];
+var pk1=[];
+var sig1=[];
+
+ctx.BLS.KeyPairGenerate(rng,sk1,pk1);
+console.log("Private key user 1: 0x"+ctx.BLS.bytestostring(sk1));
+console.log("Public key user 1: 0x"+ctx.BLS.bytestostring(pk1));
+
+console.log("Message : "+message);
+ctx.BLS.sign(sig1,message,sk1);
+console.log("Signature user 1: 0x"+ctx.BLS.bytestostring(sig1));
+
+var res=ctx.BLS.verify(sig1,message,pk1);
+if (res==0)
+    console.log("Success User 1: valid Signature");
+else
+    console.log("Error User 1: invalid Signature");
+
+// User 2
+var sk2=[];
+var pk2=[];
+var sig2=[];
+
+ctx.BLS.KeyPairGenerate(rng,sk2,pk2);
+console.log("Private key user 2: 0x"+ctx.BLS.bytestostring(sk2));
+console.log("Public key user 2: 0x"+ctx.BLS.bytestostring(pk2));
+
+console.log("Message : "+message);
+ctx.BLS.sign(sig2,message,sk2);
+console.log("Signature user 2: 0x"+ctx.BLS.bytestostring(sig2));
+
+var res=ctx.BLS.verify(sig2,message,pk2);
+if (res==0)
+    console.log("Success User 2 valid Signature");
+else
+    console.log("Error User 2 invalid Signature");
+
+// Combined
+var pk=[];
+var sig=[];
+
+// Add signatures
+ctx.BLS.add_G1(sig1,sig2,sig);
+console.log("Signature combined: 0x"+ctx.BLS.bytestostring(sig));
+
+// Add public keys
+ctx.BLS.add_G2(pk1,pk2,pk);
+console.log("Public key combined: 0x"+ctx.BLS.bytestostring(pk));
+
+var res=ctx.BLS.verify(sig,message,pk);
+if (res==0)
+    console.log("Success combined valid Signature");
+else
+    console.log("Error combined invalid Signature");
+
+// Test corrupted signature
+sig1[0] = 1;
+var res=ctx.BLS.verify(sig1,message,pk1);
+if (res==0)
+    console.log("Success User 1: valid Signature");
+else
+    console.log("Error User 1: invalid Signature");
+
+// Test corrupted message
+var message2="bad message";
+var res=ctx.BLS.verify(sig2,message2,pk2);
+if (res==0)
+    console.log("Success User 2 valid Signature");
+else
+    console.log("Error User 2 invalid Signature");
+
diff --git a/examples/node/example_DVS_BLS383.js b/examples/node/example_DVS_BLS383.js
index da1c66d..d407427 100644
--- a/examples/node/example_DVS_BLS383.js
+++ b/examples/node/example_DVS_BLS383.js
@@ -21,7 +21,7 @@ under the License.
 
 var CTX = require("../../index");
 
-var ctx = new CTX("BN254CX");
+var ctx = new CTX("BLS383");
 
 var RAW = [];
 var rng = new ctx.RAND();
diff --git a/examples/node/example_MPIN_BLS383.js b/examples/node/example_MPIN_BLS383.js
index 26acda7..14d7fe5 100644
--- a/examples/node/example_MPIN_BLS383.js
+++ b/examples/node/example_MPIN_BLS383.js
@@ -21,7 +21,7 @@ under the License.
 
 var CTX = require("../../index");
 
-var ctx = new CTX("BN254CX");
+var ctx = new CTX("BLS383");
 
 /* Test M-Pin */
 
diff --git a/examples/node/example_MPIN_FULL_BLS383.js b/examples/node/example_MPIN_FULL_BLS383.js
index 7e689b3..c7f37df 100644
--- a/examples/node/example_MPIN_FULL_BLS383.js
+++ b/examples/node/example_MPIN_FULL_BLS383.js
@@ -21,7 +21,7 @@ under the License.
 
 var CTX = require("../../index");
 
-var ctx = new CTX("BN254CX");
+var ctx = new CTX("BLS383");
 
 /* Test M-Pin */
 
diff --git a/examples/node/example_MPIN_ONE_PASS_BLS383.js b/examples/node/example_MPIN_ONE_PASS_BLS383.js
index c6f6b9f..112b868 100644
--- a/examples/node/example_MPIN_ONE_PASS_BLS383.js
+++ b/examples/node/example_MPIN_ONE_PASS_BLS383.js
@@ -21,7 +21,7 @@ under the License.
 
 var CTX = require("../../index");
 
-var ctx = new CTX("BN254CX");
+var ctx = new CTX("BLS383");
 
 /* Test M-Pin */
 
diff --git a/src/bls.js b/src/bls.js
index 8149915..b65e54e 100644
--- a/src/bls.js
+++ b/src/bls.js
@@ -114,7 +114,40 @@ var BLS = function(ctx) {
 			if (v.isunity())
 				return this.BLS_OK;
 			return this.BLS_FAIL;
-		}
+		},
+
+	        /* R=R1+R2 in group G1 */
+                add_G1(R1, R2, R) {
+                       var P = ctx.ECP.fromBytes(R1),
+                       Q = ctx.ECP.fromBytes(R2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+		       }
+
+                       P.add(Q);
+
+                       P.toBytes(R,true);
+
+                       return 0;
+                },
+
+                /* W=W1+W2 in group G2 */
+                add_G2(W1, W2, W) {
+                       var P = ctx.ECP2.fromBytes(W1),
+                       Q = ctx.ECP2.fromBytes(W2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+                       }
+
+                       P.add(Q);
+
+                       P.toBytes(W);
+
+                       return 0;
+                }
+	
     };
 
     return BLS;
diff --git a/src/bls192.js b/src/bls192.js
index 64dbd3c..e00d37b 100644
--- a/src/bls192.js
+++ b/src/bls192.js
@@ -114,6 +114,39 @@ var BLS192 = function(ctx) {
 				return this.BLS_OK;
 			return this.BLS_FAIL;
 		}
+
+	        /* R=R1+R2 in group G1 */
+                add_G1(R1, R2, R) {
+                       var P = ctx.ECP.fromBytes(R1),
+                       Q = ctx.ECP.fromBytes(R2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+		       }
+
+                       P.add(Q);
+
+                       P.toBytes(R,true);
+
+                       return 0;
+                },
+
+                /* W=W1+W2 in group G2 */
+                add_G2(W1, W2, W) {
+                       var P = ctx.ECP4.fromBytes(W1),
+                       Q = ctx.ECP4.fromBytes(W2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+                       }
+
+                       P.add(Q);
+
+                       P.toBytes(W);
+
+                       return 0;
+                }
+	
     };
 
     return BLS192;
diff --git a/src/bls256.js b/src/bls256.js
index a154fe4..3c7fac6 100644
--- a/src/bls256.js
+++ b/src/bls256.js
@@ -115,6 +115,40 @@ var BLS256 = function(ctx) {
 				return this.BLS_OK;
 			return this.BLS_FAIL;
 		}
+
+
+	        /* R=R1+R2 in group G1 */
+                add_G1(R1, R2, R) {
+                       var P = ctx.ECP.fromBytes(R1),
+                       Q = ctx.ECP.fromBytes(R2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+		       }
+
+                       P.add(Q);
+
+                       P.toBytes(R,true);
+
+                       return 0;
+                },
+
+                /* W=W1+W2 in group G2 */
+                add_G2(W1, W2, W) {
+                       var P = ctx.ECP8.fromBytes(W1),
+                           Q = ctx.ECP8.fromBytes(W2);
+
+                       if (P.is_infinity() || Q.is_infinity()) {
+                           return this.INVALID_POINT;
+                       }
+
+                       P.add(Q);
+
+                       P.toBytes(W);
+
+                       return 0;
+                }
+	
     };
 
     return BLS256;
diff --git a/test.test b/test.test
deleted file mode 100644
index e69de29..0000000