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