http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/c/tests/CMakeLists.txt b/c/tests/CMakeLists.txt deleted file mode 100644 index bdafec1..0000000 --- a/c/tests/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -# Create tests - -# add the binary tree directory to the search path for include files and linking -include_directories (${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/c ${PROJECT_BINARY_DIR}/c ) -link_directories (${PROJECT_BINARY_DIR}/c) - -# enable testing -enable_testing () - -#define a macro to simplify adding tests -macro (do_test arg result) - add_test (${arg} ${arg}) - set_tests_properties (${arg} - PROPERTIES PASS_REGULAR_EXPRESSION ${result} - ) -endmacro () - -if(BUILD_MPIN) - add_executable (test_mpin test_mpin.c) - add_executable (test_mpin_sign test_mpin_sign.c) - add_executable (test_mpin_good test_mpin_good.c) - add_executable (test_mpin_bad_pin test_mpin_bad_pin.c) - add_executable (test_mpin_bad_token test_mpin_bad_token.c) - add_executable (test_mpin_expired_tp test_mpin_expired_tp.c) - add_executable (test_mpin_tp test_mpin_tp.c config.h) - add_executable (test_mpin_random test_mpin_random.c config.h) - add_executable (test_mpinfull test_mpinfull.c) - add_executable (test_mpinfullSingle test_mpinfullSingle.c) - add_executable (test_mpinfull_random test_mpinfull_random.c config.h) - # Link the executable to the libraries - target_link_libraries (test_mpin mpin) - target_link_libraries (test_mpin_sign mpin) - target_link_libraries (test_mpin_good mpin) - target_link_libraries (test_mpin_bad_pin mpin) - target_link_libraries (test_mpin_bad_token mpin) - target_link_libraries (test_mpin_expired_tp mpin) - target_link_libraries (test_mpin_tp mpin) - target_link_libraries (test_mpin_random mpin) - target_link_libraries (test_mpinfull mpin) - target_link_libraries (test_mpinfullSingle mpin) - target_link_libraries (test_mpinfull_random mpin) - # tests - do_test (test_mpin "SUCCESS Error Code 0") - do_test (test_mpin_sign "TEST PASSED") - do_test (test_mpin_good "SUCCESS Error Code 0") - do_test (test_mpin_bad_pin "FAILURE") - do_test (test_mpin_bad_token "FAILURE Invalid Token Error Code -19") - do_test (test_mpin_expired_tp "FAILURE Invalid Token Error Code -19") - do_test (test_mpin_tp "Iteration ${MPIN_TIME_PERMIT_TESTS} SUCCESS Error Code 0") - do_test (test_mpin_random "Iteration ${MPIN_RANDOM_TESTS} SUCCESS Error Code 0") - do_test (test_mpinfull "SUCCESS") - do_test (test_mpinfullSingle "SUCCESS") - do_test (test_mpinfull_random "Iteration ${MPIN_RANDOM_TESTS} SUCCESS") -endif(BUILD_MPIN) - -if(BUILD_WCC) - add_executable (test_wcc_gcm test_wcc_gcm.c) - add_executable (test_wcc test_wcc.c) - add_executable (test_wcc_random test_wcc_random.c) - # Link the executable to the libraries - target_link_libraries (test_wcc_gcm wcc) - target_link_libraries (test_wcc wcc) - target_link_libraries (test_wcc_random wcc) - # tests - do_test (test_wcc_gcm "SUCCESS") - do_test (test_wcc "SUCCESS") - do_test (test_wcc_random "SUCCESS") -endif(BUILD_WCC) - -# General tests -add_executable (test_rsa ${PROJECT_SOURCE_DIR}/c/rsa.c test_rsa.c) -add_executable (test_ecm ${PROJECT_SOURCE_DIR}/c/ecdh.c test_ecm.c) -add_executable (test_ecdh ${PROJECT_SOURCE_DIR}/c/ecdh.c test_ecdh.c) -add_executable (test_version test_version.c) -# Link the executable to the libraries -target_link_libraries (test_rsa amcl) -target_link_libraries (test_ecm amcl) -target_link_libraries (test_ecdh amcl) -target_link_libraries (test_version amcl) -# tests -do_test (test_rsa "SUCCESS") -do_test (test_ecm "SUCCESS") -do_test (test_ecdh "SUCCESS") -do_test (test_version "Version: ${AMCL_VERSION_MAJOR}.${AMCL_VERSION_MINOR}.${AMCL_VERSION_PATCH} OS: ${OS} FIELD CHOICE: ${FIELD_CHOICE} CURVE TYPE: ${CURVE_TYPE} WORD_LENGTH: ${WORD_LENGTH}")
http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/config.h.in ---------------------------------------------------------------------- diff --git a/c/tests/config.h.in b/c/tests/config.h.in deleted file mode 100644 index 7240997..0000000 --- a/c/tests/config.h.in +++ /dev/null @@ -1,2 +0,0 @@ -const int nTimePermitTests = @MPIN_TIME_PERMIT_TESTS@; -const int nRandomTests = @MPIN_RANDOM_TESTS@; http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_ecdh.c ---------------------------------------------------------------------- diff --git a/c/tests/test_ecdh.c b/c/tests/test_ecdh.c deleted file mode 100755 index 8bb9e8c..0000000 --- a/c/tests/test_ecdh.c +++ /dev/null @@ -1,168 +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 ECDH/ECIES/ECDSA API Functions */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "ecdh.h" - -int main() -{ - int i,j=0,res; - int result; - unsigned long ran; - char *pp="M0ng00se"; - /* These octets are automatically protected against buffer overflow attacks */ - /* Note salt must be big enough to include an appended word */ - /* Note ECIES ciphertext C must be big enough to include at least 1 appended block */ - /* Recall EFS is field size in bytes. So EFS=32 for 256-bit curve */ - char s0[EGS],s1[EGS],w0[2*EFS+1],w1[2*EFS+1],z0[EFS],z1[EFS],raw[100],key[EAS],salt[32],pw[20],p1[30],p2[30],v[2*EFS+1],m[32],c[64],t[32],cs[EGS],ds[EGS]; - octet S0={0,sizeof(s0),s0}; - octet S1={0,sizeof(s1),s1}; - octet W0={0,sizeof(w0),w0}; - octet W1={0,sizeof(w1),w1}; - octet Z0={0,sizeof(z0),z0}; - octet Z1={0,sizeof(z1),z1}; - octet RAW={0,sizeof(raw),raw}; - octet KEY={0,sizeof(key),key}; - octet SALT={0,sizeof(salt),salt}; - octet PW={0,sizeof(pw),pw}; - octet P1={0,sizeof(p1),p1}; - octet P2={0,sizeof(p2),p2}; - octet V={0,sizeof(v),v}; - octet M={0,sizeof(m),m}; - octet C={0,sizeof(c),c}; - octet T={0,sizeof(t),t}; - octet CS={0,sizeof(cs),cs}; - octet DS={0,sizeof(ds),ds}; - - /* Crypto Strong RNG */ - csprng RNG; - time((time_t *)&ran); - /* fake random seed source */ - RAW.len=100; - RAW.val[0]=ran; - RAW.val[1]=ran>>8; - RAW.val[2]=ran>>16; - RAW.val[3]=ran>>24; - for (i=0;i<100;i++) RAW.val[i]=i; - /* initialise strong RNG */ - ECP_CREATE_CSPRNG(&RNG,&RAW); - - SALT.len=8; - for (i=0;i<8;i++) SALT.val[i]=i+1; // set Salt - - printf("Alice's Passphrase= %s\n",pp); - - OCT_empty(&PW); - OCT_jstring(&PW,pp); // set Password from string - - /* private key S0 of size EGS bytes derived from Password and Salt */ - ECP_PBKDF2(&PW,&SALT,1000,EGS,&S0); - printf("Alices private key= 0x"); OCT_output(&S0); - - /* Generate Key pair S/W */ - ECP_KEY_PAIR_GENERATE(NULL,&S0,&W0); - - res=ECP_PUBLIC_KEY_VALIDATE(1,&W0); - if (res!=0) - { - printf("ECP Public Key is invalid!\n"); - return 1; - } - - printf("Alice's public key= 0x"); OCT_output(&W0); - - /* Random private key for other party */ - ECP_KEY_PAIR_GENERATE(&RNG,&S1,&W1); - res=ECP_PUBLIC_KEY_VALIDATE(1,&W1); - if (res!=0) - { - printf("ECP Public Key is invalid!\n"); - return 1; - } - printf("Servers private key= 0x"); OCT_output(&S1); - printf("Servers public key= 0x"); OCT_output(&W1); - - /* Calculate common key using DH - IEEE 1363 method */ - ECP_SVDP_DH(&S0,&W1,&Z0); - ECP_SVDP_DH(&S1,&W0,&Z1); - - if (!OCT_comp(&Z0,&Z1)) - { - printf("*** ECPSVDP-DH Failed\n"); - return 0; - } - - ECP_KDF2(&Z0,NULL,EAS,&KEY); - - printf("Alice's DH Key= 0x"); OCT_output(&KEY); - printf("Servers DH Key= 0x"); OCT_output(&KEY); - - printf("Testing ECIES\n"); - - P1.len=3; P1.val[0]=0x0; P1.val[1]=0x1; P1.val[2]=0x2; - P2.len=4; P2.val[0]=0x0; P2.val[1]=0x1; P2.val[2]=0x2; P2.val[3]=0x3; - - M.len=17; - for (i=0;i<=16;i++) M.val[i]=i; - - ECP_ECIES_ENCRYPT(&P1,&P2,&RNG,&W1,&M,12,&V,&C,&T); - - printf("Ciphertext= \n"); - printf("V= 0x"); OCT_output(&V); - printf("C= 0x"); OCT_output(&C); - printf("T= 0x"); OCT_output(&T); - - if (!ECP_ECIES_DECRYPT(&P1,&P2,&V,&C,&T,&S1,&M)) - { - printf("*** ECIES Decryption Failed\n"); - return 1; - } - else printf("Decryption succeeded\n"); - - printf("Message is 0x"); OCT_output(&M); - - printf("Testing ECDSA\n"); - - if (ECP_SP_DSA(&RNG,&S0,&M,&CS,&DS)!=0) - { - printf("***ECDSA Signature Failed\n"); - return 1; - } - - printf("Signature C = 0x"); OCT_output(&CS); - printf("Signature D = 0x"); OCT_output(&DS); - - if (ECP_VP_DSA(&W0,&M,&CS,&DS)!=0) - { - printf("***ECDSA Verification Failed\n"); - return 1; - } - else printf("ECDSA Signature/Verification succeeded %d\n",j); - - ECP_KILL_CSPRNG(&RNG); - - printf("SUCCESS\n"); - return 0; -} - http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_ecm.c ---------------------------------------------------------------------- diff --git a/c/tests/test_ecm.c b/c/tests/test_ecm.c deleted file mode 100755 index c96e4ab..0000000 --- a/c/tests/test_ecm.c +++ /dev/null @@ -1,118 +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 ECDH API Functions only - suitable for testing Montgomery curves */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "ecdh.h" - -int main() -{ - int i,j=0,res; - int result; - unsigned long ran; - char *pp="M0ng00se"; - /* These octets are automatically protected against buffer overflow attacks */ - /* Note salt must be big enough to include an appended word */ - /* Note ECIES ciphertext C must be big enough to include at least 1 appended block */ - /* Recall EFS is field size in bytes. So EFS=32 for 256-bit curve */ - char s0[EGS],s1[EGS],w0[2*EFS+1],w1[2*EFS+1],z0[EFS],z1[EFS],raw[100],key[EAS],salt[32],pw[20]; - octet S0={0,sizeof(s0),s0}; - octet S1={0,sizeof(s1),s1}; - octet W0={0,sizeof(w0),w0}; - octet W1={0,sizeof(w1),w1}; - octet Z0={0,sizeof(z0),z0}; - octet Z1={0,sizeof(z1),z1}; - octet RAW={0,sizeof(raw),raw}; - octet KEY={0,sizeof(key),key}; - octet SALT={0,sizeof(salt),salt}; - octet PW={0,sizeof(pw),pw}; - - /* Crypto Strong RNG */ - csprng RNG; - time((time_t *)&ran); - /* fake random seed source */ - RAW.len=100; - 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; - - ECP_CREATE_CSPRNG(&RNG,&RAW); /* initialise strong RNG */ - - SALT.len=8; - for (i=0;i<8;i++) SALT.val[i]=i+1; // set Salt - - printf("Alice's Passphrase= %s\n",pp); - - OCT_clear(&PW); - OCT_jstring(&PW,pp); // set Password from string - - /* private key S0 of size EGS bytes derived from Password and Salt */ - ECP_PBKDF2(&PW,&SALT,1000,EGS,&S0); - printf("Alices private key= 0x"); OCT_output(&S0); - - /* Generate Key pair S/W */ - ECP_KEY_PAIR_GENERATE(NULL,&S0,&W0); - - res=ECP_PUBLIC_KEY_VALIDATE(1,&W0); - if (res!=0) - { - printf("Alice's ECP Public Key is invalid!\n"); - return 1; - } - - printf("Alice's public key= 0x"); OCT_output(&W0); - - /* Random private key for other party */ - ECP_KEY_PAIR_GENERATE(&RNG,&S1,&W1); - printf("Servers private key= 0x"); OCT_output(&S1); - printf("Servers public key= 0x"); OCT_output(&W1); - - res=ECP_PUBLIC_KEY_VALIDATE(1,&W1); - if (res!=0) - { - printf("Server's ECP Public Key is invalid!\n"); - return 1; - } - - /* Calculate common key using DH - IEEE 1363 method */ - - ECP_SVDP_DH(&S0,&W1,&Z0); - ECP_SVDP_DH(&S1,&W0,&Z1); - - if (!OCT_comp(&Z0,&Z1)) - { - printf("*** ECPSVDP-DH Failed\n"); - return 1; - } - - ECP_KDF2(&Z0,NULL,EAS,&KEY); - - printf("Alice's DH Key= 0x"); OCT_output(&KEY); - printf("Servers DH Key= 0x"); OCT_output(&KEY); - - printf("SUCCESS\n"); - return 0; -} - http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin.c b/c/tests/test_mpin.c deleted file mode 100755 index b747fc9..0000000 --- a/c/tests/test_mpin.c +++ /dev/null @@ -1,243 +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. 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}; - - /* 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}; - - 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}; - - 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); - - /* 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); - - /* Single pass MPIN protocol */ - /* 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); - - /* Server */ - rtn = MPIN_SERVER(date,NULL,&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); - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_bad_pin.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_bad_pin.c b/c/tests/test_mpin_bad_pin.c deleted file mode 100755 index 454cbfc..0000000 --- a/c/tests/test_mpin_bad_pin.c +++ /dev/null @@ -1,256 +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 incorrect PIN with D-TA */ - -#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],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 ID */ - char hcid[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - PIN1 = 1234; - PIN2 = 1237; - - /* Assign the End-User an ID */ - char* user = "[email protected]"; - OCT_jstring(&ID,user); - printf("CLIENT: ID %s\n", user); - - int date = 16512; - 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 */ - 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); - - /* 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 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; - } - - /* 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); - - /* 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) - printf("FAILURE PIN Error %d, Error Code %d\n",err, rtn); - else - printf("FAILURE Invalid Token Error Code %d\n", rtn); - } else { - printf("SUCCESS Error Code %d\n", rtn); - OCT_output_string(&ID); - printf("\n"); - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_bad_token.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_bad_token.c b/c/tests/test_mpin_bad_token.c deleted file mode 100755 index 61e4838..0000000 --- a/c/tests/test_mpin_bad_token.c +++ /dev/null @@ -1,255 +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 bad token and correct PIN with D-TA */ - -#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],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 ID */ - char hcid[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - 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); - - /* 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 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; - } - - /* 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); - - /* 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 */ - /* Set SEC to UT to simulate a bad token */ - rtn = MPIN_SERVER_2(date,&HID,&HTID,&Y,&ServerSecret,&U,&UT,&UT,&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); - } else { - printf("SUCCESS Error Code %d\n", rtn); - OCT_output_string(&ID); printf("\n"); - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_expired_tp.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_expired_tp.c b/c/tests/test_mpin_expired_tp.c deleted file mode 100755 index cb7f23e..0000000 --- a/c/tests/test_mpin_expired_tp.c +++ /dev/null @@ -1,255 +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 and expired time permit */ - -#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],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 ID */ - char hcid[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - 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); - int yesterday = date -1; - rtn = MPIN_GET_CLIENT_PERMIT(yesterday,&MS1,&HCID,&TP1); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(yesterday,&MS1,&HCID,&TP1) Error %d\n", rtn); - return 1; - } - rtn = MPIN_GET_CLIENT_PERMIT(yesterday,&MS2,&HCID,&TP2); - if (rtn != 0) { - printf("MPIN_GET_CLIENT_PERMIT(yesterday,&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); - - /* 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 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; - } - - /* 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); - - /* 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); - } else { - printf("SUCCESS Error Code %d\n", rtn); - OCT_output_string(&ID); printf("\n"); - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_good.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_good.c b/c/tests/test_mpin_good.c deleted file mode 100755 index d43de5e..0000000 --- a/c/tests/test_mpin_good.c +++ /dev/null @@ -1,259 +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 "mpin.h" - -int main() -{ - int i,PIN1,PIN2,rtn,err; - - 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[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - 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); - - /* 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 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; - } - - /* 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); - - /* Client second pass */ - rtn = MPIN_CLIENT_2(&X,&Y,&SEC); - if (rtn != 0) { - printf("MPIN_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn); - return 1; - } - 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); - } - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_random.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_random.c b/c/tests/test_mpin_random.c deleted file mode 100755 index 645cb19..0000000 --- a/c/tests/test_mpin_random.c +++ /dev/null @@ -1,298 +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 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 ID */ - char hcid[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - 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__ - 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 */ - 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 */ - char id[256]; - octet ID = {0,sizeof(id),id}; - rand_str(id,256,&RNG); - OCT_jstring(&ID,id); - printf("CLIENT: ID %s\n", id); - - /* Hash ID */ - MPIN_HASH_ID(&ID,&HCID); - OCT_output(&HCID); - -#ifdef USE_ANONYMOUS - pID = &HCID; -#else - pID = &ID; -#endif - - srand ( time (NULL) ); - PIN1 = rand()%MAX_RANGE; // Get random between 0 and MAX_RANGE - PIN2 = PIN1; - printf("PIN1 %d PIN2 %d\n", PIN1, PIN2); - - /* 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); - - /* 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); - - /* 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); - - /* 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; - } - - /* 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); - - /* Client second pass */ - rtn = MPIN_CLIENT_2(&X,&Y,&SEC); - if (rtn != 0) { - printf("MPIN_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn); - return 1; - } - 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("Iteration %d FAILURE Invalid Token Error Code %d\n", iter, rtn); - return 1; - } else { - printf("Iteration %d FAILURE PIN Error %d, Error Code %d\n", iter, err, rtn); - return 1; - } - } else { - printf("Iteration %d SUCCESS Error Code %d\n\n", iter, rtn); - } - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_sign.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_sign.c b/c/tests/test_mpin_sign.c deleted file mode 100755 index 7743e66..0000000 --- a/c/tests/test_mpin_sign.c +++ /dev/null @@ -1,324 +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 Signature */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "mpin.h" - -int main() -{ - int i,PIN1,PIN2,rtn,err; - - int failure = 0; - - char id[256]; - octet ID = {0,sizeof(id),id}; - - // Message to sign - char m[256]; - octet M={0,sizeof(m),m}; - - 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}; - - /* 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}; - - 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}; - - - - 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); - - /* 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); - - /* Good signature */ - - /* Client */ - char* message = "sign this message"; - OCT_jstring(&M,message); - TimeValue = MPIN_GET_TIME(); - printf("TimeValue %d \n", TimeValue); - rtn = MPIN_CLIENT(date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,NULL,&UT,&TP,&M,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); - - /* Server */ - rtn = MPIN_SERVER(date,NULL,&HTID,&Y2,&ServerSecret,NULL,&UT,&SEC,&E,&F,pID,&M,TimeValue); - printf("Y2 = 0x"); - OCT_output(&Y2); - if (rtn != 0) { - failure = 1; - printf("FAILURE valid signature not detected %d\n", rtn); - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - - /* Time stamp expired */ - - /* Client */ - OCT_clear(&M); - message = "sign this message"; - OCT_jstring(&M,message); - TimeValue = MPIN_GET_TIME(); - printf("TimeValue %d \n", TimeValue); - rtn = MPIN_CLIENT(date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,NULL,&UT,&TP,&M,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); - - /* Server */ - TimeValue += 10; - rtn = MPIN_SERVER(date,NULL,&HTID,&Y2,&ServerSecret,NULL,&UT,&SEC,&E,&F,pID,&M,TimeValue); - printf("Y2 = 0x"); - OCT_output(&Y2); - if (rtn != -19) { - failure = 1; - printf("FAILURE Invalid signature not detected %d\n", rtn); - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - - /* Invalid data */ - - /* Client */ - OCT_clear(&M); - message = "sign this message"; - OCT_jstring(&M,message); - TimeValue = MPIN_GET_TIME(); - printf("TimeValue %d \n", TimeValue); - rtn = MPIN_CLIENT(date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,NULL,&UT,&TP,&M,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); - - /* Server */ - OCT_clear(&M); - message = "bad message"; - OCT_jstring(&M,message); - rtn = MPIN_SERVER(date,NULL,&HTID,&Y2,&ServerSecret,NULL,&UT,&SEC,&E,&F,pID,&M,TimeValue); - printf("Y2 = 0x"); - OCT_output(&Y2); - if (rtn != -19) { - failure = 1; - printf("FAILURE Invalid signature not detected %d\n", rtn); - } else { - printf("SUCCESS Error Code %d\n", rtn); - } - - if (failure != 0) { - printf("TEST FAILED\n"); - return 1; - } - - printf("TEST PASSED\n"); - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpin_tp.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpin_tp.c b/c/tests/test_mpin_tp.c deleted file mode 100755 index 05562b9..0000000 --- a/c/tests/test_mpin_tp.c +++ /dev/null @@ -1,266 +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 for - nTimePermitTests days in the future */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include "config.h" -#include "mpin.h" - -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 ID */ - char hcid[32]; - octet HCID={sizeof(hcid),sizeof(hcid), hcid}; - - /* 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}; - - 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}; - - octet *pID; - - 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 */ -#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); - - /* 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); - - /* Generate Time Permit shares */ - date = MPIN_today(); - for(iter=1; iter<nTimePermitTests+1; iter++) - { - 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); - - /* 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; - } - - /* 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); - - /* Client second pass */ - rtn = MPIN_CLIENT_2(&X,&Y,&SEC); - if (rtn != 0) { - printf("MPIN_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn); - return 1; - } - 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("Iteration %d FAILURE Invalid Token Error Code %d\n", iter, rtn); - break; - } else { - printf("Iteration %d FAILURE PIN Error %d, Error Code %d\n", iter, err, rtn); - break; - } - } else { - printf("Iteration %d SUCCESS Error Code %d\n", iter, rtn); - } - date++; - } - return 0; -} http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto/blob/70e3a3a3/c/tests/test_mpinfull.c ---------------------------------------------------------------------- diff --git a/c/tests/test_mpinfull.c b/c/tests/test_mpinfull.c deleted file mode 100755 index 10cc857..0000000 --- a/c/tests/test_mpinfull.c +++ /dev/null @@ -1,307 +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 */ - -#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],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 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}; - - 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 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,NULL,&HTID,&Y,&ServerSecret,NULL,&UT,&SEC,&E,&F); - if (rtn != 0) { - printf("FAILURE Invalid Token Error Code %d\n", rtn); - } - - MPIN_HASH_ALL(&HCID,NULL,&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("FAILURE Keys are different\n"); - return 1; - } - - printf("SUCCESS\n"); - return 0; -}
