Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge 1b0b1f6 into aa31e19
Browse files Browse the repository at this point in the history
  • Loading branch information
kealan committed Jun 20, 2019
2 parents aa31e19 + 1b0b1f6 commit 6086158
Show file tree
Hide file tree
Showing 9 changed files with 568 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -260,5 +260,5 @@ Please add yourself here if you make or have made a contribution.
1. [Check for open issues](https://github.com/apache/incubator-milagro-crypto-c/issues) or start a discussion around a feature idea or a bug by sending a mail to dev@milagro.incubator.apache.org
2. Fork the repository to start making your changes. Please use the "development" branch as a basis.
3. Write a test which shows that the bug was fixed or that the feature works as expected.
4. Send a pull request with a reference to the issue
4. Make a pull request with a reference to the issue

180 changes: 156 additions & 24 deletions examples/testbls_ZZZ.c.in
Expand Up @@ -16,8 +16,6 @@ specific language governing permissions and limitations
under the License.
*/

/* test driver and function exerciser for BLS Signature API Functions */

/* Build executable after installation:

gcc -O0 -g ./testbls_ZZZ.c $(pkg-config --libs --cflags amcl) -o testbls_ZZZ
Expand Down Expand Up @@ -47,69 +45,203 @@ under the License.
#define G2LEN 16*BFS_ZZZ
#endif

static char message[]="This is a test message";
static char message[]="test message";

int bls(csprng *RNG)
{
int rc;
char s[BGS_ZZZ];
char w[G2LEN];

char sk1[BGS_ZZZ];
octet SK1 = {0,sizeof(sk1),sk1};
char pk1[G2LEN];
octet PK1 = {0,sizeof(pk1),pk1};
char sig1[BFS_ZZZ+1];
octet SIG1 = {0,sizeof(sig1),sig1};

char sk2[BGS_ZZZ];
octet SK2 = {0,sizeof(sk2),sk2};
char pk2[G2LEN];
octet PK2 = {0,sizeof(pk2),pk2};
char sig2[BFS_ZZZ+1];
octet SIG2 = {0,sizeof(sig2),sig2};

char sk3[BGS_ZZZ];
octet SK3 = {0,sizeof(sk3),sk3};
char pk3[G2LEN];
octet PK3 = {0,sizeof(pk3),pk3};
char sig3[BFS_ZZZ+1];
octet SIG3 = {0,sizeof(sig3),sig3};

// Combined signature and public keys
char pk[G2LEN];
octet PK = {0,sizeof(pk),pk};
char sig[BFS_ZZZ+1];
octet S= {0,sizeof(s),s};
octet W= {0,sizeof(w),w};
octet SIG= {0,sizeof(sig),sig};
octet SIG = {0,sizeof(sig),sig};

BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&S,&W);
// Generate key pairs
BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK1,&PK1);
BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK2,&PK2);
BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&SK3,&PK3);

printf("Private key: 0x");
OCT_output(&S);
printf("Public key: 0x");
OCT_output(&W);
printf("Private key SK1: ");
OCT_output(&SK1);
printf("Public key PK1: ");
OCT_output(&PK1);
printf("Private key SK2: ");
OCT_output(&SK2);
printf("Public key PK2: ");
OCT_output(&PK2);
printf("Private key SK3: ");
OCT_output(&SK2);
printf("Public key PK3: ");
OCT_output(&PK2);
printf("\n");

BLS_ZZZ_SIGN(&SIG,message,&S);
printf("Signature: 0x");
OCT_output(&SIG);
// Sign the message
BLS_ZZZ_SIGN(&SIG1,message,&SK1);
BLS_ZZZ_SIGN(&SIG2,message,&SK2);
BLS_ZZZ_SIGN(&SIG3,message,&SK3);

rc=BLS_ZZZ_VERIFY(&SIG,message,&W);
printf("SIG1: ");
OCT_output(&SIG1);
printf("SIG2: ");
OCT_output(&SIG2);
printf("SIG3: ");
OCT_output(&SIG3);
printf("\n");

// Verify signature
rc=BLS_ZZZ_VERIFY(&SIG1,message,&PK1);
if (rc==BLS_OK)
{
printf("Success: Signature is valid\n");
}
else
{
printf("Error: Invalid Signature\n");
return 1;
}

// Verify signature
rc=BLS_ZZZ_VERIFY(&SIG2,message,&PK2);
if (rc==BLS_OK)
{
printf("Success: Signature is valid\n");
}
else
{
printf("Error: Invalid Signature\n");
return 1;
}

// Verify signature
rc=BLS_ZZZ_VERIFY(&SIG3,message,&PK3);
if (rc==BLS_OK)
{
printf("Success: Signature is valid\n");
}
else
{
printf("Error: Invalid Signature\n");
return 1;
}

// Add Public keys
rc = BLS_ZZZ_ADD_G2(&PK1,&PK2,&PK);
if (rc!=BLS_OK)
{
printf("ERROR BLS_ZZZ_ADD_G2 errorCode : %d\n", rc);
return 1;
}
rc = BLS_ZZZ_ADD_G2(&PK,&PK3,&PK);
if (rc!=BLS_OK)
{
printf("ERROR BLS_ZZZ_ADD_G2 errorCode : %d\n", rc);
return 1;
}
printf("Public key PK: ");
OCT_output(&PK);
printf("\n");

// Add signatures
rc = BLS_ZZZ_ADD_G1(&SIG1,&SIG2,&SIG);
if (rc!=BLS_OK)
{
printf("ERROR BLS_ZZZ_ADD_G1 errorCode : %d\n", rc);
return 1;
}

// Verify combined signature. This should fail.
rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
if (rc==BLS_OK)
{
printf("Success: Combined signature is valid\n");
return 1;
}
else
{
printf("Error: Combined signature is invalid\n");
}

rc = BLS_ZZZ_ADD_G1(&SIG,&SIG3,&SIG);
if (rc!=BLS_OK)
{
printf("ERROR BLS_ZZZ_ADD_G1 errorCode : %d\n", rc);
return 1;
}
printf("SIG: ");
OCT_output(&SIG);
printf("\n");
// Verify combined signature.
rc=BLS_ZZZ_VERIFY(&SIG,message,&PK);
if (rc==BLS_OK)
{
printf("Success: Combined signature is valid\n");
}
else
{
printf("Error: Combined signature is invalid\n");
return 1;
}


// change the message
message[0]='Z';
printf("message %s\n", message);
rc=BLS_ZZZ_VERIFY(&SIG,message,&W);
rc=BLS_ZZZ_VERIFY(&SIG1,message,&PK1);
if (rc==BLS_OK)
{
printf("Success: Signature is valid\n");
return 1;
}
else
{
printf("Error: Invalid Signature\n");
}

// Change the signature
message[0]='T';
SIG.val[0]=5;
message[0]='t';
SIG1.val[0]=5;
printf("message %s\n", message);
printf("Signature: 0x");
OCT_output(&SIG);
rc=BLS_ZZZ_VERIFY(&SIG,message,&W);
printf("Sig1nature SIG1: ");
OCT_output(&SIG1);
rc=BLS_ZZZ_VERIFY(&SIG1,message,&PK1);
if (rc==BLS_OK)
{
printf("Success: Signature is valid\n");
return 1;
}
else
{
printf("Error: Invalid Signature\n");
}

return rc;
/* clear memory */
OCT_clear(&SK1);
OCT_clear(&SK2);
OCT_clear(&SK3);

return 0;
}


Expand Down
24 changes: 22 additions & 2 deletions include/bls.h.in
Expand Up @@ -39,8 +39,10 @@ under the License.
#define BGS_ZZZ MODBYTES_XXX /**< BLS Group Size */
#define BFS_ZZZ MODBYTES_XXX /**< BLS Field Size */

#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL -1 /**< Point is NOT on the curve */
#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL 41 /**< Invalid signature */
#define BLS_INVALID_G1 42 /**< Not a valid G1 point on the curve */
#define BLS_INVALID_G2 43 /**< Not a valid G2 point on the curve */

/* BLS API functions */

Expand Down Expand Up @@ -71,5 +73,23 @@ int BLS_ZZZ_SIGN(octet *SIG,char *m,octet *S);
*/
int BLS_ZZZ_VERIFY(octet *SIG,char *m,octet *W);

/** @brief Add two members from the group G1
*
@param R1 member of G1
@param R2 member of G1
@param R member of G1. R = R1+R2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G1(octet *R1,octet *R2,octet *R);

/** @brief Add two members from the group G2
*
@param W1 member of G2
@param W2 member of G2
@param W member of G2. W = W1+W2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G2(octet *W1,octet *W2,octet *W);

#endif

24 changes: 22 additions & 2 deletions include/bls192.h.in
Expand Up @@ -39,8 +39,10 @@ under the License.
#define BGS_ZZZ MODBYTES_XXX /**< BLS Group Size */
#define BFS_ZZZ MODBYTES_XXX /**< BLS Field Size */

#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL -1 /**< Point is NOT on the curve */
#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL 41 /**< Invalid signature */
#define BLS_INVALID_G1 42 /**< Not a valid G1 point on the curve */
#define BLS_INVALID_G2 43 /**< Not a valid G2 point on the curve */

/* BLS API functions */

Expand Down Expand Up @@ -71,5 +73,23 @@ int BLS_ZZZ_SIGN(octet *SIG,char *m,octet *S);
*/
int BLS_ZZZ_VERIFY(octet *SIG,char *m,octet *W);

/** @brief Add two members from the group G1
*
@param R1 member of G1
@param R2 member of G1
@param R member of G1. R = R1+R2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G1(octet *R1,octet *R2,octet *R);

/** @brief Add two members from the group G2
*
@param W1 member of G2
@param W2 member of G2
@param W member of G2. W = W1+W2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G2(octet *W1,octet *W2,octet *W);

#endif

24 changes: 22 additions & 2 deletions include/bls256.h.in
Expand Up @@ -39,8 +39,10 @@ under the License.
#define BGS_ZZZ MODBYTES_XXX /**< BLS Group Size */
#define BFS_ZZZ MODBYTES_XXX /**< BLS Field Size */

#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL -1 /**< Point is NOT on the curve */
#define BLS_OK 0 /**< Function completed without error */
#define BLS_FAIL 41 /**< Invalid signature */
#define BLS_INVALID_G1 42 /**< Not a valid G1 point on the curve */
#define BLS_INVALID_G2 43 /**< Not a valid G2 point on the curve */

/* BLS API functions */

Expand Down Expand Up @@ -71,5 +73,23 @@ int BLS_ZZZ_SIGN(octet *SIG,char *m,octet *S);
*/
int BLS_ZZZ_VERIFY(octet *SIG,char *m,octet *W);

/** @brief Add two members from the group G1
*
@param R1 member of G1
@param R2 member of G1
@param R member of G1. R = R1+R2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G1(octet *R1,octet *R2,octet *R);

/** @brief Add two members from the group G2
*
@param W1 member of G2
@param W2 member of G2
@param W member of G2. W = W1+W2
@return Zero for success or else an error code
*/
int BLS_ZZZ_ADD_G2(octet *W1,octet *W2,octet *W);

#endif

0 comments on commit 6086158

Please sign in to comment.