http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_ecp_arithmetics_ZZZ.c.in
----------------------------------------------------------------------
diff --git a/test/test_ecp_arithmetics_ZZZ.c.in 
b/test/test_ecp_arithmetics_ZZZ.c.in
new file mode 100644
index 0000000..0a42862
--- /dev/null
+++ b/test/test_ecp_arithmetics_ZZZ.c.in
@@ -0,0 +1,443 @@
+/**
+ * @file test_ecp_arithmetics_ZZZ.c
+ * @author Alessandro Budroni
+ * @brief Test for aritmetics with ECP_ZZZ
+ *
+ * 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 "arch.h"
+#include "amcl.h"
+#include "utils.h"
+#include "ecp_ZZZ.h"
+
+#define LINE_LEN 1000
+#define MAX_STRING 400
+#define PIN 1234
+
+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);
+}
+
+int read_ECP_ZZZ(ECP_ZZZ *ecp, char* string)
+{
+    BIG_XXX x;
+#if CURVETYPE_ZZZ!=MONTGOMERY
+    BIG_XXX y;
+#endif
+    char *stringy = strchr(string,':');
+    stringy[0] = '\0';
+    read_BIG_XXX(x,string);
+#if CURVETYPE_ZZZ==MONTGOMERY
+    return ECP_ZZZ_set(ecp,x);
+#else
+    stringy++;
+    read_BIG_XXX(y,stringy);
+    return ECP_ZZZ_set(ecp,x,y);
+#endif
+}
+
+int main(int argc, char** argv)
+{
+    if (argc != 2)
+    {
+        printf("usage: ./test_ecp_arithmetics_ZZZ [path to test vector 
file]\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int i=0, len=0;
+
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+
+    ECP_ZZZ inf, ECPaux1;
+    BIG_XXX BIGaux1;
+
+    char oct[LINE_LEN];
+    octet OCTaux = {0,sizeof(oct),oct};
+#if CURVETYPE_ZZZ!=MONTGOMERY
+    BIG_XXX BIGaux2;
+    FP_YYY FPaux1,FPaux2;
+    ECP_ZZZ ECPaux2;
+#endif
+    ECP_ZZZ ecp1;
+    const char* ECP1line = "ECP1 = ";
+#if CURVETYPE_ZZZ!=MONTGOMERY
+    ECP_ZZZ ecp2;
+    const char* ECP2line = "ECP2 = ";
+    ECP_ZZZ ecpsum;
+    const char* ECPsumline = "ECPsum = ";
+    ECP_ZZZ ecpneg;
+    const char* ECPnegline = "ECPneg = ";
+    ECP_ZZZ ecpsub;
+    const char* ECPsubline = "ECPsub = ";
+#endif
+    ECP_ZZZ ecpdbl;
+    const char* ECPdblline = "ECPdbl = ";
+    BIG_XXX BIGscalar1;
+    const char* BIGscalar1line = "BIGscalar1 = ";
+    ECP_ZZZ ecpmul;
+    const char* ECPmulline = "ECPmul = ";
+    ECP_ZZZ ecpwrong;
+    const char* ECPwrongline = "ECPwrong = ";
+    ECP_ZZZ ecpinf;
+    const char* ECPinfline = "ECPinf = ";
+#if CURVETYPE_ZZZ!=MONTGOMERY
+    ECP_ZZZ ecppinmul;
+    const char* ECPpinmulline = "ECPpinmul = ";
+    BIG_XXX BIGscalar2;
+    const char* BIGscalar2line = "BIGscalar2 = ";
+    ECP_ZZZ ecpmul2;
+    const char* ECPmul2line = "ECPmul2 = ";
+    ECP_ZZZ ecpeven;
+    const char* ECPevenline = "ECPeven = ";
+    ECP_ZZZ ecpodd;
+    const char* ECPoddline = "ECPodd = ";
+#endif
+#if CURVETYPE_ZZZ==MONTGOMERY
+    ECP_ZZZ ecpmul3;
+    const char* ECPmul3line = "ECPmul3 = ";
+#endif
+
+    ECP_ZZZ_inf(&inf);
+
+    if(!ECP_ZZZ_isinf(&inf))
+    {
+        printf("ERROR setting ECP_ZZZ to infinity\n");
+        exit(EXIT_FAILURE);
+    }
+
+    FILE *fp;
+    fp = fopen(argv[1],"r");
+    if (fp == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    while (fgets(line, LINE_LEN, fp) != NULL)
+    {
+        i++;
+        if (!strncmp(line,  ECP1line, strlen(ECP1line))) // get first test 
vector
+        {
+            len = strlen(ECP1line);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecp1,linePtr) || ECP_ZZZ_isinf(&ecp1))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+#if CURVETYPE_ZZZ!=MONTGOMERY
+            ECP_ZZZ_get(BIGaux1,BIGaux2,&ecp1);
+            FP_YYY_nres(&FPaux1,BIGaux1);
+            FP_YYY_nres(&FPaux2,BIGaux2);
+            FP_YYY_sqr(&FPaux2,&FPaux2);
+            ECP_ZZZ_rhs(&FPaux1,&FPaux1);
+            FP_YYY_reduce(&FPaux1); // in case of lazy reduction
+            FP_YYY_reduce(&FPaux2); // in case of lazy reduction
+            if (!FP_YYY_equals(&FPaux1,&FPaux2)) // test if y^2=f(x)
+            {
+                printf("ERROR computing right hand side of equation ECP_ZZZ, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+#endif
+            ECP_ZZZ_toOctet(&OCTaux,&ecp1);
+            ECP_ZZZ_fromOctet(&ECPaux1,&OCTaux);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecp1)) // test octet conversion
+            {
+                printf("ERROR converting ECP_ZZZ to/from OCTET, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#if CURVETYPE_ZZZ!=MONTGOMERY
+        if (!strncmp(line,  ECP2line, strlen(ECP2line))) // get second test 
vector
+        {
+            len = strlen(ECP2line);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecp2,linePtr) || ECP_ZZZ_isinf(&ecp2))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  ECPsumline, strlen(ECPsumline)))
+        {
+            len = strlen(ECPsumline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpsum,linePtr) || ECP_ZZZ_isinf(&ecpsum))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_add(&ECPaux1,&ecp2);
+            ECP_ZZZ_affine(&ECPaux1);
+            ECP_ZZZ_copy(&ECPaux2,&ecp2);
+            ECP_ZZZ_add(&ECPaux2,&ecp1);
+            ECP_ZZZ_affine(&ECPaux2);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpsum) || 
!ECP_ZZZ_equals(&ECPaux2,&ecpsum)) // test addition P+Q and Q+P (commutativity)
+            {
+                printf("ERROR adding two ECPs, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1); // test associativity
+            ECP_ZZZ_add(&ECPaux1,&ecp2);
+            ECP_ZZZ_add(&ECPaux1,&ecpsum);
+            ECP_ZZZ_copy(&ECPaux2,&ecpsum);
+            ECP_ZZZ_add(&ECPaux2,&ecp2);
+            ECP_ZZZ_add(&ECPaux2,&ecp1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ECPaux2)) // test associativity 
(P+Q)+R = P+(Q+R)
+            {
+                printf("ERROR testing associativity between three ECPs, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  ECPsubline, strlen(ECPsubline)))
+        {
+            len = strlen(ECPsubline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpsub,linePtr) || ECP_ZZZ_isinf(&ecpsub))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_sub(&ECPaux1,&ecp2);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpsub)) // test subtraction P-Q
+            {
+                printf("ERROR computing subtraction of two ECPs, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  ECPnegline, strlen(ECPnegline)))
+        {
+            len = strlen(ECPnegline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpneg,linePtr) || ECP_ZZZ_isinf(&ecpneg))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_neg(&ECPaux1);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpneg))
+            {
+                printf("ERROR computing negative of ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#endif
+        if (!strncmp(line,  ECPdblline, strlen(ECPdblline)))
+        {
+            len = strlen(ECPdblline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpdbl,linePtr) || ECP_ZZZ_isinf(&ecpdbl))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_dbl(&ECPaux1);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpdbl))
+            {
+                ECP_ZZZ_outputxyz(&ECPaux1);
+                ECP_ZZZ_outputxyz(&ecpdbl);
+                printf("ERROR computing double of ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#if CURVETYPE_ZZZ==MONTGOMERY
+        if (!strncmp(line,  ECPmul3line, strlen(ECPmul3line)))
+        {
+            len = strlen(ECPmul3line);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpmul3,linePtr) || ECP_ZZZ_isinf(&ecpmul3))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            BIG_XXX_one(BIGaux1);
+            BIG_XXX_inc(BIGaux1,2);
+            BIG_XXX_norm(BIGaux1);
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_mul(&ECPaux1,BIGaux1);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpmul3))
+            {
+                printf("ERROR computing multiplication of ECP_ZZZ by 3, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecpdbl);
+            ECP_ZZZ_add(&ECPaux1,&ecp1,&ecp1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpmul3))
+            {
+                printf("ERROR computing multiplication of ECP_ZZZ by 3, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#endif
+        if (!strncmp(line,  BIGscalar1line, strlen(BIGscalar1line)))
+        {
+            len = strlen(BIGscalar1line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGscalar1,linePtr);
+        }
+        if (!strncmp(line,  ECPmulline, strlen(ECPmulline)))
+        {
+            len = strlen(ECPmulline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpmul,linePtr))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_mul(&ECPaux1,BIGscalar1);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpmul))
+            {
+                ECP_ZZZ_outputxyz(&ecp1);
+                ECP_ZZZ_outputxyz(&ECPaux1);
+                ECP_ZZZ_outputxyz(&ecpmul);
+                printf("ERROR computing multiplication of ECP_ZZZ by a scalar, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#if CURVETYPE_ZZZ!=MONTGOMERY
+        if (!strncmp(line,  ECPpinmulline, strlen(ECPpinmulline)))
+        {
+            len = strlen(ECPpinmulline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecppinmul,linePtr))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_pinmul(&ECPaux1,PIN,14);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecppinmul))
+            {
+                printf("ERROR computing multiplication of ECP_ZZZ by small 
integer, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  BIGscalar2line, strlen(BIGscalar2line)))
+        {
+            len = strlen(BIGscalar2line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGscalar2,linePtr);
+        }
+        if (!strncmp(line,  ECPmul2line, strlen(ECPmul2line)))
+        {
+            len = strlen(ECPmul2line);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpmul2,linePtr))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_copy(&ECPaux1,&ecp1);
+            ECP_ZZZ_copy(&ECPaux2,&ecp2);
+            ECP_ZZZ_mul2(&ECPaux1,&ECPaux2,BIGscalar1,BIGscalar2);
+            ECP_ZZZ_affine(&ECPaux1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpmul2))
+            {
+                printf("ERROR computing linear combination of 2 ECPs, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#endif
+        if (!strncmp(line,  ECPwrongline, strlen(ECPwrongline)))
+        {
+            len = strlen(ECPwrongline);
+            linePtr = line + len;
+            if(read_ECP_ZZZ(&ecpwrong,linePtr) || !ECP_ZZZ_isinf(&ecpwrong) || 
!ECP_ZZZ_equals(&ecpwrong,&inf))
+            {
+                printf("ERROR identifying wrong ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  ECPinfline, strlen(ECPinfline)))
+        {
+            len = strlen(ECPinfline);
+            linePtr = line + len;
+            if(read_ECP_ZZZ(&ecpinf,linePtr) || !ECP_ZZZ_isinf(&ecpinf) || 
!ECP_ZZZ_equals(&ecpinf,&inf))
+            {
+                printf("ERROR identifying infinite point ECP_ZZZ, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#if CURVETYPE_ZZZ!=MONTGOMERY
+        if (!strncmp(line,  ECPevenline, strlen(ECPevenline)))
+        {
+            len = strlen(ECPevenline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpeven,linePtr))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_get(BIGaux1,BIGaux2,&ecp1);
+            BIG_XXX_norm(BIGaux1);
+            ECP_ZZZ_setx(&ECPaux1,BIGaux1,0);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpeven))
+            {
+                printf("ERROR computing ECP_ZZZ from coordinate x and with y 
even, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        if (!strncmp(line,  ECPoddline, strlen(ECPoddline)))
+        {
+            len = strlen(ECPoddline);
+            linePtr = line + len;
+            if(!read_ECP_ZZZ(&ecpodd,linePtr))
+            {
+                printf("ERROR getting test vector input ECP_ZZZ, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            ECP_ZZZ_setx(&ECPaux1,BIGaux1,1);
+            if(!ECP_ZZZ_equals(&ECPaux1,&ecpodd))
+            {
+                printf("ERROR computing ECP_ZZZ from coordinate x and with y 
odd, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#endif
+    }
+    fclose(fp);
+
+    printf("SUCCESS TEST ARITMETIC OF ECP_ZZZ PASSED\n");
+    exit(EXIT_SUCCESS);
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_fp12_arithmetics_YYY.c.in
----------------------------------------------------------------------
diff --git a/test/test_fp12_arithmetics_YYY.c.in 
b/test/test_fp12_arithmetics_YYY.c.in
new file mode 100644
index 0000000..f810dc1
--- /dev/null
+++ b/test/test_fp12_arithmetics_YYY.c.in
@@ -0,0 +1,605 @@
+/**
+ * @file test_fp_arithmetics.c
+ * @author Alessandro Budroni
+ * @brief Test for aritmetics with FP
+ *
+ * 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 "fp12_YYY.h"
+
+#define LINE_LEN 5000
+
+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_FP2_YYY(FP2_YYY *fp2, char* stringx)
+{
+    char *stringy, *end;
+    BIG_XXX x,y;
+
+    stringy = strchr(++stringx,',');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    *stringy = '\0';
+
+    end = strchr(++stringy,']');
+    if (end == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    *end = '\0';
+
+    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, *end;
+    FP2_YYY x,y;
+
+    stringy = strchr(++stringx,']');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    *(++stringy) = '\0';
+
+    end = strchr(++stringy,']');
+    if (end == NULL)
+    {
+        printf("ERROR unexpected test vector\n");
+        exit(EXIT_FAILURE);
+    }
+    *(++end) = '\0';
+
+    read_FP2_YYY(&x,stringx);
+    read_FP2_YYY(&y,stringy);
+
+    FP4_YYY_from_FP2s(fp4,&x,&y);
+}
+
+// Read a structure of the type 
[[[ax1,ax2],[ay1,ay2]],[[bx1,bx2],[by1,by2]],[[cx1,cx2],[cy1,cy2]]]
+void read_FP12_YYY(FP12_YYY *fp12, char *stringx)
+{
+    char *stringy, *stringz, *end;
+    FP4_YYY x,y,z;
+
+    stringy = strchr(++stringx,']');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector a\n");
+        exit(EXIT_FAILURE);
+    }
+    stringy = strchr(++stringy,']');
+    if (stringy == NULL)
+    {
+        printf("ERROR unexpected test vector b\n");
+        exit(EXIT_FAILURE);
+    }
+    stringy+=2;
+    *stringy = '\0';
+
+    stringz = strchr(++stringy,']');
+    if (stringz == NULL)
+    {
+        printf("ERROR unexpected test vector c\n");
+        exit(EXIT_FAILURE);
+    }
+    stringz = strchr(++stringz,']');
+    if (stringz == NULL)
+    {
+        printf("ERROR unexpected test vector d\n");
+        exit(EXIT_FAILURE);
+    }
+    stringz+=2;
+    *stringz = '\0';
+
+    end = strchr(++stringz,']');
+    if (end == NULL)
+    {
+        printf("ERROR unexpected test vector e\n");
+        exit(EXIT_FAILURE);
+    }
+    end = strchr(++end,']');
+    if (end == NULL)
+    {
+        printf("ERROR unexpected test vector f\n");
+        exit(EXIT_FAILURE);
+    }
+    end+=2;
+    *end = '\0';
+
+    read_FP4_YYY(&x,stringx);
+    read_FP4_YYY(&y,stringy);
+    read_FP4_YYY(&z,stringz);
+
+    FP12_YYY_from_FP4s(fp12,&x,&y,&z);
+
+    FP12_YYY_reduce(fp12);
+    FP12_YYY_norm(fp12);
+}
+
+int main(int argc, char** argv)
+{
+
+    if (argc != 2)
+    {
+        printf("usage: ./test_fp12_arithmetics [path to test vector file]\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int i = 0, j = 1, len = 0;
+    FILE *fp;
+
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+
+    BIG_XXX M, Fr_a, Fr_b;
+    FP2_YYY Frob;
+    FP4_YYY FP4aux1;
+    FP12_YYY FP12aux1, FP12aux2;
+
+    FP12_YYY FP_12[5];
+    const char* FP12_1line = "FP12_1 = ";
+    const char* FP12_2line = "FP12_2 = ";
+    const char* FP12_3line = "FP12_3 = ";
+    const char* FP12_4line = "FP12_4 = ";
+    const char* FP12_cline = "FP12_c = ";
+    FP12_YYY FP_12_smul_y_dtype;
+    const char* FP12smul_y_dtypeline = "FP12smul_y_dtype = ";
+    FP12_YYY FP_12_smul_y_mtype;
+    const char* FP12smul_y_mtypeline = "FP12smul_y_mtype = ";
+    FP12_YYY FP12conj;
+    const char* FP12conjline = "FP12conj = ";
+    FP12_YYY FP12usquare;
+    const char* FP12usquareline = "FP12usquare = ";
+    FP12_YYY FP12square;
+    const char* FP12squareline = "FP12square = ";
+    FP12_YYY FP12mul;
+    const char* FP12mulline = "FP12mul = ";
+    FP12_YYY FP12smul_dtype;
+    const char* FP12smuldtypeline = "FP12smul_dtype = ";
+    FP12_YYY FP12smul_mtype;
+    const char* FP12smulmtypeline = "FP12smul_mtype = ";
+    FP12_YYY FP12inv;
+    const char* FP12invline = "FP12inv = ";
+    BIG_XXX BIGsc[6];
+    const char* BIGsc1line = "BIGsc1 = ";
+    const char* BIGsc2line = "BIGsc2 = ";
+    const char* BIGsc3line = "BIGsc3 = ";
+    const char* BIGsc4line = "BIGsc4 = ";
+    const char* BIGscsline = "BIGscs = ";
+    const char* BIGscoline = "BIGsco = ";
+    FP12_YYY FP12pow;
+    const char* FP12powline = "FP12pow = ";
+    FP12_YYY FP12pinpow;
+    const char* FP12pinpowline = "FP12pinpow = ";
+    FP4_YYY FP12compows;
+    const char* FP12compowsline = "FP12compows = ";
+    FP4_YYY FP12compow;
+    const char* FP12compowline = "FP12compow = ";
+    FP12_YYY FP12pow4;
+    const char* FP12pow4line = "FP12pow4 = ";
+    FP12_YYY FP12frob;
+    const char* FP12frobline = "FP12frob = ";
+    FP4_YYY FP4trace;
+    const char* FP4traceline = "FP4trace = ";
+
+    BIG_XXX_rcopy(M,Modulus_YYY);
+    BIG_XXX_rcopy(Fr_a,Fra_YYY);
+    BIG_XXX_rcopy(Fr_b,Frb_YYY);
+    FP2_YYY_from_BIGs(&Frob,Fr_a,Fr_b);
+
+    // Set to one
+    FP12_YYY_one(&FP12aux1);
+    FP12_YYY_copy(&FP12aux2,&FP12aux1);
+
+    // Testing equal function, copy function and set one function
+    if(!FP12_YYY_equals(&FP12aux1,&FP12aux2) || !FP12_YYY_isunity(&FP12aux1) 
|| !FP12_YYY_isunity(&FP12aux2))
+    {
+        printf("ERROR comparing FP12s or setting FP12 to unity or copying 
FP12\n");
+        exit(EXIT_FAILURE);
+    }
+
+    // Testing equal to zero function
+    if(FP12_YYY_iszilch(&FP12aux1))
+    {
+        printf("ERROR checking if FP12 is not zero\n");
+        exit(EXIT_FAILURE);
+    }
+    FP4_YYY_zero(&FP4aux1);
+    FP12_YYY_from_FP4(&FP12aux1,&FP4aux1);
+    if(!FP12_YYY_iszilch(&FP12aux1))
+    {
+        printf("ERROR checking if FP12 is zero\n");
+        exit(EXIT_FAILURE);
+    }
+
+    fp = fopen(argv[1], "r");
+    if (fp == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    while (fgets(line, LINE_LEN, fp) != NULL)
+    {
+        i++;
+        // Read first FP12 and perform some tests
+        if (!strncmp(line,FP12_1line, strlen(FP12_1line)))
+        {
+            len = strlen(FP12_1line);
+            linePtr = line + len;
+            read_FP12_YYY(&FP_12[0],linePtr);
+            FP12_YYY_from_FP4(&FP12aux1,&FP_12[0].a);
+            if(!FP4_YYY_equals(&FP12aux1.a,&FP_12[0].a) || 
!FP4_YYY_iszilch(&FP12aux1.b) || !FP4_YYY_iszilch(&FP12aux1.c))
+            {
+                printf("ERROR setting FP12 from a FP4, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            FP12_YYY_from_FP4s(&FP12aux1,&FP_12[0].a,&FP_12[0].b,&FP_12[0].c);
+            if(!FP12_YYY_equals(&FP12aux1,&FP_12[0]))
+            {
+                printf("ERROR setting FP12 from three FP4s, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read second FP12
+        if (!strncmp(line,FP12_2line, strlen(FP12_2line)))
+        {
+            len = strlen(FP12_2line);
+            linePtr = line + len;
+            read_FP12_YYY(FP_12+1,linePtr);
+        }
+        // Read third FP12
+        if (!strncmp(line,FP12_3line, strlen(FP12_3line)))
+        {
+            len = strlen(FP12_3line);
+            linePtr = line + len;
+            read_FP12_YYY(FP_12+2,linePtr);
+        }
+        // Read fourth FP12
+        if (!strncmp(line,FP12_4line, strlen(FP12_4line)))
+        {
+            len = strlen(FP12_4line);
+            linePtr = line + len;
+            read_FP12_YYY(FP_12+3,linePtr);
+        }
+        // Read compow FP12
+        if (!strncmp(line,FP12_cline, strlen(FP12_cline)))
+        {
+            len = strlen(FP12_cline);
+            linePtr = line + len;
+            read_FP12_YYY(FP_12+4,linePtr);
+        }
+        // Read y for M-TYPE smul test
+        if (!strncmp(line,FP12smul_y_mtypeline, strlen(FP12smul_y_mtypeline)))
+        {
+            len = strlen(FP12smul_y_mtypeline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP_12_smul_y_mtype,linePtr);
+        }
+        // Read y for D-TYPE smul test
+        if (!strncmp(line,FP12smul_y_dtypeline, strlen(FP12smul_y_dtypeline)))
+        {
+            len = strlen(FP12smul_y_dtypeline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP_12_smul_y_dtype,linePtr);
+        }
+        // Test FP12_YYY_conj
+        if (!strncmp(line,FP12conjline, strlen(FP12conjline)))
+        {
+            len = strlen(FP12conjline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12conj,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_conj(&FP12aux1,&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12conj))
+            {
+                printf("ERROR computing conjugate of FP12, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test multiplication and commutativity
+        if (!strncmp(line,FP12mulline, strlen(FP12mulline)))
+        {
+            len = strlen(FP12mulline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12mul,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_mul(&FP12aux1,FP_12+1);
+            FP12_YYY_copy(&FP12aux2,FP_12+1);
+            FP12_YYY_mul(&FP12aux2,FP_12);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            FP12_YYY_reduce(&FP12aux2);
+            FP12_YYY_norm(&FP12aux2);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12mul) || 
!FP12_YYY_equals(&FP12aux2,&FP12mul))
+            {
+                printf("ERROR computing multiplication of two FP12s, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test squaring
+        if (!strncmp(line,FP12squareline, strlen(FP12squareline)))
+        {
+            len = strlen(FP12squareline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12square,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_sqr(&FP12aux1,&FP12aux1);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12square))
+            {
+                printf("ERROR computing square of FP12, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test usquaring
+        if (!strncmp(line,FP12usquareline, strlen(FP12usquareline)))
+        {
+            len = strlen(FP12usquareline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12usquare,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_usqr(&FP12aux1,&FP12aux1);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12usquare))
+            {
+                printf("ERROR computing usquare of FP12, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test s-multiplication for D-TYPE
+        if (!strncmp(line,FP12smuldtypeline, strlen(FP12smuldtypeline)))
+        {
+            len = strlen(FP12smuldtypeline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12smul_dtype,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_smul(&FP12aux1,&FP_12_smul_y_dtype,D_TYPE);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12smul_dtype))
+            {
+                printf("ERROR computing s-multiplication for D-TYPE, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test s-multiplication for M-TYPE
+        if (!strncmp(line,FP12smulmtypeline, strlen(FP12smulmtypeline)))
+        {
+            len = strlen(FP12smulmtypeline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12smul_mtype,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_smul(&FP12aux1,&FP_12_smul_y_mtype,M_TYPE);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12smul_mtype))
+            {
+                printf("ERROR computing s-multiplication for M-TYPE, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test inverse fuction
+        if (!strncmp(line,FP12invline, strlen(FP12invline)))
+        {
+            len = strlen(FP12invline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12inv,linePtr);
+            FP12_YYY_copy(&FP12aux1,&FP_12[0]);
+            FP12_YYY_inv(&FP12aux1,&FP12aux1);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12inv))
+            {
+                printf("ERROR computing inverse of a FP12, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read first BIG
+        if (!strncmp(line,BIGsc1line, strlen(BIGsc1line)))
+        {
+            len = strlen(BIGsc1line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[0],linePtr);
+        }
+        // Read second BIG
+        if (!strncmp(line,BIGsc2line, strlen(BIGsc2line)))
+        {
+            len = strlen(BIGsc2line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[1],linePtr);
+        }
+        // Read third BIG
+        if (!strncmp(line,BIGsc3line, strlen(BIGsc3line)))
+        {
+            len = strlen(BIGsc3line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[2],linePtr);
+        }
+        // Read fourth BIG
+        if (!strncmp(line,BIGsc4line, strlen(BIGsc4line)))
+        {
+            len = strlen(BIGsc4line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[3],linePtr);
+        }
+        // Read small BIG
+        if (!strncmp(line,BIGscsline, strlen(BIGscsline)))
+        {
+            len = strlen(BIGscsline);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[4],linePtr);
+        }
+        // Read order BIG
+        if (!strncmp(line,BIGscoline, strlen(BIGscoline)))
+        {
+            len = strlen(BIGscoline);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc[5],linePtr);
+        }
+        // Test power by a BIG
+        if (!strncmp(line,FP12powline, strlen(FP12powline)))
+        {
+            len = strlen(FP12powline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12pow,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_pow(&FP12aux1,&FP12aux1,BIGsc[0]);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12pow))
+            {
+                printf("ERROR computing power of a FP12 by a BIG, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test power by a small integer
+        if (!strncmp(line,FP12pinpowline, strlen(FP12pinpowline)))
+        {
+            len = strlen(FP12pinpowline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12pinpow,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_pinpow(&FP12aux1,j,10);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12pinpow))
+            {
+                printf("ERROR computing power of a FP12 by a small integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            j++;
+        }
+        // Test fucntion FP12_YYY_compow with small integer [< Modulus mod 
Curve_Order]
+        if (!strncmp(line,FP12compowsline, strlen(FP12compowsline)))
+        {
+            len = strlen(FP12compowsline);
+            linePtr = line + len;
+            read_FP4_YYY(&FP12compows,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12+4);
+            FP12_YYY_compow(&FP4aux1,&FP12aux1,BIGsc[4],BIGsc[5]);
+            FP4_YYY_reduce(&FP4aux1);
+            FP4_YYY_norm(&FP4aux1);
+            if(!FP4_YYY_equals(&FP4aux1,&FP12compows))
+            {
+                printf("ERROR testing function FP12_compow with small integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test fucntion FP12_YYY_compow with big integer [> Modulus mod 
Curve_Order]
+        if (!strncmp(line,FP12compowline, strlen(FP12compowline)))
+        {
+            len = strlen(FP12compowline);
+            linePtr = line + len;
+            read_FP4_YYY(&FP12compow,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12+4);
+            FP12_YYY_compow(&FP4aux1,&FP12aux1,BIGsc[0],BIGsc[5]);
+            FP4_YYY_reduce(&FP4aux1);
+            FP4_YYY_norm(&FP4aux1);
+            if(!FP4_YYY_equals(&FP4aux1,&FP12compow))
+            {
+                printf("ERROR testing function FP12_compow with big integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test function FP12_YYY_pow4
+        if (!strncmp(line,FP12pow4line, strlen(FP12pow4line)))
+        {
+            len = strlen(FP12pow4line);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12pow4,linePtr);
+            FP12_YYY_pow4(&FP12aux1,FP_12,BIGsc);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12pow4))
+            {
+                printf("ERROR testing function FP12pow4, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Raises an FP12 to the power of the internal modulus p, using the 
Frobenius constant f
+        if (!strncmp(line,FP12frobline, strlen(FP12frobline)))
+        {
+            len = strlen(FP12frobline);
+            linePtr = line + len;
+            read_FP12_YYY(&FP12frob,linePtr);
+            FP12_YYY_copy(&FP12aux1,FP_12);
+            FP12_YYY_frob(&FP12aux1,&Frob);
+            FP12_YYY_reduce(&FP12aux1);
+            FP12_YYY_norm(&FP12aux1);
+            if(!FP12_YYY_equals(&FP12aux1,&FP12frob))
+            {
+                printf("ERROR in raising FP12 by an internal modulus p, using 
the Frobenius constant f, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test computing trace of FP12
+        if (!strncmp(line,FP4traceline, strlen(FP4traceline)))
+        {
+            len = strlen(FP4traceline);
+            linePtr = line + len;
+            read_FP4_YYY(&FP4trace,linePtr);
+            FP12_YYY_copy(&FP12aux1,&FP_12[0]);
+            FP12_YYY_trace(&FP4aux1,&FP12aux1);
+            FP4_YYY_reduce(&FP4aux1);
+            FP4_YYY_norm(&FP4aux1);
+            if(!FP4_YYY_equals(&FP4aux1,&FP4trace))
+            {
+                printf("ERROR computing trace of FP12, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+    }
+
+    fclose(fp);
+
+    printf("SUCCESS TEST ARITMETIC OF FP12 PASSED\n");
+    exit(EXIT_SUCCESS);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_fp16_arithmetics_YYY.c.in
----------------------------------------------------------------------
diff --git a/test/test_fp16_arithmetics_YYY.c.in 
b/test/test_fp16_arithmetics_YYY.c.in
new file mode 100644
index 0000000..66bcc7f
--- /dev/null
+++ b/test/test_fp16_arithmetics_YYY.c.in
@@ -0,0 +1,584 @@
+/**
+ * @file test_FP16_arithmetics_YYY.c
+ * @author Samuele Andreoli
+ * @brief Test for aritmetics with FP16_YYY
+ *
+ * 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 "fp16_YYY.h"
+
+#define LINE_LEN 10000
+#define MAX_STRING 300
+
+/*
+ * 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_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);
+}
+
+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);
+}
+
+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);
+}
+
+int main(int argc, char** argv)
+{
+    if (argc != 2)
+    {
+        printf("usage: ./test_fp4_arithmetics_YYY [path to test vector 
file]\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int i = 0, len = 0, j = 0;
+    FILE *fp;
+
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+
+    FP16_YYY FP16aux1, FP16aux2, FP16aux3, FP16aux4;
+
+    FP16_YYY FP16_1;
+    const char* FP16_1line = "FP16_1 = ";
+    FP16_YYY FP16_2;
+    const char* FP16_2line = "FP16_2 = ";
+    FP16_YYY FP16add;
+    const char* FP16addline = "FP16add = ";
+    FP16_YYY FP16neg;
+    const char* FP16negline = "FP16neg = ";
+    FP16_YYY FP16sub;
+    const char* FP16subline = "FP16sub = ";
+    FP16_YYY FP16conj;
+    const char* FP16conjline = "FP16conj = ";
+    FP16_YYY FP16nconj;
+    const char* FP16nconjline = "FP16nconj = ";
+    FP8_YYY FP8sc;
+    const char* FP8scline = "FP8sc = ";
+    FP16_YYY FP16pmul;
+    const char* FP16pmulline = "FP16pmul = ";
+    FP2_YYY FP2sc;
+    const char* FP2scline = "FP2sc = ";
+    FP16_YYY FP16qmul;
+    const char* FP16qmulline = "FP16qmul = ";
+    FP16_YYY FP16imul;
+    const char* FP16imulline = "FP16imul = ";
+    FP16_YYY FP16sqr;
+    const char* FP16sqrline = "FP16sqr = ";
+    FP16_YYY FP16mul;
+    const char* FP16mulline = "FP16mul = ";
+    FP16_YYY FP16inv;
+    const char* FP16invline = "FP16inv = ";
+    FP16_YYY FP16mulj;
+    const char* FP16muljline = "FP16mulj = ";
+    BIG_XXX BIGsc1;
+    const char* BIGsc1line = "BIGsc1 = ";
+    BIG_XXX BIGsc2;
+    const char* BIGsc2line = "BIGsc2 = ";
+    FP16_YYY FP16pow;
+    const char* FP16powline = "FP16pow = ";
+#if CURVE_SECURITY_ZZZ == 256
+    FP16_YYY FP48traces[4];
+    const char* FP48_1line = "FP48_1 = ";
+    const char* FP48_2line = "FP48_2 = ";
+    const char* FP48_3line = "FP48_3 = ";
+    const char* FP48_4line = "FP48_4 = ";
+    FP16_YYY FP16_xtrA;
+    const char* FP16_xtrAline = "FP16_xtrA = ";
+    FP16_YYY FP16_xtrD;
+    const char* FP16_xtrDline = "FP16_xtrD = ";
+    FP16_YYY FP16_xtrpow;
+    const char* FP16_xtrpowline = "FP16_xtrpow = ";
+    FP16_YYY FP16_xtrpow2;
+    const char* FP16_xtrpow2line = "FP16_xtrpow2 = ";
+#endif
+
+    // Set to zero and one
+    FP16_YYY_zero(&FP16aux1);
+    FP16_YYY_zero(&FP16aux2);
+
+    // Testing equal function and set zero function
+    if(!FP16_YYY_equals(&FP16aux1,&FP16aux2) || !FP16_YYY_iszilch(&FP16aux1) 
|| !FP16_YYY_isreal(&FP16aux1))
+    {
+        printf("ERROR comparing FP16s or setting FP16 to zero FP\n");
+        exit(EXIT_FAILURE);
+    }
+
+    // Set to one
+    FP16_YYY_one(&FP16aux1);
+
+    // Testing equal function and set one function
+    if(FP16_YYY_equals(&FP16aux1,&FP16aux2) || !FP16_YYY_isunity(&FP16aux1) || 
FP16_YYY_isunity(&FP16aux2) || FP16_YYY_iszilch(&FP16aux1) || 
!FP16_YYY_isreal(&FP16aux1))
+    {
+        printf("ERROR comparing FP16s or setting FP16 to unity FP\n");
+        exit(EXIT_FAILURE);
+    }
+
+
+    fp = fopen(argv[1], "r");
+    if (fp == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    while (fgets(line, LINE_LEN, fp) != NULL)
+    {
+        i++;
+        // Read first FP16 and perform some tests
+        if (!strncmp(line,FP16_1line, strlen(FP16_1line)))
+        {
+            len = strlen(FP16_1line);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_1,linePtr);
+            // test FP16_from_FP8s
+            FP16_YYY_from_FP8s(&FP16aux1,&FP16_1.a,&FP16_1.b);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16_1))
+            {
+                printf("ERROR in generating FP16 from two FP8s, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            // test FP16_from_FP8
+            FP16_YYY_from_FP8(&FP16aux1,&FP16_1.a);
+            FP16_YYY_copy(&FP16aux2,&FP16_1);
+            FP8_YYY_zero(&FP16aux2.b);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16aux2))
+            {
+                printf("ERROR in generating FP16 from one FP8, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            // test FP16_from_FP4
+            FP16_YYY_from_FP8H(&FP16aux1,&FP16_1.b);
+            FP16_YYY_copy(&FP16aux2,&FP16_1);
+            FP8_YYY_zero(&FP16aux2.a);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16aux2))
+            {
+                printf("ERROR in generating FP16 from one FP8 as high part, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read second FP16
+        if (!strncmp(line,FP16_2line, strlen(FP16_2line)))
+        {
+            len = strlen(FP16_2line);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_2,linePtr);
+        }
+        // Addition test
+        if (!strncmp(line,FP16addline, strlen(FP16addline)))
+        {
+            len = strlen(FP16addline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16add,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_copy(&FP16aux2,&FP16_2);
+            FP16_YYY_add(&FP16aux1,&FP16aux1,&FP16aux2);
+            // test commutativity P+Q = Q+P
+            FP16_YYY_copy(&FP16aux3,&FP16_1);
+            FP16_YYY_add(&FP16aux2,&FP16aux2,&FP16aux3);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16add) || 
!FP16_YYY_equals(&FP16aux2,&FP16add))
+            {
+                printf("ERROR adding two FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            // test associativity (P+Q)+R = P+(Q+R)
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_copy(&FP16aux3,&FP16_1);
+            FP16_YYY_copy(&FP16aux2,&FP16_2);
+            FP16_YYY_copy(&FP16aux4,&FP16add);
+            FP16_YYY_add(&FP16aux1,&FP16aux1,&FP16aux2);
+            FP16_YYY_add(&FP16aux1,&FP16aux1,&FP16aux4);
+            FP16_YYY_add(&FP16aux2,&FP16aux2,&FP16aux4);
+            FP16_YYY_add(&FP16aux2,&FP16aux2,&FP16aux3);
+            FP16_YYY_reduce(&FP16aux1);
+            FP16_YYY_norm(&FP16aux2);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16aux2))
+            {
+                printf("ERROR testing associativity between three FP16s, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test negative of an FP16
+        if (!strncmp(line,FP16negline, strlen(FP16negline)))
+        {
+            len = strlen(FP16negline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16neg,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_neg(&FP16aux1,&FP16aux1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16neg))
+            {
+                printf("ERROR in computing negative of FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Subtraction test
+        if (!strncmp(line,FP16subline, strlen(FP16subline)))
+        {
+            len = strlen(FP16subline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16sub,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_copy(&FP16aux2,&FP16_2);
+            FP16_YYY_sub(&FP16aux1,&FP16aux1,&FP16aux2);
+            if(FP16_YYY_equals(&FP16aux1,&FP16sub) == 0)
+            {
+                printf("ERROR subtraction between two FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test conjugate
+        if (!strncmp(line,FP16conjline, strlen(FP16conjline)))
+        {
+            len = strlen(FP16conjline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16conj,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_conj(&FP16aux1,&FP16aux1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16conj))
+            {
+                printf("ERROR computing conjugate of FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test negative conjugate
+        if (!strncmp(line,FP16nconjline, strlen(FP16nconjline)))
+        {
+            len = strlen(FP16nconjline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16nconj,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_nconj(&FP16aux1,&FP16aux1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16nconj))
+            {
+                printf("ERROR computing negative conjugate of FP16, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read FP8 scalar
+        if (!strncmp(line,FP8scline, strlen(FP8scline)))
+        {
+            len = strlen(FP8scline);
+            linePtr = line + len;
+            read_FP8_YYY(&FP8sc,linePtr);
+        }
+        // Read FP2 scalar
+        if (!strncmp(line,FP2scline, strlen(FP2scline)))
+        {
+            len = strlen(FP2scline);
+            linePtr = line + len;
+            read_FP2_YYY(&FP2sc,linePtr);
+        }
+        // Multiplication by FP8
+        if (!strncmp(line,FP16pmulline, strlen(FP16pmulline)))
+        {
+            len = strlen(FP16pmulline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16pmul,linePtr);
+            FP16_YYY_pmul(&FP16aux1,&FP16_1,&FP8sc);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16pmul))
+            {
+                printf("ERROR in multiplication by FP8, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Multiplication by FP2
+        if (!strncmp(line,FP16qmulline, strlen(FP16qmulline)))
+        {
+            len = strlen(FP16qmulline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16qmul,linePtr);
+            FP16_YYY_qmul(&FP16aux1,&FP16_1,&FP2sc);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16qmul))
+            {
+                printf("ERROR in multiplication by FP2, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Multiplication by j = 0..2
+        if (!strncmp(line,FP16imulline, strlen(FP16imulline)))
+        {
+            len = strlen(FP16imulline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16imul,linePtr);
+            FP16_YYY_imul(&FP16aux1,&FP16_1,j);
+            j++;
+            if(!FP16_YYY_equals(&FP16aux1,&FP16imul))
+            {
+                printf("ERROR in multiplication by small integer, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Square test
+        if (!strncmp(line,FP16sqrline, strlen(FP16sqrline)))
+        {
+            len = strlen(FP16sqrline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16sqr,linePtr);
+            FP16_YYY_sqr(&FP16aux1,&FP16_1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16sqr))
+            {
+                printf("ERROR in squaring FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Multiplication between two FP16s
+        if (!strncmp(line,FP16mulline, strlen(FP16mulline)))
+        {
+            len = strlen(FP16mulline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16mul,linePtr);
+            FP16_YYY_mul(&FP16aux1,&FP16_1,&FP16_2);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16mul))
+            {
+                printf("ERROR in multiplication between two FP16s, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Inverse
+        if (!strncmp(line,FP16invline, strlen(FP16invline)))
+        {
+            len = strlen(FP16invline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16inv,linePtr);
+            FP16_YYY_inv(&FP16aux1,&FP16_1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16inv))
+            {
+                printf("ERROR in computing inverse of FP16, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test multiplication of an FP16 instance by sqrt(sqrt(1+sqrt(-1)))
+        if (!strncmp(line,FP16muljline, strlen(FP16muljline)))
+        {
+            len = strlen(FP16muljline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16mulj,linePtr);
+            FP16_YYY_copy(&FP16aux1,&FP16_1);
+            FP16_YYY_times_i(&FP16aux1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16mulj))
+            {
+                printf("ERROR in  multiplication of an FP16 instance by 
sqrt(sqrt(1+sqrt(-1))), line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read exponent
+        if (!strncmp(line,BIGsc1line, strlen(BIGsc1line)))
+        {
+            len = strlen(BIGsc1line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc1,linePtr);
+        }
+        if (!strncmp(line,BIGsc2line, strlen(BIGsc2line)))
+        {
+            len = strlen(BIGsc2line);
+            linePtr = line + len;
+            read_BIG_XXX(BIGsc2,linePtr);
+        }
+        // Raise FP16 by BIG power
+        if (!strncmp(line,FP16powline, strlen(FP16powline)))
+        {
+            len = strlen(FP16powline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16pow,linePtr);
+            FP16_YYY_pow(&FP16aux1,&FP16_1,BIGsc1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16pow))
+            {
+                printf("ERROR in raising FP16 by BIG power, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#if CURVE_SECURITY_ZZZ == 256
+        // Read first FP48 trace
+        if (!strncmp(line,FP48_1line, strlen(FP48_1line)))
+        {
+            len = strlen(FP48_1line);
+            linePtr = line + len;
+            read_FP16_YYY(FP48traces,linePtr);
+        }
+        // Read second FP48 trace
+        if (!strncmp(line,FP48_2line, strlen(FP48_2line)))
+        {
+            len = strlen(FP48_2line);
+            linePtr = line + len;
+            read_FP16_YYY(FP48traces+1,linePtr);
+        }
+        // Read third FP48 trace
+        if (!strncmp(line,FP48_3line, strlen(FP48_3line)))
+        {
+            len = strlen(FP48_3line);
+            linePtr = line + len;
+            read_FP16_YYY(FP48traces+2,linePtr);
+        }
+        // Read fourth FP48 trace
+        if (!strncmp(line,FP48_4line, strlen(FP48_4line)))
+        {
+            len = strlen(FP48_4line);
+            linePtr = line + len;
+            read_FP16_YYY(FP48traces+3,linePtr);
+        }
+        // Test the XTR addition function r=w*x-conj(x)*y+z
+        if (!strncmp(line,FP16_xtrAline, strlen(FP16_xtrAline)))
+        {
+            len = strlen(FP16_xtrAline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_xtrA,linePtr);
+            FP16_YYY_xtr_A(&FP16aux1,&FP16_1,&FP16_2,&FP16add,&FP16sub);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16_xtrA))
+            {
+                printf("ERROR in testing the XTR addition function 
r=w*x-conj(x)*y+z, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test the XTR doubling function r=x^2-2*conj(x)
+        if (!strncmp(line,FP16_xtrDline, strlen(FP16_xtrDline)))
+        {
+            len = strlen(FP16_xtrDline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_xtrD,linePtr);
+            FP16_YYY_xtr_D(&FP16aux1,&FP16_1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16_xtrD))
+            {
+                printf("ERROR in testing the XTR doubling function 
r=x^2-2*conj(x), line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Calculates FP16 trace of an FP48 raised to the power of a BIG number
+        if (!strncmp(line,FP16_xtrpowline, strlen(FP16_xtrpowline)))
+        {
+            len = strlen(FP16_xtrpowline);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_xtrpow,linePtr);
+            FP16_YYY_xtr_pow(&FP16aux1,FP48traces,BIGsc1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16_xtrpow))
+            {
+                printf("ERROR computing FP16 trace of an FP48 raised to the 
power of a BIG number, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Calculates FP16 trace of two FP48 raised to the power of two BIG 
numbers
+        if (!strncmp(line,FP16_xtrpow2line, strlen(FP16_xtrpow2line)))
+        {
+            len = strlen(FP16_xtrpow2line);
+            linePtr = line + len;
+            read_FP16_YYY(&FP16_xtrpow2,linePtr);
+            
FP16_YYY_xtr_pow2(&FP16aux1,FP48traces+1,FP48traces,FP48traces+2,FP48traces+3,BIGsc2,BIGsc1);
+            if(!FP16_YYY_equals(&FP16aux1,&FP16_xtrpow2))
+            {
+                printf("ERROR computing FP16 trace of an FP48 raised to the 
power of a BIG number (Double), line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+#endif
+    }
+    fclose(fp);
+
+    printf("SUCCESS TEST ARITMETIC OF FP PASSED\n");
+    exit(EXIT_SUCCESS);
+}

http://git-wip-us.apache.org/repos/asf/incubator-milagro-crypto-c/blob/8d28d2c3/test/test_fp24_arithmetics_YYY.c.in
----------------------------------------------------------------------
diff --git a/test/test_fp24_arithmetics_YYY.c.in 
b/test/test_fp24_arithmetics_YYY.c.in
new file mode 100644
index 0000000..29fe023
--- /dev/null
+++ b/test/test_fp24_arithmetics_YYY.c.in
@@ -0,0 +1,526 @@
+/**
+ * @file test_fp_arithmetics.c
+ * @author Samuele Andreoli
+ * @brief Test for aritmetics with FP
+ *
+ * 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 "fp24_YYY.h"
+
+#define LINE_LEN 5000
+
+/*
+ * 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_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);
+}
+
+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);
+}
+
+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 main(int argc, char** argv)
+{
+
+    if (argc != 2)
+    {
+        printf("usage: ./test_fp24_arithmetics_ZZZ [path to test vector 
file]\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int i = 0, j = 1, k, len = 0;
+    FILE *fp;
+
+    char line[LINE_LEN];
+    char * linePtr = NULL;
+
+    BIG_XXX M, Fr_a, Fr_b;
+    FP2_YYY Frob;
+    FP8_YYY FP8aux1;
+    FP24_YYY FP24aux1, FP24aux2;
+    char octaux[24*MODBYTES_XXX];
+    octet OCTaux = {0,sizeof(octaux),octaux};
+
+    FP24_YYY FP_24[3], FP_24_frobs[8];
+    const char* FP24_lines[3] =
+    {
+        "FP24_1 = ",
+        "FP24_2 = ",
+        "FP24_c = "
+    };
+    FP24_YYY FP_24_smul_y_dtype;
+    const char* FP24smul_y_dtypeline = "FP24smul_y_dtype = ";
+    FP24_YYY FP_24_smul_y_mtype;
+    const char* FP24smul_y_mtypeline = "FP24smul_y_mtype = ";
+    FP24_YYY FP24conj;
+    const char* FP24conjline = "FP24conj = ";
+    FP24_YYY FP24usquare;
+    const char* FP24usquareline = "FP24usquare = ";
+    FP24_YYY FP24square;
+    const char* FP24squareline = "FP24square = ";
+    FP24_YYY FP24mul;
+    const char* FP24mulline = "FP24mul = ";
+    FP24_YYY FP24smul_dtype;
+    const char* FP24smuldtypeline = "FP24smul_dtype = ";
+    FP24_YYY FP24smul_mtype;
+    const char* FP24smulmtypeline = "FP24smul_mtype = ";
+    FP24_YYY FP24inv;
+    const char* FP24invline = "FP24inv = ";
+    BIG_XXX BIGsc[10];
+    const char* BIGsclines[10] =
+    {
+        "BIGsc1 = ",
+        "BIGsc2 = ",
+        "BIGsc3 = ",
+        "BIGsc4 = ",
+        "BIGsc5 = ",
+        "BIGsc6 = ",
+        "BIGsc7 = ",
+        "BIGsc8 = ",
+        "BIGscs = ",
+        "BIGsco = "
+    };
+    FP24_YYY FP24pow;
+    const char* FP24powline = "FP24pow = ";
+    FP24_YYY FP24pinpow;
+    const char* FP24pinpowline = "FP24pinpow = ";
+    FP8_YYY FP24compows;
+    const char* FP24compowsline = "FP24compows = ";
+    FP8_YYY FP24compow;
+    const char* FP24compowline = "FP24compow = ";
+    FP24_YYY FP24pow8;
+    const char* FP24pow8line = "FP24pow8 = ";
+    FP24_YYY FP24frob;
+    const char* FP24frobline = "FP24frob = ";
+    FP8_YYY FP8trace;
+    const char* FP8traceline = "FP8trace = ";
+
+    BIG_XXX_rcopy(M,Modulus_YYY);
+    BIG_XXX_rcopy(Fr_a,Fra_YYY);
+    BIG_XXX_rcopy(Fr_b,Frb_YYY);
+    FP2_YYY_from_BIGs(&Frob,Fr_a,Fr_b);
+
+    // Set to one
+    FP24_YYY_one(&FP24aux1);
+    FP24_YYY_copy(&FP24aux2,&FP24aux1);
+
+    // Testing equal function
+    if(!FP24_YYY_equals(&FP24aux1,&FP24aux2))
+    {
+        printf("ERROR comparing equal FP24s or copying FP24\n");
+        exit(EXIT_FAILURE);
+    }
+    FP8_YYY_zero(&FP8aux1);
+    FP24_YYY_from_FP8(&FP24aux1,&FP8aux1);
+    if(FP24_YYY_equals(&FP24aux1,&FP24aux2))
+    {
+        printf("ERROR comparing different FP24s\n");
+        exit(EXIT_FAILURE);
+    }
+
+    if(!FP24_YYY_iszilch(&FP24aux1) || FP24_YYY_iszilch(&FP24aux2) || 
FP24_YYY_isunity(&FP24aux1) || !FP24_YYY_isunity(&FP24aux2))
+    {
+        printf("ERROR checking iszilch/isunity functions\n");
+        exit(EXIT_FAILURE);
+    }
+
+    fp = fopen(argv[1], "r");
+    if (fp == NULL)
+    {
+        printf("ERROR opening test vector file\n");
+        exit(EXIT_FAILURE);
+    }
+
+    while (fgets(line, LINE_LEN, fp) != NULL)
+    {
+        i++;
+        // Read first FP24 and perform some tests on it
+        if (!strncmp(line,FP24_lines[0], strlen(FP24_lines[0])))
+        {
+            len = strlen(FP24_lines[0]);
+            linePtr = line + len;
+            read_FP24_YYY(FP_24,linePtr);
+
+            // Test setting functions
+            FP24_YYY_from_FP8(&FP24aux1,&FP_24->a);
+            if(!FP8_YYY_equals(&FP24aux1.a,&FP_24->a) || 
!FP8_YYY_iszilch(&FP24aux1.b) || !FP8_YYY_iszilch(&FP24aux1.c))
+            {
+                printf("ERROR setting FP24 from a FP8, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            FP24_YYY_from_FP8s(&FP24aux1,&FP_24->a,&FP_24->b,&FP_24->c);
+            if(!FP24_YYY_equals(&FP24aux1,FP_24))
+            {
+                printf("ERROR setting FP24 from three FP8s, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+
+            // Test octet conversion consistency
+            FP24_YYY_toOctet(&OCTaux,FP_24);
+            FP24_YYY_fromOctet(&FP24aux1,&OCTaux);
+            if(!FP24_YYY_equals(&FP24aux1,FP_24))
+            {
+                printf("ERROR octet conversion consistency, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            FP24_YYY_copy(FP_24_frobs,FP_24);
+            for (k=1; k<8; k++)
+            {
+                FP24_YYY_copy(FP_24_frobs+k,FP_24_frobs+k-1);
+                FP24_YYY_frob(FP_24_frobs+k,&Frob,1);
+            }
+        }
+        // Read other FP24s.
+        for(k = 1; k<3; k++)
+        {
+            if (!strncmp(line,FP24_lines[k], strlen(FP24_lines[k])))
+            {
+                len = strlen(FP24_lines[k]);
+                linePtr = line + len;
+                read_FP24_YYY(FP_24+k,linePtr);
+            }
+        }
+        // Read y for M-TYPE smul test
+        if (!strncmp(line,FP24smul_y_mtypeline, strlen(FP24smul_y_mtypeline)))
+        {
+            len = strlen(FP24smul_y_mtypeline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP_24_smul_y_mtype,linePtr);
+        }
+        // Read y for D-TYPE smul test
+        if (!strncmp(line,FP24smul_y_dtypeline, strlen(FP24smul_y_dtypeline)))
+        {
+            len = strlen(FP24smul_y_dtypeline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP_24_smul_y_dtype,linePtr);
+        }
+        // Test FP24_YYY_conj
+        if (!strncmp(line,FP24conjline, strlen(FP24conjline)))
+        {
+            len = strlen(FP24conjline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24conj,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_conj(&FP24aux1,&FP24aux1);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24conj))
+            {
+                printf("ERROR computing conjugate of FP24, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test multiplication and commutativity
+        if (!strncmp(line,FP24mulline, strlen(FP24mulline)))
+        {
+            len = strlen(FP24mulline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24mul,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_mul(&FP24aux1,FP_24+1);
+            FP24_YYY_copy(&FP24aux2,FP_24+1);
+            FP24_YYY_mul(&FP24aux2,FP_24);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24mul) || 
!FP24_YYY_equals(&FP24aux2,&FP24mul))
+            {
+                printf("ERROR computing multiplication of two FP24s, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test squaring
+        if (!strncmp(line,FP24squareline, strlen(FP24squareline)))
+        {
+            len = strlen(FP24squareline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24square,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_sqr(&FP24aux1,&FP24aux1);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24square))
+            {
+                printf("ERROR computing square of FP24, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test usquaring
+        if (!strncmp(line,FP24usquareline, strlen(FP24usquareline)))
+        {
+            len = strlen(FP24usquareline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24usquare,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_usqr(&FP24aux1,&FP24aux1);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24usquare))
+            {
+                printf("ERROR computing usquare of FP24, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test s-multiplication for D-TYPE
+        if (!strncmp(line,FP24smuldtypeline, strlen(FP24smuldtypeline)))
+        {
+            len = strlen(FP24smuldtypeline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24smul_dtype,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_smul(&FP24aux1,&FP_24_smul_y_dtype,D_TYPE);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24smul_dtype))
+            {
+                printf("ERROR computing s-multiplication for D-TYPE, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test s-multiplication for M-TYPE
+        if (!strncmp(line,FP24smulmtypeline, strlen(FP24smulmtypeline)))
+        {
+            len = strlen(FP24smulmtypeline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24smul_mtype,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_smul(&FP24aux1,&FP_24_smul_y_mtype,M_TYPE);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24smul_mtype))
+            {
+                printf("ERROR computing s-multiplication for M-TYPE, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test inverse fuction
+        if (!strncmp(line,FP24invline, strlen(FP24invline)))
+        {
+            len = strlen(FP24invline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24inv,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_inv(&FP24aux1,&FP24aux1);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24inv))
+            {
+                printf("ERROR computing inverse of a FP24, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Read BIGS
+        for(k=0; k<10; k++)
+        {
+            if (!strncmp(line,BIGsclines[k], strlen(BIGsclines[k])))
+            {
+                len = strlen(BIGsclines[k]);
+                linePtr = line + len;
+                read_BIG_XXX(BIGsc[k],linePtr);
+            }
+        }
+        // Test power by a BIG
+        if (!strncmp(line,FP24powline, strlen(FP24powline)))
+        {
+            len = strlen(FP24powline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24pow,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_pow(&FP24aux1,&FP24aux1,BIGsc[0]);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24pow))
+            {
+                printf("ERROR computing power of a FP24 by a BIG, line 
%d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test power by a small integer
+        if (!strncmp(line,FP24pinpowline, strlen(FP24pinpowline)))
+        {
+            len = strlen(FP24pinpowline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24pinpow,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_pinpow(&FP24aux1,j,10);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24pinpow))
+            {
+                printf("ERROR computing power of a FP24 by a small integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+            j++;
+        }
+        // Test fucntion FP24_YYY_compow with small integer [< Modulus mod 
Curve_Order]
+        if (!strncmp(line,FP24compowsline, strlen(FP24compowsline)))
+        {
+            len = strlen(FP24compowsline);
+            linePtr = line + len;
+            read_FP8_YYY(&FP24compows,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24+2);
+            FP24_YYY_compow(&FP8aux1,&FP24aux1,BIGsc[8],BIGsc[9]);
+            if(!FP8_YYY_equals(&FP8aux1,&FP24compows))
+            {
+                printf("ERROR testing function FP24_compow with small integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test fucntion FP24_YYY_compow with big integer [> Modulus mod 
Curve_Order]
+        if (!strncmp(line,FP24compowline, strlen(FP24compowline)))
+        {
+            len = strlen(FP24compowline);
+            linePtr = line + len;
+            read_FP8_YYY(&FP24compow,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24+2);
+            FP24_YYY_compow(&FP8aux1,&FP24aux1,BIGsc[0],BIGsc[9]);
+            if(!FP8_YYY_equals(&FP8aux1,&FP24compow))
+            {
+                printf("ERROR testing function FP24_compow with big integer, 
line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test function FP24_YYY_pow8
+        if (!strncmp(line,FP24pow8line, strlen(FP24pow8line)))
+        {
+            len = strlen(FP24pow8line);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24pow8,linePtr);
+            FP24_YYY_pow8(&FP24aux1,FP_24_frobs,BIGsc);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24pow8))
+            {
+                printf("ERROR testing function FP24pow8, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Raises an FP24 to the power of the internal modulus p, using the 
Frobenius constant f
+        if (!strncmp(line,FP24frobline, strlen(FP24frobline)))
+        {
+            len = strlen(FP24frobline);
+            linePtr = line + len;
+            read_FP24_YYY(&FP24frob,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_frob(&FP24aux1,&Frob,1);
+            if(!FP24_YYY_equals(&FP24aux1,&FP24frob) || 
!FP24_YYY_equals(FP_24_frobs+1,&FP24frob))
+            {
+                printf("ERROR in raising FP24 by an internal modulus p, using 
the Frobenius constant f, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+        // Test computing trace of FP24
+        if (!strncmp(line,FP8traceline, strlen(FP8traceline)))
+        {
+            len = strlen(FP8traceline);
+            linePtr = line + len;
+            read_FP8_YYY(&FP8trace,linePtr);
+            FP24_YYY_copy(&FP24aux1,FP_24);
+            FP24_YYY_trace(&FP8aux1,&FP24aux1);
+            if(!FP8_YYY_equals(&FP8aux1,&FP8trace))
+            {
+                printf("ERROR computing trace of FP24, line %d\n",i);
+                exit(EXIT_FAILURE);
+            }
+        }
+    }
+
+    fclose(fp);
+
+    printf("SUCCESS TEST ARITMETIC OF FP24 PASSED\n");
+    exit(EXIT_SUCCESS);
+}
\ No newline at end of file

Reply via email to