http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_mpinfull_onepass_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_mpinfull_onepass_ZZZ.c.in 
b/test/test_mpinfull_onepass_ZZZ.c.in
new file mode 100644
index 0000000..5016bbc
--- /dev/null
+++ b/test/test_mpinfull_onepass_ZZZ.c.in
@@ -0,0 +1,331 @@
+/**
+ * @file test_mpinfull_onepass_ZZZ.c
+ * @author Kealan McCusker
+ * @brief Test M-Pin Full Single pass
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* Test M-Pin Full Single pass */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "config_curve_ZZZ.h"
+#include "pbc_support.h"
+#include "randapi.h"
+#if CURVE_SECURITY_ZZZ == 128
+#include "mpin_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 192
+#include "mpin192_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 256
+#include "mpin256_ZZZ.h"
+#endif
+
+#if CURVE_SECURITY_ZZZ == 128
+#define G2LEN 4*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 192
+#define G2LEN 8*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 256
+#define G2LEN 16*PFS_ZZZ
+#endif
+#define GTLEN 3*G2LEN
+
+int main()
+{
+    int i,PIN1,PIN2,rtn;
+
+    char id[256];
+    octet ID = {0,sizeof(id),id};
+
+    char x[PGS_ZZZ],y1[PGS_ZZZ],y2[PGS_ZZZ];
+    octet X= {0, sizeof(x),x};
+    octet Y1= {0,sizeof(y1),y1};
+    octet Y2= {0,sizeof(y2),y2};
+
+    /* Master secret shares */
+    char ms1[PGS_ZZZ], ms2[PGS_ZZZ];
+    octet MS1= {0,sizeof(ms1),ms1};
+    octet MS2= {0,sizeof(ms2),ms2};
+
+    /* Hash values of client ID */
+    char hcid[PFS_ZZZ];
+    octet HCID= {0,sizeof(hcid), hcid};
+
+    /* Hash values of messages */
+    char hm[PFS_ZZZ];
+    octet HM= {0,sizeof(hm), hm};
+
+    /* Client secret and shares */
+    char cs1[2*PFS_ZZZ+1], cs2[2*PFS_ZZZ+1], sec[2*PFS_ZZZ+1];
+    octet SEC= {0,sizeof(sec),sec};
+    octet CS1= {0,sizeof(cs1), cs1};
+    octet CS2= {0,sizeof(cs2), cs2};
+
+    /* Server secret and shares */
+    char ss1[G2LEN], ss2[G2LEN], serverSecret[G2LEN];
+    octet ServerSecret= {0,sizeof(serverSecret),serverSecret};
+    octet SS1= {0,sizeof(ss1),ss1};
+    octet SS2= {0,sizeof(ss2),ss2};
+
+    /* Time Permit and shares */
+    char tp1[2*PFS_ZZZ+1], tp2[2*PFS_ZZZ+1], tp[2*PFS_ZZZ+1];
+    octet TP= {0,sizeof(tp),tp};
+    octet TP1= {0,sizeof(tp1),tp1};
+    octet TP2= {0,sizeof(tp2),tp2};
+
+    /* Token stored on device */
+    char token[2*PFS_ZZZ+1];
+    octet TOKEN= {0,sizeof(token),token};
+
+    /* Precomputed values stored on device */
+    char g1[GTLEN],g2[GTLEN];
+    octet G1= {0,sizeof(g1),g1};
+    octet G2= {0,sizeof(g2),g2};
+
+    char ut[2*PFS_ZZZ+1];
+    octet UT= {0,sizeof(ut),ut};
+
+    char hid[2*PFS_ZZZ+1],htid[2*PFS_ZZZ+1];
+    octet HID= {0,sizeof(hid),hid};
+    octet HTID= {0,sizeof(htid),htid};
+
+    char e[GTLEN], f[GTLEN];
+    octet E= {0,sizeof(e),e};
+    octet F= {0,sizeof(f),f};
+
+    char r[PGS_ZZZ],z[2*PFS_ZZZ+1],w[PGS_ZZZ],t[2*PFS_ZZZ+1];
+    char ck[AESKEY_ZZZ],sk[AESKEY_ZZZ];
+    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 */
+    CREATE_CSPRNG(&RNG,&SEED);
+
+    /* Hash ID */
+    HASH_ID(HASH_TYPE_ZZZ,&ID,&HCID);
+    OCT_output(&HCID);
+
+    /* Generate Client master secret for MIRACL and Customer */
+    rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_GET_SERVER_SECRET(&MS1,&SS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_SERVER_SECRET(&MS2,&SS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G2(&SS1, &SS2, &ServerSecret);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RECOMBINE_G2(&SS1, &SS2, &ServerSecret) Error %d\n", 
rtn);
+        return 1;
+    }
+    printf("ServerSecret = 0x");
+    OCT_output(&ServerSecret);
+
+    /* Generate client secret shares */
+    rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS2,&HCID,&CS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", rtn);
+        return 1;
+    }
+    printf("Client Secret = 0x");
+    OCT_output(&TOKEN);
+
+    /* Generate Time Permit shares */
+    date = today();
+    printf("Date %d \n", date);
+    rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS1,&HCID,&TP1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS1,&HCID,&TP1) 
Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS2,&HCID,&TP2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,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_ZZZ_RECOMBINE_G1(&TP1, &TP2, &TP);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n");
+    printf("Encoded Time Permit= ");
+    OCT_output(&TP);
+    if (MPIN_ZZZ_DECODING(&TP)!=0) printf("Decoding error\n");
+    printf("Decoded Time Permit= ");
+    OCT_output(&TP);
+
+    /* Client extracts PIN1 from secret to create Token */
+    rtn = MPIN_ZZZ_EXTRACT_PIN(HASH_TYPE_ZZZ,&ID, PIN1, &TOKEN);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_EXTRACT_PIN( &ID, PIN, &TOKEN) Error %d\n", rtn);
+        return 1;
+    }
+    printf("Token = 0x");
+    OCT_output(&TOKEN);
+
+    /* Client precomputation */
+    MPIN_ZZZ_PRECOMPUTE(&TOKEN,&HCID,NULL,&G1,&G2);
+
+    /* Client  */
+    TimeValue = GET_TIME();
+    printf("TimeValue %d \n", TimeValue);
+    rtn = 
MPIN_ZZZ_CLIENT(HASH_TYPE_ZZZ,date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,NULL,&UT,&TP,NULL,TimeValue,&Y1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_GET_G1_MULTIPLE(&RNG,1,&R,&HCID,&Z);
+
+    /* Server  */
+    rtn = 
MPIN_ZZZ_SERVER(HASH_TYPE_ZZZ,date,&HID,&HTID,&Y2,&ServerSecret,NULL,&UT,&SEC,&E,&F,&ID,NULL,TimeValue,NULL);
+
+    printf("Y2 = 0x");
+    OCT_output(&Y2);
+    if (rtn != 0)
+    {
+        printf("FAILURE Invalid Token Error Code %d\n", rtn);
+        return 1;
+    }
+    else
+    {
+        printf("Authenticated Error Code %d\n", rtn);
+    }
+
+    /* Server sends T=w.ID to client */
+    MPIN_ZZZ_GET_G1_MULTIPLE(&RNG,0,&W,&HTID,&T);
+    printf("T = 0x");
+    OCT_output(&T);
+
+    HASH_ALL(HASH_TYPE_ZZZ,&HCID,NULL,&UT,&SEC,&Y1,&Z,&T,&HM);
+    MPIN_ZZZ_CLIENT_KEY(HASH_TYPE_ZZZ,&G1,&G2,PIN2,&R,&X,&HM,&T,&CK);
+    printf("Client Key = ");
+    OCT_output(&CK);
+
+    HASH_ALL(HASH_TYPE_ZZZ,&HCID,NULL,&UT,&SEC,&Y2,&Z,&T,&HM);
+    
MPIN_ZZZ_SERVER_KEY(HASH_TYPE_ZZZ,&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-c/blob/8d28d2c3/test/test_mpinfull_random_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_mpinfull_random_ZZZ.c.in 
b/test/test_mpinfull_random_ZZZ.c.in
new file mode 100644
index 0000000..3ec74bc
--- /dev/null
+++ b/test/test_mpinfull_random_ZZZ.c.in
@@ -0,0 +1,389 @@
+/**
+ * @file test_mpinfull_random_ZZZ.c
+ * @author Kealan McCusker
+ * @brief Test Mpin-full good token and correct PIN with D-TA
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* Test good token and correct PIN with D-TA */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "config_curve_ZZZ.h"
+#include "config_test.h"
+#include "pbc_support.h"
+#include "randapi.h"
+#if CURVE_SECURITY_ZZZ == 128
+#include "mpin_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 192
+#include "mpin192_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 256
+#include "mpin256_ZZZ.h"
+#endif
+
+#if CURVE_SECURITY_ZZZ == 128
+#define G2LEN 4*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 192
+#define G2LEN 8*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 256
+#define G2LEN 16*PFS_ZZZ
+#endif
+#define GTLEN 3*G2LEN
+
+// Define PIN range:
+#define MAX_RANGE 10000
+
+void rand_str(char *dest, size_t length,csprng *RNG)
+{
+    BIG_XXX r;
+    char charset[] = "0123456789@.*"
+                     "abcdefghijklmnopqrstuvwxyz"
+                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    while (length-- > 0)
+    {
+        BIG_XXX_random(r,RNG);
+        size_t index = r[0] % (sizeof charset);
+        *dest++ = charset[index];
+    }
+    *dest = '\0';
+}
+
+int main()
+{
+    int PIN1,PIN2,rtn,err,iter;
+
+    char id[256];
+    octet ID = {0,sizeof(id),id};
+
+    char x[PGS_ZZZ],y[PGS_ZZZ];
+    octet X= {sizeof(x), sizeof(x),x};
+    octet Y= {sizeof(y),sizeof(y),y};
+
+    /* Master secret shares */
+    char ms1[PGS_ZZZ], ms2[PGS_ZZZ];
+    octet MS1= {sizeof(ms1),sizeof(ms1),ms1};
+    octet MS2= {sizeof(ms2),sizeof(ms2),ms2};
+
+    /* Hash values of client ID */
+    char hcid[PFS_ZZZ];
+    octet HCID= {sizeof(hcid),sizeof(hcid), hcid};
+
+    /* Hash values of messages */
+    char hm[PFS_ZZZ];
+    octet HM= {sizeof(hm),sizeof(hm), hm};
+
+    /* Client secret and shares */
+    char cs1[2*PFS_ZZZ+1], cs2[2*PFS_ZZZ+1], sec[2*PFS_ZZZ+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[G2LEN], ss2[G2LEN], serverSecret[G2LEN];
+    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_ZZZ+1], tp2[2*PFS_ZZZ+1], tp[2*PFS_ZZZ+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_ZZZ+1];
+    octet TOKEN= {sizeof(token),sizeof(token),token};
+
+    /* Precomputed values stored on device */
+    char g1[GTLEN],g2[GTLEN];
+    octet G1= {0,sizeof(g1),g1};
+    octet G2= {0,sizeof(g2),g2};
+
+    char ut[2*PFS_ZZZ+1],u[2*PFS_ZZZ+1];
+    octet UT= {sizeof(ut),sizeof(ut),ut};
+    octet U= {sizeof(u),sizeof(u),u};
+
+    char hid[2*PFS_ZZZ+1],htid[2*PFS_ZZZ+1];
+    octet HID= {0,sizeof(hid),hid};
+    octet HTID= {0,sizeof(htid),htid};
+
+    char e[GTLEN], f[GTLEN];
+    octet E= {sizeof(e),sizeof(e),e};
+    octet F= {sizeof(f),sizeof(f),f};
+
+    char r[PGS_ZZZ],z[2*PFS_ZZZ+1],w[PGS_ZZZ],t[2*PFS_ZZZ+1];
+    char ck[AESKEY_ZZZ],sk[AESKEY_ZZZ];
+    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 date = 0;
+
+    int byte_count = 32;
+    char seed[32] = {0};
+    octet SEED = {sizeof(seed),sizeof(seed),seed};
+    csprng RNG;
+#ifdef __linux__
+    FILE *fp;
+    fp = fopen("/dev/urandom", "r");
+    if (fread(&seed, 1, byte_count, fp)) {};
+    fclose(fp);
+#else
+    /* non random seed value! */
+    int i;
+    unsigned long ran;
+    time((time_t *)&ran);
+    SEED.val[0]=ran;
+    SEED.val[1]=ran>>8;
+    SEED.val[2]=ran>>16;
+    SEED.val[3]=ran>>24;
+    for (i=4; i<byte_count; i++) SEED.val[i]=i+1;
+#endif
+    printf("SEED 0x");
+    OCT_output(&SEED);
+
+    /* initialise random number generator */
+    CREATE_CSPRNG(&RNG,&SEED);
+
+    for(iter=1; iter<nRandomTests+1; iter++)
+    {
+        /* Generate Client master secret for MIRACL and Customer */
+        rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn);
+            return 1;
+        }
+        rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS2);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_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_ZZZ_GET_SERVER_SECRET(&MS1,&SS1);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn);
+            return 1;
+        }
+        rtn = MPIN_ZZZ_GET_SERVER_SECRET(&MS2,&SS2);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G2(&SS1, &SS2, &ServerSecret);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_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,255,&RNG);
+        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 */
+        HASH_ID(HASH_TYPE_ZZZ,&ID,&HCID);
+        OCT_output(&HCID);
+
+        /* Generate client secret shares */
+        rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", 
rtn);
+            return 1;
+        }
+        rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS2,&HCID,&CS2);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", 
rtn);
+            return 1;
+        }
+        printf("Client Secret = 0x");
+        OCT_output(&TOKEN);
+
+        /* Generate Time Permit shares */
+        date = today();
+        printf("Date %d \n", date);
+        rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS1,&HCID,&TP1);
+        if (rtn != 0)
+        {
+            
printf("MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS1,&HCID,&TP1) Error 
%d\n", rtn);
+            return 1;
+        }
+        rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,date,&MS2,&HCID,&TP2);
+        if (rtn != 0)
+        {
+            
printf("MPIN_ZZZ_GET_CLIENT_PERMIT(HASH_TYPE_ZZZ,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_ZZZ_RECOMBINE_G1(&TP1, &TP2, &TP);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_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_ZZZ_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n");
+        printf("Encoded Time Permit= ");
+        OCT_output(&TP);
+        if (MPIN_ZZZ_DECODING(&TP)!=0) printf("Decoding error\n");
+        printf("Decoded Time Permit= ");
+        OCT_output(&TP);
+
+        /* Client extracts PIN1 from secret to create Token */
+        rtn = MPIN_ZZZ_EXTRACT_PIN(HASH_TYPE_ZZZ,&ID, PIN1, &TOKEN);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_EXTRACT_PIN( &ID, PIN, &TOKEN) Error %d\n", rtn);
+            return 1;
+        }
+        printf("Token = 0x");
+        OCT_output(&TOKEN);
+
+        /* Client precomputation */
+        MPIN_ZZZ_PRECOMPUTE(&TOKEN,&HCID,NULL,&G1,&G2);
+
+        /* Client first pass */
+        rtn = 
MPIN_ZZZ_CLIENT_1(HASH_TYPE_ZZZ,date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,&U,&UT,&TP);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_CLIENT_1 ERROR %d\n", rtn);
+            return 1;
+        }
+
+        /* Client sends Z=r.ID to Server */
+        MPIN_ZZZ_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_ZZZ_SERVER_1(HASH_TYPE_ZZZ,date,&ID,&HID,&HTID);
+
+        /* Server generates Random number Y and sends it to Client */
+        rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&Y);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn);
+            return 1;
+        }
+        printf("Y = 0x");
+        OCT_output(&Y);
+
+        /* Server sends T=w.ID to client */
+        MPIN_ZZZ_GET_G1_MULTIPLE(&RNG,0,&W,&HTID,&T);
+        printf("T = 0x");
+        OCT_output(&T);
+
+        /* Client second pass */
+        rtn = MPIN_ZZZ_CLIENT_2(&X,&Y,&SEC);
+        if (rtn != 0)
+        {
+            printf("MPIN_ZZZ_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn);
+        }
+        printf("V = 0x");
+        OCT_output(&SEC);
+
+        /* Server second pass */
+        rtn = 
MPIN_ZZZ_SERVER_2(date,&HID,&HTID,&Y,&ServerSecret,&U,&UT,&SEC,&E,&F,NULL);
+
+        if (rtn != 0)
+        {
+            err=MPIN_ZZZ_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);
+            }
+        }
+
+        HASH_ALL(HASH_TYPE_ZZZ,&HCID,&U,&UT,&SEC,&Y,&Z,&T,&HM);
+        MPIN_ZZZ_CLIENT_KEY(HASH_TYPE_ZZZ,&G1,&G2,PIN2,&R,&X,&HM,&T,&CK);
+        printf("Client Key = ");
+        OCT_output(&CK);
+
+        /* Server will use the hashed ID if anonymous connection required.
+        HASH_ID(HASH_TYPE_ZZZ,&ID,&HSID);
+        HASH_ALL(HASH_TYPE_ZZZ,&HSID,NULL,&UT,&SEC,&Y,&Z,&T,&HM);
+        */
+        
MPIN_ZZZ_SERVER_KEY(HASH_TYPE_ZZZ,&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-c/blob/8d28d2c3/test/test_mpinfull_tp_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_mpinfull_tp_ZZZ.c.in b/test/test_mpinfull_tp_ZZZ.c.in
new file mode 100644
index 0000000..bb7f9be
--- /dev/null
+++ b/test/test_mpinfull_tp_ZZZ.c.in
@@ -0,0 +1,382 @@
+/**
+ * @file test_mpinfull_time_permits_ZZZ.c
+ * @author Kealan McCusker
+ * @brief Test M-pin Full
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* Test M-Pin Full */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "config_curve_ZZZ.h"
+#include "pbc_support.h"
+#include "randapi.h"
+#if CURVE_SECURITY_ZZZ == 128
+#include "mpin_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 192
+#include "mpin192_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 256
+#include "mpin256_ZZZ.h"
+#endif
+
+#if CURVE_SECURITY_ZZZ == 128
+#define G2LEN 4*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 192
+#define G2LEN 8*PFS_ZZZ
+#elif CURVE_SECURITY_ZZZ == 256
+#define G2LEN 16*PFS_ZZZ
+#endif
+#define GTLEN 3*G2LEN
+
+// #define DEBUG
+
+int main()
+{
+    int i,PIN1,PIN2,rtn;
+
+    char id[256];
+    octet ID = {0,sizeof(id),id};
+
+    char x[PGS_ZZZ],y[PGS_ZZZ];
+    octet X= {0,sizeof(x),x};
+    octet Y= {0,sizeof(y),y};
+
+    /* Master secret shares */
+    char ms1[PGS_ZZZ], ms2[PGS_ZZZ];
+    octet MS1= {0,sizeof(ms1),ms1};
+    octet MS2= {0,sizeof(ms2),ms2};
+
+    /* Hash values of client ID */
+    char hcid[PFS_ZZZ];
+    octet HCID= {0,sizeof(hcid), hcid};
+
+    /* Hash values of messages */
+    char hm[PFS_ZZZ];
+    octet HM= {0,sizeof(hm), hm};
+
+    /* Client secret and shares */
+    char cs1[2*PFS_ZZZ+1], cs2[2*PFS_ZZZ+1], sec[2*PFS_ZZZ+1];
+    octet SEC= {0,sizeof(sec),sec};
+    octet CS1= {0,sizeof(cs1), cs1};
+    octet CS2= {0,sizeof(cs2), cs2};
+
+    /* Server secret and shares */
+    char ss1[G2LEN], ss2[G2LEN], serverSecret[G2LEN];
+    octet ServerSecret= {0,sizeof(serverSecret),serverSecret};
+    octet SS1= {0,sizeof(ss1),ss1};
+    octet SS2= {0,sizeof(ss2),ss2};
+
+    /* Time Permit and shares */
+    char tp1[2*PFS_ZZZ+1], tp2[2*PFS_ZZZ+1], tp[2*PFS_ZZZ+1];
+    octet TP= {0,sizeof(tp),tp};
+    octet TP1= {0,sizeof(tp1),tp1};
+    octet TP2= {0,sizeof(tp2),tp2};
+
+    /* Token stored on device */
+    char token[2*PFS_ZZZ+1];
+    octet TOKEN= {0,sizeof(token),token};
+
+    /* Precomputed values stored on device */
+    char g1[GTLEN],g2[GTLEN];
+    octet G1= {0,sizeof(g1),g1};
+    octet G2= {0,sizeof(g2),g2};
+
+    char ut[2*PFS_ZZZ+1],u[2*PFS_ZZZ+1];
+    octet UT= {0,sizeof(ut),ut};
+    octet U= {0,sizeof(u),u};
+
+    char hid[2*PFS_ZZZ+1],htid[2*PFS_ZZZ+1];
+    octet HID= {0,sizeof(hid),hid};
+    octet HTID= {0,sizeof(htid),htid};
+
+    char e[GTLEN], f[GTLEN];
+    octet E= {0,sizeof(e),e};
+    octet F= {0,sizeof(f),f};
+
+    char r[PGS_ZZZ],z[2*PFS_ZZZ+1],w[PGS_ZZZ],t[2*PFS_ZZZ+1];
+
+    char ck[AESKEY_ZZZ],sk[AESKEY_ZZZ];
+    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};
+
+    /* AES-GCM */
+    char raw[256], header[16], ciphertext[32], res[32], plaintext[32], 
tag[16], iv[16];
+    octet HEADER= {0,0,header}, Ciphertext= {0,sizeof(ciphertext),ciphertext};
+    octet Plaintext= {0,sizeof(plaintext),plaintext}, Res= 
{0,sizeof(res),res}, Tag= {0,sizeof(tag),tag}, IV= {0,sizeof(iv),iv};
+    csprng rng;
+
+    int hash = SHA256;
+
+    /* Fake random source */
+    RAND_clean(&rng);
+    for (i=0; i<256; i++) raw[i]=(char)i;
+    RAND_seed(&rng,256,raw);
+
+    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 */
+    CREATE_CSPRNG(&RNG,&SEED);
+
+    /* Hash ID */
+    HASH_ID(hash,&ID,&HCID);
+    OCT_output(&HCID);
+
+    /* Generate Client master secret for MIRACL and Customer */
+    rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&MS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_GET_SERVER_SECRET(&MS1,&SS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_SERVER_SECRET(&MS2,&SS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G2(&SS1, &SS2, &ServerSecret);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RECOMBINE_G2(&SS1, &SS2, &ServerSecret) Error %d\n", 
rtn);
+        return 1;
+    }
+    printf("ServerSecret = 0x");
+    OCT_output(&ServerSecret);
+
+    /* Generate client secret shares */
+    rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_CLIENT_SECRET(&MS2,&HCID,&CS2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", rtn);
+        return 1;
+    }
+    printf("Client Secret = 0x");
+    OCT_output(&TOKEN);
+
+    /* Generate Time Permit shares */
+    date = today();
+    printf("Date %d \n", date);
+    rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(hash,date,&MS1,&HCID,&TP1);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_PERMIT(hash,date,&MS1,&HCID,&TP1) Error 
%d\n", rtn);
+        return 1;
+    }
+    rtn = MPIN_ZZZ_GET_CLIENT_PERMIT(hash,date,&MS2,&HCID,&TP2);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_GET_CLIENT_PERMIT(hash,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_ZZZ_RECOMBINE_G1(&TP1, &TP2, &TP);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_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_ZZZ_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n");
+    printf("Encoded Time Permit= ");
+    OCT_output(&TP);
+    if (MPIN_ZZZ_DECODING(&TP)!=0) printf("Decoding error\n");
+    printf("Decoded Time Permit= ");
+    OCT_output(&TP);
+
+    /* Client extracts PIN1 from secret to create Token */
+    rtn = MPIN_ZZZ_EXTRACT_PIN(hash,&ID, PIN1, &TOKEN);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_EXTRACT_PIN( &ID, PIN, &TOKEN) Error %d\n", rtn);
+        return 1;
+    }
+    printf("Token = 0x");
+    OCT_output(&TOKEN);
+
+    /* Client precomputation */
+    MPIN_ZZZ_PRECOMPUTE(&TOKEN,&HCID,NULL,&G1,&G2);
+
+    /* Client first pass */
+    rtn = MPIN_ZZZ_CLIENT_1(hash,date,&ID,&RNG,&X,PIN2,&TOKEN,&SEC,&U,&UT,&TP);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_CLIENT_1 ERROR %d\n", rtn);
+        return 1;
+    }
+
+    /* Client sends Z=r.ID to Server */
+    MPIN_ZZZ_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_ZZZ_SERVER_1(hash,date,&ID,&HID,&HTID);
+
+    /* Server generates Random number Y and sends it to Client */
+    rtn = MPIN_ZZZ_RANDOM_GENERATE(&RNG,&Y);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn);
+        return 1;
+    }
+    printf("Y = 0x");
+    OCT_output(&Y);
+
+    /* Server sends T=w.ID to client */
+    MPIN_ZZZ_GET_G1_MULTIPLE(&RNG,0,&W,&HTID,&T);
+    printf("T = 0x");
+    OCT_output(&T);
+
+    /* Client second pass */
+    rtn = MPIN_ZZZ_CLIENT_2(&X,&Y,&SEC);
+    if (rtn != 0)
+    {
+        printf("MPIN_ZZZ_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn);
+    }
+    printf("V = 0x");
+    OCT_output(&SEC);
+
+    /* Server second pass */
+    rtn = 
MPIN_ZZZ_SERVER_2(date,NULL,&HTID,&Y,&ServerSecret,NULL,&UT,&SEC,&E,&F,NULL);
+
+    if (rtn != 0)
+    {
+        printf("FAILURE Invalid Token Error Code %d\n", rtn);
+    }
+
+    HASH_ALL(hash,&HCID,NULL,&UT,&SEC,&Y,&Z,&T,&HM);
+    MPIN_ZZZ_CLIENT_KEY(hash,&G1,&G2,PIN2,&R,&X,&HM,&T,&CK);
+    printf("Client Key = ");
+    OCT_output(&CK);
+
+    /* Server will use the hashed ID if anonymous connection required.
+    HASH_ID(hash,&ID,&HSID);
+    HASH_ALL(&HSID,NULL,&UT,&SEC,&Y,&Z,&T,&HM);
+    */
+    MPIN_ZZZ_SERVER_KEY(hash,&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;
+    }
+
+    for (i=0; i<10; i++)
+    {
+        /* Self test AES-GCM encyption/decryption */
+        OCT_rand(&IV,&rng,16);
+        OCT_rand(&Plaintext,&rng,32);
+        OCT_copy(&Res,&Plaintext);
+#ifdef DEBUG
+        printf("Plaintext = ");
+        OCT_output(&Plaintext);
+        printf("IV = ");
+        OCT_output(&IV);
+#endif
+        AES_GCM_ENCRYPT(&CK,&IV,&HEADER,&Plaintext,&Ciphertext,&Tag);
+        AES_GCM_DECRYPT(&CK,&IV,&HEADER,&Ciphertext,&Plaintext,&Tag);
+#ifdef DEBUG
+        printf("Ciphertext = ");
+        OCT_output(&Ciphertext);
+#endif
+
+        if (!OCT_comp(&Res,&Plaintext))
+        {
+            printf("FAILURE Encryption/Decryption with AES-GCM\n");
+            return 1;
+        }
+    }
+
+    printf("SUCCESS\n");
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_octet_consistency.c
----------------------------------------------------------------------
diff --git a/test/test_octet_consistency.c b/test/test_octet_consistency.c
new file mode 100644
index 0000000..fa17af1
--- /dev/null
+++ b/test/test_octet_consistency.c
@@ -0,0 +1,134 @@
+/**
+ * @file test_octet_consistency.c
+ * @author Alessandro Budroni
+ * @brief Test function for octect consistency
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* test driver and function exerciser for ECDH/ECIES/ECDSA API Functions */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <time.h>
+#include "amcl.h"
+
+int main()
+{
+    int i,j,len=100;
+    int len64 = ((len/3) + 2)*4+1, lenHex = 28*len;
+    char raw[256], bytes[len+1], bytes64[len64+1], bytesHex[lenHex+1], v[len], 
w[len];
+    octet V= {0,sizeof(v),v}, W= {0,sizeof(w),w};
+    csprng rng;
+
+    /* Fake random source */
+    RAND_clean(&rng);
+    for (i=0; i<256; i++) raw[i]=(char)i;
+    RAND_seed(&rng,256,raw);
+
+    /* test comparison */
+    for (len = 1; len <= 101; len=len+10)
+    {
+        OCT_rand(&W,&rng,len);
+        OCT_copy(&V,&W);
+        if(!OCT_comp(&V,&W))
+        {
+            printf("ERROR comparing two equal octet, OCTET\n");
+            exit(EXIT_FAILURE);
+        }
+        for (i = 0; i < len; ++i)
+        {
+            if(!OCT_ncomp(&V,&W,i))
+            {
+                printf("ERROR comparing two equal octet, OCTET\n");
+                exit(EXIT_FAILURE);
+            }
+        }
+        OCT_rand(&V,&rng,len);
+        if(OCT_comp(&V,&W))
+        {
+            printf("ERROR comparing two different octet, OCTET\n");
+            exit(EXIT_FAILURE);
+        }
+    }
+    OCT_rand(&W,&rng,0);
+    OCT_copy(&V,&W);
+    if(!OCT_comp(&V,&W))
+    {
+        printf("ERROR comparing two equal octet, OCTET\n");
+        exit(EXIT_FAILURE);
+    }
+
+    for (len = 100; len > 0; len=len-10)
+    {
+
+        W.max = len;
+        V.max = len;
+        /* test conversion to and from base64 */
+        for (j = 0; j < 10; ++j)
+        {
+            OCT_rand(&W,&rng,len);
+            OCT_copy(&V,&W);
+            OCT_tobase64(bytes64,&W);
+            OCT_frombase64(&W,bytes64);
+            if(!OCT_comp(&V,&W))
+            {
+                printf("ERROR converting to and from base64 OCTET\n");
+                exit(EXIT_FAILURE);
+            }
+        }
+
+        /* test conversion to and from hex */
+        for (i = 0; i < 10; ++i)
+        {
+            OCT_rand(&W,&rng,len);
+            OCT_copy(&V,&W);
+            OCT_toHex(&W,bytesHex);
+            OCT_fromHex(&W,bytesHex);
+            if(!OCT_comp(&V,&W))
+            {
+                printf("ERROR converting to and from Hex OCTET\n");
+                exit(EXIT_FAILURE);
+            }
+        }
+
+        /* test conversion to and from string */
+        for (i = 0; i < 10; ++i)
+        {
+            OCT_rand(&W,&rng,len);
+            OCT_copy(&V,&W);
+            OCT_toStr(&W,bytes);
+            OCT_jstring(&W,bytes);
+            if(!OCT_comp(&V,&W))
+            {
+                printf("ERROR converting to and from string, OCTET\n");
+                exit(EXIT_FAILURE);
+            }
+        }
+    }
+
+
+
+    printf("SUCCESS\n");
+    return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_output_functions_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_output_functions_ZZZ.c.in 
b/test/test_output_functions_ZZZ.c.in
new file mode 100644
index 0000000..378f015
--- /dev/null
+++ b/test/test_output_functions_ZZZ.c.in
@@ -0,0 +1,695 @@
+/**
+ * @file test_output_functions.c
+ * @author Alessandro Budroni
+ * @brief Test output functions for debug
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "arch.h"
+#include "amcl.h"
+#include "utils.h"
+#include "big_XXX.h"
+#include "fp_YYY.h"
+#include "fp2_YYY.h"
+#include "fp4_YYY.h"
+#include "ecp_ZZZ.h"
+#if CURVE_SECURITY_ZZZ == 128
+#include "fp12_YYY.h"
+#include "ecp2_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 192
+#include "fp8_YYY.h"
+#include "fp24_YYY.h"
+#include "ecp4_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 256
+#include "fp8_YYY.h"
+#include "fp16_YYY.h"
+#include "fp48_YYY.h"
+#include "ecp8_ZZZ.h"
+#endif
+
+extern int dup(int oldfd);
+extern int dup2(int oldfd, int newfd);
+extern int close(int fildes);
+extern int fileno(FILE *stream);
+
+#if CURVE_SECURITY_ZZZ == 128
+#define LINE_LEN 2000
+#elif CURVE_SECURITY_ZZZ == 192
+#define LINE_LEN 4000
+#elif CURVE_SECURITY_ZZZ == 256
+#define LINE_LEN 8000
+#endif
+
+
+/*
+ * Skips n closed brackets.
+ * Null terminates after the nth bracket and
+ * returns a pointer to the next char
+ */
+char* skip_cb(char* str, int n)
+{
+    int i;
+    char* next=str;
+
+    for(i=0; i<n; i++)
+    {
+        next = strchr(++next,']');
+        if (next == NULL)
+        {
+            printf("ERROR unexpected test vector\n");
+            exit(EXIT_FAILURE);
+        }
+    }
+    *(++next) = '\0';
+
+    return next++;
+}
+
+void read_BIG_XXX(BIG_XXX A, char* string)
+{
+    int len;
+    char support[LINE_LEN];
+    BIG_XXX_zero(A);
+    len = strlen(string)+1;
+    amcl_hex2bin(string,support,len);
+    len = (len-1)/2;
+    BIG_XXX_fromBytesLen(A,support,len);
+    BIG_XXX_norm(A);
+}
+
+void read_DBIG_XXX(DBIG_XXX A, char* string)
+{
+    int len;
+    char support[LINE_LEN] = "0";
+    BIG_XXX_dzero(A);
+
+    // replace eventual line feed
+    len=strlen(string);
+    if(string[len-1] == '\x0a')
+    {
+        string[len-1]='\0';
+        len--;
+    }
+
+    // Handle odd length strings
+    if(len %2 == 0)
+        support[0]='\0';
+    strcat(support,string);
+
+    len = strlen(support);
+    amcl_hex2bin(support,support,len);
+    BIG_XXX_dfromBytesLen(A,support,len/2);
+    BIG_XXX_dnorm(A);
+}
+
+void read_FP2_YYY(FP2_YYY *fp2, char* stringx)
+{
+    char *stringy;
+    BIG_XXX x,y;
+
+    stringy = strchr(++stringx,',');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    *(stringy)=0;
+    skip_cb(stringy++,1);
+
+    read_BIG_XXX(x,stringx);
+    read_BIG_XXX(y,stringy);
+
+    FP2_YYY_from_BIGs(fp2,x,y);
+}
+
+void read_FP4_YYY(FP4_YYY *fp4, char* stringx)
+{
+    char *stringy;
+    FP2_YYY x,y;
+
+    stringy = skip_cb(stringx++,1);
+    skip_cb(stringy++,1);
+
+    read_FP2_YYY(&x,stringx);
+    read_FP2_YYY(&y,stringy);
+
+    FP4_YYY_from_FP2s(fp4,&x,&y);
+}
+
+int read_ECP_ZZZ(ECP_ZZZ *ecp, char* string)
+{
+    BIG_XXX x;
+    char *end;
+    BIG_XXX y;
+    char *stringy;
+    string++;
+    stringy = strchr(string,',');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    stringy[0] = '\0';
+    stringy++;
+    end = strchr(stringy,')');
+    if (end == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    end[0] = '\0';
+    read_BIG_XXX(x,string);
+    read_BIG_XXX(y,stringy);
+    return ECP_ZZZ_set(ecp,x,y);
+}
+
+#if CURVE_SECURITY_ZZZ == 128
+void read_FP12_YYY(FP12_YYY *fp12, char *stringx)
+{
+    char *stringy, *stringz;
+    FP4_YYY x,y,z;
+
+    stringy = skip_cb(stringx++,3);
+    stringz = skip_cb(stringy++,3);
+    skip_cb(stringz++,3);
+
+    read_FP4_YYY(&x,stringx);
+    read_FP4_YYY(&y,stringy);
+    read_FP4_YYY(&z,stringz);
+
+    FP12_YYY_from_FP4s(fp12,&x,&y,&z);
+}
+int read_ECP2_ZZZ(ECP2_ZZZ *ecp2, char* stringx)
+{
+    char *stringy;
+    FP2_YYY x,y;
+
+    stringy = skip_cb(stringx++,1);
+    skip_cb(stringy++,1);
+
+    read_FP2_YYY(&x,stringx);
+    read_FP2_YYY(&y,stringy);
+
+    return ECP2_ZZZ_set(ecp2,&x,&y);
+}
+#else
+void read_FP8_YYY(FP8_YYY *fp8, char* stringx)
+{
+    char *stringy;
+    FP4_YYY x,y;
+
+    stringy = skip_cb(stringx++,3);
+    skip_cb(stringy++,3);
+
+    read_FP4_YYY(&x,stringx);
+    read_FP4_YYY(&y,stringy);
+
+    FP8_YYY_from_FP4s(fp8,&x,&y);
+}
+#if CURVE_SECURITY_ZZZ == 192
+void read_FP24_YYY(FP24_YYY *fp24, char *stringx)
+{
+    char *stringy, *stringz;
+    FP8_YYY x,y,z;
+
+    stringy = skip_cb(stringx++,7);
+    stringz = skip_cb(stringy++,7);
+    skip_cb(stringz++,7);
+
+    read_FP8_YYY(&x,stringx);
+    read_FP8_YYY(&y,stringy);
+    read_FP8_YYY(&z,stringz);
+
+    FP24_YYY_from_FP8s(fp24,&x,&y,&z);
+
+}
+int read_ECP4_ZZZ(ECP4_ZZZ *ecp4, char* stringx)
+{
+    char *stringy;
+    FP4_YYY x,y;
+
+    stringy = skip_cb(stringx++,3);
+    skip_cb(stringy++,3);
+
+    read_FP4_YYY(&x,stringx);
+    read_FP4_YYY(&y,stringy);
+
+    return ECP4_ZZZ_set(ecp4,&x,&y);
+}
+#elif CURVE_SECURITY_ZZZ == 256
+void read_FP16_YYY(FP16_YYY *fp16, char* stringx)
+{
+    char *stringy;
+    FP8_YYY x,y;
+
+    stringy = skip_cb(stringx++,7);
+    skip_cb(stringy++,7);
+    read_FP8_YYY(&x,stringx);
+    read_FP8_YYY(&y,stringy);
+
+    FP16_YYY_from_FP8s(fp16,&x,&y);
+}
+void read_FP48_YYY(FP48_YYY *fp48, char *stringx)
+{
+    char *stringy, *stringz;
+    FP16_YYY x,y,z;
+
+    stringy = skip_cb(stringx++,15);
+    stringz = skip_cb(stringy++,15);
+    skip_cb(stringz++,15);
+
+    read_FP16_YYY(&x,stringx);
+    read_FP16_YYY(&y,stringy);
+    read_FP16_YYY(&z,stringz);
+
+    FP48_YYY_from_FP16s(fp48,&x,&y,&z);
+}
+int read_ECP8_ZZZ(ECP8_ZZZ *ecp8, char* stringx)
+{
+    char *stringy;
+    FP8_YYY x,y;
+
+    stringy = skip_cb(stringx++,7);
+    skip_cb(stringy++,7);
+
+    read_FP8_YYY(&x,stringx);
+    read_FP8_YYY(&y,stringy);
+
+    return ECP8_ZZZ_set(ecp8,&x,&y);
+}
+#endif
+#endif
+
+void read_OCT(octet *oct, char* string, int len)
+{
+    char buff[len-1];
+    strncpy(buff,string,len-1);
+    buff[len-1] = '\0';
+    OCT_fromHex(oct,buff);
+}
+
+int main(int argc, char** argv)
+{
+    if (argc != 3)
+    {
+        printf("usage: ./test_ECP2_ZZZ_arithmetics [path to test vector file] 
[path to output directory]\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int fd, len, ch1 = 0, ch2 = 0, i=0, done;
+    fpos_t pos;
+    FILE *testVectFile, *writtenFile;
+
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+
+    BIG_XXX big, bigaux1, bigaux2;
+    const char* BIGline = "BIG = ";
+    const char* BIGrawline = "BIGraw = ";
+    DBIG_XXX dbig;
+    const char* DBIGline = "DBIG = ";
+    FP_YYY fp;
+    const char* FPline = "FP = ";
+    const char* FPrawline = "FPraw = ";
+    ECP_ZZZ ecp;
+    ECP_ZZZ ecpinf;
+    const char* ECPline = "ECP = ";
+    const char* ECPxyzline = "ECPxyz = ";
+    const char* ECPrawline = "ECPraw = ";
+    const char* ECPinfline = "ECPinf = ";
+    const char* ECPinfxyzline = "ECPinfxyz = ";
+    const char* ECPinfrawline = "ECPinfraw = ";
+    FP2_YYY fp2;
+    const char* FP2line = "FP2 = ";
+    const char* FP2rawline = "FP2raw = ";
+    FP4_YYY fp4;
+    const char* FP4line = "FP4 = ";
+    const char* FP4rawline = "FP4raw = ";
+# if CURVE_SECURITY_ZZZ == 128
+    FP12_YYY fp12;
+    const char* FP12line = "FP12 = ";
+    FP2_YYY fp2aux;
+    ECP2_ZZZ ecp2;
+    ECP2_ZZZ ecp2inf;
+    const char* ECP2line = "ECP2 = ";
+    const char* ECP2xyzline = "ECP2xyz = ";
+    const char* ECP2infline = "ECP2inf = ";
+    const char* ECP2infxyzline = "ECP2infxyz = ";
+#else
+    FP8_YYY fp8;
+    const char* FP8line = "FP8 = ";
+    const char* FP8rawline = "FP8raw = ";
+#if CURVE_SECURITY_ZZZ == 192
+    FP24_YYY fp24;
+    const char* FP24line = "FP24 = ";
+    FP4_YYY fp4aux;
+    ECP4_ZZZ ecp4;
+    ECP4_ZZZ ecp4inf;
+    const char* ECP4line = "ECP4 = ";
+    const char* ECP4infline = "ECP4inf = ";
+#elif CURVE_SECURITY_ZZZ == 256
+    FP16_YYY fp16;
+    const char* FP16line = "FP16 = ";
+    const char* FP16rawline = "FP16raw = ";
+    FP48_YYY fp48;
+    const char* FP48line = "FP48 = ";
+    FP8_YYY fp8aux;
+    ECP8_ZZZ ecp8;
+    ECP8_ZZZ ecp8inf;
+    const char* ECP8line = "ECP8 = ";
+    const char* ECP8infline = "ECP8inf = ";
+#endif
+#endif
+    char octbuf[LINE_LEN];
+    octet oct = {0,sizeof(octbuf),octbuf};
+    const char* OCTline = "OCT = ";
+    //const char* OCTstringline = "OCTstring = ";
+    char bin[32];
+    const char* HEXline = "HEX = ";
+
+    testVectFile = fopen(argv[1],"r");
+    if (testVectFile == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    fgetpos(stdout, &pos);
+    fd = dup(fileno(stdout));
+
+    if(freopen(argv[2], "w", stdout) == NULL)
+    {
+        printf("ERROR redirecting stdout\n");
+        exit(EXIT_FAILURE);
+    }
+
+    while (fgets(line, LINE_LEN, testVectFile) != NULL)
+    {
+        i++;
+        done=0;
+        if (!strncmp(line,  BIGline, strlen(BIGline)))
+        {
+            len = strlen(BIGline);
+            linePtr = line + len;
+            read_BIG_XXX(big, linePtr);
+            printf("%s",BIGline);
+            BIG_XXX_output(big);
+            printf("\n");
+            printf("%s",BIGrawline);
+            BIG_XXX_rawoutput(big);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  DBIGline, strlen(DBIGline)))
+        {
+            len = strlen(DBIGline);
+            linePtr = line + len;
+            read_DBIG_XXX(dbig, linePtr);
+            printf("%s",DBIGline);
+            BIG_XXX_doutput(dbig);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  FPline, strlen(FPline)))
+        {
+            len = strlen(FPline);
+            linePtr = line + len;
+            read_BIG_XXX(big,linePtr);
+            FP_YYY_nres(&fp,big);
+            printf("%s",FPline);
+            FP_YYY_output(&fp);
+            printf("\n");
+            printf("%s",FPrawline);
+            FP_YYY_rawoutput(&fp);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  FP2line, strlen(FP2line)))
+        {
+            len = strlen(FP2line);
+            linePtr = line + len;
+            read_FP2_YYY(&fp2,linePtr);
+            printf("%s",FP2line);
+            FP2_YYY_output(&fp2);
+            printf("\n");
+            printf("%s",FP2rawline);
+            FP2_YYY_rawoutput(&fp2);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  FP4line, strlen(FP4line)))
+        {
+            len = strlen(FP4line);
+            linePtr = line + len;
+            read_FP4_YYY(&fp4,linePtr);
+            printf("%s",FP4line);
+            FP4_YYY_output(&fp4);
+            printf("\n");
+            printf("%s",FP4rawline);
+            FP4_YYY_rawoutput(&fp4);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  ECPline, strlen(ECPline)))
+        {
+            len = strlen(ECPline);
+            linePtr = line + len;
+            read_ECP_ZZZ(&ecp,linePtr);
+            printf("%s",ECPline);
+            ECP_ZZZ_output(&ecp);
+            printf("%s",ECPxyzline);
+            ECP_ZZZ_outputxyz(&ecp);
+            printf("%s",ECPrawline);
+            ECP_ZZZ_rawoutput(&ecp);
+            FP_YYY_redc(bigaux1,&ecp.x);
+            FP_YYY_redc(bigaux2,&ecp.y);
+            BIG_XXX_inc(bigaux1,100);
+            ECP_ZZZ_set(&ecpinf,bigaux1,bigaux2);
+            printf("%s",ECPinfline);
+            ECP_ZZZ_output(&ecpinf);
+            printf("%s",ECPinfxyzline);
+            ECP_ZZZ_outputxyz(&ecpinf);
+            printf("%s",ECPinfrawline);
+            ECP_ZZZ_rawoutput(&ecpinf);
+            done = 1;
+        }
+#if CURVE_SECURITY_ZZZ == 128
+        if (!strncmp(line,  FP12line, strlen(FP12line)))
+        {
+            len = strlen(FP12line);
+            linePtr = line + len;
+            read_FP12_YYY(&fp12,linePtr);
+            printf("%s",FP12line);
+            FP12_YYY_output(&fp12);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  ECP2line, strlen(ECP2line)))
+        {
+            len = strlen(ECP2line);
+            linePtr = line + len;
+            read_ECP2_ZZZ(&ecp2,linePtr);
+            printf("%s",ECP2line);
+            ECP2_ZZZ_output(&ecp2);
+            printf("%s",ECP2xyzline);
+            ECP2_ZZZ_outputxyz(&ecp2);
+            FP2_YYY_add(&fp2aux,&ecp2.x,&ecp2.y);
+            ECP2_ZZZ_set(&ecp2inf,&fp2aux,&fp2aux);
+            printf("%s",ECP2infline);
+            ECP2_ZZZ_output(&ecp2inf);
+            printf("%s",ECP2infxyzline);
+            ECP2_ZZZ_outputxyz(&ecp2inf);
+            done = 1;
+        }
+#else
+        if (!strncmp(line,  FP8line, strlen(FP8line)))
+        {
+            len = strlen(FP8line);
+            linePtr = line + len;
+            read_FP8_YYY(&fp8,linePtr);
+            printf("%s",FP8line);
+            FP8_YYY_output(&fp8);
+            printf("\n");
+            printf("%s",FP8rawline);
+            FP8_YYY_rawoutput(&fp8);
+            printf("\n");
+            done = 1;
+        }
+#if CURVE_SECURITY_ZZZ == 192
+        if (!strncmp(line,  FP24line, strlen(FP24line)))
+        {
+            len = strlen(FP24line);
+            linePtr = line + len;
+            read_FP24_YYY(&fp24,linePtr);
+            printf("%s",FP24line);
+            FP24_YYY_output(&fp24);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  ECP4line, strlen(ECP4line)))
+        {
+            len = strlen(ECP4line);
+            linePtr = line + len;
+            read_ECP4_ZZZ(&ecp4,linePtr);
+            printf("%s",ECP4line);
+            ECP4_ZZZ_output(&ecp4);
+            FP4_YYY_add(&fp4aux,&ecp4.x,&ecp4.y);
+            ECP4_ZZZ_set(&ecp4inf,&fp4aux,&fp4aux);
+            printf("%s",ECP4infline);
+            ECP4_ZZZ_output(&ecp4inf);
+            done = 1;
+        }
+#elif CURVE_SECURITY_ZZZ == 256
+        if (!strncmp(line,  FP16line, strlen(FP16line)))
+        {
+            len = strlen(FP16line);
+            linePtr = line + len;
+            read_FP16_YYY(&fp16,linePtr);
+            printf("%s",FP16line);
+            FP16_YYY_output(&fp16);
+            printf("\n");
+            printf("%s",FP16rawline);
+            FP16_YYY_rawoutput(&fp16);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  FP48line, strlen(FP48line)))
+        {
+            len = strlen(FP48line);
+            linePtr = line + len;
+            read_FP48_YYY(&fp48,linePtr);
+            printf("%s",FP48line);
+            FP48_YYY_output(&fp48);
+            printf("\n");
+            done = 1;
+        }
+        if (!strncmp(line,  ECP8line, strlen(ECP8line)))
+        {
+            len = strlen(ECP8line);
+            linePtr = line + len;
+            read_ECP8_ZZZ(&ecp8,linePtr);
+            printf("%s",ECP8line);
+            ECP8_ZZZ_output(&ecp8);
+            FP8_YYY_add(&fp8aux,&ecp8.x,&ecp8.y);
+            ECP8_ZZZ_set(&ecp8inf,&fp8aux,&fp8aux);
+            printf("%s",ECP8infline);
+            ECP8_ZZZ_output(&ecp8inf);
+            done = 1;
+        }
+#endif
+#endif
+        if (!strncmp(line,  OCTline, strlen(OCTline)))
+        {
+            len = strlen(OCTline);
+            linePtr = line + len;
+            read_OCT(&oct,linePtr,strlen(linePtr));
+            printf("%s",OCTline);
+            OCT_output(&oct);
+            done = 1;
+        }
+        if (!strncmp(line,  HEXline, strlen(HEXline)))
+        {
+            len = strlen(HEXline);
+            linePtr = line + len;
+            amcl_hex2bin(linePtr, bin, 64);
+            printf("%s", HEXline);
+            amcl_print_hex(bin,32);
+            done = 1;
+        }
+        if (!strncmp(line, BIGrawline, strlen(BIGrawline))||
+                !strncmp(line, FPrawline, strlen(FPrawline))||
+                !strncmp(line, ECPxyzline, strlen(ECPxyzline))||
+                !strncmp(line, ECPrawline, strlen(ECPrawline))||
+                !strncmp(line, ECPinfline, strlen(ECPinfline))||
+                !strncmp(line, ECPinfxyzline, strlen(ECPinfxyzline))||
+                !strncmp(line, ECPinfrawline, strlen(ECPinfrawline))||
+                !strncmp(line, FP2rawline, strlen(FP2rawline))||
+                !strncmp(line, FP4rawline, strlen(FP4rawline)))
+            done=1;
+#if CURVE_SECURITY_ZZZ == 128
+        if (!strncmp(line, ECP2xyzline, strlen(ECP2xyzline))||
+                !strncmp(line, ECP2infline, strlen(ECP2infline))||
+                !strncmp(line, ECP2infxyzline, strlen(ECP2infxyzline)))
+            done=1;
+#elif CURVE_SECURITY_ZZZ == 192
+        if (!strncmp(line, FP8rawline, strlen(FP8rawline))||
+                !strncmp(line, ECP4infline, strlen(ECP4infline)))
+            done=1;
+#elif CURVE_SECURITY_ZZZ == 256
+        if (!strncmp(line, FP8rawline, strlen(FP8rawline))||
+                !strncmp(line, FP16rawline, strlen(FP16rawline))||
+                !strncmp(line, ECP8infline, strlen(ECP8infline)))
+            done=1;
+#endif
+        if(!done)
+            printf("%s",line);
+    }
+
+    // Restore stdout
+    fflush(stdout);
+    dup2(fd, fileno(stdout));
+    close(fd);
+    clearerr(stdout);
+    fsetpos(stdout, &pos);        /* for C9X */
+
+    writtenFile = fopen(argv[2],"r");
+    if (writtenFile == NULL)
+    {
+        printf("ERROR opening output file\n");
+        exit(EXIT_FAILURE);
+    }
+    fclose(testVectFile);
+
+    // Check the equality of the output with the test vector file
+
+    testVectFile = fopen(argv[1],"r");
+    if (testVectFile == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    ch1 = getc(testVectFile);
+    ch2 = getc(writtenFile);
+
+    while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2))
+    {
+        ch1 = getc(testVectFile);
+        ch2 = getc(writtenFile);
+    }
+
+    if (ch1 != ch2)
+    {
+        printf("ERROR output does not match the expected one \n");
+        exit(EXIT_FAILURE);
+    }
+    fclose(writtenFile);
+    fclose(testVectFile);
+
+    remove(argv[2]);
+
+    printf("SUCCESS TEST OUTPUT FUNCTIONS PASSED\n");
+    exit(EXIT_SUCCESS);
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_pair_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_pair_ZZZ.c.in b/test/test_pair_ZZZ.c.in
new file mode 100644
index 0000000..e84eb86
--- /dev/null
+++ b/test/test_pair_ZZZ.c.in
@@ -0,0 +1,229 @@
+/**
+ * @file test_pair_ZZZ.c
+ * @author Alessandro Budroni
+ * @brief Test function for pairing
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "randapi.h"
+#include "config_curve_ZZZ.h"
+#if CURVE_SECURITY_ZZZ == 128
+#include "pair_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 192
+#include "pair192_ZZZ.h"
+#elif CURVE_SECURITY_ZZZ == 256
+#include "pair256_ZZZ.h"
+#endif
+
+// Number of iterations in pairing test
+#if CURVE_SECURITY_ZZZ == 128
+#define N_ITER 16
+#elif CURVE_SECURITY_ZZZ == 192
+#define N_ITER 12
+#elif CURVE_SECURITY_ZZZ == 256
+#define N_ITER 8
+#endif
+
+// Renamings for multiple security level support
+#if CURVE_SECURITY_ZZZ == 128
+#define ECPG2_ZZZ_generator ECP2_ZZZ_generator
+#define ECPG2_ZZZ_copy ECP2_ZZZ_copy
+#define ECPG2_ZZZ_mul ECP2_ZZZ_mul
+#define ECPG2_ZZZ_add ECP2_ZZZ_add
+#define ECPG2_ZZZ_affine ECP2_ZZZ_affine
+#define ECPG2_ZZZ_isinf ECP2_ZZZ_isinf
+#define GT_YYY_equals FP12_YYY_equals
+#define GT_YYY_copy FP12_YYY_copy
+#define GT_YYY_mul FP12_YYY_mul
+#elif CURVE_SECURITY_ZZZ == 192
+#define ECPG2_ZZZ_generator ECP4_ZZZ_generator
+#define ECPG2_ZZZ_copy ECP4_ZZZ_copy
+#define ECPG2_ZZZ_mul ECP4_ZZZ_mul
+#define ECPG2_ZZZ_add ECP4_ZZZ_add
+#define ECPG2_ZZZ_affine ECP4_ZZZ_affine
+#define ECPG2_ZZZ_isinf ECP4_ZZZ_isinf
+#define GT_YYY_equals FP24_YYY_equals
+#define GT_YYY_copy FP24_YYY_copy
+#define GT_YYY_mul FP24_YYY_mul
+#elif CURVE_SECURITY_ZZZ == 256
+#define ECPG2_ZZZ_generator ECP8_ZZZ_generator
+#define ECPG2_ZZZ_copy ECP8_ZZZ_copy
+#define ECPG2_ZZZ_mul ECP8_ZZZ_mul
+#define ECPG2_ZZZ_add ECP8_ZZZ_add
+#define ECPG2_ZZZ_affine ECP8_ZZZ_affine
+#define ECPG2_ZZZ_isinf ECP8_ZZZ_isinf
+#define GT_YYY_equals FP48_YYY_equals
+#define GT_YYY_copy FP48_YYY_copy
+#define GT_YYY_mul FP48_YYY_mul
+#endif
+
+int main()
+{
+    int i;
+    BIG_XXX s,r,x,y;
+    ECP_ZZZ G,P1,P2,P3;
+
+#if CURVE_SECURITY_ZZZ == 128
+    ECP2_ZZZ W,Q1,Q2,Q3;
+    FP12_YYY g11,gs1,gs2;
+#elif CURVE_SECURITY_ZZZ == 192
+    ECP4_ZZZ W,Q1,Q2,Q3;
+    FP24_YYY g11,gs1,gs2;
+#elif CURVE_SECURITY_ZZZ == 256
+    ECP8_ZZZ W,Q1,Q2,Q3;
+    FP48_YYY g11,gs1,gs2;
+#endif
+
+    char seed[100] = {0};
+    octet SEED = {0,sizeof(seed),seed};
+    csprng RNG;
+
+    /* non random seed value! */
+    SEED.len=100;
+    for (i=0; i<100; i++) SEED.val[i]=i+1;
+
+    /* initialise random number generator */
+    CREATE_CSPRNG(&RNG,&SEED);
+
+    // Set Generator of G1
+    ECP_ZZZ_generator(&G);
+
+    // Set Generator of G2
+    ECPG2_ZZZ_generator(&W);
+
+    // Check that scalar multiplication by curve order gives the infinte point
+    BIG_XXX_rcopy(r,CURVE_Order_ZZZ);
+    ECP_ZZZ_copy(&P1,&G);
+    PAIR_ZZZ_G1mul(&P1,r);
+    if (!ECP_ZZZ_isinf(&P1))
+    {
+        printf("FAILURE - rP!=O\n");
+        return 1;
+    }
+
+    BIG_XXX_randomnum(s,r,&RNG);
+    ECPG2_ZZZ_copy(&Q1,&W);
+    ECPG2_ZZZ_mul(&Q1,r);
+
+    if (!ECPG2_ZZZ_isinf(&Q1))
+    {
+        printf("FAILURE - rQ!=O\n");
+        return 0;
+    }
+
+    for (i = 0; i < N_ITER; ++i)
+    {
+        // Pick a random point in G1
+        BIG_XXX_randomnum(x,r,&RNG);
+        ECP_ZZZ_copy(&P1,&G);
+        ECP_ZZZ_mul(&P1,x);
+        ECP_ZZZ_copy(&P2,&P1);
+
+        // Pick a random point in G2
+        BIG_XXX_randomnum(y,r,&RNG);
+        ECPG2_ZZZ_copy(&Q1,&W);
+        ECPG2_ZZZ_mul(&Q1,y);
+        ECPG2_ZZZ_copy(&Q2,&Q1);
+
+        // Precompute e(Q1,P1)
+        PAIR_ZZZ_ate(&g11,&Q1,&P1);
+        PAIR_ZZZ_fexp(&g11);
+
+        // Test that e(sQ,P) = e(Q,sP) = e(Q,P)^s, s random
+        BIG_XXX_randomnum(s,r,&RNG);
+        PAIR_ZZZ_G1mul(&P2,s);
+        ECPG2_ZZZ_mul(&Q2,s);
+        PAIR_ZZZ_ate(&gs1,&Q1,&P2);
+        PAIR_ZZZ_fexp(&gs1);
+        PAIR_ZZZ_ate(&gs2,&Q2,&P1);
+        PAIR_ZZZ_fexp(&gs2);
+        if (!GT_ZZZ_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - e(sQ,P)!=e(Q,sP)\n");
+            return 1;
+        }
+        GT_ZZZ_copy(&gs2,&g11);
+        PAIR_ZZZ_GTpow(&gs2,s);
+        if (!GT_ZZZ_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - e(sQ,P)!=e(Q,P)^s\n");
+            return 1;
+        }
+
+        // Test that e(Q,P1+P2) = e(Q,P1).e(Q,P2)
+        PAIR_ZZZ_ate(&gs2,&Q1,&P2);
+        PAIR_ZZZ_fexp(&gs2);
+        GT_YYY_copy(&gs1,&g11);
+        GT_YYY_mul(&gs1,&gs2);
+        ECP_ZZZ_copy(&P3,&P1);
+        ECP_ZZZ_add(&P3,&P2);
+        ECP_ZZZ_affine(&P3);
+        PAIR_ZZZ_ate(&gs2,&Q1,&P3);
+        PAIR_ZZZ_fexp(&gs2);
+        if (!GT_YYY_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - e(Q,P1+P2)!=e(Q,P1).e(Q,P2)\n");
+            return 1;
+        }
+
+        // Test double_ate function on G1
+        PAIR_ZZZ_double_ate(&gs1,&Q1,&P1,&Q1,&P2);
+        PAIR_ZZZ_fexp(&gs1);
+        if (!GT_YYY_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - double ate failed\n");
+            return 1;
+        }
+
+        // Test that e(Q1+Q2,P1) = e(Q1,P1).e(Q2,P1)
+        PAIR_ZZZ_ate(&gs2,&Q2,&P1);
+        PAIR_ZZZ_fexp(&gs2);
+        GT_YYY_copy(&gs1,&g11);
+        GT_YYY_mul(&gs1,&gs2);
+        ECPG2_ZZZ_copy(&Q3,&Q1);
+        ECPG2_ZZZ_add(&Q3,&Q2);
+        ECPG2_ZZZ_affine(&Q3);
+        PAIR_ZZZ_ate(&gs2,&Q3,&P1);
+        PAIR_ZZZ_fexp(&gs2);
+        if (!GT_YYY_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - e(Q1+Q2,P1)!=e(Q1,P1).e(Q2,P1)\n");
+            return 1;
+        }
+
+        // Test double_ate function on G2
+        PAIR_ZZZ_double_ate(&gs1,&Q1,&P1,&Q2,&P1);
+        PAIR_ZZZ_fexp(&gs1);
+        if (!GT_YYY_equals(&gs1,&gs2))
+        {
+            printf("FAILURE - double ate failed\n");
+            return 1;
+        }
+
+    }
+
+    KILL_CSPRNG(&RNG);
+    printf("SUCCESS\n");
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_rsa_WWW.c.in
----------------------------------------------------------------------
diff --git a/test/test_rsa_WWW.c.in b/test/test_rsa_WWW.c.in
new file mode 100644
index 0000000..c1ba203
--- /dev/null
+++ b/test/test_rsa_WWW.c.in
@@ -0,0 +1,116 @@
+/**
+ * @file test_rsa_WWW.c
+ * @author Kealan McCusker
+ * @brief Test RSA
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* test driver and function exerciser for RSA API Functions */
+
+
+#include <stdio.h>
+#include <time.h>
+#include "rsa_WWW.h"
+#include "randapi.h"
+
+int main()
+{
+    int i;
+    unsigned long ran;
+    char m[RFS_WWW],ml[RFS_WWW],c[RFS_WWW],e[RFS_WWW],s[RFS_WWW],raw[100];
+    rsa_public_key_WWW pub;
+    rsa_private_key_WWW 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 S= {0,sizeof(s),s};
+    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=0; i<100; i++) RAW.val[i]=i;
+
+    CREATE_CSPRNG(&RNG,&RAW);   /* initialise strong RNG */
+
+    printf("Generating public/private key pair\n");
+    RSA_WWW_KEY_PAIR(&RNG,65537,&priv,&pub,NULL,NULL);
+
+    printf("Encrypting test string\n");
+    OCT_jstring(&M,(char *)"Hello World\n");
+
+    OAEP_ENCODE(HASH_TYPE_RSA_WWW,&M,&RNG,NULL,&E); /* OAEP encode message m 
to e  */
+
+    RSA_WWW_ENCRYPT(&pub,&E,&C);     /* encrypt encoded message */
+    printf("Ciphertext= ");
+    OCT_output(&C);
+
+    printf("Decrypting test string\n");
+    RSA_WWW_DECRYPT(&priv,&C,&ML);   /* ... and then decrypt it */
+
+    OAEP_DECODE(HASH_TYPE_RSA_WWW,NULL,&ML);    /* decode it */
+    OCT_output_string(&ML);
+
+
+    if (!OCT_comp(&M,&ML))
+    {
+        printf("FAILURE RSA Encryption failed");
+        return 1;
+    }
+
+    printf("Signing message\n");
+    PKCS15(HASH_TYPE_RSA_WWW,&M,&C);
+
+    RSA_WWW_DECRYPT(&priv,&C,&S); /* create signature in S */
+
+    printf("Signature= ");
+    OCT_output(&S);
+
+    RSA_WWW_ENCRYPT(&pub,&S,&ML);
+
+    if (OCT_comp(&C,&ML))
+    {
+        printf("Signature is valid\n");
+    }
+    else
+    {
+        printf("FAILURE RSA Signature Verification failed");
+        return 1;
+    }
+
+    KILL_CSPRNG(&RNG);
+    RSA_WWW_PRIVATE_KEY_KILL(&priv);
+
+    OCT_clear(&M);
+    OCT_clear(&ML);   /* clean up afterwards */
+    OCT_clear(&C);
+    OCT_clear(&RAW);
+    OCT_clear(&E);
+
+    printf("SUCCESS\n");
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_rsa_sign_WWW_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_rsa_sign_WWW_ZZZ.c.in b/test/test_rsa_sign_WWW_ZZZ.c.in
new file mode 100644
index 0000000..652920e
--- /dev/null
+++ b/test/test_rsa_sign_WWW_ZZZ.c.in
@@ -0,0 +1,310 @@
+/**
+ * @file test_rsa_sign_WWW_ZZZ.c
+ * @author Kealan McCusker
+ * @brief Test RSA signature
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* Build executible after installation:
+
+  gcc -std=c99 -g ./test_rsa_sign.c -I/opt/amcl/include -L/opt/amcl/lib -lx509 
-lrsa -lecdh -lamcl -o test_rsa_sign_WWW_ZZZ
+
+*/
+
+#include "rsa_WWW.h"
+#include "ecdh_ZZZ.h"
+#include "x509.h"
+#include "utils.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "randapi.h"
+
+#define RSA 2
+#define H160 1
+#define H256 2
+#define H384 3
+#define H512 4
+
+#define LINE_LEN 10000
+//#define DEBUG
+
+#define MAXMODBYTES 66
+#define MAXFFLEN 16
+
+char sig[MAXMODBYTES*MAXFFLEN];
+octet SIG= {0,sizeof(sig),sig};
+
+char sig2[MAXMODBYTES*MAXFFLEN];
+octet SIG2= {0,sizeof(sig2),sig2};
+
+char r[MAXMODBYTES];
+octet R= {0,sizeof(r),r};
+
+char s[MAXMODBYTES];
+octet S= {0,sizeof(s),s};
+
+char cakey[MAXMODBYTES*MAXFFLEN];
+octet CAKEY= {0,sizeof(cakey),cakey};
+
+char certkey[MAXMODBYTES*MAXFFLEN];
+octet CERTKEY= {0,sizeof(certkey),certkey};
+
+char h[5000];
+octet H= {0,sizeof(h),h};
+
+char hh[5000];
+octet HH= {0,sizeof(hh),hh};
+
+int main(int argc, char** argv)
+{
+    if (argc != 2)
+    {
+        printf("usage: ./test_rsa_sign_WWW_ZZZ [path to test vector file]\n");
+        exit(EXIT_FAILURE);
+    }
+    int sha;
+    pktype st,ca;
+    int rc;
+    FILE * fp = NULL;
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+    int l1=0;
+    const char* CERTStr = "CERT = ";
+
+    fp = fopen(argv[1], "r");
+    if (fp == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    rsa_public_key_WWW pub;
+    rsa_private_key_WWW priv;
+
+    // Prime p:
+    char p[RFS_WWW/2];
+    octet P= {sizeof(p),sizeof(p),p};
+    const char* PStr = "p = ";
+
+    // Prime q:
+    char q[RFS_WWW/2];
+    octet Q= {sizeof(q),sizeof(q),q};
+    const char* QStr = "q = ";
+
+    bool readLine = false;
+    int i=0;
+    while (fgets(line, LINE_LEN, fp) != NULL)
+    {
+        i++;
+        readLine = true;
+        if (!strncmp(line, PStr, strlen(PStr)))
+        {
+#ifdef DEBUG
+            printf("line %d %s\n", i,line);
+#endif
+            // Find hex value in string
+            linePtr = line + strlen(PStr);
+
+            // p binary value
+            l1 = strlen(linePtr)-1;
+            amcl_hex2bin(linePtr, P.val, l1);
+        }
+
+        if (!strncmp(line, QStr, strlen(QStr)))
+        {
+#ifdef DEBUG
+            printf("line %d %s\n", i,line);
+#endif
+            // Find hex value in string
+            linePtr = line + strlen(QStr);
+
+            // q binary value
+            l1 = strlen(linePtr)-1;
+            amcl_hex2bin(linePtr, Q.val, l1);
+        }
+
+        // Self-Signed CA cert
+        if (!strncmp(line, CERTStr, strlen(CERTStr)))
+        {
+#ifdef DEBUG
+            printf("line %d %s\n", i,line);
+#endif
+            // Find base64 value in string
+            char io[5000];
+            octet IO= {0,sizeof(io),io};
+            linePtr = line + strlen(CERTStr);
+            l1 = strlen(linePtr);
+            char* ca_b64 = (char*) calloc (l1,sizeof(char));
+            strncpy(ca_b64,linePtr,l1-1);
+            OCT_frombase64(&IO,ca_b64);
+
+#ifdef DEBUG
+            printf("CA Self-Signed Cert= \n");
+            OCT_output(&IO);
+            printf("\n");
+#endif
+
+            free(ca_b64);
+            ca_b64 = NULL;
+
+            // returns signature type
+            st=X509_extract_cert_sig(&IO,&SIG);
+
+#ifdef DEBUG
+            printf("SIG= \n");
+            OCT_output(&SIG);
+            printf("\n");
+#endif
+
+            // Extract Cert from signed Cert
+            X509_extract_cert(&IO,&H);
+
+#ifdef DEBUG
+            printf("Cert= \n");
+            OCT_output(&H);
+            printf("\n");
+
+            int c;
+            c=X509_extract_cert(&IO,&H);
+
+            // Print email
+            int ic,len;
+            char en[9]= {0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x01};
+            octet EN= {9,sizeof(en),en};
+            printf("Issuer Details\n");
+            ic=X509_find_issuer(&H);
+            c=X509_find_entity_property(&H,&EN,ic,&len);
+            print_out("email=",&H,c,len);
+            printf("\n");
+#endif
+
+            ca=X509_extract_public_key(&H,&CAKEY);
+
+            if (ca.type==0)
+            {
+                printf("Not supported by library\n");
+                exit(EXIT_FAILURE);
+            }
+            if (ca.type!=st.type)
+            {
+                printf("Not self-signed\n");
+                exit(EXIT_FAILURE);
+            }
+
+#ifdef DEBUG
+            printf("EXTRACTED RSA PUBLIC KEY= \n");
+            OCT_output(&CAKEY);
+            printf("\n");
+#endif
+
+            // Assign public key
+            pub.e=65537;
+            FF_WWW_fromOctet(pub.n,&CAKEY,FFLEN_WWW);
+
+#ifdef DEBUG
+            printf("pub.n ");
+            FF_WWW_output(pub.n,FFLEN_WWW);
+            printf("\n");
+#endif
+
+            // Checking Self-Signed Signature
+            sha=0;
+            if (st.hash==H256) sha=SHA256;
+            if (st.hash==H384) sha=SHA384;
+            if (st.hash==H512) sha=SHA512;
+            if (st.hash==0)
+            {
+                printf("Hash Function not supported\n");
+                exit(EXIT_FAILURE);
+            }
+            char mp[RFS_WWW];
+            octet MP= {0,sizeof(mp),mp};
+            PKCS15(sha,&H,&MP);
+            RSA_WWW_ENCRYPT(&pub,&SIG,&HH);
+
+#ifdef DEBUG
+            printf("MP ");
+            OCT_output(&MP);
+            printf("\n");
+#endif
+
+            rc = OCT_comp(&MP,&HH);
+            if (!rc)
+            {
+                printf("TEST RSA VERIFICATION FAILED LINE %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+
+            // Generating public/private key pair from p amd q
+            RSA_WWW_KEY_PAIR(NULL,65537,&priv,&pub,&P,&Q);
+
+#ifdef DEBUG
+            printf("priv.p ");
+            FF_WWW_output(priv.p,FFLEN_WWW/2);
+            printf("\n");
+            printf("priv.q ");
+            FF_WWW_output(priv.q,FFLEN_WWW/2);
+            printf("\n");
+            printf("priv.dp ");
+            FF_WWW_output(priv.dp,FFLEN_WWW/2);
+            printf("\n");
+            printf("priv.dq ");
+            FF_WWW_output(priv.dq,FFLEN_WWW/2);
+            printf("\n");
+            printf("priv.c ");
+            FF_WWW_output(priv.c,FFLEN_WWW/2);
+            printf("\n");
+#endif
+
+            char hp[RFS_WWW];
+            octet HP= {0,sizeof(hp),hp};
+
+            // Sign message
+            PKCS15(sha,&H,&HP);
+            RSA_WWW_DECRYPT(&priv,&HP,&SIG2);
+
+#ifdef DEBUG
+            printf("HP= ");
+            OCT_output(&HP);
+            printf("\r\n");
+
+            printf("SIG2= ");
+            OCT_output(&SIG2);
+            printf("\r\n");
+#endif
+            rc = OCT_comp(&SIG,&SIG2);
+            if (!rc)
+            {
+                printf("TEST RSA SIGNING FAILED LINE %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+    }
+    fclose(fp);
+    if (!readLine)
+    {
+        printf("ERROR Empty test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+    printf("SUCCESS TEST RSA SIGNATURE PASSED\n");
+    exit(EXIT_SUCCESS);
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_utils.c
----------------------------------------------------------------------
diff --git a/test/test_utils.c b/test/test_utils.c
new file mode 100644
index 0000000..c90bdea
--- /dev/null
+++ b/test/test_utils.c
@@ -0,0 +1,106 @@
+/**
+ * @file test_utils.c
+ * @author Kealan McCusker
+ * @brief Test driver and function exerciser for util Functions
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* test driver and function exerciser for util Functions */
+/* Version 3.0 - supports Time Permits */
+
+/* Build executible after installation:
+
+  gcc -std=c99 -g ./test_utils.c -I/opt/amcl/include -L/opt/amcl/lib 
-lamcl_core -o test_utils
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "utils.h"
+#include "randapi.h"
+
+const int nIter = 32;
+
+const int V1[32] = {822451, 201197, 585864, 720907, 90685, 361405, 461117, 
804736, 882396, 392044, 677418, 227782, 67488, 755001, 202246, 715416, 267781, 
950041, 440029, 566511, 965344, 403316, 756645, 272421, 633043, 868514, 201805, 
234612, 169985, 670987, 93770, 961852};
+
+char* V2[32] = 
{"7ec2d70f9883b3ff1d7963d069ff7576f3e5d782511766854cd6d6eb1ad8863c", 
"02def0995797f3408573edd6e06895220ce17f2a2a85c01c993fcbd265a4d76d", 
"c5c7d86e71c5fea739a54beb952cbad1a16a18fac3f9bd4fe846728e80936f0e", 
"f4cdd3ac0611961b7ab8fda1c52ac76fd9ed61a17d75ba0d2ab2f76409a6a757", 
"6ed936c269224750a74685b3d9d0c3f2bdf8a67ec25f25befb2f91ba525364ec", 
"8cd0a96bbd5e14557a3c47a90d51d46029be3b1a4429a96e595c21ed7c505280", 
"e97b3ab62ea88aceae7de70067dd07c9d6d69c4b981bd8784e8fd826a2a2ec6f", 
"5c0166bbbf175f2ce55ea04cf1e0f8e2967092c23a03a7250090876612ff1c2c", 
"e8d3ae8fb6a42ec7e1bf43d1ad75ac63d54b3034dc16bb215f69a875e697870f", 
"e4599f0a66b60254beda71dab4cdac88af9fb405e4cde02a72144425296feda3", 
"09d6330a165363dceb87a21c4784af57060221fbb2c61add5d34b38d7e9089ac", 
"4aa4efa6e639999ad220743ae899749f26900ed753dc4b5993ba09b91f227830", 
"7ec39006697d6db8310f7f8f7bc1501a3251ba2aaf4d0418a55a5d598f67a5f4", 
"a6afb85fa403645cc0e45054386e98adb119491070371b4fac4e375fa8bf2fa6", 
"eac07fe6d84b4181bbaac33aea64
 94ea1557809b4f62bf8011a33359aec4feca", 
"5f96dfea25fb205ba21ae6c7b491c65c0b65f96d88320a39a0d0e58c42ad8a9c", 
"bf97a5180ac699ff2bd8046e77e32495a9774c557844363686a6203159eeb8c4", 
"921a5321fc5b16ab46755a3a8da130c727556e26279b3659d46945c85a92230d", 
"85f87cfd7b915d989c62d7abbf93c851d845f2b850e014caf01370d45e123af5", 
"45b1d889b8e36c4320476007bb93908c8c993d728cbfb66014335fa557a289ff", 
"ea6fcfad4286d7f15cef2011d4e79fb4e6bd5ea5680b0f0a5eace597270f2723", 
"0b075ac0885abd70bac20a436a272adea717af6dad7c94f16d1d20ec49d9d146", 
"4109be2fbd2d4c959f0e6bf2550c02860b5ca06a09913f004bb1f1b9fff91d47", 
"15afd5efad90f3768775c7097dd0feb95215e9a9013239d2d76ca8b95fc10915", 
"21f03a1f17e46a1d69c35c6985e275297db68ed4254166f4c8cd5595ebbf0fcb", 
"a0ee64a19552712708f2262017e7bb4edfa03873895f976c791a45ca733ef375", 
"5b06bce9f720d5588b6758241607040a12d2a1b7c4db82546fc894fd0c95d05d", 
"26654e23604fa6269e8944d8a9edda1073ecba5bde9173a277ca9bac3969bb77", 
"e570ede6303222e2fe055c4a33463de0406f441c5df32494b9432cc7f24dcf95", "14d82
 666b07485a88accf5533b06a4c637ad7c7316117e1963e0d369e2dbaeb2", 
"9ac996b9dc3d99e13db15569ca7adc927e0b4c9ad38da427ed6be7863d551d85", 
"571957d348629392f7f7f186d72f3f41ddb23813b116b3de776d2fe888adf82e"};
+
+char temp[32+1];
+char bintemp[16+1];
+
+int main()
+{
+    int i,otp;
+    char x[32];
+    octet X= {sizeof(x),sizeof(x),x};
+
+    char vector[32];
+    octet VECTOR= {sizeof(vector),sizeof(vector),vector};
+
+    char seed[32] = {0};
+    octet SEED = {0,sizeof(seed),seed};
+    csprng RNG;
+
+    /* non random seed value! */
+    SEED.len=32;
+    for (i=0; i<32; i++)
+        SEED.val[i]=i+1;
+
+    /* initialise random number generator */
+    CREATE_CSPRNG(&RNG,&SEED);
+
+    for (i=0; i<nIter; i++)
+    {
+        otp = generateOTP(&RNG);
+        if (otp != V1[i])
+        {
+            printf("FAILURE generateOTP failure\n");
+            return 1;
+        }
+    }
+
+    for (i=0; i<nIter; i++)
+    {
+        generateRandom(&RNG,&X);
+        OCT_fromHex(&VECTOR,V2[i]);
+        if (!OCT_comp(&X,&VECTOR))
+        {
+            printf("FAILURE generateRandom failure\n");
+            return 1;
+        }
+    }
+
+    for (i=0; i<nIter; i++)
+    {
+        amcl_hex2bin(V2[i], bintemp, 64);
+        amcl_bin2hex(bintemp, temp, 32);
+        if (strncmp(V2[i], temp, 64))
+        {
+            printf("FAILURE conversion hex/bin\n");
+            return 1;
+        }
+    }
+
+    printf("SUCCESS\n");
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_version.c
----------------------------------------------------------------------
diff --git a/test/test_version.c b/test/test_version.c
new file mode 100644
index 0000000..e15028e
--- /dev/null
+++ b/test/test_version.c
@@ -0,0 +1,38 @@
+/**
+ * @file test_version.c
+ * @author Kealan McCusker
+ * @brief Test version function
+ *
+ * LICENSE
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* Test version function */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "amcl.h"
+#include "version.h"
+
+int main()
+{
+    amcl_version();
+    return 0;
+}

Reply via email to