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/08/06 13:09:41 UTC

[incubator-milagro-crypto-c] branch issue34 created (now f364bd1)

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

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


      at f364bd1  add ability to generate BLS public key from external private key

This branch includes the following new commits:

     new f364bd1  add ability to generate BLS public key from external private key

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-c] 01/01: add ability to generate BLS public key from external private key

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

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

commit f364bd1aaa0860f38d1399eaa567af8a5a4d95a7
Author: Kealan McCusker <ke...@gmail.com>
AuthorDate: Tue Aug 6 14:09:18 2019 +0100

    add ability to generate BLS public key from external private key
---
 Makefile                                  |   2 +-
 VERSION                                   |   2 +-
 examples/example_bls_ZZZ.c.in             |  35 ++++++----
 examples/example_mpin_ZZZ.c.in            |   4 +-
 include/bls.h.in                          |   2 +-
 include/bls192.h.in                       |   2 +-
 include/bls256.h.in                       |   2 +-
 src/bls.c.in                              |  16 ++++-
 src/bls192.c.in                           |  16 ++++-
 src/bls256.c.in                           |  16 ++++-
 test/test_bls_ZZZ.c.in                    |  38 ++++++----
 wrappers/python/TestMPINInstall_ZZZ.py.in |   4 +-
 wrappers/python/TimeMPIN_ZZZ.py.in        |   3 +-
 wrappers/python/bls_ZZZ.py.in             | 111 ++++++++++++++++++------------
 wrappers/python/mpin_ZZZ.py.in            |  34 +++++----
 wrappers/python/wcc_ZZZ.py.in             |  19 ++---
 16 files changed, 194 insertions(+), 112 deletions(-)

diff --git a/Makefile b/Makefile
index 13d5744..1ae0cb7 100644
--- a/Makefile
+++ b/Makefile
@@ -245,7 +245,7 @@ format:
 	astyle --style=allman --recursive --suffix=none 'examples/*.c'
 	astyle --style=allman --recursive --suffix=none 'examples/*.c.in'
 	astyle --style=allman --recursive --suffix=none 'benchmark/*.c.in'
-	autopep8 --in-place --aggressive --aggressive ./wrappers/python/*.py
+	autopep8 --in-place --aggressive --aggressive ./wrappers/python/*.py.in
 
 # Remove any build artifact
 clean:
diff --git a/VERSION b/VERSION
index 6e8bf73..3eefcb9 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.0
+1.0.0
diff --git a/examples/example_bls_ZZZ.c.in b/examples/example_bls_ZZZ.c.in
index bc7cdd0..736e54d 100644
--- a/examples/example_bls_ZZZ.c.in
+++ b/examples/example_bls_ZZZ.c.in
@@ -53,6 +53,8 @@ int bls(csprng *RNG)
 
     char sk1[BGS_ZZZ];
     octet SK1 = {0,sizeof(sk1),sk1};
+    char pktmp[G2LEN];
+    octet PKTMP = {0,sizeof(pktmp),pktmp};
     char pk1[G2LEN];
     octet PK1 = {0,sizeof(pk1),pk1};
     char sig1[BFS_ZZZ+1];
@@ -72,19 +74,24 @@ int bls(csprng *RNG)
     char sig3[BFS_ZZZ+1];
     octet SIG3 = {0,sizeof(sig3),sig3};
 
-    // Combined signature and public keys
+    // Aggregated signature and public keys
     char pk[G2LEN];
     octet PK = {0,sizeof(pk),pk};
     char sig[BFS_ZZZ+1];
     octet SIG = {0,sizeof(sig),sig};
 
     // Generate key pairs
-    BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK1,&PK1);
+    BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK1,&PKTMP);
     BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK2,&PK2);
     BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK3,&PK3);
 
+    // Generate PK2 using external secret key
+    BLS_ZZZ_KEY_PAIR_GENERATE(NULL,&SK1,&PK1);
+
     printf("Private key SK1: ");
     OCT_output(&SK1);
+    printf("Public key PKTMP: ");
+    OCT_output(&PKTMP);
     printf("Public key PK1: ");
     OCT_output(&PK1);
     printf("Private key SK2: ");
@@ -171,16 +178,16 @@ int bls(csprng *RNG)
         return 1;
     }
 
-    // Verify combined signature. This should fail.
+    // Verify aggregated signature. This should fail.
     rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
     if (rc==BLS_OK)
     {
-        printf("Success: Combined signature is valid\n");
+        printf("Success: Aggregated signature is valid\n");
         return 1;
     }
     else
     {
-        printf("Error: Combined signature is invalid\n");
+        printf("Error: Aggregated signature is invalid (expected result) \n");
     }
 
     rc = BLS_ZZZ_ADD_G1(&SIG,&SIG3,&SIG);
@@ -192,15 +199,15 @@ int bls(csprng *RNG)
     printf("SIG: ");
     OCT_output(&SIG);
     printf("\n");
-    // Verify combined signature.
+    // Verify aggregated signature.
     rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
     if (rc==BLS_OK)
     {
-        printf("Success: Combined signature is valid\n");
+        printf("Success: Aggregated signature is valid\n");
     }
     else
     {
-        printf("Error: Combined signature is invalid\n");
+        printf("Error: Aggregated signature is invalid\n");
         return 1;
     }
 
@@ -216,14 +223,14 @@ int bls(csprng *RNG)
     }
     else
     {
-        printf("Error: Invalid Signature\n");
+        printf("Error: Invalid Signature (expected result) \n");
     }
 
     // Change the signature
     message[0]='t';
     SIG1.val[0]=5;
     printf("message %s\n", message);
-    printf("Sig1nature SIG1: ");
+    printf("Signature SIG1: ");
     OCT_output(&SIG1);
     rc=BLS_ZZZ_VERIFY(&SIG1,message,&PK1);
     if (rc==BLS_OK)
@@ -233,7 +240,7 @@ int bls(csprng *RNG)
     }
     else
     {
-        printf("Error: Invalid Signature\n");
+        printf("Error: Invalid Signature  (expected result) \n");
     }
 
     /* clear memory */
@@ -254,17 +261,17 @@ int main()
     char* seedHex = "78d0fb6705ce77dee47d03eb5b9c5d30";
     char seed[16] = {0};
     octet SEED = {sizeof(seed),sizeof(seed),seed};
-    
+
     // CSPRNG
     csprng RNG;
 
-    // fake random source 
+    // fake random source
     OCT_fromHex(&SEED,seedHex);
     printf("SEED: ");
     OCT_output(&SEED);
     printf("\n");
 
-    // initialise strong RNG 
+    // initialise strong RNG
     CREATE_CSPRNG(&RNG,&SEED);
 
     printf("\nTesting BLS signature for curve ZZZ\n");
diff --git a/examples/example_mpin_ZZZ.c.in b/examples/example_mpin_ZZZ.c.in
index ed0b96a..91e78de 100644
--- a/examples/example_mpin_ZZZ.c.in
+++ b/examples/example_mpin_ZZZ.c.in
@@ -351,13 +351,13 @@ int main()
     // CSPRNG
     csprng RNG;
 
-    // fake random source 
+    // fake random source
     OCT_fromHex(&SEED,seedHex);
     printf("SEED: ");
     OCT_output(&SEED);
     printf("\n");
 
-    // initialise strong RNG 
+    // initialise strong RNG
     CREATE_CSPRNG(&RNG,&SEED);
 
     mpin(&RNG);
diff --git a/include/bls.h.in b/include/bls.h.in
index 8905ddd..cf5ceca 100644
--- a/include/bls.h.in
+++ b/include/bls.h.in
@@ -49,7 +49,7 @@ under the License.
 /**	@brief Generate Key Pair
  *
 	@param RNG  Pointer to a cryptographically secure random number generator
-	@param S    Private key
+	@param S    Private key. Generated externally if RNG set to NULL
 	@param W    Public Key. W = S*G, where G is fixed generator
 	@return     Zero for success or else an error code
  */
diff --git a/include/bls192.h.in b/include/bls192.h.in
index ae8ab26..4e4a489 100644
--- a/include/bls192.h.in
+++ b/include/bls192.h.in
@@ -49,7 +49,7 @@ under the License.
 /**	@brief Generate Key Pair
  *
 	@param RNG  Pointer to a cryptographically secure random number generator
-	@param S    Private key
+	@param S    Private key. Generated externally if RNG set to NULL
 	@param W    Public Key. W = S*G, where G is fixed generator
 	@return     Zero for success or else an error code
  */
diff --git a/include/bls256.h.in b/include/bls256.h.in
index ad9dfb0..5af8f61 100644
--- a/include/bls256.h.in
+++ b/include/bls256.h.in
@@ -49,7 +49,7 @@ under the License.
 /**	@brief Generate Key Pair
  *
 	@param RNG  Pointer to a cryptographically secure random number generator
-	@param S    Private key
+	@param S    Private key. Generated externally if RNG set to NULL
 	@param W    Public Key. W = S*G, where G is fixed generator
 	@return     Zero for success or else an error code
  */
diff --git a/src/bls.c.in b/src/bls.c.in
index 0d4c899..6cfe38c 100644
--- a/src/bls.c.in
+++ b/src/bls.c.in
@@ -46,9 +46,19 @@ int BLS_ZZZ_KEY_PAIR_GENERATE(csprng *RNG,octet* S,octet *W)
     BIG_XXX s,q;
     BIG_XXX_rcopy(q,CURVE_Order_ZZZ);
     ECP2_ZZZ_generator(&G);
-    BIG_XXX_randomnum(s,q,RNG);
-    BIG_XXX_toBytes(S->val,s);
-    S->len=MODBYTES_XXX;
+
+    if (RNG!=NULL)
+    {
+        BIG_XXX_randomnum(s,q,RNG);
+        BIG_XXX_toBytes(S->val,s);
+        S->len=MODBYTES_XXX;
+    }
+    else
+    {
+        S->len=MODBYTES_XXX;
+        BIG_XXX_fromBytes(s,S->val);
+    }
+
     PAIR_ZZZ_G2mul(&G,s);
     ECP2_ZZZ_toOctet(W,&G);
     return BLS_OK;
diff --git a/src/bls192.c.in b/src/bls192.c.in
index 79a1c20..3857f10 100644
--- a/src/bls192.c.in
+++ b/src/bls192.c.in
@@ -46,9 +46,19 @@ int BLS_ZZZ_KEY_PAIR_GENERATE(csprng *RNG,octet* S,octet *W)
     BIG_XXX s,q;
     BIG_XXX_rcopy(q,CURVE_Order_ZZZ);
     ECP4_ZZZ_generator(&G);
-    BIG_XXX_randomnum(s,q,RNG);
-    BIG_XXX_toBytes(S->val,s);
-    S->len=MODBYTES_XXX;
+
+    if (RNG!=NULL)
+    {
+        BIG_XXX_randomnum(s,q,RNG);
+        BIG_XXX_toBytes(S->val,s);
+        S->len=MODBYTES_XXX;
+    }
+    else
+    {
+        S->len=MODBYTES_XXX;
+        BIG_XXX_fromBytes(s,S->val);
+    }
+
     PAIR_ZZZ_G2mul(&G,s);
     ECP4_ZZZ_toOctet(W,&G);
     return BLS_OK;
diff --git a/src/bls256.c.in b/src/bls256.c.in
index 19f7e43..135d450 100644
--- a/src/bls256.c.in
+++ b/src/bls256.c.in
@@ -46,9 +46,19 @@ int BLS_ZZZ_KEY_PAIR_GENERATE(csprng *RNG,octet* S,octet *W)
     BIG_XXX s,q;
     BIG_XXX_rcopy(q,CURVE_Order_ZZZ);
     ECP8_ZZZ_generator(&G);
-    BIG_XXX_randomnum(s,q,RNG);
-    BIG_XXX_toBytes(S->val,s);
-    S->len=MODBYTES_XXX;
+
+    if (RNG!=NULL)
+    {
+        BIG_XXX_randomnum(s,q,RNG);
+        BIG_XXX_toBytes(S->val,s);
+        S->len=MODBYTES_XXX;
+    }
+    else
+    {
+        S->len=MODBYTES_XXX;
+        BIG_XXX_fromBytes(s,S->val);
+    }
+
     PAIR_ZZZ_G2mul(&G,s);
     ECP8_ZZZ_toOctet(W,&G);
     return BLS_OK;
diff --git a/test/test_bls_ZZZ.c.in b/test/test_bls_ZZZ.c.in
index 556268a..92c4154 100644
--- a/test/test_bls_ZZZ.c.in
+++ b/test/test_bls_ZZZ.c.in
@@ -50,6 +50,8 @@ int bls(csprng *RNG)
 
     char sk1[BGS_ZZZ];
     octet SK1 = {0,sizeof(sk1),sk1};
+    char pktmp[G2LEN];
+    octet PKTMP = {0,sizeof(pktmp),pktmp};
     char pk1[G2LEN];
     octet PK1 = {0,sizeof(pk1),pk1};
     char sig1[BFS_ZZZ+1];
@@ -69,19 +71,30 @@ int bls(csprng *RNG)
     char sig3[BFS_ZZZ+1];
     octet SIG3 = {0,sizeof(sig3),sig3};
 
-    // Combined signature and public keys
+    // Aggregated signature and public keys
     char pk[G2LEN];
     octet PK = {0,sizeof(pk),pk};
     char sig[BFS_ZZZ+1];
     octet SIG = {0,sizeof(sig),sig};
 
     // Generate key pairs
-    BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK1,&PK1);
+    BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK1,&PKTMP);
     BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK2,&PK2);
     BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK3,&PK3);
 
+    // Generate PK2 using external secret key
+    BLS_ZZZ_KEY_PAIR_GENERATE(NULL,&SK1,&PK1);
+
+    if (!OCT_comp(&PKTMP,&PK1))
+    {
+        printf("FAILURE OCT_comp(&PKTMP,&PK1)\n");
+        return 1;
+    }
+
     printf("Private key SK1: ");
     OCT_output(&SK1);
+    printf("Public key PKTMP: ");
+    OCT_output(&PKTMP);
     printf("Public key PK1: ");
     OCT_output(&PK1);
     printf("Private key SK2: ");
@@ -168,7 +181,7 @@ int bls(csprng *RNG)
         return 1;
     }
 
-    // Verify combined signature. This should fail.
+    // Verify aggregated signature. This should fail.
     rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
     if (rc==BLS_FAIL)
     {
@@ -190,7 +203,7 @@ int bls(csprng *RNG)
     OCT_output(&SIG);
     printf("\n");
 
-    // Verify combined signature.
+    // Verify aggregated signature.
     rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
     if (rc==BLS_OK)
     {
@@ -222,10 +235,10 @@ int bls(csprng *RNG)
     message[0]='t';
     SIG1.val[0]=5;
     printf("message %s\n", message);
-    printf("Sig1nature SIG1: ");
+    printf("Signature SIG1: ");
     OCT_output(&SIG1);
     rc=BLS_ZZZ_VERIFY(&SIG1,message,&PK1);
-    if (rc==BLS_FAIL)
+    if (rc==BLS_INVALID_G1)
     {
         printf("Test Passed invalid signature / valid message\n");
     }
@@ -253,27 +266,26 @@ int main()
     char* seedHex = "78d0fb6705ce77dee47d03eb5b9c5d30";
     char seed[16] = {0};
     octet SEED = {sizeof(seed),sizeof(seed),seed};
-    
+
     // CSPRNG
     csprng RNG;
 
-    // fake random source 
+    // fake random source
     OCT_fromHex(&SEED,seedHex);
     printf("SEED: ");
     OCT_output(&SEED);
-    printf("\n");
 
-    // initialise strong RNG 
+    // initialise strong RNG
     CREATE_CSPRNG(&RNG,&SEED);
 
     printf("\nTesting BLS signature for curve ZZZ\n");
-    if (bls(&RNG))
+    if (!bls(&RNG))
     {
-        printf("SUCCESS");
+        printf("SUCCESS\n");
     }
     else
     {
-        printf("FAILURE");
+        printf("FAILURE\n");
     }
 
     KILL_CSPRNG(&RNG);
diff --git a/wrappers/python/TestMPINInstall_ZZZ.py.in b/wrappers/python/TestMPINInstall_ZZZ.py.in
index 1b46807..c02936c 100644
--- a/wrappers/python/TestMPINInstall_ZZZ.py.in
+++ b/wrappers/python/TestMPINInstall_ZZZ.py.in
@@ -24,6 +24,7 @@ import json
 import hashlib
 import mpin_ZZZ
 
+
 class TestMPIN(unittest.TestCase):
     """Tests M-Pin crypto code"""
 
@@ -39,7 +40,8 @@ class TestMPIN(unittest.TestCase):
         self.mpin_id = json.dumps(endUserData)
 
         # Hash value of MPIN_ID
-        self.hash_mpin_id = mpin_ZZZ.hash_id(mpin_ZZZ.HASH_TYPE_ZZZ, self.mpin_id)
+        self.hash_mpin_id = mpin_ZZZ.hash_id(
+            mpin_ZZZ.HASH_TYPE_ZZZ, self.mpin_id)
 
         # Assign a seed value
         seedHex = "3ade3d4a5c698e8910bf92f25d97ceeb7c25ed838901a5cb5db2cf25434c1fe76c7f79b7af2e5e1e4988e4294dbd9bd9fa3960197fb7aec373609fb890d74b16a4b14b2ae7e23b75f15d36c21791272372863c4f8af39980283ae69a79cf4e48e908f9e0"
diff --git a/wrappers/python/TimeMPIN_ZZZ.py.in b/wrappers/python/TimeMPIN_ZZZ.py.in
index 8305fb0..7faf631 100755
--- a/wrappers/python/TimeMPIN_ZZZ.py.in
+++ b/wrappers/python/TimeMPIN_ZZZ.py.in
@@ -33,7 +33,8 @@ def time_func(stmt, n=10, setup='from __main__ import *'):
     total_time = t.timeit(n)
     iter_time = total_time / n
     iter_per_sec = n / total_time
-    print "func:%s nIter:%s total_time:%s iter_time:%s iter_per_sec: %s" % (stmt, n, total_time, iter_time, iter_per_sec)
+    print "func:%s nIter:%s total_time:%s iter_time:%s iter_per_sec: %s" % (
+        stmt, n, total_time, iter_time, iter_per_sec)
 
 
 nIter = 100
diff --git a/wrappers/python/bls_ZZZ.py.in b/wrappers/python/bls_ZZZ.py.in
index 2f78793..fe0734d 100755
--- a/wrappers/python/bls_ZZZ.py.in
+++ b/wrappers/python/bls_ZZZ.py.in
@@ -79,17 +79,17 @@ BFS = @NB@
 
 CURVE_SECURITY = @CS@
 
-G1LEN = BFS+1
+G1LEN = BFS + 1
 
 if CURVE_SECURITY == 128:
-    G2LEN = 4*BFS
+    G2LEN = 4 * BFS
 
 if CURVE_SECURITY == 192:
-    G2LEN = 8*BFS
+    G2LEN = 8 * BFS
 
 if CURVE_SECURITY == 256:
-    G2LEN = 16*BFS
-    
+    G2LEN = 16 * BFS
+
 
 def to_hex(octet_value):
     """Converts an octet type into a string
@@ -113,11 +113,12 @@ def to_hex(octet_value):
     while i < octet_value.len:
         val.append(octet_value.val[i])
         i = i + 1
-    out=b''
+    out = b''
     for x in val:
         out = out + x
     return out.hex()
 
+
 def make_octet(length, value=None):
     """Generates an octet pointer
 
@@ -149,6 +150,7 @@ def make_octet(length, value=None):
         oct_ptr.len = length
     return oct_ptr, val
 
+
 def create_csprng(seed):
     """Make a Cryptographically secure pseudo-random number generator instance
 
@@ -195,7 +197,8 @@ def kill_csprng(rng):
 
     return 0
 
-def key_pair_generate(rng):
+
+def key_pair_generate(rng, sk=None):
     """Generate key pair
 
     Generate key pair
@@ -203,6 +206,7 @@ def key_pair_generate(rng):
     Args::
 
         rng: Pointer to cryptographically secure pseudo-random number generator instance
+        sk: secret key. Externally generated
 
     Returns::
 
@@ -213,21 +217,27 @@ def key_pair_generate(rng):
     Raises:
 
     """
-    sk1, sk1val = make_octet(BGS)
-    pk1, pk1val = make_octet(G2LEN)    
-    error_code = libamcl_bls_ZZZ.BLS_ZZZ_KEY_PAIR_GENERATE(rng, sk1,pk1)
+    if sk:
+        sk1, sk1_val = make_octet(None, sk)
+        rng = ffi.NULL
+    else:
+        sk1, sk1val = make_octet(BGS)
+
+    pk1, pk1val = make_octet(G2LEN)
+    error_code = libamcl_bls_ZZZ.BLS_ZZZ_KEY_PAIR_GENERATE(rng, sk1, pk1)
 
     sk_hex = to_hex(sk1)
-    pk_hex = to_hex(pk1)    
+    pk_hex = to_hex(pk1)
 
     # clear memory
     libamcl_core.OCT_clear(sk1)
-    libamcl_core.OCT_clear(pk1)    
+    libamcl_core.OCT_clear(pk1)
 
     sk = bytes.fromhex(sk_hex)
-    pk = bytes.fromhex(pk_hex)        
+    pk = bytes.fromhex(pk_hex)
     return error_code, sk, pk
 
+
 def sign(message, sk):
     """Calculate a signature
 
@@ -247,18 +257,19 @@ def sign(message, sk):
 
     """
     sk1, sk1_val = make_octet(None, sk)
-    signature1, signature1_val = make_octet(G1LEN)    
+    signature1, signature1_val = make_octet(G1LEN)
     error_code = libamcl_bls_ZZZ.BLS_ZZZ_SIGN(signature1, message, sk1)
 
     signature_hex = to_hex(signature1)
 
     # clear memory
     libamcl_core.OCT_clear(sk1)
-    libamcl_core.OCT_clear(signature1)    
+    libamcl_core.OCT_clear(signature1)
 
     signature = bytes.fromhex(signature_hex)
     return error_code, signature
 
+
 def verify(signature, message, pk):
     """Verify a signature
 
@@ -283,10 +294,11 @@ def verify(signature, message, pk):
 
     # clear memory
     libamcl_core.OCT_clear(pk1)
-    libamcl_core.OCT_clear(signature1)    
+    libamcl_core.OCT_clear(signature1)
 
     return error_code
 
+
 def add_G1(R1, R2):
     """Add two members from the group G1
 
@@ -306,20 +318,21 @@ def add_G1(R1, R2):
 
     """
     R11, R11_val = make_octet(None, R1)
-    R21, R21_val = make_octet(None, R2)    
-    R1, R1_val = make_octet(G1LEN)        
+    R21, R21_val = make_octet(None, R2)
+    R1, R1_val = make_octet(G1LEN)
     error_code = libamcl_bls_ZZZ.BLS_ZZZ_ADD_G1(R11, R21, R1)
 
     R_hex = to_hex(R1)
-    
+
     # clear memory
     libamcl_core.OCT_clear(R11)
     libamcl_core.OCT_clear(R21)
-    libamcl_core.OCT_clear(R1)    
+    libamcl_core.OCT_clear(R1)
 
     R = bytes.fromhex(R_hex)
     return error_code, R
 
+
 def add_G2(R1, R2):
     """Add two members from the group G2
 
@@ -339,20 +352,21 @@ def add_G2(R1, R2):
 
     """
     R11, R11_val = make_octet(None, R1)
-    R21, R21_val = make_octet(None, R2)    
-    R1, R1_val = make_octet(G2LEN)        
+    R21, R21_val = make_octet(None, R2)
+    R1, R1_val = make_octet(G2LEN)
     error_code = libamcl_bls_ZZZ.BLS_ZZZ_ADD_G2(R11, R21, R1)
 
     R_hex = to_hex(R1)
-    
+
     # clear memory
     libamcl_core.OCT_clear(R11)
     libamcl_core.OCT_clear(R21)
-    libamcl_core.OCT_clear(R1)    
+    libamcl_core.OCT_clear(R1)
 
     R = bytes.fromhex(R_hex)
     return error_code, R
 
+
 if __name__ == "__main__":
     # Print hex values
     DEBUG = False
@@ -368,24 +382,31 @@ if __name__ == "__main__":
     rng = create_csprng(seed)
 
     # Generate key pairs
-    rtn, sk1, pk1 = key_pair_generate(rng)
+    rtn, sk1, pktmp = key_pair_generate(rng)
     if rtn != 0:
-        print("Error: key_pair_generate {}".format(rtn))                
-        raise SystemExit(0)        
+        print("Error: key_pair_generate {}".format(rtn))
+        raise SystemExit(0)
+    print("sk1: {}".format(sk1.hex()))
+    print("pktmp: {}".format(pktmp.hex()))
+
+    rtn, sk1, pk1 = key_pair_generate(rng, sk1)
+    if rtn != 0:
+        print("Error: key_pair_generate {}".format(rtn))
+        raise SystemExit(0)
     print("sk1: {}".format(sk1.hex()))
     print("pk1: {}".format(pk1.hex()))
 
     rtn, sk2, pk2 = key_pair_generate(rng)
     if rtn != 0:
-        print("Error: key_pair_generate {}".format(rtn))        
-        raise SystemExit(0)        
+        print("Error: key_pair_generate {}".format(rtn))
+        raise SystemExit(0)
     print("sk2: {}".format(sk2.hex()))
     print("pk2: {}".format(pk2.hex()))
 
     rtn, sk3, pk3 = key_pair_generate(rng)
     if rtn != 0:
-        print("Error: key_pair_generate {}".format(rtn))        
-        raise SystemExit(0)        
+        print("Error: key_pair_generate {}".format(rtn))
+        raise SystemExit(0)
     print("sk3: {}".format(sk3.hex()))
     print("pk3: {}".format(pk3.hex()))
 
@@ -393,7 +414,7 @@ if __name__ == "__main__":
     rtn, sig1 = sign(message, sk1)
     if rtn != 0:
         print("Error: sign {}".format(rtn))
-        raise SystemExit(0)                
+        raise SystemExit(0)
     print("sig1: {}".format(sig1.hex()))
 
     rtn = verify(sig1, message, pk1)
@@ -405,7 +426,7 @@ if __name__ == "__main__":
     rtn, sig2 = sign(message, sk2)
     if rtn != 0:
         print("Error: sign {}".format(rtn))
-        raise SystemExit(0)                
+        raise SystemExit(0)
     print("sig2: {}".format(sig2.hex()))
 
     rtn = verify(sig2, message, pk2)
@@ -413,13 +434,13 @@ if __name__ == "__main__":
         print("Error: Invalid signature {}".format(rtn))
         raise SystemExit(0)
     print("Success: Signature is valid")
-    
+
     rtn, sig3 = sign(message, sk3)
     if rtn != 0:
         print("Error: sign {}".format(rtn))
-        raise SystemExit(0)                
+        raise SystemExit(0)
     print("sig3: {}".format(sig3.hex()))
-    
+
     rtn = verify(sig3, message, pk3)
     if rtn != 0:
         print("Error: Invalid signature {}".format(rtn))
@@ -431,26 +452,26 @@ if __name__ == "__main__":
     if rtn != 0:
         print("Error: add_G1 {}".format(rtn))
         raise SystemExit(0)
-    print("sig12: {}".format(sig12.hex()))    
+    print("sig12: {}".format(sig12.hex()))
 
     rtn, sig123 = add_G1(sig12, sig3)
     if rtn != 0:
         print("Error: add_G1 {}".format(rtn))
         raise SystemExit(0)
-    print("sig123: {}".format(sig123.hex()))    
+    print("sig123: {}".format(sig123.hex()))
 
     # Add Public keys
     rtn, pk12 = add_G2(pk1, pk2)
     if rtn != 0:
         print("Error: add_G2 {}".format(rtn))
         raise SystemExit(0)
-    print("pk12: {}".format(pk12.hex()))    
+    print("pk12: {}".format(pk12.hex()))
 
     rtn, pk123 = add_G2(pk12, pk3)
     if rtn != 0:
         print("Error: add_G2 {}".format(rtn))
         raise SystemExit(0)
-    print("pk123: {}".format(pk123.hex()))    
+    print("pk123: {}".format(pk123.hex()))
 
     # Verify aggretated values
     rtn = verify(sig123, message, pk123)
@@ -458,12 +479,12 @@ if __name__ == "__main__":
         print("Error: Invalid aggregated signature {}".format(rtn))
         raise SystemExit(0)
     print("Success: Aggregated signature is valid")
-    
-    # Clear memory    
+
+    # Clear memory
     kill_csprng(rng)
     del sk1
-    del pk1    
+    del pk1
     del sk2
-    del pk2    
+    del pk2
     del sk3
-    del pk3    
+    del pk3
diff --git a/wrappers/python/mpin_ZZZ.py.in b/wrappers/python/mpin_ZZZ.py.in
index 4b89707..944a609 100644
--- a/wrappers/python/mpin_ZZZ.py.in
+++ b/wrappers/python/mpin_ZZZ.py.in
@@ -108,22 +108,22 @@ PFS = @NB@
 CURVE_SECURITY = @CS@
 
 if CURVE_SECURITY == 128:
-    G2 = 4*PFS
+    G2 = 4 * PFS
     HASH_TYPE_ZZZ = 32
-    AESKEY_ZZZ = 16    
-    
+    AESKEY_ZZZ = 16
+
 if CURVE_SECURITY == 192:
-    G2 = 8*PFS
-    HASH_TYPE_ZZZ = 48    
+    G2 = 8 * PFS
+    HASH_TYPE_ZZZ = 48
     AESKEY_ZZZ = 24
-    
+
 if CURVE_SECURITY == 256:
-    G2 = 16*PFS
+    G2 = 16 * PFS
     HASH_TYPE_ZZZ = 64
     AESKEY_ZZZ = 32
-    
+
 G1 = 2 * PFS + 1
-GT = 3*G2
+GT = 3 * G2
 
 # AES-GCM IV length
 IVL = 12
@@ -968,7 +968,17 @@ def server_2(epoch_date, HID, HTID, y, server_secret, u, ut, v, pa):
     return error_code, e_hex.decode("hex"), f_hex.decode("hex")
 
 
-def server(hash_type, epoch_date, server_secret, u, ut, v, mpin_id, message, epoch_time, pa):
+def server(
+    hash_type,
+    epoch_date,
+    server_secret,
+    u,
+    ut,
+    v,
+    mpin_id,
+    message,
+    epoch_time,
+        pa):
     """Perform server side of the one-pass version of the M-Pin protocol
 
     Perform server side of the one-pass version of the M-Pin protocol. If Time
@@ -1421,8 +1431,6 @@ if __name__ == "__main__":
     MPIN_ZZZ_FULL = True
     PIN_ERROR = True
 
-
-
     if TIME_PERMITS:
         date = today()
     else:
@@ -1547,7 +1555,7 @@ if __name__ == "__main__":
         rtn, x, u, ut, v, y = client(
             HASH_TYPE_ZZZ, date, mpin_id, rng, None, PIN, token, time_permit, None, epoch_time)
         if DEBUG:
-            print "y1 ", y.encode("hex")        
+            print "y1 ", y.encode("hex")
         if rtn != 0:
             print "MPIN_ZZZ_CLIENT ERROR %s" % rtn
 
diff --git a/wrappers/python/wcc_ZZZ.py.in b/wrappers/python/wcc_ZZZ.py.in
index 2b083e8..3ab6611 100644
--- a/wrappers/python/wcc_ZZZ.py.in
+++ b/wrappers/python/wcc_ZZZ.py.in
@@ -83,25 +83,26 @@ PFS = @NB@
 CURVE_SECURITY = @CS@
 
 if CURVE_SECURITY == 128:
-    G2 = 4*PFS
+    G2 = 4 * PFS
     HASH_TYPE_ZZZ = 32
-    AESKEY_ZZZ = 16    
-    
+    AESKEY_ZZZ = 16
+
 if CURVE_SECURITY == 192:
-    G2 = 8*PFS
-    HASH_TYPE_ZZZ = 48    
+    G2 = 8 * PFS
+    HASH_TYPE_ZZZ = 48
     AESKEY_ZZZ = 24
-    
+
 if CURVE_SECURITY == 256:
-    G2 = 16*PFS
+    G2 = 16 * PFS
     HASH_TYPE_ZZZ = 64
     AESKEY_ZZZ = 32
-    
+
 G1 = 2 * PFS + 1
 
 # AES-GCM IV length
 IVL = 12
 
+
 def toHex(octetValue):
     """Converts an octet type into a string
 
@@ -301,7 +302,7 @@ if __name__ == "__main__":
     if DEBUG:
         print "IdB: %s" % toHex(IdB)
         print "HIdB: %s" % toHex(HIdB)
-        
+
     # Generate master secret for MILAGRO and Customer
     rtn = libamcl_wcc_ZZZ.WCC_ZZZ_RANDOM_GENERATE(RNG, MS1)
     if rtn != 0: