| 1 |
#ifndef _MONTGOMERY_UTILS_H |
| 2 |
#define _MONTGOMERY_UTILS_H |
| 3 |
|
| 4 |
#include "common.h" |
| 5 |
|
| 6 |
void expand_seed(uint64_t seed_in, void* seed_out, size_t out_len); |
| 7 |
|
| 8 |
struct BitWindow_LR { |
| 9 |
|
| 10 |
unsigned window_size; |
| 11 |
|
| 12 |
|
| 13 |
unsigned nr_windows; |
| 14 |
|
| 15 |
|
| 16 |
unsigned tg; |
| 17 |
|
| 18 |
|
| 19 |
unsigned available; |
| 20 |
|
| 21 |
|
| 22 |
unsigned scan_exp; |
| 23 |
|
| 24 |
|
| 25 |
const uint8_t *exp; |
| 26 |
}; |
| 27 |
|
| 28 |
struct BitWindow_RL { |
| 29 |
unsigned window_size; |
| 30 |
unsigned nr_windows; |
| 31 |
unsigned bytes_left; |
| 32 |
unsigned bits_left; |
| 33 |
const uint8_t *cursor; |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
struct BitWindow_LR init_bit_window_lr(unsigned window_size, const uint8_t *exp, size_t exp_len); |
| 41 |
struct BitWindow_RL init_bit_window_rl(unsigned window_size, const uint8_t *exp, size_t exp_len); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
unsigned get_next_digit_lr(struct BitWindow_LR *bw); |
| 47 |
unsigned get_next_digit_rl(struct BitWindow_RL *bw); |
| 48 |
|
| 49 |
typedef struct _ProtMemory { |
| 50 |
void *scattered; |
| 51 |
uint16_t *scramble; |
| 52 |
unsigned nr_arrays; |
| 53 |
unsigned array_len; |
| 54 |
} ProtMemory; |
| 55 |
|
| 56 |
int scatter(ProtMemory** pprot, const void *arrays[], uint8_t nr_arrays, size_t array_len, uint64_t seed); |
| 57 |
void gather(void *out, const ProtMemory *prot, unsigned index); |
| 58 |
void free_scattered(ProtMemory *prot); |
| 59 |
|
| 60 |
#endif |