forked from sysprog21/fibdrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbn_kernel.h
65 lines (53 loc) · 1.37 KB
/
bn_kernel.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
/*
* bignum data structure
* number[0] contains least significant bits
* number[size - 1] contains most significant bits
* sign = 1 for negative number
*/
typedef struct _bn {
unsigned int *number;
unsigned int size;
int sign;
} bn;
/*
* output bn to decimal string
* Note: the returned string should be freed with the kfree()
*/
char *bn_to_string(const bn *src);
/*
* alloc a bn structure with the given size
* the value is initialized to +0
*/
bn *bn_alloc(size_t size);
/*
* free entire bn data structure
* return 0 on success, -1 on error
*/
int bn_free(bn *src);
/*
* copy the value from src to dest
* return 0 on success, -1 on error
*/
int bn_cpy(bn *dest, bn *src);
/*
* compare length
* return 1 if |a| > |b|
* return -1 if |a| < |b|
* return 0 if |a| = |b|
*/
int bn_cmp(const bn *a, const bn *b);
/* swap bn ptr */
void bn_swap(bn *a, bn *b);
/* left bit shift on bn (maximun shift 31) */
void bn_lshift(bn *src, size_t shift);
/* right bit shift on bn (maximun shift 31) */
void bn_rshift(bn *src, size_t shift);
/* c = a + b */
void bn_add(const bn *a, const bn *b, bn *c);
/* c = a - b */
void bn_sub(const bn *a, const bn *b, bn *c);
/* c = a x b */
void bn_mult(const bn *a, const bn *b, bn *c);
/* calc n-th Fibonacci number and save into dest */
void bn_fib_fdoubling(bn *dest, unsigned int n);
void bn_fib(bn *dest, unsigned int n);