http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpinfullSingle.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpinfullSingle.c b/c/tests/test_mpinfullSingle.c deleted file mode 100755 index c2a657d..0000000 --- a/c/tests/test_mpinfullSingle.c +++ /dev/null @@ -1,296 +0,0 @@ -/* -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 M-Pin Full Single pass */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "mpin.h" - -int main() -{ - int i,PIN1,PIN2,rtn,err; - - char id[256]; - octet ID = {0,sizeof(id),id}; - - char x[PGS],y1[PGS],y2[PGS]; - octet X={sizeof(x), sizeof(x),x}; - octet Y1={sizeof(y1),sizeof(y1),y1}; - octet Y2={sizeof(y2),sizeof(y2),y2}; - - /* 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[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* Hash values of messages */ - char hm[HASH_BYTES]; - 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 device */ - 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}; - - int TimeValue = 0; - - PIN1 = 1234; - PIN2 = 1234; - - /* Assign the End-User an ID */ - char* user = "[email protected]"; - OCT_jstring(&ID,user); - printf("CLIENT: ID %s\n", user); - - int date = 0; - char seed[100] = {0}; - octet SEED = {0,sizeof(seed),seed}; - csprng RNG; - - /* unrandom seed value! */ - SEED.len=100; - for (i=0;i<100;i++) SEED.val[i]=i+1; - - /* initialise random number generator */ - MPIN_CREATE_CSPRNG(&RNG,&SEED); - - /* Hash ID */ - MPIN_HASH_ID(&ID,&HCID); - OCT_output(&HCID); - - /* When set only send hashed IDs to server */ - octet *pID; -#ifdef USE_ANONYMOUS - pID = &HCID; -#else - pID = &ID; -#endif - - /* Generate Client master secret for MIRACL and Customer */ - rtn = MPIN_RANDOM_GENERATE(&RNG,&MS1); - if (rtn != 0) { - printf("MPIN_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_RANDOM_GENERATE(&RNG,&MS2); - if (rtn != 0) { - printf("MPIN_RANDOM_GENERATE(&RNG,&MS2) Error %d\n", rtn); - return 1; - } - printf("MASTER SECRET MIRACL:= 0x"); - OCT_output(&MS1); - printf("MASTER SECRET CUSTOMER:= 0x"); - OCT_output(&MS2); - - /* Generate server secret shares */ - rtn = MPIN_GET_SERVER_SECRET(&MS1,&SS1); - if (rtn != 0) { - printf("MPIN_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_SERVER_SECRET(&MS2,&SS2); - if (rtn != 0) { - printf("MPIN_GET_SERVER_SECRET(&MS2,&SS2) Error %d\n", rtn); - return 1; - } - printf("SS1 = 0x"); - OCT_output(&SS1); - printf("SS2 = 0x"); - OCT_output(&SS2); - - /* Combine server secret share */ - rtn = MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret) Error %d\n", rtn); - return 1; - } - printf("ServerSecret = 0x"); - OCT_output(&ServerSecret); - - /* Generate client secret shares */ - rtn = MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2) Error %d\n", rtn); - return 1; - } - printf("CS1 = 0x"); - OCT_output(&CS1); - printf("CS2 = 0x"); - OCT_output(&CS2); - - /* Combine client secret shares : TOKEN is the full client secret */ - rtn = MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", rtn); - return 1; - } - printf("Client Secret = 0x"); - OCT_output(&TOKEN); - - /* Generate Time Permit shares */ - date = MPIN_today(); - printf("Date %d \n", date); - rtn = MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2) Error %d\n", rtn); - return 1; - } - printf("TP1 = 0x"); - OCT_output(&TP1); - printf("TP2 = 0x"); - OCT_output(&TP2); - - /* Combine Time Permit shares */ - rtn = MPIN_RECOMBINE_G1(&TP1, &TP2, &TP); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G1(&TP1, &TP2, &TP) Error %d\n", rtn); - return 1; - } - printf("Time Permit = 0x"); - OCT_output(&TP); - - /* This encoding makes Time permit look random */ - if (MPIN_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n"); - printf("Encoded Time Permit= "); OCT_output(&TP); - if (MPIN_DECODING(&TP)!=0) printf("Decoding error\n"); - printf("Decoded Time Permit= "); OCT_output(&TP); - - /* Client extracts PIN1 from secret to create Token */ - rtn = MPIN_EXTRACT_PIN(&ID, PIN1, &TOKEN); - if (rtn != 0) { - printf("MPIN_EXTRACT_PIN( &ID, PIN, &TOKEN) Error %d\n", rtn); - return 1; - } - printf("Token = 0x"); - OCT_output(&TOKEN); - - /* Client precomputation */ - MPIN_PRECOMPUTE(&TOKEN,&HCID,&G1,&G2); - - /* Client */ - TimeValue = MPIN_GET_TIME(); - printf("TimeValue %d \n", TimeValue); - rtn = MPIN_CLIENT(date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,NULL,&UT,&TP,NULL,TimeValue,&Y1); - if (rtn != 0) { - printf("MPIN_CLIENT ERROR %d\n", rtn); - return 1; - } - printf("Y1 = 0x"); - OCT_output(&Y1); - printf("V = 0x"); - OCT_output(&SEC); - - /* Client sends Z=r.ID to Server */ - MPIN_GET_G1_MULTIPLE(&RNG,1,&R,&HCID,&Z); - - /* Server */ - rtn = MPIN_SERVER(date,&HID,&HTID,&Y2,&ServerSecret,NULL,&UT,&SEC,&E,&F,pID,NULL,TimeValue); - - printf("Y2 = 0x"); - OCT_output(&Y2); - if (rtn != 0) { - printf("FAILURE Invalid Token Error Code %d\n", rtn); - return 1; - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - - /* Server sends T=w.ID to client */ - MPIN_GET_G1_MULTIPLE(&RNG,0,&W,&HTID,&T); - printf("T = 0x"); - OCT_output(&T); - - MPIN_HASH_ALL(&HCID,NULL,&UT,&SEC,&Y1,&Z,&T,&HM); - MPIN_CLIENT_KEY(&G1,&G2,PIN2,&R,&X,&HM,&T,&CK); - printf("Client Key = "); - OCT_output(&CK); - - MPIN_HASH_ALL(&HCID,NULL,&UT,&SEC,&Y2,&Z,&T,&HM); - MPIN_SERVER_KEY(&Z,&ServerSecret,&W,&HM,&HID,NULL,&UT,&SK); - printf("Server Key = "); - OCT_output(&SK); - - if (!OCT_comp(&CK,&SK)) { - printf("FAILURE Keys are different\n"); - return 1; - } - - printf("SUCCESS\n"); - return 0; -}
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpinfull_random.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpinfull_random.c b/c/tests/test_mpinfull_random.c deleted file mode 100755 index 1638464..0000000 --- a/c/tests/test_mpinfull_random.c +++ /dev/null @@ -1,349 +0,0 @@ -/* -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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "config.h" -#include "mpin.h" - -// Define PIN range: -#define MAX_RANGE 10000 - -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 main() -{ - int i,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[HASH_BYTES]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - char hsid[HASH_BYTES]; - octet HSID={sizeof(hsid),sizeof(hsid), hsid}; - - /* Hash values of messages */ - char hm[HASH_BYTES]; - 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; - - unsigned long ran; - int byte_count = 32; - FILE *fp; - char seed[32] = {0}; - octet SEED = {sizeof(seed),sizeof(seed),seed}; - csprng RNG; -#ifdef __linux__ - fp = fopen("/dev/urandom", "r"); - fread(&seed, 1, byte_count, fp); - fclose(fp); -#else - /* non random seed value! */ - 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<byte_count;i++) SEED.val[i]=i+1; -#endif - printf("SEED 0x"); - OCT_output(&SEED); - - /* initialise random number generator */ - MPIN_CREATE_CSPRNG(&RNG,&SEED); - - for(iter=1; iter<nRandomTests+1; iter++) - { - /* Generate Client master secret for MIRACL and Customer */ - rtn = MPIN_RANDOM_GENERATE(&RNG,&MS1); - if (rtn != 0) { - printf("MPIN_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_RANDOM_GENERATE(&RNG,&MS2); - if (rtn != 0) { - printf("MPIN_RANDOM_GENERATE(&RNG,&MS2) Error %d\n", rtn); - return 1; - } - printf("MASTER SECRET MIRACL:= 0x"); - OCT_output(&MS1); - printf("MASTER SECRET CUSTOMER:= 0x"); - OCT_output(&MS2); - - /* Generate server secret shares */ - rtn = MPIN_GET_SERVER_SECRET(&MS1,&SS1); - if (rtn != 0) { - printf("MPIN_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_SERVER_SECRET(&MS2,&SS2); - if (rtn != 0) { - printf("MPIN_GET_SERVER_SECRET(&MS2,&SS2) Error %d\n", rtn); - return 1; - } - printf("SS1 = 0x"); - OCT_output(&SS1); - printf("SS2 = 0x"); - OCT_output(&SS2); - - /* Combine server secret share */ - rtn = MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret) Error %d\n", rtn); - return 1; - } - printf("ServerSecret = 0x"); - OCT_output(&ServerSecret); - - /* Assign the End-User an ID */ - rand_str(id,256,&RNG); - OCT_jstring(&ID,id); - printf("CLIENT: ID %s\n", id); - - srand(time(NULL)); - PIN1 = rand()%MAX_RANGE; // Get random between 0 and MAX_RANGE - PIN2 = PIN1; - printf("PIN1 %d PIN2 %d\n", PIN1, PIN2); - - /* Hash ID */ - MPIN_HASH_ID(&ID,&HCID); - OCT_output(&HCID); - - /* When set only send hashed IDs to server */ -#ifdef USE_ANONYMOUS - pID = &HCID; -#else - pID = &ID; -#endif - - /* Generate client secret shares */ - rtn = MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2) Error %d\n", rtn); - return 1; - } - printf("CS1 = 0x"); - OCT_output(&CS1); - printf("CS2 = 0x"); - OCT_output(&CS2); - - /* Combine client secret shares : TOKEN is the full client secret */ - rtn = MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", rtn); - return 1; - } - printf("Client Secret = 0x"); - OCT_output(&TOKEN); - - /* Generate Time Permit shares */ - date = MPIN_today(); - printf("Date %d \n", date); - rtn = MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2) Error %d\n", rtn); - return 1; - } - printf("TP1 = 0x"); - OCT_output(&TP1); - printf("TP2 = 0x"); - OCT_output(&TP2); - - /* Combine Time Permit shares */ - rtn = MPIN_RECOMBINE_G1(&TP1, &TP2, &TP); - if (rtn != 0) { - printf("MPIN_RECOMBINE_G1(&TP1, &TP2, &TP) Error %d\n", rtn); - return 1; - } - printf("Time Permit = 0x"); - OCT_output(&TP); - - /* This encoding makes Time permit look random */ - if (MPIN_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n"); - printf("Encoded Time Permit= "); OCT_output(&TP); - if (MPIN_DECODING(&TP)!=0) printf("Decoding error\n"); - printf("Decoded Time Permit= "); OCT_output(&TP); - - /* Client extracts PIN1 from secret to create Token */ - rtn = MPIN_EXTRACT_PIN(&ID, PIN1, &TOKEN); - if (rtn != 0) { - printf("MPIN_EXTRACT_PIN( &ID, PIN, &TOKEN) Error %d\n", rtn); - return 1; - } - printf("Token = 0x"); - OCT_output(&TOKEN); - - /* Client precomputation */ - MPIN_PRECOMPUTE(&TOKEN,&HCID,&G1,&G2); - - /* Client first pass */ - rtn = MPIN_CLIENT_1(date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,&U,&UT,&TP); - if (rtn != 0) { - printf("MPIN_CLIENT_1 ERROR %d\n", rtn); - return 1; - } - - /* Client sends Z=r.ID to Server */ - MPIN_GET_G1_MULTIPLE(&RNG,1,&R,&HCID,&Z); - - /* Server calculates H(ID) and H(T|H(ID)) (if time permits enabled), and maps them to points on the curve HID and HTID resp. */ - MPIN_SERVER_1(date,pID,&HID,&HTID); - - /* Server generates Random number Y and sends it to Client */ - rtn = MPIN_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("MPIN_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } - printf("Y = 0x"); - OCT_output(&Y); - - /* Server sends T=w.ID to client */ - MPIN_GET_G1_MULTIPLE(&RNG,0,&W,&HTID,&T); - printf("T = 0x"); - OCT_output(&T); - - /* Client second pass */ - rtn = MPIN_CLIENT_2(&X,&Y,&SEC); - if (rtn != 0) { - printf("MPIN_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn); - } - printf("V = 0x"); - OCT_output(&SEC); - - /* Server second pass */ - rtn = MPIN_SERVER_2(date,&HID,&HTID,&Y,&ServerSecret,&U,&UT,&SEC,&E,&F); - if (rtn != 0) { - err=MPIN_KANGAROO(&E,&F); - if (err==0) { - printf("FAILURE Invalid Token Error Code %d\n", rtn); - } else { - printf("FAILURE PIN Error %d, Error Code %d\n",err, rtn); - } - } - - MPIN_HASH_ALL(&HCID,&U,&UT,&SEC,&Y,&Z,&T,&HM); - MPIN_CLIENT_KEY(&G1,&G2,PIN2,&R,&X,&HM,&T,&CK); - printf("Client Key = "); - OCT_output(&CK); - - /* Server will use the hashed ID if anonymous connection required. - MPIN_HASH_ID(&ID,&HSID); - MPIN_HASH_ALL(&HSID,NULL,&UT,&SEC,&Y,&Z,&T,&HM); - */ - MPIN_SERVER_KEY(&Z,&ServerSecret,&W,&HM,&HID,NULL,&UT,&SK); - printf("Server Key = "); - OCT_output(&SK); - - if (!OCT_comp(&CK,&SK)) { - printf("Iteration %d FAILURE keys are different\n", iter); - return 1; - } else { - printf("Iteration %d SUCCESS\n\n", iter); - } - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_rsa.c ---------------------------------------------------------------------- diff --git a/c/tests/test_rsa.c b/c/tests/test_rsa.c deleted file mode 100755 index d2aa8a3..0000000 --- a/c/tests/test_rsa.c +++ /dev/null @@ -1,82 +0,0 @@ -/* -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 RSA API Functions */ - -#include <stdio.h> -#include <time.h> -#include "rsa.h" - -int main() -{ - int i,bytes,res; - unsigned long ran; - char m[RFS],ml[RFS],c[RFS],e[RFS],raw[100]; - rsa_public_key pub; - rsa_private_key priv; - csprng RNG; - octet M={0,sizeof(m),m}; - octet ML={0,sizeof(ml),ml}; - octet C={0,sizeof(c),c}; - octet E={0,sizeof(e),e}; - octet RAW={0,sizeof(raw),raw}; - - time((time_t *)&ran); - - RAW.len=100; /* fake random seed source */ - RAW.val[0]=ran; - RAW.val[1]=ran>>8; - RAW.val[2]=ran>>16; - RAW.val[3]=ran>>24; - for (i=4;i<100;i++) RAW.val[i]=i; - - RSA_CREATE_CSPRNG(&RNG,&RAW); /* initialise strong RNG */ - - printf("Generating public/private key pair\n"); - RSA_KEY_PAIR(&RNG,65537,&priv,&pub); - - printf("Encrypting test string\n"); - OCT_jstring(&M,(char *)"Hello World\n"); - RSA_OAEP_ENCODE(&M,&RNG,NULL,&E); /* OAEP encode message m to e */ - - RSA_ENCRYPT(&pub,&E,&C); /* encrypt encoded message */ - printf("Ciphertext= "); OCT_output(&C); - - printf("Decrypting test string\n"); - RSA_DECRYPT(&priv,&C,&ML); /* ... and then decrypt it */ - - RSA_OAEP_DECODE(NULL,&ML); /* decode it */ - OCT_output_string(&ML); - - if (!OCT_comp(&M,&ML)) - { - printf("FAILURE RSA Encryption failed"); - return 1; - } - - OCT_clear(&M); OCT_clear(&ML); /* clean up afterwards */ - OCT_clear(&C); OCT_clear(&RAW); OCT_clear(&E); - - RSA_KILL_CSPRNG(&RNG); - - RSA_PRIVATE_KEY_KILL(&priv); - - printf("SUCCESS\n"); - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_version.c ---------------------------------------------------------------------- diff --git a/c/tests/test_version.c b/c/tests/test_version.c deleted file mode 100755 index a3f726c..0000000 --- a/c/tests/test_version.c +++ /dev/null @@ -1,35 +0,0 @@ -/* -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 version function */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "amcl.h" -#include "config.h" -#include "version.h" - -int main() -{ - char info[200] = {0}; - version(info); - printf("%s\n", info); - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_wcc.c ---------------------------------------------------------------------- diff --git a/c/tests/test_wcc.c b/c/tests/test_wcc.c deleted file mode 100755 index d5204fa..0000000 --- a/c/tests/test_wcc.c +++ /dev/null @@ -1,208 +0,0 @@ -/* -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 and without time permits */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "wcc.h" -#include "utils.h" - -int main() -{ - int i,rtn; - - /* Master secret */ - char ms[PGS]; - octet MS={sizeof(ms),sizeof(ms),ms}; - - // sender key - char akeyG1[2*PFS+1]; - octet AKeyG1={0,sizeof(akeyG1), akeyG1}; - - // receiver key - char bkeyG2[4*PFS]; - octet BKeyG2={0,sizeof(bkeyG2), bkeyG2}; - - char hv[HASH_BYTES],alice_id[256],bob_id[256]; - octet HV={0,sizeof(hv),hv}; - - octet IdA={0,sizeof(alice_id),alice_id}; - octet IdB={0,sizeof(bob_id),bob_id}; - - char x[PGS]; - octet X={sizeof(x),sizeof(x),x}; - char y[PGS]; - octet Y={sizeof(y),sizeof(y),y}; - char w[PGS]; - octet W={sizeof(w),sizeof(w),w}; - char pia[PGS]; - octet PIA={sizeof(pia),sizeof(pia),pia}; - char pib[PGS]; - octet PIB={sizeof(pib),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 seed[32] = {0}; - octet SEED = {0,sizeof(seed),seed}; - csprng RNG; - - char message1[256]; - octet MESSAGE1 = {0, sizeof(message1), message1}; - OCT_jstring(&MESSAGE1,"Hello Bob"); - - char t1[16]; // Tag - char t2[16]; // Tag - char k1[16]; // AES Key - char k2[16]; // AES Key - char iv[12]; // 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; - - int hashDoneOn = 1; - int hashDoneOff = 0; - - date = 0; - - /* unrandom seed value! */ - SEED.len=32; - for (i=0;i<32;i++) SEED.val[i]=i+1; - - /* initialise random number generator */ - WCC_CREATE_CSPRNG(&RNG,&SEED); - - /* TA: Generate master secret */ - rtn = WCC_RANDOM_GENERATE(&RNG,&MS); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS) Error %d\n", rtn); - return 1; - } - - // Alice's ID - OCT_jstring(&IdA,"[email protected]"); - - // TA: Generate Alices's sender key - WCC_HASH_ID(&IdA,&HV); - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS,&HV,&AKeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } - - // Bob's ID - OCT_jstring(&IdB,"[email protected]"); - - // TA: Generate Bob's receiver key - WCC_HASH_ID(&IdB,&HV); - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS,&HV,&BKeyG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_MULTIPLE() Error %d\n", rtn); - return 1; - } - - rtn = WCC_RANDOM_GENERATE(&RNG,&X); - if (rtn != 0) { - printf("Alice WCC_RANDOM_GENERATE(&RNG,&X) Error %d\n", rtn); - return 1; - } - - rtn = WCC_GET_G1_MULTIPLE(hashDoneOff,&X,&IdA,&PaG1); - if (rtn != 0) { - printf("Alice WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } - - rtn = WCC_RANDOM_GENERATE(&RNG,&W); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&W) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G1_MULTIPLE(hashDoneOff,&W,&IdA,&PgG1); - if (rtn != 0) { - printf("Bob WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } - - rtn = WCC_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } - - rtn = WCC_GET_G2_MULTIPLE(hashDoneOff,&Y,&IdB,&PbG2); - if (rtn != 0) { - printf("Bob WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - - // Bob calculates AES Key - WCC_RECEIVER_KEY(date, &Y, &W, &PIA, &PIB, &PaG1, &PgG1, &BKeyG2, NULL, &IdA, &K2); - if (rtn != 0) { - printf("Bob WCC_RECEIVER_KEY() Error %d\n", rtn); - return 1; - } - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - - // Alice calculates AES Key - rtn = WCC_SENDER_KEY(date, &X, &PIA, &PIB, &PbG2, &PgG1, &AKeyG1, NULL, &IdB, &K1); - if (rtn != 0) { - printf("Alice WCC_SENDER_KEY() Error %d\n", rtn); - return 1; - } - - if (!OCT_comp(&K1,&K2)) - { - printf("FAILURE No Time Permit Test. OCT_comp(&K1,&K2)\n"); - return 1; - } - - WCC_KILL_CSPRNG(&RNG); - - printf("SUCCESS\n"); - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_wcc_gcm.c ---------------------------------------------------------------------- diff --git a/c/tests/test_wcc_gcm.c b/c/tests/test_wcc_gcm.c deleted file mode 100755 index 5cef3a9..0000000 --- a/c/tests/test_wcc_gcm.c +++ /dev/null @@ -1,105 +0,0 @@ -/* -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. -*/ - -#include <stdlib.h> -#include <string.h> -#include "amcl.h" -#include "wcc.h" -#include "utils.h" - - -int main() -{ - char* KT="feffe9928665731c6d6a8f9467308308"; - char* MT="d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39"; - char* HT="feedfacedeadbeeffeedfacedeadbeefabaddad2"; - char* NT="9313225df88406e555909c5aff5269aa6a7a9538534f7da1e4c303d2a318a728c3c0c95156809539fcf0e2429a6b525416aedbf5a0de6a57a637b39b"; - // Tag should be 619cc5aefffe0bfa462af43c1699d050 - - int lenM=strlen(MT)/2; - int lenH=strlen(HT)/2; - int lenK=strlen(KT)/2; - int lenIV=strlen(NT)/2; - - char t1[16]; // Tag - char t2[16]; // Tag - char k[16]; // AES Key - char h[64]; // Header - to be included in Authentication, but not encrypted - char iv[100]; // IV - Initialisation vector - char m[100]; // Plaintext to be encrypted/authenticated - char c[100]; // Ciphertext - char p[100]; // Recovered Plaintext - octet T1={sizeof(t1),sizeof(t1),t1}; - octet T2={sizeof(t2),sizeof(t2),t2}; - octet K={0,sizeof(k),k}; - octet H={0,sizeof(h),h}; - octet IV={0,sizeof(iv),iv}; - octet M={0,sizeof(m),m}; - octet C={0,sizeof(c),c}; - octet P={0,sizeof(p),p}; - M.len=lenM; - K.len=lenK; - H.len=lenH; - IV.len=lenIV; - - hex2bytes(MT, m); - hex2bytes(HT, h); - hex2bytes(NT, iv); - hex2bytes(KT, k); - - printf("Plaintext: "); - OCT_output(&M); - printf("\n"); - - WCC_AES_GCM_ENCRYPT(&K, &IV, &H, &M, &C, &T1); - - printf("Ciphertext: "); - OCT_output(&C); - printf("\n"); - - printf("Encryption Tag: "); - OCT_output(&T1); - printf("\n"); - - WCC_AES_GCM_DECRYPT(&K, &IV, &H, &C, &P, &T2); - - printf("Plaintext: "); - OCT_output(&P); - printf("\n"); - - printf("Decryption Tag: "); - OCT_output(&T2); - printf("\n"); - - if (!OCT_comp(&M,&P)) - { - printf("FAILURE Decryption\n"); - return 1; - } - - if (!OCT_comp(&T1,&T2)) - { - printf("FAILURE TAG mismatch\n"); - return 1; - } - - printf("SUCCESS\n"); - return 0; -} - http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_wcc_random.c ---------------------------------------------------------------------- diff --git a/c/tests/test_wcc_random.c b/c/tests/test_wcc_random.c deleted file mode 100755 index 5749adf..0000000 --- a/c/tests/test_wcc_random.c +++ /dev/null @@ -1,469 +0,0 @@ -/* -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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "config.h" -#include "wcc.h" - -#define DEBUG - -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 main() -{ - int i,rtn,iter; - - /* Master secret shares */ - char ms1[PGS], ms2[PGS]; - octet MS1={sizeof(ms1),sizeof(ms1),ms1}; - octet MS2={sizeof(ms2),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={sizeof(a1TPG1),sizeof(a1TPG1), a1TPG1}; - octet A2TPG1={sizeof(a2TPG1),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={sizeof(b1TPG2),sizeof(b1TPG2), b1TPG2}; - octet B2TPG2={sizeof(b2TPG2),sizeof(b2TPG2), b2TPG2}; - char bTPG2[4*PFS]; - octet BTPG2={0,sizeof(bTPG2), bTPG2}; - - char ahv[HASH_BYTES],alice_id[256],bhv[HASH_BYTES],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={sizeof(x),sizeof(x),x}; - char y[PGS]; - octet Y={sizeof(y),sizeof(y),y}; - char w[PGS]; - octet W={sizeof(w),sizeof(w),w}; - char pia[PGS]; - octet PIA={sizeof(pia),sizeof(pia),pia}; - char pib[PGS]; - octet PIB={sizeof(pib),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[16]; // Tag - char t2[16]; // Tag - char k1[16]; // AES Key - char k2[16]; // AES Key - char iv[12]; // 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; - int hashDoneOff = 0; - - OCT_jstring(&MESSAGE1,"Hello Bob"); - OCT_jstring(&MESSAGE2,"Hello Alice"); - - unsigned long ran; - int byte_count = 32; - FILE *fp; - char seed[32] = {0}; - octet SEED = {sizeof(seed),sizeof(seed),seed}; - csprng RNG; - -#ifdef __linux__ - size_t readSize; - fp = fopen("/dev/urandom", "r"); - readSize = fread(&seed, 1, byte_count, fp); - fclose(fp); -#else - /* non random seed value! */ - 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<byte_count;i++) SEED.val[i]=i+1; -#endif - printf("SEED 0x"); - OCT_output(&SEED); - - /* initialise random number generator */ - WCC_CREATE_CSPRNG(&RNG,&SEED); - - for(iter=1; iter<nRandomTests+1; iter++) { - - /* Generate Client master secret for MIRACL and Customer */ - rtn = WCC_RANDOM_GENERATE(&RNG,&MS1); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn); - return 1; - } - rtn = WCC_RANDOM_GENERATE(&RNG,&MS2); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS2) Error %d\n", rtn); - return 1; - } - printf("TA MASTER SECRET MIRACL: "); - OCT_output(&MS1); - printf("TA MASTER SECRET CUSTOMER: "); - OCT_output(&MS2); - - // Alice's ID - rand_str(alice_id,256,&RNG); - OCT_jstring(&IdA,alice_id); - printf("ALICE ID: %s\n", alice_id); - - // TA: Generate Alice's sender key - WCC_HASH_ID(&IdA,&AHV); - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS1,&AHV,&A1KeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE(hashDoneOn,&MS1,&AHV,&A1KeyG1) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS2,&AHV,&A2KeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE(hashDoneOn,&MS2,&AHV,&A2KeyG1) Error %d\n", rtn); - return 1; - } - printf("TA A1KeyG1: "); - OCT_output(&A1KeyG1); - printf("TA A2KeyG1: "); - OCT_output(&A2KeyG1); - - rtn = WCC_RECOMBINE_G1(&A1KeyG1, &A2KeyG1, &AKeyG1); - if (rtn != 0) { - printf("TA WCC_RECOMBINE_G1(&A1KeyG1, &A2KeyG1, &AKeyG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender key: "); - OCT_output(&AKeyG1); - - // TA: Generate Alice's G1 time permit - rtn = WCC_GET_G1_PERMIT(date,&MS1,&AHV,&A1TPG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_PERMIT(date,&MS1,&AHV,&A1TPG1) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G1_PERMIT(date,&MS2,&AHV,&A2TPG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_PERMIT(date,&MS2,&AHV,&A2TPG1) Error %d\n", rtn); - return 1; - } - printf("TA A1TPG1: "); - OCT_output(&A1TPG1); - printf("TA A2TPG1: "); - OCT_output(&A2TPG1); - - rtn = WCC_RECOMBINE_G1(&A1TPG1, &A2TPG1, &ATPG1); - if (rtn != 0) { - printf("Alice WCC_RECOMBINE_G1(&A1TPG1, &A2TPG1, &ATPG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender time permit: "); - OCT_output(&ATPG1); - - // Bob's ID - rand_str(bob_id,256,&RNG); - OCT_jstring(&IdB,bob_id); - printf("BOB ID: %s\n", bob_id); - - // TA: Generate Bob's receiver key - WCC_HASH_ID(&IdB,&BHV); - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS1,&BHV,&B1KeyG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_MULTIPLE(hashDoneOn,&MS1,&BHV,&B1KeyG2) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS2,&BHV,&B2KeyG2); - if (rtn != 0) { - printf("Bob WCC_GET_G2_MULTIPLE(hashDoneOn,&MS2,&BHV,&B2KeyG2) Error %d\n", rtn); - return 1; - } - printf("TA B1KeyG2: "); - OCT_output(&B1KeyG2); - printf("TA B2KeyG2: "); - OCT_output(&B2KeyG2); - - rtn = WCC_RECOMBINE_G2(&B1KeyG2, &B2KeyG2, &BKeyG2); - if (rtn != 0) { - printf("Bob WCC_RECOMBINE_G2(&B1KeyG1, &B2KeyG1, &BKeyG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver key: "); - OCT_output(&BKeyG2); - - // TA: Generate Bob's receiver time permit - rtn = WCC_GET_G2_PERMIT(date,&MS1,&BHV,&B1TPG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_PERMIT(date,&MS1,&BHV,&B1TPG2) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G2_PERMIT(date,&MS2,&BHV,&B2TPG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_PERMIT(date,&MS2,&BHV,&B2TPG2) Error %d\n", rtn); - return 1; - } - printf("TA B1TPG2: "); - OCT_output(&B1TPG2); - printf("TA B2TPG2: "); - OCT_output(&B2TPG2); - - rtn = WCC_RECOMBINE_G2(&B1TPG2, &B2TPG2, &BTPG2); - if (rtn != 0) { - printf("Bob WCC_RECOMBINE_G2(&B1TPG2, &B2TPG2, &BTPG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver time permit: "); - OCT_output(&BTPG2); - printf("\n"); - - printf("Alice\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&X); - if (rtn != 0) { - printf("Alice WCC_RANDOM_GENERATE(&RNG,&X) Error %d\n", rtn); - return 1; - } - #ifdef DEBUG - printf("Alice X: "); - OCT_output(&X); - printf("\n"); - #endif - - rtn = WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1); - if (rtn != 0) { - printf("Alice WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1) Error %d\n", rtn); - return 1; - } - - printf("Alice sends IdA and PaG1 to Bob\n\n"); - printf("Alice IdA: "); - OCT_output_string(&IdA); - printf("\n"); - printf("Alice PaG1: "); - OCT_output(&PaG1); - printf("\n"); - - printf("Bob\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&W); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&W) Error %d\n", rtn); - return 1; - } - #ifdef DEBUG - printf("Bob W: "); - OCT_output(&W); - printf("\n"); - #endif - rtn = WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1) Error %d\n", rtn); - return 1; - } - #ifdef DEBUG - printf("PgG1: "); - OCT_output(&PgG1); - printf("\n"); - #endif - - rtn = WCC_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } - #ifdef DEBUG - printf("Bob Y: "); - OCT_output(&Y); - printf("\n"); - #endif - rtn = WCC_GET_G2_TPMULT(date,&Y,&IdB,&PbG2); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&Y,&IdB,&PbG2) Error %d\n", rtn); - return 1; - } - #ifdef DEBUG - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); - #endif - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - - #ifdef DEBUG - printf("Bob PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Bob PIB: "); - OCT_output(&PIB); - printf("\n"); - #endif - - // Bob calculates AES Key - WCC_RECEIVER_KEY(date, &Y, &W, &PIA, &PIB, &PaG1, &PgG1, &BKeyG2, &BTPG2, &IdA, &K2); - if (rtn != 0) { - printf("Bob WCC_RECEIVER_KEY() Error %d\n", rtn); - return 1; - } - printf("Bob AES Key: "); - OCT_output(&K2); - - printf("Bob sends IdB, PbG2 and PgG1 to Alice\n\n"); - printf("Bob IdB: "); - OCT_output_string(&IdB); - printf("\n"); - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); - printf("Bob PgG1: "); - OCT_output(&PgG1); - printf("\n"); - - printf("Alice\n"); - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - - #ifdef DEBUG - printf("Alice PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Alice PIB: "); - OCT_output(&PIB); - printf("\n"); - #endif - - // Alice calculates AES Key - rtn = WCC_SENDER_KEY(date, &X, &PIA, &PIB, &PbG2, &PgG1, &AKeyG1, &ATPG1, &IdB, &K1); - if (rtn != 0) { - printf("Alice WCC_SENDER_KEY() Error %d\n", rtn); - return 1; - } - printf("Alice AES Key: "); - OCT_output(&K1); - - // Send message - IV.len=12; - for (i=0;i<IV.len;i++) - IV.val[i]=i+1; - printf("Alice: IV "); - OCT_output(&IV); - - printf("Alice: Message to encrypt for Bob: "); - OCT_output_string(&MESSAGE1); - printf("\n"); - - WCC_AES_GCM_ENCRYPT(&K1, &IV, &IdA, &MESSAGE1, &C, &T1); - - printf("Alice: Ciphertext: "); - OCT_output(&C); - - printf("Alice: Encryption Tag: "); - OCT_output(&T1); - printf("\n"); - - WCC_AES_GCM_DECRYPT(&K2, &IV, &IdA, &C, &P, &T2); - - printf("Bob: Decrypted message received from Alice: "); - OCT_output_string(&P); - printf("\n"); - - printf("Bob: Decryption Tag: "); - OCT_output(&T2); - printf("\n"); - - if (!OCT_comp(&MESSAGE1,&P)) { - printf("FAILURE Decryption\n"); - return 1; - } - - if (!OCT_comp(&T1,&T2)) { - printf("FAILURE TAG mismatch\n"); - return 1; - } - printf("Iteration %d SUCCESS \n\n", iter); - } - - WCC_KILL_CSPRNG(&RNG); - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/testwcc.c ---------------------------------------------------------------------- diff --git a/c/testwcc.c b/c/testwcc.c deleted file mode 100755 index f01300d..0000000 --- a/c/testwcc.c +++ /dev/null @@ -1,340 +0,0 @@ -/* -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. -*/ - - -/* Demonstrate WCC with one TA and no time permits */ - -/* Build executible after installation: - gcc -std=c99 -g testwcc.c -I/opt/amcl/include -L/opt/amcl/lib -lamcl -lwcc -o testwcc */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "wcc.h" - -#define DEBUG - -int main() -{ - int i,rtn; - - /* Master secret */ - char ms[PGS]; - octet MS={sizeof(ms),sizeof(ms),ms}; - - // sender keys - char akeyG1[2*PFS+1]; - octet AKeyG1={0,sizeof(akeyG1), akeyG1}; - - // receiver keys - char bkeyG2[4*PFS]; - octet BKeyG2={0,sizeof(bkeyG2), bkeyG2}; - - char hv[HASH_BYTES],alice_id[256],bob_id[256]; - octet HV={0,sizeof(hv),hv}; - - octet IdA={0,sizeof(alice_id),alice_id}; - octet IdB={0,sizeof(bob_id),bob_id}; - - char x[PGS]; - octet X={sizeof(x),sizeof(x),x}; - char y[PGS]; - octet Y={sizeof(y),sizeof(y),y}; - char w[PGS]; - octet W={sizeof(w),sizeof(w),w}; - char pia[PGS]; - octet PIA={sizeof(pia),sizeof(pia),pia}; - char pib[PGS]; - octet PIB={sizeof(pib),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 seed[32] = {0}; - octet SEED = {0,sizeof(seed),seed}; - csprng RNG; - - char message1[256]; - octet MESSAGE1 = {0, sizeof(message1), message1}; - OCT_jstring(&MESSAGE1,"Hello Bob"); - - char t1[16]; // Tag - char t2[16]; // Tag - char k1[16]; // AES Key - char k2[16]; // AES Key - char iv[12]; // 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; - - int hashDoneOn = 1; - int hashDoneOff = 0; - - date = 0; -#ifdef DEBUG - printf("Date %d \n", date); -#endif - - /* unrandom seed value! */ - SEED.len=32; - for (i=0;i<32;i++) SEED.val[i]=i+1; -#ifdef DEBUG - printf("SEED: "); - OCT_output(&SEED); - printf("\n"); -#endif - - /* initialise random number generator */ - WCC_CREATE_CSPRNG(&RNG,&SEED); - - /* TA: Generate master secret */ - rtn = WCC_RANDOM_GENERATE(&RNG,&MS); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("TA MASTER SECRET: "); - OCT_output(&MS); - printf("\n"); -#endif - - // Alice's ID - OCT_jstring(&IdA,"[email protected]"); - - // TA: Generate Alices's sender key - WCC_HASH_ID(&IdA,&HV); - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS,&HV,&AKeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("TA Alice's sender key: "); - OCT_output(&AKeyG1); -#endif - - // Bob's ID - OCT_jstring(&IdB,"[email protected]"); - - // TA: Generate Bob's receiver key - WCC_HASH_ID(&IdB,&HV); - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS,&HV,&BKeyG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_MULTIPLE() Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("TA Bob's receiver key: "); - OCT_output(&BKeyG2); - printf("\n"); -#endif - - printf("Alice\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&X); - if (rtn != 0) { - printf("Alice WCC_RANDOM_GENERATE(&RNG,&X) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Alice X: "); - OCT_output(&X); - printf("\n"); -#endif - - rtn = WCC_GET_G1_MULTIPLE(hashDoneOff,&X,&IdA,&PaG1); - if (rtn != 0) { - printf("Alice WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } - - printf("Alice sends IdA and PaG1 to Bob\n\n"); - printf("Alice IdA: "); - OCT_output_string(&IdA); - printf("\n"); - printf("Alice PaG1: "); - OCT_output(&PaG1); - printf("\n"); - - printf("Bob\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&W); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&W) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob W: "); - OCT_output(&W); - printf("\n"); -#endif - rtn = WCC_GET_G1_MULTIPLE(hashDoneOff,&W,&IdA,&PgG1); - if (rtn != 0) { - printf("Bob WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("PgG1: "); - OCT_output(&PgG1); - printf("\n"); -#endif - - rtn = WCC_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob Y: "); - OCT_output(&Y); - printf("\n"); -#endif - rtn = WCC_GET_G2_MULTIPLE(hashDoneOff,&Y,&IdB,&PbG2); - if (rtn != 0) { - printf("Bob WCC_GET_G1_MULTIPLE() Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); -#endif - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Bob PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Bob PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Bob calculates AES Key - WCC_RECEIVER_KEY(date, &Y, &W, &PIA, &PIB, &PaG1, &PgG1, &BKeyG2, NULL, &IdA, &K2); - if (rtn != 0) { - printf("Bob WCC_RECEIVER_KEY() Error %d\n", rtn); - return 1; - } - printf("Bob AES Key: "); - OCT_output(&K2); - - printf("Bob sends IdB, PbG2 and PgG1 to Alice\n\n"); - printf("Bob IdB: "); - OCT_output_string(&IdB); - printf("\n"); - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); - printf("Bob PgG1: "); - OCT_output(&PgG1); - printf("\n"); - - printf("Alice\n"); - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Alice PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Alice PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Alice calculates AES Key - rtn = WCC_SENDER_KEY(date, &X, &PIA, &PIB, &PbG2, &PgG1, &AKeyG1, NULL, &IdB, &K1); - if (rtn != 0) { - printf("Alice WCC_SENDER_KEY() Error %d\n", rtn); - return 1; - } - printf("Alice AES Key: "); - OCT_output(&K1); - - - // Send message - IV.len=12; - for (i=0;i<IV.len;i++) - IV.val[i]=i+1; - printf("Alice: IV "); - OCT_output(&IV); - - printf("Alice: Message to encrypt for Bob: "); - OCT_output_string(&MESSAGE1); - printf("\n"); - - WCC_AES_GCM_ENCRYPT(&K1, &IV, &IdA, &MESSAGE1, &C, &T1); - - printf("Alice: Ciphertext: "); - OCT_output(&C); - - printf("Alice: Encryption Tag: "); - OCT_output(&T1); - printf("\n"); - - WCC_AES_GCM_DECRYPT(&K2, &IV, &IdA, &C, &P, &T2); - - printf("Bob: Decrypted message received from Alice: "); - OCT_output_string(&P); - printf("\n"); - - printf("Bob: Decryption Tag: "); - OCT_output(&T2); - printf("\n"); - - if (!OCT_comp(&MESSAGE1,&P)) { - printf("FAILURE Decryption\n"); - return 1; - } - - if (!OCT_comp(&T1,&T2)) { - printf("FAILURE TAG mismatch\n"); - return 1; - } - - WCC_KILL_CSPRNG(&RNG); - - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/testwcc_dta.c ---------------------------------------------------------------------- diff --git a/c/testwcc_dta.c b/c/testwcc_dta.c deleted file mode 100755 index d05d70f..0000000 --- a/c/testwcc_dta.c +++ /dev/null @@ -1,438 +0,0 @@ -/* -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. -*/ - - -/* Demonstrate WCC with two TAs and time permits */ - -/* Build executible after installation: - gcc -std=c99 -g testwcc_dta.c -I/opt/amcl/include -L/opt/amcl/lib -lamcl -lwcc -o testwcc_dta */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "mpin.h" -#include "wcc.h" - -#define DEBUG - -int main() -{ - int i,rtn; - - /* Master secret shares */ - char ms1[PGS], ms2[PGS]; - octet MS1={sizeof(ms1),sizeof(ms1),ms1}; - octet MS2={sizeof(ms2),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={sizeof(a1TPG1),sizeof(a1TPG1), a1TPG1}; - octet A2TPG1={sizeof(a2TPG1),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={sizeof(b1TPG2),sizeof(b1TPG2), b1TPG2}; - octet B2TPG2={sizeof(b2TPG2),sizeof(b2TPG2), b2TPG2}; - char bTPG2[4*PFS]; - octet BTPG2={0,sizeof(bTPG2), bTPG2}; - - char ahv[HASH_BYTES],alice_id[256],bhv[HASH_BYTES],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={sizeof(x),sizeof(x),x}; - char y[PGS]; - octet Y={sizeof(y),sizeof(y),y}; - char w[PGS]; - octet W={sizeof(w),sizeof(w),w}; - char pia[PGS]; - octet PIA={sizeof(pia),sizeof(pia),pia}; - char pib[PGS]; - octet PIB={sizeof(pib),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 seed[32] = {0}; - octet SEED = {0,sizeof(seed),seed}; - csprng RNG; - - char message1[256]; - char message2[256]; - octet MESSAGE1 = {0, sizeof(message1), message1}; - octet MESSAGE2 = {0, sizeof(message2), message2}; - - char t1[16]; // Tag - char t2[16]; // Tag - char k1[16]; // AES Key - char k2[16]; // AES Key - char iv[12]; // 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; - int hashDoneOff = 0; - - OCT_jstring(&MESSAGE1,"Hello Bob"); - OCT_jstring(&MESSAGE2,"Hello Alice"); - - /* unrandom seed value! */ - SEED.len=32; - for (i=0;i<32;i++) SEED.val[i]=i+1; - - /* initialise random number generator */ - WCC_CREATE_CSPRNG(&RNG,&SEED); - - /* Generate Client master secret for MIRACL and Customer */ - rtn = WCC_RANDOM_GENERATE(&RNG,&MS1); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn); - return 1; - } - rtn = WCC_RANDOM_GENERATE(&RNG,&MS2); - if (rtn != 0) - { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS2) Error %d\n", rtn); - return 1; - } - printf("TA MASTER SECRET MIRACL: "); - OCT_output(&MS1); - printf("TA MASTER SECRET CUSTOMER: "); - OCT_output(&MS2); - - // Alice's ID - OCT_jstring(&IdA,"[email protected]"); - - // TA: Generate Alice's sender key - WCC_HASH_ID(&IdA,&AHV); - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS1,&AHV,&A1KeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE(hashDoneOn,&MS1,&AHV,&A1KeyG1) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS2,&AHV,&A2KeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE(hashDoneOn,&MS2,&AHV,&A2KeyG1) Error %d\n", rtn); - return 1; - } - printf("TA A1KeyG1: "); - OCT_output(&A1KeyG1); - printf("TA A2KeyG1: "); - OCT_output(&A2KeyG1); - - rtn = WCC_RECOMBINE_G1(&A1KeyG1, &A2KeyG1, &AKeyG1); - if (rtn != 0) { - printf("TA WCC_RECOMBINE_G1(&A1KeyG1, &A2KeyG1, &AKeyG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender key: "); - OCT_output(&AKeyG1); - - // TA: Generate Alice's G1 time permit - rtn = WCC_GET_G1_PERMIT(date,&MS1,&AHV,&A1TPG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_PERMIT(date,&MS1,&AHV,&A1TPG1) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G1_PERMIT(date,&MS2,&AHV,&A2TPG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_PERMIT(date,&MS2,&AHV,&A2TPG1) Error %d\n", rtn); - return 1; - } - printf("TA A1TPG1: "); - OCT_output(&A1TPG1); - printf("TA A2TPG1: "); - OCT_output(&A2TPG1); - - rtn = WCC_RECOMBINE_G1(&A1TPG1, &A2TPG1, &ATPG1); - if (rtn != 0) { - printf("Alice WCC_RECOMBINE_G1(&A1TPG1, &A2TPG1, &ATPG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender time permit: "); - OCT_output(&ATPG1); - - // Bob's ID - OCT_jstring(&IdB,"[email protected]"); - - // TA: Generate Bob's receiver key - WCC_HASH_ID(&IdB,&BHV); - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS1,&BHV,&B1KeyG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_MULTIPLE(hashDoneOn,&MS1,&BHV,&B1KeyG2) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS2,&BHV,&B2KeyG2); - if (rtn != 0) { - printf("Bob WCC_GET_G2_MULTIPLE(hashDoneOn,&MS2,&BHV,&B2KeyG2) Error %d\n", rtn); - return 1; - } - printf("TA B1KeyG2: "); - OCT_output(&B1KeyG2); - printf("TA B2KeyG2: "); - OCT_output(&B2KeyG2); - - rtn = WCC_RECOMBINE_G2(&B1KeyG2, &B2KeyG2, &BKeyG2); - if (rtn != 0) { - printf("Bob WCC_RECOMBINE_G2(&B1KeyG1, &B2KeyG1, &BKeyG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver key: "); - OCT_output(&BKeyG2); - - // TA: Generate Bob's receiver time permit - rtn = WCC_GET_G2_PERMIT(date,&MS1,&BHV,&B1TPG2); - if (rtn != 0) - { - printf("TA WCC_GET_G2_PERMIT(date,&MS1,&BHV,&B1TPG2) Error %d\n", rtn); - return 1; - } - rtn = WCC_GET_G2_PERMIT(date,&MS2,&BHV,&B2TPG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_PERMIT(date,&MS2,&BHV,&B2TPG2) Error %d\n", rtn); - return 1; - } - printf("TA B1TPG2: "); - OCT_output(&B1TPG2); - printf("TA B2TPG2: "); - OCT_output(&B2TPG2); - - rtn = WCC_RECOMBINE_G2(&B1TPG2, &B2TPG2, &BTPG2); - if (rtn != 0) { - printf("Bob WCC_RECOMBINE_G2(&B1TPG2, &B2TPG2, &BTPG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver time permit: "); - OCT_output(&BTPG2); - printf("\n"); - - printf("Alice\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&X); - if (rtn != 0) { - printf("Alice WCC_RANDOM_GENERATE(&RNG,&X) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Alice X: "); - OCT_output(&X); - printf("\n"); -#endif - - rtn = WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1); - if (rtn != 0) { - printf("Alice WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1) Error %d\n", rtn); - return 1; - } - - printf("Alice sends IdA and PaG1 to Bob\n\n"); - printf("Alice IdA: "); - OCT_output_string(&IdA); - printf("\n"); - printf("Alice PaG1: "); - OCT_output(&PaG1); - printf("\n"); - - printf("Bob\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&W); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&W) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob W: "); - OCT_output(&W); - printf("\n"); -#endif - rtn = WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("PgG1: "); - OCT_output(&PgG1); - printf("\n"); -#endif - - rtn = WCC_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob Y: "); - OCT_output(&Y); - printf("\n"); -#endif - rtn = WCC_GET_G2_TPMULT(date,&Y,&IdB,&PbG2); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&Y,&IdB,&PbG2) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); -#endif - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Bob PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Bob PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Bob calculates AES Key - WCC_RECEIVER_KEY(date, &Y, &W, &PIA, &PIB, &PaG1, &PgG1, &BKeyG2, &BTPG2, &IdA, &K2); - if (rtn != 0) { - printf("Bob WCC_RECEIVER_KEY() Error %d\n", rtn); - return 1; - } - printf("Bob AES Key: "); - OCT_output(&K2); - - printf("Bob sends IdB, PbG2 and PgG1 to Alice\n\n"); - printf("Bob IdB: "); - OCT_output_string(&IdB); - printf("\n"); - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); - printf("Bob PgG1: "); - OCT_output(&PgG1); - printf("\n"); - - printf("Alice\n"); - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Alice PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Alice PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Alice calculates AES Key - rtn = WCC_SENDER_KEY(date, &X, &PIA, &PIB, &PbG2, &PgG1, &AKeyG1, &ATPG1, &IdB, &K1); - if (rtn != 0) { - printf("Alice WCC_SENDER_KEY() Error %d\n", rtn); - return 1; - } - printf("Alice AES Key: "); - OCT_output(&K1); - - // Send message - IV.len=12; - for (i=0;i<IV.len;i++) - IV.val[i]=i+1; - printf("Alice: IV "); - OCT_output(&IV); - - printf("Alice: Message to encrypt for Bob: "); - OCT_output_string(&MESSAGE1); - printf("\n"); - - WCC_AES_GCM_ENCRYPT(&K1, &IV, &IdA, &MESSAGE1, &C, &T1); - - printf("Alice: Ciphertext: "); - OCT_output(&C); - - printf("Alice: Encryption Tag: "); - OCT_output(&T1); - printf("\n"); - - WCC_AES_GCM_DECRYPT(&K2, &IV, &IdA, &C, &P, &T2); - - printf("Bob: Decrypted message received from Alice: "); - OCT_output_string(&P); - printf("\n"); - - printf("Bob: Decryption Tag: "); - OCT_output(&T2); - printf("\n"); - - if (!OCT_comp(&MESSAGE1,&P)) { - printf("FAILURE Decryption\n"); - return 1; - } - - if (!OCT_comp(&T1,&T2)) { - printf("FAILURE TAG mismatch\n"); - return 1; - } - - WCC_KILL_CSPRNG(&RNG); - - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/testwcc_tp.c ---------------------------------------------------------------------- diff --git a/c/testwcc_tp.c b/c/testwcc_tp.c deleted file mode 100755 index 280fa85..0000000 --- a/c/testwcc_tp.c +++ /dev/null @@ -1,357 +0,0 @@ -/* -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. -*/ - - -/* Demonstrate WCC with time permits */ - -/* Build executible after installation: - gcc -std=c99 -g testwcc_dta.c -I/opt/amcl/include -L/opt/amcl/lib -lamcl -lwcc -o testwcc_dta */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "mpin.h" -#include "wcc.h" - -#define DEBUG - -int main() -{ - int i,rtn; - - /* Master secret shares */ - char ms[PGS]; - octet MS={sizeof(ms),sizeof(ms),ms}; - - // Sender key - char akeyG1[2*PFS+1]; - octet AKeyG1={0,sizeof(akeyG1), akeyG1}; - - // Sender time permits - char aTPG1[2*PFS+1]; - octet ATPG1={sizeof(aTPG1),sizeof(aTPG1), aTPG1}; - - // Receiver keys - char bkeyG2[4*PFS]; - octet BKeyG2={0,sizeof(bkeyG2), bkeyG2}; - - // Receiver time permits - char bTPG2[4*PFS]; - octet BTPG2={sizeof(bTPG2),sizeof(bTPG2), bTPG2}; - - char ahv[HASH_BYTES],alice_id[256],bhv[HASH_BYTES],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={sizeof(x),sizeof(x),x}; - char y[PGS]; - octet Y={sizeof(y),sizeof(y),y}; - char w[PGS]; - octet W={sizeof(w),sizeof(w),w}; - char pia[PGS]; - octet PIA={sizeof(pia),sizeof(pia),pia}; - char pib[PGS]; - octet PIB={sizeof(pib),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 seed[32] = {0}; - octet SEED = {0,sizeof(seed),seed}; - csprng RNG; - - char message1[256]; - char message2[256]; - octet MESSAGE1 = {0, sizeof(message1), message1}; - octet MESSAGE2 = {0, sizeof(message2), message2}; - - char t1[16]; // Tag - char t2[16]; // Tag - char k1[16]; // AES Key - char k2[16]; // AES Key - char iv[12]; // 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; - int hashDoneOff = 0; - - OCT_jstring(&MESSAGE1,"Hello Bob"); - OCT_jstring(&MESSAGE2,"Hello Alice"); - - /* unrandom seed value! */ - SEED.len=32; - for (i=0;i<32;i++) SEED.val[i]=i+1; - - /* initialise random number generator */ - WCC_CREATE_CSPRNG(&RNG,&SEED); - - /* Generate Client master secret for MIRACL and Customer */ - rtn = WCC_RANDOM_GENERATE(&RNG,&MS); - if (rtn != 0) { - printf("TA WCC_RANDOM_GENERATE(&RNG,&MS) Error %d\n", rtn); - return 1; - } - printf("TA MASTER SECRET: "); - OCT_output(&MS); - - // Alice's ID - OCT_jstring(&IdA,"[email protected]"); - - // TA: Generate Alice's sender key - WCC_HASH_ID(&IdA,&AHV); - rtn = WCC_GET_G1_MULTIPLE(hashDoneOn,&MS,&AHV,&AKeyG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_MULTIPLE(hashDoneOn,&MS,&AHV,&AKeyG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender key: "); - OCT_output(&AKeyG1); - - // TA: Generate Alice's G1 time permit - rtn = WCC_GET_G1_PERMIT(date,&MS,&AHV,&ATPG1); - if (rtn != 0) { - printf("TA WCC_GET_G1_PERMIT(date,&MS,&AHV,&ATPG1) Error %d\n", rtn); - return 1; - } - printf("TA Alice's sender time permit: "); - OCT_output(&ATPG1); - - // Bob's ID - OCT_jstring(&IdB,"[email protected]"); - - // TA: Generate Bob's receiver key - WCC_HASH_ID(&IdB,&BHV); - rtn = WCC_GET_G2_MULTIPLE(hashDoneOn,&MS,&BHV,&BKeyG2); - if (rtn != 0) { - printf("TA WCC_GET_G2_MULTIPLE(hashDoneOn,&MS,&BHV,&BKeyG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver key: "); - OCT_output(&BKeyG2); - - // TA: Generate Bob's receiver time permit - rtn = WCC_GET_G2_PERMIT(date,&MS,&BHV,&BTPG2); - if (rtn != 0) - { - printf("TA WCC_GET_G2_PERMIT(date,&MS,&BHV,&BTPG2) Error %d\n", rtn); - return 1; - } - printf("TA Bob's receiver time permit: "); - OCT_output(&BTPG2); - printf("\n"); - - printf("Alice\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&X); - if (rtn != 0) { - printf("Alice WCC_RANDOM_GENERATE(&RNG,&X) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Alice X: "); - OCT_output(&X); - printf("\n"); -#endif - - rtn = WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1); - if (rtn != 0) { - printf("Alice WCC_GET_G1_TPMULT(date,&X,&IdA,&PaG1) Error %d\n", rtn); - return 1; - } - - printf("Alice sends IdA and PaG1 to Bob\n\n"); - printf("Alice IdA: "); - OCT_output_string(&IdA); - printf("\n"); - printf("Alice PaG1: "); - OCT_output(&PaG1); - printf("\n"); - - printf("Bob\n"); - - rtn = WCC_RANDOM_GENERATE(&RNG,&W); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&W) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob W: "); - OCT_output(&W); - printf("\n"); -#endif - rtn = WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&W,&IdA,&PgG1) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("PgG1: "); - OCT_output(&PgG1); - printf("\n"); -#endif - - rtn = WCC_RANDOM_GENERATE(&RNG,&Y); - if (rtn != 0) { - printf("Bob WCC_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob Y: "); - OCT_output(&Y); - printf("\n"); -#endif - rtn = WCC_GET_G2_TPMULT(date,&Y,&IdB,&PbG2); - if (rtn != 0) { - printf("Bob WCC_GET_G1_TPMULT(date,&Y,&IdB,&PbG2) Error %d\n", rtn); - return 1; - } -#ifdef DEBUG - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); -#endif - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Bob PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Bob PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Bob calculates AES Key - WCC_RECEIVER_KEY(date, &Y, &W, &PIA, &PIB, &PaG1, &PgG1, &BKeyG2, &BTPG2, &IdA, &K2); - if (rtn != 0) { - printf("Bob WCC_RECEIVER_KEY() Error %d\n", rtn); - return 1; - } - printf("Bob AES Key: "); - OCT_output(&K2); - - printf("Bob sends IdB, PbG2 and PgG1 to Alice\n\n"); - printf("Bob IdB: "); - OCT_output_string(&IdB); - printf("\n"); - printf("Bob PbG2: "); - OCT_output(&PbG2); - printf("\n"); - printf("Bob PgG1: "); - OCT_output(&PgG1); - printf("\n"); - - printf("Alice\n"); - - // pia = Hq(PaG1,PbG2,PgG1,IdB) - WCC_Hq(&PaG1,&PbG2,&PgG1,&IdB,&PIA); - - // pib = Hq(PbG2,PaG1,PgG1,IdA) - WCC_Hq(&PbG2,&PaG1,&PgG1,&IdA,&PIB); - -#ifdef DEBUG - printf("Alice PIA: "); - OCT_output(&PIA); - printf("\n"); - printf("Alice PIB: "); - OCT_output(&PIB); - printf("\n"); -#endif - - // Alice calculates AES Key - rtn = WCC_SENDER_KEY(date, &X, &PIA, &PIB, &PbG2, &PgG1, &AKeyG1, &ATPG1, &IdB, &K1); - if (rtn != 0) { - printf("Alice WCC_SENDER_KEY() Error %d\n", rtn); - return 1; - } - printf("Alice AES Key: "); - OCT_output(&K1); - - // Send message - IV.len=12; - for (i=0;i<IV.len;i++) - IV.val[i]=i+1; - printf("Alice: IV "); - OCT_output(&IV); - - printf("Alice: Message to encrypt for Bob: "); - OCT_output_string(&MESSAGE1); - printf("\n"); - - WCC_AES_GCM_ENCRYPT(&K1, &IV, &IdA, &MESSAGE1, &C, &T1); - - printf("Alice: Ciphertext: "); - OCT_output(&C); - - printf("Alice: Encryption Tag: "); - OCT_output(&T1); - printf("\n"); - - WCC_AES_GCM_DECRYPT(&K2, &IV, &IdA, &C, &P, &T2); - - printf("Bob: Decrypted message received from Alice: "); - OCT_output_string(&P); - printf("\n"); - - printf("Bob: Decryption Tag: "); - OCT_output(&T2); - printf("\n"); - - if (!OCT_comp(&MESSAGE1,&P)) { - printf("FAILURE Decryption\n"); - return 1; - } - - if (!OCT_comp(&T1,&T2)) { - printf("FAILURE TAG mismatch\n"); - return 1; - } - - WCC_KILL_CSPRNG(&RNG); - - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/utils.c ---------------------------------------------------------------------- diff --git a/c/utils.c b/c/utils.c deleted file mode 100755 index 592780e..0000000 --- a/c/utils.c +++ /dev/null @@ -1,97 +0,0 @@ -/* -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. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "amcl.h" -#include "utils.h" - -void hex2bytes(char *hex, char *bin) -{ - int i; - char v; - int len=strlen(hex); - for (i = 0; i < len/2; i++) { - char c = hex[2*i]; - if (c >= '0' && c <= '9') { - v = c - '0'; - } else if (c >= 'A' && c <= 'F') { - v = c - 'A' + 10; - } else if (c >= 'a' && c <= 'f') { - v = c - 'a' + 10; - } else { - v = 0; - } - v <<= 4; - c = hex[2*i + 1]; - if (c >= '0' && c <= '9') { - v += c - '0'; - } else if (c >= 'A' && c <= 'F') { - v += c - 'A' + 10; - } else if (c >= 'a' && c <= 'f') { - v += c - 'a' + 10; - } else { - v = 0; - } - bin[i] = v; - } -} - -/*! \brief Generate a random six digit one time password - * - * Generates a random six digit one time password - * - * @param RNG random number generator - * @return OTP One Time Password - */ -int generateOTP(csprng* RNG) -{ - int OTP=0; - - int i = 0; - int val = 0; - char byte[6] = {0}; - - /* Generate random 6 digit random value */ - for (i=0;i<6;i++) - { - byte[i]=RAND_byte(RNG); - val = byte[i]; - OTP = ((abs(val) % 10) * pow(10.0,i)) + OTP; - } - - return OTP; -} - -/*! \brief Generate a random Octet - * - * Generate a random Octet - * - * @param RNG random number generator - * @return randomValue random Octet - */ -void generateRandom(csprng *RNG,octet *randomValue) -{ - int i; - for (i=0;i<randomValue->len;i++) - randomValue->val[i]=RAND_byte(RNG); -} - - http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/utils.h ---------------------------------------------------------------------- diff --git a/c/utils.h b/c/utils.h deleted file mode 100755 index d1cbae0..0000000 --- a/c/utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -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. -*/ - -#ifndef UTILS_H -#define UTILS_H - -#include "amcl.h" -#include <math.h> - -DLL_EXPORT void hex2bytes(char *hex, char *bin); -DLL_EXPORT void generateRandom(csprng*, octet*); -DLL_EXPORT int generateOTP(csprng*); - -#endif http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/version.c ---------------------------------------------------------------------- diff --git a/c/version.c b/c/version.c deleted file mode 100755 index 8c2d899..0000000 --- a/c/version.c +++ /dev/null @@ -1,32 +0,0 @@ -/* -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. -*/ - -#include "version.h" - - -/*! \brief Print version number and information about the build - * - * Print version number and information about the build - * - */ -void version(char* info) -{ - sprintf(info,"Version: %d.%d.%d OS: %s FIELD CHOICE: %s CURVE TYPE: %s WORD_LENGTH: %d", AMCL_VERSION_MAJOR, AMCL_VERSION_MINOR, AMCL_VERSION_PATCH, OS, FIELD_CHOICE, CURVE_TYPE, CHUNK); -} - http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/version.h ---------------------------------------------------------------------- diff --git a/c/version.h b/c/version.h deleted file mode 100755 index 18a899f..0000000 --- a/c/version.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -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. -*/ - -#ifndef VERSION_H -#define VERSION_H - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "amcl.h" - -DLL_EXPORT void version(char* info); - -#endif
