diff options
Diffstat (limited to 'src/lib/libcrypto/engine/vendor_defns/cswift.h')
-rw-r--r-- | src/lib/libcrypto/engine/vendor_defns/cswift.h | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/src/lib/libcrypto/engine/vendor_defns/cswift.h b/src/lib/libcrypto/engine/vendor_defns/cswift.h new file mode 100644 index 0000000000..0af14a1a92 --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/cswift.h | |||
@@ -0,0 +1,213 @@ | |||
1 | /* Attribution notice: Rainbow have generously allowed me to reproduce | ||
2 | * the necessary definitions here from their API. This means the support | ||
3 | * can build independently of whether application builders have the | ||
4 | * API or hardware. This will allow developers to easily produce software | ||
5 | * that has latent hardware support for any users that have accelertors | ||
6 | * installed, without the developers themselves needing anything extra. | ||
7 | * | ||
8 | * I have only clipped the parts from the CryptoSwift header files that | ||
9 | * are (or seem) relevant to the CryptoSwift support code. This is | ||
10 | * simply to keep the file sizes reasonable. | ||
11 | * [Geoff] | ||
12 | */ | ||
13 | |||
14 | |||
15 | /* NB: These type widths do *not* seem right in general, in particular | ||
16 | * they're not terribly friendly to 64-bit architectures (unsigned long) | ||
17 | * will be 64-bit on IA-64 for a start. I'm leaving these alone as they | ||
18 | * agree with Rainbow's API and this will only be called into question | ||
19 | * on platforms with Rainbow support anyway! ;-) */ | ||
20 | |||
21 | #ifdef __cplusplus | ||
22 | extern "C" { | ||
23 | #endif /* __cplusplus */ | ||
24 | |||
25 | typedef long SW_STATUS; /* status */ | ||
26 | typedef unsigned char SW_BYTE; /* 8 bit byte */ | ||
27 | typedef unsigned short SW_U16; /* 16 bit number */ | ||
28 | #if defined(_IRIX) | ||
29 | #include <sgidefs.h> | ||
30 | typedef __uint32_t SW_U32; | ||
31 | #else | ||
32 | typedef unsigned long SW_U32; /* 32 bit integer */ | ||
33 | #endif | ||
34 | |||
35 | #if defined(WIN32) | ||
36 | typedef struct _SW_U64 { | ||
37 | SW_U32 low32; | ||
38 | SW_U32 high32; | ||
39 | } SW_U64; /* 64 bit integer */ | ||
40 | #elif defined(MAC) | ||
41 | typedef longlong SW_U64 | ||
42 | #else /* Unix variants */ | ||
43 | typedef struct _SW_U64 { | ||
44 | SW_U32 low32; | ||
45 | SW_U32 high32; | ||
46 | } SW_U64; /* 64 bit integer */ | ||
47 | #endif | ||
48 | |||
49 | /* status codes */ | ||
50 | #define SW_OK (0L) | ||
51 | #define SW_ERR_BASE (-10000L) | ||
52 | #define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ | ||
53 | #define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ | ||
54 | /* up yet */ | ||
55 | #define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ | ||
56 | /* time out */ | ||
57 | #define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ | ||
58 | /* execute the command */ | ||
59 | #define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ | ||
60 | /* NULL */ | ||
61 | #define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ | ||
62 | /* small, too large. */ | ||
63 | #define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ | ||
64 | /* handle */ | ||
65 | #define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ | ||
66 | /* standing at this */ | ||
67 | /* context handle */ | ||
68 | #define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ | ||
69 | #define SW_ERR_NO_PENDING (SW_ERR_BASE-10)/* No request is pending. */ | ||
70 | #define SW_ERR_NO_MEMORY (SW_ERR_BASE-11)/* Not enough memory */ | ||
71 | #define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12)/* Invalid algorithm type */ | ||
72 | /* in SW_PARAM structure */ | ||
73 | #define SW_ERR_MISSING_KEY (SW_ERR_BASE-13)/* No key is associated with */ | ||
74 | /* context. */ | ||
75 | /* swAttachKeyParam() is */ | ||
76 | /* not called. */ | ||
77 | #define SW_ERR_KEY_CMD_MISMATCH \ | ||
78 | (SW_ERR_BASE-14)/* Cannot perform requested */ | ||
79 | /* SW_COMMAND_CODE since */ | ||
80 | /* key attached via */ | ||
81 | /* swAttachKeyParam() */ | ||
82 | /* cannot be used for this*/ | ||
83 | /* SW_COMMAND_CODE. */ | ||
84 | #define SW_ERR_NOT_IMPLEMENTED \ | ||
85 | (SW_ERR_BASE-15)/* Not implemented */ | ||
86 | #define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16)/* Bad command code */ | ||
87 | #define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17)/* too small or too large in */ | ||
88 | /* the "initems" or */ | ||
89 | /* "outitems". */ | ||
90 | #define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18)/* Bad accelerator number */ | ||
91 | #define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19)/* At least one of the self */ | ||
92 | /* test fail, look at the */ | ||
93 | /* selfTestBitmap in */ | ||
94 | /* SW_ACCELERATOR_INFO for*/ | ||
95 | /* details. */ | ||
96 | #define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/ | ||
97 | /* key materials aligned */ | ||
98 | /* in certain order, e.g. */ | ||
99 | /* 128 bit for CRT */ | ||
100 | #define SW_ERR_OUTPUT_NULL_PTR \ | ||
101 | (SW_ERR_BASE-21)/* a required pointer is */ | ||
102 | /* NULL */ | ||
103 | #define SW_ERR_OUTPUT_SIZE \ | ||
104 | (SW_ERR_BASE-22)/* size is invalid, too */ | ||
105 | /* small, too large. */ | ||
106 | #define SW_ERR_FIRMWARE_CHECKSUM \ | ||
107 | (SW_ERR_BASE-23)/* firmware checksum mismatch*/ | ||
108 | /* download failed. */ | ||
109 | #define SW_ERR_UNKNOWN_FIRMWARE \ | ||
110 | (SW_ERR_BASE-24)/* unknown firmware error */ | ||
111 | #define SW_ERR_INTERRUPT (SW_ERR_BASE-25)/* request is abort when */ | ||
112 | /* it's waiting to be */ | ||
113 | /* completed. */ | ||
114 | #define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26)/* error in writing to Non- */ | ||
115 | /* volatile memory */ | ||
116 | #define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27)/* out of range error in */ | ||
117 | /* writing to NV memory */ | ||
118 | #define SW_ERR_RNG_ERROR (SW_ERR_BASE-28)/* Random Number Generation */ | ||
119 | /* failure */ | ||
120 | #define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29)/* DSS Sign or Verify failure*/ | ||
121 | #define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30)/* Failure in various math */ | ||
122 | /* calculations */ | ||
123 | #define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */ | ||
124 | /* board memory */ | ||
125 | #define SW_ERR_FIRMWARE_VERSION \ | ||
126 | (SW_ERR_BASE-32)/* Wrong version in firmware */ | ||
127 | /* update */ | ||
128 | #define SW_ERR_ZERO_WORKING_ACCELERATOR \ | ||
129 | (SW_ERR_BASE-44)/* All accelerators are bad */ | ||
130 | |||
131 | |||
132 | /* algorithm type */ | ||
133 | #define SW_ALG_CRT 1 | ||
134 | #define SW_ALG_EXP 2 | ||
135 | #define SW_ALG_DSA 3 | ||
136 | #define SW_ALG_NVDATA 4 | ||
137 | |||
138 | /* command code */ | ||
139 | #define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ | ||
140 | /* Chinese Remainder Theorem (CRT) */ | ||
141 | #define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ | ||
142 | #define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ | ||
143 | #define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ | ||
144 | #define SW_CMD_RAND 5 /* perform random number generation */ | ||
145 | #define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ | ||
146 | #define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ | ||
147 | |||
148 | typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ | ||
149 | typedef SW_U32 SW_STATE; /* state */ | ||
150 | typedef SW_U32 SW_COMMAND_CODE; /* command code */ | ||
151 | typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ | ||
152 | |||
153 | typedef struct _SW_LARGENUMBER { | ||
154 | SW_U32 nbytes; /* number of bytes in the buffer "value" */ | ||
155 | SW_BYTE* value; /* the large integer as a string of */ | ||
156 | /* bytes in network (big endian) order */ | ||
157 | } SW_LARGENUMBER; | ||
158 | |||
159 | typedef struct _SW_CRT { | ||
160 | SW_LARGENUMBER p; /* prime number p */ | ||
161 | SW_LARGENUMBER q; /* prime number q */ | ||
162 | SW_LARGENUMBER dmp1; /* exponent1 */ | ||
163 | SW_LARGENUMBER dmq1; /* exponent2 */ | ||
164 | SW_LARGENUMBER iqmp; /* CRT coefficient */ | ||
165 | } SW_CRT; | ||
166 | |||
167 | typedef struct _SW_EXP { | ||
168 | SW_LARGENUMBER modulus; /* modulus */ | ||
169 | SW_LARGENUMBER exponent;/* exponent */ | ||
170 | } SW_EXP; | ||
171 | |||
172 | typedef struct _SW_DSA { | ||
173 | SW_LARGENUMBER p; /* */ | ||
174 | SW_LARGENUMBER q; /* */ | ||
175 | SW_LARGENUMBER g; /* */ | ||
176 | SW_LARGENUMBER key; /* private/public key */ | ||
177 | } SW_DSA; | ||
178 | |||
179 | typedef struct _SW_NVDATA { | ||
180 | SW_U32 accnum; /* accelerator board number */ | ||
181 | SW_U32 offset; /* offset in byte */ | ||
182 | } SW_NVDATA; | ||
183 | |||
184 | typedef struct _SW_PARAM { | ||
185 | SW_ALGTYPE type; /* type of the alogrithm */ | ||
186 | union { | ||
187 | SW_CRT crt; | ||
188 | SW_EXP exp; | ||
189 | SW_DSA dsa; | ||
190 | SW_NVDATA nvdata; | ||
191 | } up; | ||
192 | } SW_PARAM; | ||
193 | |||
194 | typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ | ||
195 | |||
196 | |||
197 | /* Now the OpenSSL bits, these function types are the for the function | ||
198 | * pointers that will bound into the Rainbow shared libraries. */ | ||
199 | typedef SW_STATUS t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac); | ||
200 | typedef SW_STATUS t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, | ||
201 | SW_PARAM *key_params); | ||
202 | typedef SW_STATUS t_swSimpleRequest(SW_CONTEXT_HANDLE hac, | ||
203 | SW_COMMAND_CODE cmd, | ||
204 | SW_LARGENUMBER pin[], | ||
205 | SW_U32 pin_count, | ||
206 | SW_LARGENUMBER pout[], | ||
207 | SW_U32 pout_count); | ||
208 | typedef SW_STATUS t_swReleaseAccContext(SW_CONTEXT_HANDLE hac); | ||
209 | |||
210 | #ifdef __cplusplus | ||
211 | } | ||
212 | #endif /* __cplusplus */ | ||
213 | |||