-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scalar_arithmetic.cpp
51 lines (45 loc) · 2.03 KB
/
Scalar_arithmetic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************/
/*** FILE : Scalar_arithmetic.c ***/
/*** AUTHOR: David P Jacobs ***/
/*** PROGRAMMER: Sekhar Muddana ***/
/*** PUBLIC ROUTINES: ***/
/*** Scalar S_init() ***/
/*** Scalar S_zero() ***/
/*** Scalar S_one() ***/
/*** Scalar S_minus1() ***/
/*** Scalar S_minus() ***/
/*** Scalar S_add() ***/
/*** Scalar S_sub() ***/
/*** Scalar S_div() ***/
/*** Scalar S_mul() ***/
/*** Scalar S_inv() ***/
/*** PRIVATE ROUTINES: ***/
/*** void Print_inv_table() ***/
/*** MODULE DESCRIPTION: ***/
/*** This module contains routines dealing with Scalar ***/
/*** Arithmatic. ***/
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "Scalar_arithmetic.h"
#include "Build_defs.h"
#include "driver.h"
Scalar Prime;
Scalar Inverse_table[PRIME_BOUND];
uint16_t _d_;
uint32_t _c_;
void S_init() {
Prime = GetField(); /* Initialize the global variable Prime. */
_d_ = Prime;
_c_ = (~(0U)) / _d_ + 1;
/* Initialize the global table of inverses. */
for (Scalar i = 1; i < Prime; i++) {
for (Scalar j = 1; j < Prime; j++) {
if (_modp(i * j) == 1) {
Inverse_table[i] = j;
break;
}
}
}
}