/** * @file test_mpinfull_random.c * @author Kealan McCusker * @brief Test Mpin-full good token and correct PIN with D-TA * * 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 good token and correct PIN with D-TA */ #include #include #include #include #include "mpin.h" #include "randapi.h" static const int nRandomTests = 10; /**< MPin Random Tests */ // Define PIN range: #define MAX_RANGE 10000 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_mpinfull_random() { printf("test_mpinfull_random() started\n"); int PIN1,PIN2,rtn,err,iter; char id[256]; octet ID = {0,sizeof(id),id}; char x[PGS],y[PGS]; octet X= {sizeof(x), sizeof(x),x}; octet Y= {sizeof(y),sizeof(y),y}; /* Master secret shares */ char ms1[PGS], ms2[PGS]; octet MS1= {sizeof(ms1),sizeof(ms1),ms1}; octet MS2= {sizeof(ms2),sizeof(ms2),ms2}; /* Hash values of client ID */ char hcid[PFS]; octet HCID= {sizeof(hcid),sizeof(hcid), hcid}; /* Hash values of messages */ char hm[PFS]; octet HM= {sizeof(hm),sizeof(hm), hm}; /* Client secret and shares */ char cs1[2*PFS+1], cs2[2*PFS+1], sec[2*PFS+1]; octet SEC= {sizeof(sec),sizeof(sec),sec}; octet CS1= {sizeof(cs1),sizeof(cs1), cs1}; octet CS2= {sizeof(cs2),sizeof(cs2), cs2}; /* Server secret and shares */ char ss1[4*PFS], ss2[4*PFS], serverSecret[4*PFS]; octet ServerSecret= {sizeof(serverSecret),sizeof(serverSecret),serverSecret}; octet SS1= {sizeof(ss1),sizeof(ss1),ss1}; octet SS2= {sizeof(ss2),sizeof(ss2),ss2}; /* Time Permit and shares */ char tp1[2*PFS+1], tp2[2*PFS+1], tp[2*PFS+1]; octet TP= {sizeof(tp),sizeof(tp),tp}; octet TP1= {sizeof(tp1),sizeof(tp1),tp1}; octet TP2= {sizeof(tp2),sizeof(tp2),tp2}; /* Token stored on computer */ char token[2*PFS+1]; octet TOKEN= {sizeof(token),sizeof(token),token}; /* Precomputed values stored on device */ char g1[12*PFS],g2[12*PFS]; octet G1= {0,sizeof(g1),g1}; octet G2= {0,sizeof(g2),g2}; char ut[2*PFS+1],u[2*PFS+1]; octet UT= {sizeof(ut),sizeof(ut),ut}; octet U= {sizeof(u),sizeof(u),u}; char hid[2*PFS+1],htid[2*PFS+1]; octet HID= {0,sizeof(hid),hid}; octet HTID= {0,sizeof(htid),htid}; char e[12*PFS], f[12*PFS]; octet E= {sizeof(e),sizeof(e),e}; octet F= {sizeof(f),sizeof(f),f}; char r[PGS],z[2*PFS+1],w[PGS],t[2*PFS+1]; char ck[PAS],sk[PAS]; octet R= {0,sizeof(r),r}; octet Z= {0,sizeof(z),z}; octet W= {0,sizeof(w),w}; octet T= {0,sizeof(t),t}; octet SK= {0,sizeof(sk),sk}; octet CK= {0,sizeof(ck),ck}; octet *pID; int date = 0; 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! */ int i; 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