diff --git a/Makefile b/Makefile index e69de29..12d40fd 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,18 @@ +CC?=gcc +AS=$(CC) -c +AR?=ar + +CFLAGS?=-g +CFLAGS+=-Wall -Wextra + +SRCDIR=src +TESTDIR=tests +BINDIR=bin + +test_codes = tests/test.c tests/test_util.c + +bin/test: + $(CC) $(CFLAGS) -I$(SRCDIR) $(test_codes) -o $@ + +clean: + rm -f $(BINDIR)/* diff --git a/README.md b/README.md index 8a02c3c..618ebed 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ C polynomial library for ECC based cryptography. Libntru use some custom data types declared in `types.h`. +> `uint8_t` : Unsigned 8-bit integer +> `uint16_t` : Unsigned 16-bit integer + `NtruIntPoly` : Polynomial with 16-bit integer coefficients ```c @@ -38,7 +41,7 @@ Libntru use some custom data types declared in `types.h`. - [ ] Advance Operation (Inversion) - [ ] Bitwise for array - [ ] Pointer management for polynomial indexes -- [ ] Random Generators +- [ ] ~~Random Generators~~ diff --git a/bin/test b/bin/test new file mode 100755 index 0000000..5288641 Binary files /dev/null and b/bin/test differ diff --git a/src/poly.c b/src/poly.c index 9093717..26f8d1e 100644 --- a/src/poly.c +++ b/src/poly.c @@ -1,4 +1,15 @@ #include +#include #include +#include "types.h" + +uint8_t inf_mult_poly(NtruIntPoly *a,NtruIntPoly *b, NtruIntPoly *c, uint16_t modulus) { + +} + + + + + diff --git a/src/types.h b/src/types.h index f8ffedc..5a7a457 100644 --- a/src/types.h +++ b/src/types.h @@ -1,5 +1,11 @@ /* Here we Declared our custom data types */ -struct infPoly { +#include -} +#define NTRU_MAX_DEGREE (1499+1) +#define NTRU_INT_POLY_SIZE ((NTRU_MAX_DEGREE+16+7)&0XFFF8) + +typedef struct NtruIntPoly { + uint16_t N; + int16_t coeffs[NTRU_INT_POLY_SIZE]; +} NtruIntPoly; diff --git a/test.o b/test.o new file mode 100644 index 0000000..e5a8666 Binary files /dev/null and b/test.o differ diff --git a/test_util.o b/test_util.o new file mode 100644 index 0000000..1aecf44 Binary files /dev/null and b/test_util.o differ diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..6b659fa --- /dev/null +++ b/tests/test.c @@ -0,0 +1,27 @@ +#include +#include +#include "test_util.h" + +int main(int argc, char** argv) { + + printf("Running Test....\n"); + + uint16_t i; + uint16_t modulus; + uint16_t N; + // int16_t coeffs[NTRU_INT_POLY_SIZE]; + // uint16_t a; + + + + modulus = 4; + N = 739; + NtruIntPoly a, c; + // a = 739; + + printf("%d\n", modulus); + printf("%d\n", N); + // printf("%d\n", &a); + + rand_poly(&a, N, modulus); +} diff --git a/tests/test_util.c b/tests/test_util.c new file mode 100644 index 0000000..a9a138e --- /dev/null +++ b/tests/test_util.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include "test_util.h" + + +void rand_poly(NtruIntPoly *a, uint16_t N, uint16_t modulus){ + uint16_t i; + int16_t coeffs[N]; + // int16_t coeffs; + a->N = N; + printf("-> "); + for (i=0; icoeffs[i] = random() % modulus; + printf("%d %d\n ", i+1, coeffs[i] ); + } +} + diff --git a/tests/test_util.h b/tests/test_util.h new file mode 100644 index 0000000..4ac2b52 --- /dev/null +++ b/tests/test_util.h @@ -0,0 +1,11 @@ +#ifndef TEST_UTIL_H +#define TEST_UTIL_H + +#include +#include "types.h" + +void rand_poly(NtruIntPoly *a, uint16_t N, uint16_t modulus); + +int main(int argc, char** argv); + +#endif diff --git a/tests/testparams.h b/tests/testparams.h new file mode 100644 index 0000000..78b2168 --- /dev/null +++ b/tests/testparams.h @@ -0,0 +1,9 @@ +#include +#include + +#define NTRU_P 739 +#define NTRU_Q 9820 +#define NTRU_T 204 + + +uint8_t ntruprime_mult_poly(NtruIntPoly *a, NtruIntPoly *b, NtruIntPoly *c, uint16_t modulus);