1296341Sdelphij/* 2296341Sdelphij * Attribution notice: Rainbow have generously allowed me to reproduce the 3296341Sdelphij * necessary definitions here from their API. This means the support can 4296341Sdelphij * build independently of whether application builders have the API or 5296341Sdelphij * hardware. This will allow developers to easily produce software that has 6296341Sdelphij * latent hardware support for any users that have accelertors installed, 7296341Sdelphij * without the developers themselves needing anything extra. I have only 8296341Sdelphij * clipped the parts from the CryptoSwift header files that are (or seem) 9296341Sdelphij * relevant to the CryptoSwift support code. This is simply to keep the file 10296341Sdelphij * sizes reasonable. [Geoff] 11160814Ssimon */ 12160814Ssimon 13296341Sdelphij/* 14296341Sdelphij * NB: These type widths do *not* seem right in general, in particular 15296341Sdelphij * they're not terribly friendly to 64-bit architectures (unsigned long) will 16296341Sdelphij * be 64-bit on IA-64 for a start. I'm leaving these alone as they agree with 17296341Sdelphij * Rainbow's API and this will only be called into question on platforms with 18296341Sdelphij * Rainbow support anyway! ;-) 19296341Sdelphij */ 20160814Ssimon 21160814Ssimon#ifdef __cplusplus 22160814Ssimonextern "C" { 23296341Sdelphij#endif /* __cplusplus */ 24160814Ssimon 25296341Sdelphij typedef long SW_STATUS; /* status */ 26296341Sdelphij typedef unsigned char SW_BYTE; /* 8 bit byte */ 27296341Sdelphij typedef unsigned short SW_U16; /* 16 bit number */ 28160814Ssimon#if defined(_IRIX) 29296341Sdelphij# include <sgidefs.h> 30296341Sdelphij typedef __uint32_t SW_U32; 31160814Ssimon#else 32296341Sdelphij typedef unsigned long SW_U32; /* 32 bit integer */ 33160814Ssimon#endif 34296341Sdelphij 35160814Ssimon#if defined(OPENSSL_SYS_WIN32) 36296341Sdelphij typedef struct _SW_U64 { 37296341Sdelphij SW_U32 low32; 38296341Sdelphij SW_U32 high32; 39296341Sdelphij } SW_U64; /* 64 bit integer */ 40160814Ssimon#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 41296341Sdelphij typedef longlong SW_U64 42296341Sdelphij#else /* Unix variants */ 43296341Sdelphij typedef struct _SW_U64 { 44296341Sdelphij SW_U32 low32; 45296341Sdelphij SW_U32 high32; 46296341Sdelphij } SW_U64; /* 64 bit integer */ 47160814Ssimon#endif 48160814Ssimon 49160814Ssimon/* status codes */ 50160814Ssimon#define SW_OK (0L) 51160814Ssimon#define SW_ERR_BASE (-10000L) 52296341Sdelphij#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ 53296341Sdelphij#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ 54296341Sdelphij /* up yet */ 55296341Sdelphij#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ 56296341Sdelphij /* time out */ 57296341Sdelphij#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ 58296341Sdelphij /* execute the command */ 59296341Sdelphij#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ 60296341Sdelphij /* NULL */ 61296341Sdelphij#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ 62296341Sdelphij /* small, too large. */ 63296341Sdelphij#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ 64296341Sdelphij /* handle */ 65160814Ssimon#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ 66296341Sdelphij /* standing at this */ 67296341Sdelphij /* context handle */ 68296341Sdelphij#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ 69296341Sdelphij#define SW_ERR_NO_PENDING (SW_ERR_BASE-10) /* No request is pending. */ 70296341Sdelphij#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11) /* Not enough memory */ 71296341Sdelphij#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12) /* Invalid algorithm type */ 72296341Sdelphij /* in SW_PARAM structure */ 73296341Sdelphij#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13) /* No key is associated with */ 74296341Sdelphij /* context. */ 75296341Sdelphij /* swAttachKeyParam() is */ 76296341Sdelphij /* not called. */ 77160814Ssimon#define SW_ERR_KEY_CMD_MISMATCH \ 78296341Sdelphij (SW_ERR_BASE-14) /* Cannot perform requested */ 79296341Sdelphij /* SW_COMMAND_CODE since */ 80296341Sdelphij /* key attached via */ 81296341Sdelphij /* swAttachKeyParam() */ 82296341Sdelphij /* cannot be used for this */ 83296341Sdelphij /* SW_COMMAND_CODE. */ 84160814Ssimon#define SW_ERR_NOT_IMPLEMENTED \ 85296341Sdelphij (SW_ERR_BASE-15) /* Not implemented */ 86296341Sdelphij#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16) /* Bad command code */ 87296341Sdelphij#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17) /* too small or too large in */ 88296341Sdelphij /* the "initems" or */ 89296341Sdelphij /* "outitems". */ 90296341Sdelphij#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18) /* Bad accelerator number */ 91296341Sdelphij#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19) /* At least one of the self */ 92296341Sdelphij /* test fail, look at the */ 93296341Sdelphij /* selfTestBitmap in */ 94296341Sdelphij /* SW_ACCELERATOR_INFO for */ 95296341Sdelphij /* details. */ 96296341Sdelphij#define SW_ERR_MISALIGN (SW_ERR_BASE-20) /* Certain alogrithms require */ 97296341Sdelphij /* key materials aligned */ 98296341Sdelphij /* in certain order, e.g. */ 99296341Sdelphij /* 128 bit for CRT */ 100160814Ssimon#define SW_ERR_OUTPUT_NULL_PTR \ 101296341Sdelphij (SW_ERR_BASE-21) /* a required pointer is */ 102296341Sdelphij /* NULL */ 103160814Ssimon#define SW_ERR_OUTPUT_SIZE \ 104296341Sdelphij (SW_ERR_BASE-22) /* size is invalid, too */ 105296341Sdelphij /* small, too large. */ 106160814Ssimon#define SW_ERR_FIRMWARE_CHECKSUM \ 107296341Sdelphij (SW_ERR_BASE-23) /* firmware checksum mismatch */ 108296341Sdelphij /* download failed. */ 109160814Ssimon#define SW_ERR_UNKNOWN_FIRMWARE \ 110296341Sdelphij (SW_ERR_BASE-24) /* unknown firmware error */ 111296341Sdelphij#define SW_ERR_INTERRUPT (SW_ERR_BASE-25) /* request is abort when */ 112296341Sdelphij /* it's waiting to be */ 113296341Sdelphij /* completed. */ 114296341Sdelphij#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26) /* error in writing to Non- */ 115296341Sdelphij /* volatile memory */ 116296341Sdelphij#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27) /* out of range error in */ 117296341Sdelphij /* writing to NV memory */ 118296341Sdelphij#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28) /* Random Number Generation */ 119296341Sdelphij /* failure */ 120296341Sdelphij#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29) /* DSS Sign or Verify failure */ 121296341Sdelphij#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30) /* Failure in various math */ 122296341Sdelphij /* calculations */ 123296341Sdelphij#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31) /* Error in accessing on - */ 124296341Sdelphij /* board memory */ 125160814Ssimon#define SW_ERR_FIRMWARE_VERSION \ 126296341Sdelphij (SW_ERR_BASE-32) /* Wrong version in firmware */ 127296341Sdelphij /* update */ 128160814Ssimon#define SW_ERR_ZERO_WORKING_ACCELERATOR \ 129296341Sdelphij (SW_ERR_BASE-44) /* All accelerators are bad */ 130160814Ssimon 131296341Sdelphij /* algorithm type */ 132160814Ssimon#define SW_ALG_CRT 1 133160814Ssimon#define SW_ALG_EXP 2 134160814Ssimon#define SW_ALG_DSA 3 135160814Ssimon#define SW_ALG_NVDATA 4 136160814Ssimon 137296341Sdelphij /* command code */ 138296341Sdelphij#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ 139296341Sdelphij /* Chinese Remainder Theorem (CRT) */ 140296341Sdelphij#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ 141296341Sdelphij#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ 142296341Sdelphij#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ 143296341Sdelphij#define SW_CMD_RAND 5 /* perform random number generation */ 144296341Sdelphij#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ 145296341Sdelphij#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ 146160814Ssimon 147296341Sdelphij typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ 148296341Sdelphij typedef SW_U32 SW_STATE; /* state */ 149296341Sdelphij typedef SW_U32 SW_COMMAND_CODE; /* command code */ 150296341Sdelphij typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ 151160814Ssimon 152296341Sdelphij typedef struct _SW_LARGENUMBER { 153296341Sdelphij SW_U32 nbytes; /* number of bytes in the buffer "value" */ 154296341Sdelphij SW_BYTE *value; /* the large integer as a string of */ 155296341Sdelphij /* bytes in network (big endian) order */ 156296341Sdelphij } SW_LARGENUMBER; 157160814Ssimon 158160814Ssimon#if defined(OPENSSL_SYS_WIN32) 159296341Sdelphij# include <windows.h> 160296341Sdelphij typedef HANDLE SW_OSHANDLE; /* handle to kernel object */ 161296341Sdelphij# define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE 162296341Sdelphij# define SW_CALLCONV _stdcall 163160814Ssimon#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 164160814Ssimon /* async callback mechanisms */ 165160814Ssimon /* swiftCallbackLevel */ 166296341Sdelphij# define SW_MAC_CALLBACK_LEVEL_NO 0 167296341Sdelphij# define SW_MAC_CALLBACK_LEVEL_HARDWARE 1/* from the hardware ISR */ 168296341Sdelphij# define SW_MAC_CALLBACK_LEVEL_SECONDARY 2/* as secondary ISR */ 169296341Sdelphij typedef int SW_MAC_CALLBACK_LEVEL; 170296341Sdelphij typedef int SW_OSHANDLE; 171296341Sdelphij# define SW_OS_INVALID_HANDLE (-1) 172296341Sdelphij# define SW_CALLCONV 173296341Sdelphij#else /* Unix variants */ 174296341Sdelphij typedef int SW_OSHANDLE; /* handle to driver */ 175296341Sdelphij# define SW_OS_INVALID_HANDLE (-1) 176296341Sdelphij# define SW_CALLCONV 177296341Sdelphij#endif 178160814Ssimon 179296341Sdelphij typedef struct _SW_CRT { 180296341Sdelphij SW_LARGENUMBER p; /* prime number p */ 181296341Sdelphij SW_LARGENUMBER q; /* prime number q */ 182296341Sdelphij SW_LARGENUMBER dmp1; /* exponent1 */ 183296341Sdelphij SW_LARGENUMBER dmq1; /* exponent2 */ 184296341Sdelphij SW_LARGENUMBER iqmp; /* CRT coefficient */ 185296341Sdelphij } SW_CRT; 186160814Ssimon 187296341Sdelphij typedef struct _SW_EXP { 188296341Sdelphij SW_LARGENUMBER modulus; /* modulus */ 189296341Sdelphij SW_LARGENUMBER exponent; /* exponent */ 190296341Sdelphij } SW_EXP; 191160814Ssimon 192296341Sdelphij typedef struct _SW_DSA { 193296341Sdelphij SW_LARGENUMBER p; /* */ 194296341Sdelphij SW_LARGENUMBER q; /* */ 195296341Sdelphij SW_LARGENUMBER g; /* */ 196296341Sdelphij SW_LARGENUMBER key; /* private/public key */ 197296341Sdelphij } SW_DSA; 198160814Ssimon 199296341Sdelphij typedef struct _SW_NVDATA { 200296341Sdelphij SW_U32 accnum; /* accelerator board number */ 201296341Sdelphij SW_U32 offset; /* offset in byte */ 202296341Sdelphij } SW_NVDATA; 203160814Ssimon 204296341Sdelphij typedef struct _SW_PARAM { 205296341Sdelphij SW_ALGTYPE type; /* type of the alogrithm */ 206296341Sdelphij union { 207296341Sdelphij SW_CRT crt; 208296341Sdelphij SW_EXP exp; 209296341Sdelphij SW_DSA dsa; 210296341Sdelphij SW_NVDATA nvdata; 211296341Sdelphij } up; 212296341Sdelphij } SW_PARAM; 213160814Ssimon 214296341Sdelphij typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ 215160814Ssimon 216296341Sdelphij /* 217296341Sdelphij * Now the OpenSSL bits, these function types are the for the function 218296341Sdelphij * pointers that will bound into the Rainbow shared libraries. 219296341Sdelphij */ 220296341Sdelphij typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE 221296341Sdelphij *hac); 222296341Sdelphij typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, 223296341Sdelphij SW_PARAM *key_params); 224296341Sdelphij typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac, 225296341Sdelphij SW_COMMAND_CODE cmd, 226296341Sdelphij SW_LARGENUMBER pin[], 227296341Sdelphij SW_U32 pin_count, 228296341Sdelphij SW_LARGENUMBER pout[], 229296341Sdelphij SW_U32 pout_count); 230296341Sdelphij typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE 231296341Sdelphij hac); 232160814Ssimon 233160814Ssimon#ifdef __cplusplus 234160814Ssimon} 235296341Sdelphij#endif /* __cplusplus */ 236