-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib.h
84 lines (75 loc) · 2.76 KB
/
lib.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* The size of the words, in bytes
*/
#define SIZE 128
/**
* Displays the last result on the coprocessor
* (for testing purposes only)
*/
void display_result();
/**
* Multiplies 2 numbers provided in a and b. Stores the result in z. z must be preallocated.
*
* @param a 1024-bit big-endian operand
* @param b 1024-bit big-endian operand
* @param z 2048-bit big-endian result
*/
void multiply1024(__xdata unsigned char *a, __xdata unsigned char *b, __xdata unsigned char *z);
/**
* Checks if z is larger or equal than p
*
* @param z 8*size-bit big-endian number
* @param p 8*size-bit big-endian number
* @param size size in bytes
* @return 1 when z >= p, 0 otherwise
*/
char larger_or_equal(__xdata unsigned char *z, __xdata unsigned char *p, unsigned char size);
/**
* Adds 2 numbers provided in a and b. Stores the result in z. z must be preallocated.
* The numbers have to be aligned on a 1024-bit boundary.
*
* @param a 1024-bit big-endian operand
* @param b 1024-bit big-endian operand
* @param z 1024-bit big-endian result
* @return 1 if overflow, 0 if no overflow
*/
char add1024(__xdata unsigned char *a, __xdata unsigned char *b, __xdata unsigned char *z);
/**
* Subtracts 2 numbers provided in a and b. Stores the result in z. z must be preallocated.
* The numbers have to be aligned on a 1024-bit boundary.
*
* @param a 1024-bit big-endian first operand
* @param b 1024-bit big-endian second operand
* @param z 1024-bit big-endian result
* @return 1 if borrow needed, 0 if no borrow needed
*/
char subtract1024(__xdata unsigned char *a, __xdata unsigned char *b, __xdata unsigned char *z);
/**
* Copies source number to destination number
* @param dest destination 1024-bit number
* @param src source 1024-bit number
*/
void copy(__xdata unsigned char *dest, __xdata unsigned char *src);
/**
* Product in Montgomery domain (a * b * R mod n, R = 2^1024)
* @param a 1024-bit big-endian operand
* @param b 1024-bit big-endian operand
* @param m 1024-bit big-endian result
* @param n 1024-bit big-endian modulus
*/
void montpro(__xdata unsigned char *a, __xdata unsigned char *b, __xdata unsigned char *m, __xdata unsigned char *n);
/**
* Inversion in Montgomery domain (a^-1 mod n, R = 2^1024)
* @param a 1024-bit big-endian operand
* @param p 1024-bit big-endian modulus
* @param r 1024-bit big-endian result
*/
void montinv(__xdata unsigned char *a, __xdata unsigned char *p, __xdata unsigned char *r);
/**
* Modular exponentiation in Montgomery domain yt = xt^exp mod n
* @param xt base (in Montgomery domain)
* @param exp exponent
* @param yt result (in Montgomery domain)
* @param R R mod n
*/
void modexp(__xdata unsigned char *xt, __xdata unsigned char *exp, __xdata unsigned char *yt, __xdata unsigned char *R);