/** * @file test_wcc_random.c * @author Kealan McCusker * @brief Test WCC with two TAs and time permits for random values * * LICENSE * * 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 WCC with two TAs and time permits for random values */ #include #include #include #include #include "wcc.h" #include "randapi.h" static const int nRandomTests = 10; /**< MPin Random Tests */ static void rand_str(char *dest, size_t length,csprng *RNG) { BIG r; char charset[] = "0123456789@.*" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; while (length-- > 0) { BIG_random(r,RNG); size_t index = r[0] % (sizeof charset); *dest++ = charset[index]; } *dest = '\0'; } int test_wcc_random() { int i,rtn,iter; printf("test_wcc_random() started\n"); /* Master secret shares */ char ms1[PGS], ms2[PGS]; octet MS1= {0,sizeof(ms1),ms1}; octet MS2= {0,sizeof(ms2),ms2}; // Sender keys char a1keyG1[2*PFS+1], a2keyG1[2*PFS+1]; octet A1KeyG1= {0,sizeof(a1keyG1), a1keyG1}; octet A2KeyG1= {0,sizeof(a2keyG1), a2keyG1}; char akeyG1[2*PFS+1]; octet AKeyG1= {0,sizeof(akeyG1), akeyG1}; // Sender time permits char a1TPG1[2*PFS+1], a2TPG1[2*PFS+1]; octet A1TPG1= {0,sizeof(a1TPG1), a1TPG1}; octet A2TPG1= {0,sizeof(a2TPG1), a2TPG1}; char aTPG1[2*PFS+1]; octet ATPG1= {0,sizeof(aTPG1), aTPG1}; // Receiver keys char b1keyG2[4*PFS], b2keyG2[4*PFS]; octet B1KeyG2= {0,sizeof(b1keyG2), b1keyG2}; octet B2KeyG2= {0,sizeof(b2keyG2), b2keyG2}; char bkeyG2[4*PFS]; octet BKeyG2= {0,sizeof(bkeyG2), bkeyG2}; // Receiver time permits char b1TPG2[4*PFS], b2TPG2[4*PFS]; octet B1TPG2= {0,sizeof(b1TPG2), b1TPG2}; octet B2TPG2= {0,sizeof(b2TPG2), b2TPG2}; char bTPG2[4*PFS]; octet BTPG2= {0,sizeof(bTPG2), bTPG2}; char ahv[PFS],alice_id[256],bhv[PFS],bob_id[256]; octet AHV= {0,sizeof(ahv),ahv}; octet BHV= {0,sizeof(bhv),bhv}; octet IdA= {0,sizeof(alice_id),alice_id}; octet IdB= {0,sizeof(bob_id),bob_id}; char x[PGS]; octet X= {0,sizeof(x),x}; char y[PGS]; octet Y= {0,sizeof(y),y}; char w[PGS]; octet W= {0,sizeof(w),w}; char pia[PGS]; octet PIA= {0,sizeof(pia),pia}; char pib[PGS]; octet PIB= {0,sizeof(pib),pib}; char pgg1[2*PFS+1]; octet PgG1= {0,sizeof(pgg1), pgg1}; char pag1[2*PFS+1]; octet PaG1= {0,sizeof(pag1), pag1}; char pbg2[4*PFS]; octet PbG2= {0,sizeof(pbg2), pbg2}; char message1[256]; char message2[256]; octet MESSAGE1 = {0, sizeof(message1), message1}; octet MESSAGE2 = {0, sizeof(message2), message2}; char t1[PTAG]; // Tag char t2[PTAG]; // Tag char k1[PAS]; // AES Key char k2[PAS]; // AES Key char iv[PIV]; // IV - Initialisation vector char c[100]; // Ciphertext char p[100]; // Recovered Plaintext octet T1= {sizeof(t1),sizeof(t1),t1}; octet T2= {sizeof(t2),sizeof(t2),t2}; octet K1= {0,sizeof(k1),k1}; octet K2= {0,sizeof(k2),k2}; octet IV= {0,sizeof(iv),iv}; octet C= {0,sizeof(c),c}; octet P= {0,sizeof(p),p}; int date; date = WCC_today(); printf("Date %d \n", date); int hashDoneOn = 1; OCT_jstring(&MESSAGE1,"Hello Bob"); OCT_jstring(&MESSAGE2,"Hello Alice"); int byte_count = 32; char seed[32] = {0}; octet SEED = {sizeof(seed),sizeof(seed),seed}; csprng RNG; #ifdef __linux__ FILE *fp; fp = fopen("/dev/urandom", "r"); if (fread(&seed, 1, byte_count, fp)) {}; fclose(fp); #else /* non random seed value! */ unsigned long ran; time((time_t *)&ran); SEED.val[0]=ran; SEED.val[1]=ran>>8; SEED.val[2]=ran>>16; SEED.val[3]=ran>>24; for (i=4; i