This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from apache/add-bls
add bls to library
- Loading branch information
Showing
24 changed files
with
961 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
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 | ||
|
||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "config_curve_ZZZ.h" | ||
#include "randapi.h" | ||
|
||
#if CURVE_SECURITY_ZZZ == 128 | ||
#include "bls_ZZZ.h" | ||
#elif CURVE_SECURITY_ZZZ == 192 | ||
#include "bls192_ZZZ.h" | ||
#elif CURVE_SECURITY_ZZZ == 256 | ||
#include "bls256_ZZZ.h" | ||
#endif | ||
|
||
// Support multiple security levels | ||
#if CURVE_SECURITY_ZZZ == 128 | ||
#define G2LEN 4*BFS_ZZZ | ||
#elif CURVE_SECURITY_ZZZ == 192 | ||
#define G2LEN 8*BFS_ZZZ | ||
#elif CURVE_SECURITY_ZZZ == 256 | ||
#define G2LEN 16*BFS_ZZZ | ||
#endif | ||
|
||
static char message[]="This is a test message"; | ||
|
||
int bls(csprng *RNG) | ||
{ | ||
int rc; | ||
char s[BGS_ZZZ]; | ||
char w[G2LEN]; | ||
char sig[BFS_ZZZ+1]; | ||
octet S= {0,sizeof(s),s}; | ||
octet W= {0,sizeof(w),w}; | ||
octet SIG= {0,sizeof(sig),sig}; | ||
|
||
BLS_ZZZ_KEY_PAIR_GENERATE(RNG,&S,&W); | ||
|
||
printf("Private key: 0x"); | ||
OCT_output(&S); | ||
printf("Public key: 0x"); | ||
OCT_output(&W); | ||
|
||
BLS_ZZZ_SIGN(&SIG,message,&S); | ||
printf("Signature: 0x"); | ||
OCT_output(&SIG); | ||
|
||
rc=BLS_ZZZ_VERIFY(&SIG,message,&W); | ||
if (rc==BLS_OK) | ||
{ | ||
printf("Success: Signature is valid\n"); | ||
} | ||
else | ||
{ | ||
printf("Error: Invalid Signature\n"); | ||
} | ||
|
||
// change the message | ||
message[0]='Z'; | ||
printf("message %s\n", message); | ||
rc=BLS_ZZZ_VERIFY(&SIG,message,&W); | ||
if (rc==BLS_OK) | ||
{ | ||
printf("Success: Signature is valid\n"); | ||
} | ||
else | ||
{ | ||
printf("Error: Invalid Signature\n"); | ||
} | ||
|
||
// Change the signature | ||
message[0]='T'; | ||
SIG.val[0]=5; | ||
printf("message %s\n", message); | ||
printf("Signature: 0x"); | ||
OCT_output(&SIG); | ||
rc=BLS_ZZZ_VERIFY(&SIG,message,&W); | ||
if (rc==BLS_OK) | ||
{ | ||
printf("Success: Signature is valid\n"); | ||
} | ||
else | ||
{ | ||
printf("Error: Invalid Signature\n"); | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
#ifdef DEBUG | ||
printf("%d bit build\n",CHUNK); | ||
#endif | ||
|
||
// non random seed value | ||
char seed[32] = {0}; | ||
octet SEED = {sizeof(seed),sizeof(seed),seed}; | ||
for (int i=0; i<32; i++) SEED.val[i]=i+1; | ||
printf("SEED: "); | ||
OCT_output(&SEED); | ||
printf("\n"); | ||
|
||
// initialise random number generator | ||
csprng RNG; | ||
CREATE_CSPRNG(&RNG,&SEED); | ||
|
||
printf("\nTesting BLS signature for curve ZZZ\n"); | ||
bls(&RNG); | ||
|
||
KILL_CSPRNG(&RNG); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
/** | ||
* @file bls_ZZZ.h | ||
* @author Mike Scott | ||
* @date 28th Novemebr 2018 | ||
* @brief BLS Header file | ||
* | ||
* Allows some user configuration | ||
* defines structures | ||
* declares functions | ||
* | ||
*/ | ||
|
||
#ifndef BLS_ZZZ_H | ||
#define BLS_ZZZ_H | ||
|
||
#include "pair_ZZZ.h" | ||
|
||
/* Field size is assumed to be greater than or equal to group size */ | ||
|
||
#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 */ | ||
|
||
/* BLS API functions */ | ||
|
||
/** @brief Generate Key Pair | ||
* | ||
@param RNG Pointer to a cryptographically secure random number generator | ||
@param S Private key | ||
@param W Public Key. W = S*G, where G is fixed generator | ||
@return Zero for success or else an error code | ||
*/ | ||
int BLS_ZZZ_KEY_PAIR_GENERATE(csprng *RNG,octet* S,octet *W); | ||
|
||
/** @brief Calculate a signature | ||
* | ||
@param SIG signature | ||
@param m message to be signed | ||
@param S Private key | ||
@return Zero for success or else an error code | ||
*/ | ||
int BLS_ZZZ_SIGN(octet *SIG,char *m,octet *S); | ||
|
||
/** @brief Verify a signature | ||
* | ||
@param SIG signature | ||
@param m message whose signature is to be verified. | ||
@param W Public key | ||
@return Zero for success or else an error code | ||
*/ | ||
int BLS_ZZZ_VERIFY(octet *SIG,char *m,octet *W); | ||
|
||
#endif | ||
|
Oops, something went wrong.