Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
utilities.c File Reference
#include "utilities.h"
Include dependency graph for utilities.c:

Go to the source code of this file.

Functions

void multiplication_u64 (uint64_t *output_low, uint64_t *output_high, uint64_t input_a, uint64_t input_b)
void conditional_move_u64 (uint64_t *output, uint8_t input_decision, uint64_t input_a, uint64_t input_b)
uint64_t constant_time_is_nonzero_u64 (uint64_t x)
uint64_t constant_time_is_zero_u64 (uint64_t x)
uint64_t constant_time_is_lessthan_u64 (uint64_t x, uint64_t y)
uint8_t constant_time_compare (const uint8_t *input_a, const uint8_t *input_b, uint64_t input_length)
void constant_time_conditional_mov (uint8_t *output, const uint8_t *input, uint64_t input_length, uint8_t input_selector)
void multiprecision_shift_to_right (uint64_t *input_a_output_shifted_a, uint64_t input_words_length)
void multiprecision_shift_to_left (uint64_t *input_a_output_shifted_a, uint64_t input_words_length)
void multiprecision_addition (uint64_t *output, const uint64_t *input_a, const uint64_t *input_b, uint64_t input_length)
void multiprecision_subtraction (uint64_t *output, const uint64_t *input_a, const uint64_t *input_b, uint64_t input_length)
uint8_t multiprecision_is_smaller (const uint64_t *input_a, const uint64_t *input_b, uint64_t input_length)

Function Documentation

◆ conditional_move_u64()

void conditional_move_u64 ( uint64_t * output,
uint8_t input_decision,
uint64_t input_a,
uint64_t input_b )

Definition at line 40 of file utilities.c.

40 {
41 uint8_t x1;
42 uint64_t x2;
43 uint64_t x3;
44 x1 = (!(!input_decision));
45 x2 = ((int8_t) (0x0 - x1) & UINT64_C(0xffffffffffffffff));
46 x3 = ((x2 & input_b) | ((~x2) & input_a));
47 *output = x3;
48}

◆ constant_time_compare()

uint8_t constant_time_compare ( const uint8_t * input_a,
const uint8_t * input_b,
uint64_t input_length )

Definition at line 62 of file utilities.c.

62 {
63 uint64_t r = 0;
64 uint64_t i;
65
66 for (i = 0; i < input_length; i++)
67 r |= input_a[i] ^ input_b[i];
68
69 r = (-r);
70 r = r >> 63;
71 return (uint8_t)(1 - r);
72}
for i

References i.

Referenced by multiprecision_is_smaller().

Here is the caller graph for this function:

◆ constant_time_conditional_mov()

void constant_time_conditional_mov ( uint8_t * output,
const uint8_t * input,
uint64_t input_length,
uint8_t input_selector )

Definition at line 74 of file utilities.c.

74 {
75 uint64_t i;
76 for (i = 0; i < input_length; i++)
77 output[i] ^= input_selector & (input[i] ^ output[i]);
78}

References i.

Referenced by fp2_sqrt_fast().

Here is the caller graph for this function:

◆ constant_time_is_lessthan_u64()

uint64_t constant_time_is_lessthan_u64 ( uint64_t x,
uint64_t y )

Definition at line 58 of file utilities.c.

58 {
59 return (uint64_t) ((x ^ ((x ^ y) | ((x - y) ^ y))) >> 63);
60}

Referenced by isogeny_walks_3_fp(), isogeny_walks_3_fp(), and multiprecision_is_smaller().

Here is the caller graph for this function:

◆ constant_time_is_nonzero_u64()

uint64_t constant_time_is_nonzero_u64 ( uint64_t x)

Definition at line 50 of file utilities.c.

50 {
51 return (uint64_t) ((x | (0 - x)) >> 63);
52}

Referenced by constant_time_is_zero_u64().

Here is the caller graph for this function:

◆ constant_time_is_zero_u64()

uint64_t constant_time_is_zero_u64 ( uint64_t x)

Definition at line 54 of file utilities.c.

54 {
55 return (uint64_t) (1 ^ constant_time_is_nonzero_u64(x));
56}
uint64_t constant_time_is_nonzero_u64(uint64_t x)
Definition utilities.c:50

References constant_time_is_nonzero_u64().

Here is the call graph for this function:

◆ multiplication_u64()

void multiplication_u64 ( uint64_t * output_low,
uint64_t * output_high,
uint64_t input_a,
uint64_t input_b )

Definition at line 7 of file utilities.c.

7 {
8 register uint64_t al, ah, bl, bh, temp;
9 uint64_t albl, albh, ahbl, ahbh, res1, res2, res3, carry;
10 uint64_t mask_low = (uint64_t) (-1) >> (sizeof(uint64_t) * 4), mask_high =
11 (uint64_t) (-1) << (sizeof(uint64_t) * 4);
12
13 al = input_a & mask_low; // Low part
14 ah = input_a >> (sizeof(uint64_t) * 4); // High part
15 bl = input_b & mask_low;
16 bh = input_b >> (sizeof(uint64_t) * 4);
17
18 albl = al * bl;
19 albh = al * bh;
20 ahbl = ah * bl;
21 ahbh = ah * bh;
22 *output_low = albl & mask_low; // C00
23
24 res1 = albl >> (sizeof(uint64_t) * 4);
25 res2 = ahbl & mask_low;
26 res3 = albh & mask_low;
27 temp = res1 + res2 + res3;
28 carry = temp >> (sizeof(uint64_t) * 4);
29 *output_low ^= temp << (sizeof(uint64_t) * 4); // C01
30
31 res1 = ahbl >> (sizeof(uint64_t) * 4);
32 res2 = albh >> (sizeof(uint64_t) * 4);
33 res3 = ahbh & mask_low;
34 temp = res1 + res2 + res3 + carry;
35 *output_high = temp & mask_low; // C10
36 carry = temp & mask_high;
37 *output_high ^= (ahbh & mask_high) + carry; // C11
38}

◆ multiprecision_addition()

void multiprecision_addition ( uint64_t * output,
const uint64_t * input_a,
const uint64_t * input_b,
uint64_t input_length )

Definition at line 98 of file utilities.c.

98 {
99 uint64_t i, carry = 0;
100 for (i = 0; i < input_length; i++) {addition_with_carry_u64(output[i], carry, carry, input_a[i], input_b[i]); }
101}
#define addition_with_carry_u64(output, output_carry, input_carry, input_a, input_b)
Definition utilities.h:34

References addition_with_carry_u64, and i.

◆ multiprecision_is_smaller()

uint8_t multiprecision_is_smaller ( const uint64_t * input_a,
const uint64_t * input_b,
uint64_t input_length )

Definition at line 111 of file utilities.c.

111 {
112 uint8_t ret = 0;
113 uint8_t is_equal[input_length], is_smaller[input_length];
114 uint64_t i, j;
115 for(i = 0; i < input_length; i++) {
116 uint8_t *ta = (uint8_t *) &input_a[i];
117 uint8_t *tb = (uint8_t *) &input_b[i];
118 is_equal[i] = constant_time_compare(ta, tb, 8);
119 is_smaller[i] = constant_time_is_lessthan_u64(input_a[i], input_b[i]);
120 }
121
122 for(i = input_length - 1; (int)i >= 0; i--) {
123 uint8_t t = 1;
124 for(j = input_length - 1; j > i; j--) {
125 t &= is_equal[j];
126 }
127 ret |= (is_smaller[i] & t);
128 }
129
130 return ret;
131}
for j
uint64_t constant_time_is_lessthan_u64(uint64_t x, uint64_t y)
Definition utilities.c:58
uint8_t constant_time_compare(const uint8_t *input_a, const uint8_t *input_b, uint64_t input_length)
Definition utilities.c:62

References constant_time_compare(), constant_time_is_lessthan_u64(), i, and j.

Referenced by fp_is_smaller(), and fp_sample().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ multiprecision_shift_to_left()

void multiprecision_shift_to_left ( uint64_t * input_a_output_shifted_a,
uint64_t input_words_length )

Definition at line 89 of file utilities.c.

89 {
90 uint64_t i;
91 for (i = input_words_length - 1; i > 0; i--) {
92 constant_time_shift_to_left_u64(input_a_output_shifted_a[i], input_a_output_shifted_a[i],
93 input_a_output_shifted_a[i - 1], 1, 64);
94 }
95 input_a_output_shifted_a[0] <<= 1;
96}
#define constant_time_shift_to_left_u64(shiftOut, highIn, lowIn, shift, DigitSize)
Definition utilities.h:48

References constant_time_shift_to_left_u64, and i.

◆ multiprecision_shift_to_right()

void multiprecision_shift_to_right ( uint64_t * input_a_output_shifted_a,
uint64_t input_words_length )

Definition at line 80 of file utilities.c.

80 {
81 uint64_t i;
82 for (i = 0; i < input_words_length - 1; i++) {
83 constant_time_shift_to_right_u64(input_a_output_shifted_a[i], input_a_output_shifted_a[i + 1],
84 input_a_output_shifted_a[i], 1, 64);
85 }
86 input_a_output_shifted_a[input_words_length - 1] >>= 1;
87}
#define constant_time_shift_to_right_u64(shiftOut, highIn, lowIn, shift, DigitSize)
Definition utilities.h:45

References constant_time_shift_to_right_u64, and i.

Referenced by fp_half().

Here is the caller graph for this function:

◆ multiprecision_subtraction()

void multiprecision_subtraction ( uint64_t * output,
const uint64_t * input_a,
const uint64_t * input_b,
uint64_t input_length )

Definition at line 103 of file utilities.c.

103 {
104 uint64_t i;
105 uint8_t borrow = 0;
106 for (i = 0; i < input_length; i++) {
107 subtraction_with_borrow_u64(output[i], borrow, borrow, input_a[i], input_b[i]);
108 }
109}
#define subtraction_with_borrow_u64(output, output_borrow, input_borrow, input_a, input_b)
Definition utilities.h:39

References i, and subtraction_with_borrow_u64.