binary_field.h
1.59 KB
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
/*
* binary_field.h
* definitions for binary arithmetic: characteristic two,
* vector length n: field2n.
* number of bits for field fixed here
*/
#ifndef BINARY_FIELD_H
#define BINARY_FIELD_H
/*
* polynomial arithmetic is done using this
* number of bits. Make sure the irreducible polynomial has this
* degree
*/
/*change later to 233 */
#define NUM_BITS 233
#define NULL 0
/*
#define NUM_BITS 111
*/
/* number of bits in machine
* word: make sure this is right = 32 bits = sizeof (element)
* later
*/
#define WORD_SIZE (sizeof(int) *8)
/* to determine size of array of big int structure
*/
#define NUM_WORD (NUM_BITS/WORD_SIZE)
/* number of shifts needed to get to MSB of zero
* offset of polynomial coeff list
*/
#define UPR_SHIFT (NUM_BITS % WORD_SIZE)
/* number of machine words to
* hold polynomial or large int
*/
#define MAX_LONG (NUM_WORD + 1)
#define MAX_BITS (MAX_LONG *WORD_SIZE)
#define MAX_SHIFT (WORD_SIZE -1)
/* mask for most significant bit */
#define MSB (1L << MAX_SHIFT)
#define UPR_BIT (1L << (UPR_SHIFT -1))
#define UPR_MASK (~ (-1L << UPR_SHIFT))
typedef unsigned long element; /* single word*/
/* the binary field representation */
typedef struct {
element e[MAX_LONG];
} field_2n;
/*errors */
typedef enum { BSL_OK = 0,
BSL_OVERFLOW,
BSL_DIVIDE_BY_ZERO,
BSL_SHA_ERROR,
BSL_BAD_KEY,
BSL_NULL_POINTER
} BSL_error;
typedef enum { BSL_TRUE = 0,
BSL_FALSE
} BSL_boolean;
#ifndef WIN32
typedef BSL_boolean boolean;
#endif
#endif /* for ifndef binary_field_h */