Skip to content

Commit

Permalink
Adjust types in low-level functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed May 8, 2024
1 parent 514358d commit a4acd46
Show file tree
Hide file tree
Showing 77 changed files with 328 additions and 407 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ else()
endif()

# Remove annoying flags when compiler cannot compute buffer sizes.
set(CFLAGS "${CFLAGS} -Wno-stringop-overflow -Wno-stringop-overread")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CFLAGS "${CFLAGS} -Wno-stringop-overflow -Wno-stringop-overread")
endif()

if(AUSAN)
set(DFLAGS "${DFLAGS} -ggdb -fsanitize=address -fsanitize=undefined")
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void arith(void) {
fb_st t[RLC_FB_TABLE_MAX];
dv_t e;
bn_t f;
int bits;
uint_t bits;

fb_null(a);
fb_null(b);
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <sys/stat.h>
#include <fcntl.h>

static void test_bytes(uint8_t *buf, int size, void *args) {
static void test_bytes(uint8_t *buf, size_t size, void *args) {
int c, l, fd = *(int *)args;

if (fd == -1) {
Expand Down
49 changes: 30 additions & 19 deletions include/low/relic_bn_low.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* @param[in] size - the number of digits in the first operand.
* @return the carry of the last digit addition.
*/
dig_t bn_add1_low(dig_t *c, const dig_t *a, const dig_t digit, const int size);
dig_t bn_add1_low(dig_t *c, const dig_t *a, const dig_t digit, size_t size);

/**
* Adds two digit vectors of the same size. Computes c = a + b.
Expand All @@ -86,7 +86,7 @@ dig_t bn_add1_low(dig_t *c, const dig_t *a, const dig_t digit, const int size);
* @param[in] size - the number of digits to add.
* @return the carry of the last digit addition.
*/
dig_t bn_addn_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
dig_t bn_addn_low(dig_t *c, const dig_t *a, const dig_t *b, size_t size);

/**
* Subtracts a digit from a digit vector. Computes c = a - digit.
Expand All @@ -97,7 +97,7 @@ dig_t bn_addn_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
* @param[in] size - the number of digits in a.
* @return the carry of the last digit subtraction.
*/
dig_t bn_sub1_low(dig_t *c, const dig_t *a, dig_t digit, int size);
dig_t bn_sub1_low(dig_t *c, const dig_t *a, dig_t digit, size_t size);

/**
* Subtracts a digit vector from another digit vector. Computes c = a - b.
Expand All @@ -108,7 +108,18 @@ dig_t bn_sub1_low(dig_t *c, const dig_t *a, dig_t digit, int size);
* @param[in] size - the number of digits to subtract.
* @return the carry of the last digit subtraction.
*/
dig_t bn_subn_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
dig_t bn_subn_low(dig_t *c, const dig_t *a, const dig_t *b, size_t size);

/**
* Conditionally negate a digit vector using two's complement representation.
*
* @param[out] c - the result.
* @param[in] a - the digit vector to conditionally negate.
* @param[in] sa - the sign of the digit vector.
* @param[in] n - the number of digits to conditionally negate.
* @return the carry of the last digit negation.
*/
dig_t bn_negs_low(dig_t *c, const dig_t *a, dig_t sa, size_t size);

/**
* Compares two digits.
Expand All @@ -127,7 +138,7 @@ int bn_cmp1_low(dig_t a, dig_t b);
* @param[in] size - the number of digits to compare.
* @return BN_LT if a < b, BN_EQ if a == b and BN_GT if a > b.
*/
int bn_cmpn_low(const dig_t *a, const dig_t *b, int size);
int bn_cmpn_low(const dig_t *a, const dig_t *b, size_t size);

/**
* Shifts a digit vector to the left by 1 bit. Computes c = a << 1.
Expand All @@ -137,7 +148,7 @@ int bn_cmpn_low(const dig_t *a, const dig_t *b, int size);
* @param[in] size - the number of digits to shift.
* @return the carry of the last digit shift.
*/
dig_t bn_lsh1_low(dig_t *c, const dig_t *a, int size);
dig_t bn_lsh1_low(dig_t *c, const dig_t *a, size_t size);

/**
* Shifts a digit vector to the left by an amount smaller than a digit. Computes
Expand All @@ -149,7 +160,7 @@ dig_t bn_lsh1_low(dig_t *c, const dig_t *a, int size);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t bn_lshb_low(dig_t *c, const dig_t *a, int size, int bits);
dig_t bn_lshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits);

/**
* Shifts a digit vector to the right by 1 bit. Computes c = a >> 1.
Expand All @@ -159,7 +170,7 @@ dig_t bn_lshb_low(dig_t *c, const dig_t *a, int size, int bits);
* @param[in] size - the number of digits to shift.
* @return the carry of the last digit shift.
*/
dig_t bn_rsh1_low(dig_t *c, const dig_t *a, int size);
dig_t bn_rsh1_low(dig_t *c, const dig_t *a, size_t size);

/**
* Shifts a digit vector to the right by an amount smaller than a digit.
Expand All @@ -171,7 +182,7 @@ dig_t bn_rsh1_low(dig_t *c, const dig_t *a, int size);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t bn_rshb_low(dig_t *c, const dig_t *a, int size, int bits);
dig_t bn_rshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits);

/**
* Shifts a signed digit vector to the right by an amount smaller than a digit.
Expand All @@ -183,7 +194,7 @@ dig_t bn_rshb_low(dig_t *c, const dig_t *a, int size, int bits);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t bn_rshs_low(dig_t *c, const dig_t *a, int size, int bits);
dig_t bn_rshs_low(dig_t *c, const dig_t *a, size_t size, uint_t bits);

/**
* Multiplies a digit vector by a digit and adds this result to another digit
Expand All @@ -195,7 +206,7 @@ dig_t bn_rshs_low(dig_t *c, const dig_t *a, int size, int bits);
* @param[in] size - the number of digits to multiply.
* @return the carry of the last addition.
*/
dig_t bn_mula_low(dig_t *c, const dig_t *a, dig_t digit, int size);
dig_t bn_mula_low(dig_t *c, const dig_t *a, dig_t digit, size_t size);

/**
* Multiplies a digit vector by a digit and stores this result in another digit
Expand All @@ -207,7 +218,7 @@ dig_t bn_mula_low(dig_t *c, const dig_t *a, dig_t digit, int size);
* @param[in] size - the number of digits to multiply.
* @return the most significant digit.
*/
dig_t bn_mul1_low(dig_t *c, const dig_t *a, dig_t digit, int size);
dig_t bn_mul1_low(dig_t *c, const dig_t *a, dig_t digit, size_t size);

/**
* Multiplies a signed digit vector by a signed digit and stores this result in
Expand All @@ -220,7 +231,7 @@ dig_t bn_mul1_low(dig_t *c, const dig_t *a, dig_t digit, int size);
* @param[in] size - the number of digits to multiply.
* @return the most significant digit.
*/
dig_t bn_muls_low(dig_t *c, const dig_t *a, dig_t sa, dis_t digit, int size);
dig_t bn_muls_low(dig_t *c, const dig_t *a, dig_t sa, dis_t digit, size_t size);

/**
* Multiplies two digit vectors of the same size. Computes c = a * b.
Expand All @@ -230,7 +241,7 @@ dig_t bn_muls_low(dig_t *c, const dig_t *a, dig_t sa, dis_t digit, int size);
* @param[in] b - the second digit vector to multiply.
* @param[in] size - the number of digits to multiply.
*/
void bn_muln_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
void bn_muln_low(dig_t *c, const dig_t *a, const dig_t *b, size_t size);

/**
* Multiplies two digit vectors of different sizes, with sa > sb. Computes
Expand All @@ -245,8 +256,8 @@ void bn_muln_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
* @param[in] low - the first digit to compute.
* @param[in] high - the last digit to compute.
*/
void bn_muld_low(dig_t *c, const dig_t *a, int sa, const dig_t *b, int sb,
int low, int high);
void bn_muld_low(dig_t *c, const dig_t *a, size_t sa, const dig_t *b, size_t sb,
uint_t low, uint_t high);

/**
* Squares a digit vector and adds this result to another digit vector.
Expand All @@ -257,7 +268,7 @@ void bn_muld_low(dig_t *c, const dig_t *a, int sa, const dig_t *b, int sb,
* @param[in] size - the number of digits to square.
* @return the carry of the last addition.
*/
dig_t bn_sqra_low(dig_t *c, const dig_t *a, int size);
dig_t bn_sqra_low(dig_t *c, const dig_t *a, size_t size);

/**
* Squares a digit vector. Computes c = a * a.
Expand All @@ -266,7 +277,7 @@ dig_t bn_sqra_low(dig_t *c, const dig_t *a, int size);
* @param[in] a - the digit vector to square.
* @param[in] size - the number of digits to square.
*/
void bn_sqrn_low(dig_t *c, const dig_t *a, int size);
void bn_sqrn_low(dig_t *c, const dig_t *a, size_t size);

/**
* Divides a digit vector by another digit vector. Computes c = floor(a / b) and
Expand All @@ -291,7 +302,7 @@ void bn_divn_low(dig_t *c, dig_t *d, dig_t *a, int sa, dig_t *b, int sb);
* @param[in] size - the size of the dividend.
* @param[in] digit - the divisor.
*/
void bn_div1_low(dig_t *c, dig_t *d, const dig_t *a, int size, dig_t digit);
void bn_div1_low(dig_t *c, dig_t *d, const dig_t *a, size_t size, dig_t digit);

/**
* Reduces a digit vector modulo m by Montgomery's algorithm.
Expand Down
10 changes: 5 additions & 5 deletions include/low/relic_fb_low.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void fb_addn_low(dig_t *c, const dig_t *a, const dig_t *b);
* @param[in] b - the second digit vector to add.
* @param[in] size - the number of digits to add.
*/
void fb_addd_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
void fb_addd_low(dig_t *c, const dig_t *a, const dig_t *b, size_t size);

/**
* Shifts a digit vector to the left by 1 bit. Computes c = a * z.
Expand All @@ -106,7 +106,7 @@ dig_t fb_lsh1_low(dig_t *c, const dig_t *a);
* @param[in] bits - the shift ammount.
* @return the carry of the last digit shift.
*/
dig_t fb_lshb_low(dig_t *c, const dig_t *a, int bits);
dig_t fb_lshb_low(dig_t *c, const dig_t *a, uint_t bits);

/**
* Shifts a digit vector to the right by 1 bit. Computes c = a / z.
Expand All @@ -127,7 +127,7 @@ dig_t fb_rsh1_low(dig_t *c, const dig_t *a);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t fb_rshb_low(dig_t *c, const dig_t *a, int bits);
dig_t fb_rshb_low(dig_t *c, const dig_t *a, uint_t bits);

/**
* Adds a left-shifted digit vector to another digit vector.
Expand All @@ -140,7 +140,7 @@ dig_t fb_rshb_low(dig_t *c, const dig_t *a, int bits);
* @param[in] bits - the shift amount.
* @return the carry of the last shift.
*/
dig_t fb_lsha_low(dig_t *c, const dig_t *a, int bits, int size);
dig_t fb_lsha_low(dig_t *c, const dig_t *a, uint_t bits, size_t size);

/**
* Multiplies a digit vector by a digit.
Expand Down Expand Up @@ -169,7 +169,7 @@ void fb_muln_low(dig_t *c, const dig_t *a, const dig_t *b);
* @param[in] b - the second digit vector to multiply.
* @param[in] size - the size of the digit vectors.
*/
void fb_muld_low(dig_t *c, const dig_t *a, const dig_t *b, int size);
void fb_muld_low(dig_t *c, const dig_t *a, const dig_t *b, size_t size);

/**
* Multiplies two digit vectors of the same size with embedded modular
Expand Down
4 changes: 2 additions & 2 deletions include/low/relic_fp_low.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ dig_t fp_lsh1_low(dig_t *c, const dig_t *a);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t fp_lshb_low(dig_t *c, const dig_t *a, int bits);
dig_t fp_lshb_low(dig_t *c, const dig_t *a, uint_t bits);

/**
* Shifts a digit vector to the right by 1 bit. Computes c = a >> 1.
Expand All @@ -236,7 +236,7 @@ dig_t fp_rsh1_low(dig_t *c, const dig_t *a);
* @param[in] bits - the shift amount.
* @return the carry of the last digit shift.
*/
dig_t fp_rshb_low(dig_t *c, const dig_t *a, int bits);
dig_t fp_rshb_low(dig_t *c, const dig_t *a, uint_t bits);

/**
* Multiplies a digit vector by a digit and adds this result to another digit
Expand Down
2 changes: 1 addition & 1 deletion include/relic_eb.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ void eb_print(const eb_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int eb_size_bin(const eb_t a, int pack);
size_t eb_size_bin(const eb_t a, int pack);

/**
* Reads a binary elliptic curve point from a byte vector in big-endian format.
Expand Down
2 changes: 1 addition & 1 deletion include/relic_ed.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ int ed_on_curve(const ed_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ed_size_bin(const ed_t a, int pack);
size_t ed_size_bin(const ed_t a, int pack);

/**
* Reads an Edwards elliptic curve point from a byte vector in big-endian format.
Expand Down
2 changes: 1 addition & 1 deletion include/relic_ep.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ void ep_print(const ep_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ep_size_bin(const ep_t a, int pack);
size_t ep_size_bin(const ep_t a, int pack);

/**
* Reads a prime elliptic curve point from a byte vector in big-endian format.
Expand Down
8 changes: 4 additions & 4 deletions include/relic_epx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ void ep2_print(const ep2_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ep2_size_bin(const ep2_t a, int pack);
size_t ep2_size_bin(const ep2_t a, int pack);

/**
* Reads a prime elliptic curve point over a quadratic extension from a byte
Expand Down Expand Up @@ -1798,7 +1798,7 @@ void ep3_print(const ep3_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ep3_size_bin(const ep3_t a, int pack);
size_t ep3_size_bin(const ep3_t a, int pack);

/**
* Reads a prime elliptic curve point over a cubic extension from a byte
Expand Down Expand Up @@ -2442,7 +2442,7 @@ void ep4_print(const ep4_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ep4_size_bin(const ep4_t a, int pack);
size_t ep4_size_bin(const ep4_t a, int pack);

/**
* Reads a prime elliptic curve point over a quartic extension from a byte
Expand Down Expand Up @@ -3087,7 +3087,7 @@ void ep8_print(const ep8_t p);
* @param[in] pack - the flag to indicate compression.
* @return the number of bytes.
*/
int ep8_size_bin(const ep8_t a, int pack);
size_t ep8_size_bin(const ep8_t a, int pack);

/**
* Reads a prime elliptic curve point over an octic extension from a byte
Expand Down
Loading

0 comments on commit a4acd46

Please sign in to comment.