Skip to content

Commit

Permalink
fix: convert fourq patch into DOS format
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie-Cui committed Oct 31, 2024
1 parent f2b18c4 commit ce9649b
Showing 1 changed file with 126 additions and 126 deletions.
252 changes: 126 additions & 126 deletions bazel/patches/FourQlib.patch
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
diff --git a/FourQ_64bit_and_portable/FourQ_internal.h b/FourQ_64bit_and_portable/FourQ_internal.h
index 30d4387..5104320 100644
--- a/FourQ_64bit_and_portable/FourQ_internal.h
+++ b/FourQ_64bit_and_portable/FourQ_internal.h
@@ -128,15 +128,15 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 64x64-bit multiplication
#define MUL128(multiplier, multiplicand, product) \
- mp_mul((digit_t*)&(multiplier), (digit_t*)&(multiplicand), (digit_t*)&(product), NWORDS_FIELD/2);
+ FourQlib_mp_mul((digit_t*)&(multiplier), (digit_t*)&(multiplicand), (digit_t*)&(product), NWORDS_FIELD/2);

// 128-bit addition, inputs < 2^127
#define ADD128(addend1, addend2, addition) \
- mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);
+ FourQlib_mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);

// 128-bit addition with output carry
#define ADC128(addend1, addend2, carry, addition) \
- (carry) = mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);
+ (carry) = FourQlib_mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);

#elif (TARGET == TARGET_AMD64 && OS_TARGET == OS_WIN)

@@ -228,10 +228,10 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)
bool is_zero_ct(digit_t* a, unsigned int nwords);

// Multiprecision addition, c = a+b. Returns the carry bit
-unsigned int mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords);
+unsigned int FourQlib_mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords);

// Schoolbook multiprecision multiply, c = a*b
-void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords);
+void FourQlib_mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords);

// Multiprecision subtraction, c = a-b. Returns the borrow bit
#if defined (GENERIC_IMPLEMENTATION)
diff --git a/FourQ_64bit_and_portable/generic/fp.h b/FourQ_64bit_and_portable/generic/fp.h
index 3083c06..e51997d 100644
--- a/FourQ_64bit_and_portable/generic/fp.h
+++ b/FourQ_64bit_and_portable/generic/fp.h
@@ -183,7 +183,7 @@ void mod1271(felm_t a)
}


-void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
+void FourQlib_mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
{ // Schoolbook multiprecision multiply, c = a*b
unsigned int i, j;
digit_t u, v, UV[2];
@@ -206,7 +206,7 @@ void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int n
}


-unsigned int mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords)
+unsigned int FourQlib_mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit
unsigned int i, carry = 0;

@@ -270,14 +270,14 @@ void fpinv1271(felm_t a)
static __inline void multiply(const digit_t* a, const digit_t* b, digit_t* c)
{ // Schoolbook multiprecision multiply, c = a*b

- mp_mul(a, b, c, NWORDS_ORDER);
+ FourQlib_mp_mul(a, b, c, NWORDS_ORDER);
}


static __inline unsigned int add(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit

- return mp_add((digit_t*)a, (digit_t*)b, c, (unsigned int)nwords);
+ return FourQlib_mp_add((digit_t*)a, (digit_t*)b, c, (unsigned int)nwords);
}


diff --git a/FourQ_64bit_and_portable/makefile b/FourQ_64bit_and_portable/makefile
index 7b6fd07..3bf1f56 100644
--- a/FourQ_64bit_and_portable/makefile
+++ b/FourQ_64bit_and_portable/makefile
@@ -92,9 +92,13 @@ ifeq "$(SERIAL_PUSH)" "TRUE"
endif

SHARED_LIB_TARGET=libFourQ.so
+STATIC_LIB_TARGET=libFourQ.a
ifeq "$(SHARED_LIB)" "TRUE"
DO_MAKE_SHARED_LIB=-fPIC
SHARED_LIB_O=$(SHARED_LIB_TARGET)
+else
+ DO_MAKE_SHARED_LIB=-fPIC
+ STATIC_LIB_O=$(STATIC_LIB_TARGET)
endif

cc=$(COMPILER)
@@ -116,8 +120,11 @@ OBJECTS_ALL=$(OBJECTS) $(OBJECTS_FP_TEST) $(OBJECTS_ECC_TEST) $(OBJECTS_CRYPTO_T
all: crypto_test ecc_test fp_test $(SHARED_LIB_O)

ifeq "$(SHARED_LIB)" "TRUE"
- $(SHARED_LIB_O): $(OBJECTS)
+ libFourQ: $(OBJECTS)
$(CC) -shared -o $(SHARED_LIB_O) $(OBJECTS)
+else
+ libFourQ: $(OBJECTS)
+ ar rcs $(STATIC_LIB_O) $(OBJECTS)
endif

crypto_test: $(OBJECTS_CRYPTO_TEST)
@@ -186,3 +193,6 @@ fp_tests.o: tests/fp_tests.c
clean:
rm -rf $(SHARED_LIB_TARGET) crypto_test ecc_test fp_test *.o AMD64/consts.s

+install:
+ cp $(STATIC_LIB_O) $(SHARED_LIB_O) $(PREFIX)/lib
+ cp FourQ.h FourQ_api.h FourQ_internal.h ../random/random.h $(PREFIX)/include
diff --git a/FourQ_64bit_and_portable/schnorrq.c b/FourQ_64bit_and_portable/schnorrq.c
index da89f86..040db60 100644
--- a/FourQ_64bit_and_portable/schnorrq.c
+++ b/FourQ_64bit_and_portable/schnorrq.c
@@ -14,7 +14,7 @@
#include "FourQ_params.h"
#include "../random/random.h"
#include "../sha512/sha512.h"
-#include <malloc.h>
+#include <stdlib.h>
#include <string.h>


diff --git a/FourQ_64bit_and_portable/FourQ_internal.h b/FourQ_64bit_and_portable/FourQ_internal.h
index 30d4387..5104320 100644
--- a/FourQ_64bit_and_portable/FourQ_internal.h
+++ b/FourQ_64bit_and_portable/FourQ_internal.h
@@ -128,15 +128,15 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 64x64-bit multiplication
#define MUL128(multiplier, multiplicand, product) \
- mp_mul((digit_t*)&(multiplier), (digit_t*)&(multiplicand), (digit_t*)&(product), NWORDS_FIELD/2);
+ FourQlib_mp_mul((digit_t*)&(multiplier), (digit_t*)&(multiplicand), (digit_t*)&(product), NWORDS_FIELD/2);

// 128-bit addition, inputs < 2^127
#define ADD128(addend1, addend2, addition) \
- mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);
+ FourQlib_mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);

// 128-bit addition with output carry
#define ADC128(addend1, addend2, carry, addition) \
- (carry) = mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);
+ (carry) = FourQlib_mp_add((digit_t*)(addend1), (digit_t*)(addend2), (digit_t*)(addition), NWORDS_FIELD);

#elif (TARGET == TARGET_AMD64 && OS_TARGET == OS_WIN)

@@ -228,10 +228,10 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)
bool is_zero_ct(digit_t* a, unsigned int nwords);

// Multiprecision addition, c = a+b. Returns the carry bit
-unsigned int mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords);
+unsigned int FourQlib_mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords);

// Schoolbook multiprecision multiply, c = a*b
-void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords);
+void FourQlib_mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords);

// Multiprecision subtraction, c = a-b. Returns the borrow bit
#if defined (GENERIC_IMPLEMENTATION)
diff --git a/FourQ_64bit_and_portable/generic/fp.h b/FourQ_64bit_and_portable/generic/fp.h
index 3083c06..e51997d 100644
--- a/FourQ_64bit_and_portable/generic/fp.h
+++ b/FourQ_64bit_and_portable/generic/fp.h
@@ -183,7 +183,7 @@ void mod1271(felm_t a)
}


-void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
+void FourQlib_mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
{ // Schoolbook multiprecision multiply, c = a*b
unsigned int i, j;
digit_t u, v, UV[2];
@@ -206,7 +206,7 @@ void mp_mul(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int n
}


-unsigned int mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords)
+unsigned int FourQlib_mp_add(digit_t* a, digit_t* b, digit_t* c, unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit
unsigned int i, carry = 0;

@@ -270,14 +270,14 @@ void fpinv1271(felm_t a)
static __inline void multiply(const digit_t* a, const digit_t* b, digit_t* c)
{ // Schoolbook multiprecision multiply, c = a*b

- mp_mul(a, b, c, NWORDS_ORDER);
+ FourQlib_mp_mul(a, b, c, NWORDS_ORDER);
}


static __inline unsigned int add(const digit_t* a, const digit_t* b, digit_t* c, const unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit

- return mp_add((digit_t*)a, (digit_t*)b, c, (unsigned int)nwords);
+ return FourQlib_mp_add((digit_t*)a, (digit_t*)b, c, (unsigned int)nwords);
}


diff --git a/FourQ_64bit_and_portable/makefile b/FourQ_64bit_and_portable/makefile
index 7b6fd07..3bf1f56 100644
--- a/FourQ_64bit_and_portable/makefile
+++ b/FourQ_64bit_and_portable/makefile
@@ -92,9 +92,13 @@ ifeq "$(SERIAL_PUSH)" "TRUE"
endif

SHARED_LIB_TARGET=libFourQ.so
+STATIC_LIB_TARGET=libFourQ.a
ifeq "$(SHARED_LIB)" "TRUE"
DO_MAKE_SHARED_LIB=-fPIC
SHARED_LIB_O=$(SHARED_LIB_TARGET)
+else
+ DO_MAKE_SHARED_LIB=-fPIC
+ STATIC_LIB_O=$(STATIC_LIB_TARGET)
endif

cc=$(COMPILER)
@@ -116,8 +120,11 @@ OBJECTS_ALL=$(OBJECTS) $(OBJECTS_FP_TEST) $(OBJECTS_ECC_TEST) $(OBJECTS_CRYPTO_T
all: crypto_test ecc_test fp_test $(SHARED_LIB_O)

ifeq "$(SHARED_LIB)" "TRUE"
- $(SHARED_LIB_O): $(OBJECTS)
+ libFourQ: $(OBJECTS)
$(CC) -shared -o $(SHARED_LIB_O) $(OBJECTS)
+else
+ libFourQ: $(OBJECTS)
+ ar rcs $(STATIC_LIB_O) $(OBJECTS)
endif

crypto_test: $(OBJECTS_CRYPTO_TEST)
@@ -186,3 +193,6 @@ fp_tests.o: tests/fp_tests.c
clean:
rm -rf $(SHARED_LIB_TARGET) crypto_test ecc_test fp_test *.o AMD64/consts.s

+install:
+ cp $(STATIC_LIB_O) $(SHARED_LIB_O) $(PREFIX)/lib
+ cp FourQ.h FourQ_api.h FourQ_internal.h ../random/random.h $(PREFIX)/include
diff --git a/FourQ_64bit_and_portable/schnorrq.c b/FourQ_64bit_and_portable/schnorrq.c
index da89f86..040db60 100644
--- a/FourQ_64bit_and_portable/schnorrq.c
+++ b/FourQ_64bit_and_portable/schnorrq.c
@@ -14,7 +14,7 @@
#include "FourQ_params.h"
#include "../random/random.h"
#include "../sha512/sha512.h"
-#include <malloc.h>
+#include <stdlib.h>
#include <string.h>


0 comments on commit ce9649b

Please sign in to comment.