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