Loading Makefile 0 → 100644 +20 −0 Original line number Diff line number Diff line export CC= gcc export CFLAGS= -W -Wall -ansi -pedantic -g -std=c99 export LFLAGS= -lgmp -lcrypto SRC_C= $(wildcard src/*.c) export SRC_OBJ= $(abspath $(SRC_C:.c=.o)) all: src tests .PHONY: clean src tests src: @(cd src && $(MAKE) all) tests: src @(cd tests && $(MAKE) all) clean: @rm -rf *~ @(cd src && $(MAKE) $@) @(cd tests && $(MAKE) $@) src/Makefile 0 → 100644 +14 −0 Original line number Diff line number Diff line SRC=$(wildcard *.c) OBJ=$(SRC:.c=.o) all: objs objs: $(OBJ) %.o: %.c @$(CC) $(CFLAGS) -o $@ -c $< $(LFLAGS) .PHONY: clean all clean: @(rm -rf *.o *~) src/bignum.c 0 → 100644 +96 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <gmp.h> typedef mpz_t* bignum_t; bignum_t bignum_zero(){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init(*x); return x; } bignum_t bignum_from_int(int n){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init_set_si(*x, (signed long int) n); return x; } bignum_t bignum_copy(bignum_t x){ bignum_t y = bignum_zero(); mpz_set(*y, *x); return y; } void bignum_destroy(bignum_t x){ mpz_clear(*x); free(x); } int bignum_eq(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) == 0; } int bignum_lte(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) <= 0; } int bignum_lt(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) < 0; } int bignum_gt(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) > 0; } int bignum_gte(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) >= 0; } bignum_t bignum_add(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_add(*x, *a, *b); return x; } bignum_t bignum_sub(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_sub(*x, *a, *b); return x; } bignum_t bignum_mul(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_mul(*x, *a, *b); return x; } bignum_t bignum_div(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_div(*x, *a, *b); return x; } bignum_t bignum_mod(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_mod(*x, *a, *b); return x; } bignum_t bignum_powm(bignum_t x, bignum_t n, bignum_t m){ bignum_t z = bignum_zero(); mpz_powm(*z, *x, *n, *m); return z; } bignum_t bignum_pow(bignum_t x, bignum_t exp){ bignum_t z = bignum_zero(); unsigned long int e = mpz_get_ui(*exp); mpz_pow_ui(*z, *x, e); return z; } char* bignum_to_str(bignum_t x){ return mpz_get_str(NULL, 10, *x); } src/bignum.h 0 → 100644 +28 −0 Original line number Diff line number Diff line #ifndef __BIGNUM__ #define __BIGNUM__ #include <gmp.h> typedef mpz_t* bignum_t; bignum_t bignum_zero(); bignum_t bignum_from_int(int); bignum_t bignum_copy(bignum_t); void bignum_destroy(bignum_t); int bignum_eq(bignum_t, bignum_t); int bignum_lt(bignum_t, bignum_t); int bignum_lte(bignum_t, bignum_t); int bignum_gt(bignum_t, bignum_t); int bignum_gte(bignum_t, bignum_t); bignum_t bignum_add(bignum_t, bignum_t); bignum_t bignum_sub(bignum_t, bignum_t); bignum_t bignum_mul(bignum_t, bignum_t); bignum_t bignum_div(bignum_t, bignum_t); bignum_t bignum_mod(bignum_t, bignum_t); bignum_t bignum_powm(bignum_t, bignum_t, bignum_t); bignum_t bignum_pow(bignum_t, bignum_t); char* bignum_to_str(bignum_t); #endif src/bst.h 0 → 100644 +24 −0 Original line number Diff line number Diff line #ifndef __BST__ #define __BST__ struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { unsigned long int size; struct node_t* tree; } bst_t; unsigned long int hash(void*); bst_t bst_empty(void); int bst_is_empty(bst_t); bst_t bst_add(bst_t, void*); void bst_destroy(bst_t, void (*free_void)(void*)); int bst_in(bst_t, void*); unsigned long int bst_size(bst_t); #endif Loading
Makefile 0 → 100644 +20 −0 Original line number Diff line number Diff line export CC= gcc export CFLAGS= -W -Wall -ansi -pedantic -g -std=c99 export LFLAGS= -lgmp -lcrypto SRC_C= $(wildcard src/*.c) export SRC_OBJ= $(abspath $(SRC_C:.c=.o)) all: src tests .PHONY: clean src tests src: @(cd src && $(MAKE) all) tests: src @(cd tests && $(MAKE) all) clean: @rm -rf *~ @(cd src && $(MAKE) $@) @(cd tests && $(MAKE) $@)
src/Makefile 0 → 100644 +14 −0 Original line number Diff line number Diff line SRC=$(wildcard *.c) OBJ=$(SRC:.c=.o) all: objs objs: $(OBJ) %.o: %.c @$(CC) $(CFLAGS) -o $@ -c $< $(LFLAGS) .PHONY: clean all clean: @(rm -rf *.o *~)
src/bignum.c 0 → 100644 +96 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <gmp.h> typedef mpz_t* bignum_t; bignum_t bignum_zero(){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init(*x); return x; } bignum_t bignum_from_int(int n){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init_set_si(*x, (signed long int) n); return x; } bignum_t bignum_copy(bignum_t x){ bignum_t y = bignum_zero(); mpz_set(*y, *x); return y; } void bignum_destroy(bignum_t x){ mpz_clear(*x); free(x); } int bignum_eq(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) == 0; } int bignum_lte(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) <= 0; } int bignum_lt(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) < 0; } int bignum_gt(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) > 0; } int bignum_gte(bignum_t a, bignum_t b){ return mpz_cmp(*a, *b) >= 0; } bignum_t bignum_add(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_add(*x, *a, *b); return x; } bignum_t bignum_sub(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_sub(*x, *a, *b); return x; } bignum_t bignum_mul(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_mul(*x, *a, *b); return x; } bignum_t bignum_div(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_div(*x, *a, *b); return x; } bignum_t bignum_mod(bignum_t a, bignum_t b){ bignum_t x = bignum_zero(); mpz_mod(*x, *a, *b); return x; } bignum_t bignum_powm(bignum_t x, bignum_t n, bignum_t m){ bignum_t z = bignum_zero(); mpz_powm(*z, *x, *n, *m); return z; } bignum_t bignum_pow(bignum_t x, bignum_t exp){ bignum_t z = bignum_zero(); unsigned long int e = mpz_get_ui(*exp); mpz_pow_ui(*z, *x, e); return z; } char* bignum_to_str(bignum_t x){ return mpz_get_str(NULL, 10, *x); }
src/bignum.h 0 → 100644 +28 −0 Original line number Diff line number Diff line #ifndef __BIGNUM__ #define __BIGNUM__ #include <gmp.h> typedef mpz_t* bignum_t; bignum_t bignum_zero(); bignum_t bignum_from_int(int); bignum_t bignum_copy(bignum_t); void bignum_destroy(bignum_t); int bignum_eq(bignum_t, bignum_t); int bignum_lt(bignum_t, bignum_t); int bignum_lte(bignum_t, bignum_t); int bignum_gt(bignum_t, bignum_t); int bignum_gte(bignum_t, bignum_t); bignum_t bignum_add(bignum_t, bignum_t); bignum_t bignum_sub(bignum_t, bignum_t); bignum_t bignum_mul(bignum_t, bignum_t); bignum_t bignum_div(bignum_t, bignum_t); bignum_t bignum_mod(bignum_t, bignum_t); bignum_t bignum_powm(bignum_t, bignum_t, bignum_t); bignum_t bignum_pow(bignum_t, bignum_t); char* bignum_to_str(bignum_t); #endif
src/bst.h 0 → 100644 +24 −0 Original line number Diff line number Diff line #ifndef __BST__ #define __BST__ struct node_t { unsigned long int key; void* val; struct node_t* left; struct node_t* right; }; typedef struct bst_t { unsigned long int size; struct node_t* tree; } bst_t; unsigned long int hash(void*); bst_t bst_empty(void); int bst_is_empty(bst_t); bst_t bst_add(bst_t, void*); void bst_destroy(bst_t, void (*free_void)(void*)); int bst_in(bst_t, void*); unsigned long int bst_size(bst_t); #endif