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.
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.
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! ;-) */
23 #endif /* __cplusplus */
25 typedef long SW_STATUS; /* status */
26 typedef unsigned char SW_BYTE; /* 8 bit byte */
27 typedef unsigned short SW_U16; /* 16 bit number */
30 typedef __uint32_t SW_U32;
32 typedef unsigned long SW_U32; /* 32 bit integer */
35 #if defined(OPENSSL_SYS_WIN32)
36 typedef struct _SW_U64 {
39 } SW_U64; /* 64 bit integer */
40 #else /* Unix variants */
41 typedef struct _SW_U64 {
44 } SW_U64; /* 64 bit integer */
49 #define SW_ERR_BASE (-10000L)
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 */
53 #define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */
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 */
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 */
63 #define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */
64 /* standing at this */
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 */
73 /* swAttachKeyParam() is */
75 #define SW_ERR_KEY_CMD_MISMATCH \
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. */
82 #define SW_ERR_NOT_IMPLEMENTED \
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 */
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*/
94 #define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/
95 /* key materials aligned */
96 /* in certain order, e.g. */
98 #define SW_ERR_OUTPUT_NULL_PTR \
99 (SW_ERR_BASE-21)/* a required pointer is */
101 #define SW_ERR_OUTPUT_SIZE \
102 (SW_ERR_BASE-22)/* size is invalid, too */
103 /* small, too large. */
104 #define SW_ERR_FIRMWARE_CHECKSUM \
105 (SW_ERR_BASE-23)/* firmware checksum mismatch*/
106 /* download failed. */
107 #define SW_ERR_UNKNOWN_FIRMWARE \
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 */
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 */
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 */
121 #define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */
123 #define SW_ERR_FIRMWARE_VERSION \
124 (SW_ERR_BASE-32)/* Wrong version in firmware */
126 #define SW_ERR_ZERO_WORKING_ACCELERATOR \
127 (SW_ERR_BASE-44)/* All accelerators are bad */
134 #define SW_ALG_NVDATA 4
137 #define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */
138 /* Chinese Remainder Theorem (CRT) */
139 #define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */
140 #define SW_CMD_DSS_SIGN 3 /* perform DSS sign */
141 #define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */
142 #define SW_CMD_RAND 5 /* perform random number generation */
143 #define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */
144 #define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */
146 typedef SW_U32 SW_ALGTYPE; /* alogrithm type */
147 typedef SW_U32 SW_STATE; /* state */
148 typedef SW_U32 SW_COMMAND_CODE; /* command code */
149 typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */
151 typedef struct _SW_LARGENUMBER {
152 SW_U32 nbytes; /* number of bytes in the buffer "value" */
153 SW_BYTE* value; /* the large integer as a string of */
154 /* bytes in network (big endian) order */
157 #if defined(OPENSSL_SYS_WIN32)
159 typedef HANDLE SW_OSHANDLE; /* handle to kernel object */
160 #define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE
161 #define SW_CALLCONV _stdcall
162 #else /* Unix variants */
163 typedef int SW_OSHANDLE; /* handle to driver */
164 #define SW_OS_INVALID_HANDLE (-1)
168 typedef struct _SW_CRT {
169 SW_LARGENUMBER p; /* prime number p */
170 SW_LARGENUMBER q; /* prime number q */
171 SW_LARGENUMBER dmp1; /* exponent1 */
172 SW_LARGENUMBER dmq1; /* exponent2 */
173 SW_LARGENUMBER iqmp; /* CRT coefficient */
176 typedef struct _SW_EXP {
177 SW_LARGENUMBER modulus; /* modulus */
178 SW_LARGENUMBER exponent;/* exponent */
181 typedef struct _SW_DSA {
182 SW_LARGENUMBER p; /* */
183 SW_LARGENUMBER q; /* */
184 SW_LARGENUMBER g; /* */
185 SW_LARGENUMBER key; /* private/public key */
188 typedef struct _SW_NVDATA {
189 SW_U32 accnum; /* accelerator board number */
190 SW_U32 offset; /* offset in byte */
193 typedef struct _SW_PARAM {
194 SW_ALGTYPE type; /* type of the alogrithm */
203 typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */
206 /* Now the OpenSSL bits, these function types are the for the function
207 * pointers that will bound into the Rainbow shared libraries. */
208 typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac);
209 typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac,
210 SW_PARAM *key_params);
211 typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac,
213 SW_LARGENUMBER pin[],
215 SW_LARGENUMBER pout[],
217 typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE hac);
221 #endif /* __cplusplus */