/* * Copyright (c) 2012-2020 MIRACL UK Ltd. * * This file is part of MIRACL Core * (see https://github.com/miracl/core). * * Licensed 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 Boneh-Lynn-Shacham BLS Signature API Functions */ #include #include #include #include #include "bls_BN254.h" #if CHUNK==32 || CHUNK==64 #include "bls_BLS12383.h" #include "bls192_BLS24479.h" #include "bls256_BLS48556.h" #endif #include "randapi.h" /* To reverse the groups G1 and G2, edit BLS*.cpp Swap G1 <-> G2 Swap ECP <-> ECPn Disable G2 precomputation Switch G1/G2 parameter order in pairing function calls #define REVERSE here See BLSREV*.cpp */ //#define REVERSE using namespace core; static char message[] = "This is a test message"; int bls_BN254(csprng *RNG) { using namespace BN254; int i,res; char s[BGS_BN254]; char ikm[64]; #ifdef REVERSE char w[BFS_BN254+1], sig[4 * BFS_BN254 + 1]; // w is 2* if not compressed else 1*. sig is 4* if not compressed, else 2* #else char w[4 * BFS_BN254 + 1], sig[BFS_BN254 + 1]; // w is 4* if not compressed else 2*. sig is 2* if not compressed, else 1* #endif octet S = {0, sizeof(s), s}; octet W = {0, sizeof(w), w}; octet SIG = {0, sizeof(sig), sig}; octet IKM = {0, sizeof(ikm), ikm}; octet M = {0,sizeof(message), message}; OCT_jstring(&M,message); res = BLS_INIT(); if (res == BLS_FAIL) { printf("Failed to initialize\n"); return res; } OCT_rand(&IKM,RNG,32); //IKM.len=32; //for (i=0;i> 8; RAW.val[2] = ran >> 16; RAW.val[3] = ran >> 24; for (i = 4; i < 100; i++) RAW.val[i] = i; CREATE_CSPRNG(&RNG, &RAW); // initialise strong RNG printf("%d bit build\n", CHUNK); printf("\nTesting BLS signature for curve BN254\n"); bls_BN254(&RNG); #if CHUNK!=16 printf("\nTesting BLS signature for curve BLS12383\n"); bls_BLS12383(&RNG); printf("\nTesting BLS signature for curve BLS24479\n"); bls_BLS24479(&RNG); printf("\nTesting BLS signature for curve BLS48556\n"); bls_BLS48556(&RNG); #endif KILL_CSPRNG(&RNG); }