1280304Sjkim/* 2280304Sjkim * Attribution notice: Rainbow have generously allowed me to reproduce the 3280304Sjkim * necessary definitions here from their API. This means the support can 4280304Sjkim * build independently of whether application builders have the API or 5280304Sjkim * hardware. This will allow developers to easily produce software that has 6280304Sjkim * latent hardware support for any users that have accelertors installed, 7280304Sjkim * without the developers themselves needing anything extra. I have only 8280304Sjkim * clipped the parts from the CryptoSwift header files that are (or seem) 9280304Sjkim * relevant to the CryptoSwift support code. This is simply to keep the file 10280304Sjkim * sizes reasonable. [Geoff] 11160814Ssimon */ 12160814Ssimon 13280304Sjkim/* 14280304Sjkim * NB: These type widths do *not* seem right in general, in particular 15280304Sjkim * they're not terribly friendly to 64-bit architectures (unsigned long) will 16280304Sjkim * be 64-bit on IA-64 for a start. I'm leaving these alone as they agree with 17280304Sjkim * Rainbow's API and this will only be called into question on platforms with 18280304Sjkim * Rainbow support anyway! ;-) 19280304Sjkim */ 20160814Ssimon 21160814Ssimon#ifdef __cplusplus 22160814Ssimonextern "C" { 23280304Sjkim#endif /* __cplusplus */ 24160814Ssimon 25280304Sjkim typedef long SW_STATUS; /* status */ 26280304Sjkim typedef unsigned char SW_BYTE; /* 8 bit byte */ 27280304Sjkim typedef unsigned short SW_U16; /* 16 bit number */ 28160814Ssimon#if defined(_IRIX) 29280304Sjkim# include <sgidefs.h> 30280304Sjkim typedef __uint32_t SW_U32; 31160814Ssimon#else 32280304Sjkim typedef unsigned long SW_U32; /* 32 bit integer */ 33160814Ssimon#endif 34280304Sjkim 35160814Ssimon#if defined(OPENSSL_SYS_WIN32) 36280304Sjkim typedef struct _SW_U64 { 37280304Sjkim SW_U32 low32; 38280304Sjkim SW_U32 high32; 39280304Sjkim } SW_U64; /* 64 bit integer */ 40160814Ssimon#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 41280304Sjkim typedef longlong SW_U64 42280304Sjkim#else /* Unix variants */ 43280304Sjkim typedef struct _SW_U64 { 44280304Sjkim SW_U32 low32; 45280304Sjkim SW_U32 high32; 46280304Sjkim } SW_U64; /* 64 bit integer */ 47160814Ssimon#endif 48160814Ssimon 49160814Ssimon/* status codes */ 50160814Ssimon#define SW_OK (0L) 51160814Ssimon#define SW_ERR_BASE (-10000L) 52280304Sjkim#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ 53280304Sjkim#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ 54280304Sjkim /* up yet */ 55280304Sjkim#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ 56280304Sjkim /* time out */ 57280304Sjkim#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ 58280304Sjkim /* execute the command */ 59280304Sjkim#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ 60280304Sjkim /* NULL */ 61280304Sjkim#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ 62280304Sjkim /* small, too large. */ 63280304Sjkim#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ 64280304Sjkim /* handle */ 65160814Ssimon#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ 66280304Sjkim /* standing at this */ 67280304Sjkim /* context handle */ 68280304Sjkim#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ 69280304Sjkim#define SW_ERR_NO_PENDING (SW_ERR_BASE-10) /* No request is pending. */ 70280304Sjkim#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11) /* Not enough memory */ 71280304Sjkim#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12) /* Invalid algorithm type */ 72280304Sjkim /* in SW_PARAM structure */ 73280304Sjkim#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13) /* No key is associated with */ 74280304Sjkim /* context. */ 75280304Sjkim /* swAttachKeyParam() is */ 76280304Sjkim /* not called. */ 77160814Ssimon#define SW_ERR_KEY_CMD_MISMATCH \ 78280304Sjkim (SW_ERR_BASE-14) /* Cannot perform requested */ 79280304Sjkim /* SW_COMMAND_CODE since */ 80280304Sjkim /* key attached via */ 81280304Sjkim /* swAttachKeyParam() */ 82280304Sjkim /* cannot be used for this */ 83280304Sjkim /* SW_COMMAND_CODE. */ 84160814Ssimon#define SW_ERR_NOT_IMPLEMENTED \ 85280304Sjkim (SW_ERR_BASE-15) /* Not implemented */ 86280304Sjkim#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16) /* Bad command code */ 87280304Sjkim#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17) /* too small or too large in */ 88280304Sjkim /* the "initems" or */ 89280304Sjkim /* "outitems". */ 90280304Sjkim#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18) /* Bad accelerator number */ 91280304Sjkim#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19) /* At least one of the self */ 92280304Sjkim /* test fail, look at the */ 93280304Sjkim /* selfTestBitmap in */ 94280304Sjkim /* SW_ACCELERATOR_INFO for */ 95280304Sjkim /* details. */ 96280304Sjkim#define SW_ERR_MISALIGN (SW_ERR_BASE-20) /* Certain alogrithms require */ 97280304Sjkim /* key materials aligned */ 98280304Sjkim /* in certain order, e.g. */ 99280304Sjkim /* 128 bit for CRT */ 100160814Ssimon#define SW_ERR_OUTPUT_NULL_PTR \ 101280304Sjkim (SW_ERR_BASE-21) /* a required pointer is */ 102280304Sjkim /* NULL */ 103160814Ssimon#define SW_ERR_OUTPUT_SIZE \ 104280304Sjkim (SW_ERR_BASE-22) /* size is invalid, too */ 105280304Sjkim /* small, too large. */ 106160814Ssimon#define SW_ERR_FIRMWARE_CHECKSUM \ 107280304Sjkim (SW_ERR_BASE-23) /* firmware checksum mismatch */ 108280304Sjkim /* download failed. */ 109160814Ssimon#define SW_ERR_UNKNOWN_FIRMWARE \ 110280304Sjkim (SW_ERR_BASE-24) /* unknown firmware error */ 111280304Sjkim#define SW_ERR_INTERRUPT (SW_ERR_BASE-25) /* request is abort when */ 112280304Sjkim /* it's waiting to be */ 113280304Sjkim /* completed. */ 114280304Sjkim#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26) /* error in writing to Non- */ 115280304Sjkim /* volatile memory */ 116280304Sjkim#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27) /* out of range error in */ 117280304Sjkim /* writing to NV memory */ 118280304Sjkim#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28) /* Random Number Generation */ 119280304Sjkim /* failure */ 120280304Sjkim#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29) /* DSS Sign or Verify failure */ 121280304Sjkim#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30) /* Failure in various math */ 122280304Sjkim /* calculations */ 123280304Sjkim#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31) /* Error in accessing on - */ 124280304Sjkim /* board memory */ 125160814Ssimon#define SW_ERR_FIRMWARE_VERSION \ 126280304Sjkim (SW_ERR_BASE-32) /* Wrong version in firmware */ 127280304Sjkim /* update */ 128160814Ssimon#define SW_ERR_ZERO_WORKING_ACCELERATOR \ 129280304Sjkim (SW_ERR_BASE-44) /* All accelerators are bad */ 130160814Ssimon 131280304Sjkim /* 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 137280304Sjkim /* command code */ 138280304Sjkim#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ 139280304Sjkim /* Chinese Remainder Theorem (CRT) */ 140280304Sjkim#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ 141280304Sjkim#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ 142280304Sjkim#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ 143280304Sjkim#define SW_CMD_RAND 5 /* perform random number generation */ 144280304Sjkim#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ 145280304Sjkim#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ 146160814Ssimon 147280304Sjkim typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ 148280304Sjkim typedef SW_U32 SW_STATE; /* state */ 149280304Sjkim typedef SW_U32 SW_COMMAND_CODE; /* command code */ 150280304Sjkim typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ 151160814Ssimon 152280304Sjkim typedef struct _SW_LARGENUMBER { 153280304Sjkim SW_U32 nbytes; /* number of bytes in the buffer "value" */ 154280304Sjkim SW_BYTE *value; /* the large integer as a string of */ 155280304Sjkim /* bytes in network (big endian) order */ 156280304Sjkim } SW_LARGENUMBER; 157160814Ssimon 158160814Ssimon#if defined(OPENSSL_SYS_WIN32) 159280304Sjkim# include <windows.h> 160280304Sjkim typedef HANDLE SW_OSHANDLE; /* handle to kernel object */ 161280304Sjkim# define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE 162280304Sjkim# define SW_CALLCONV _stdcall 163160814Ssimon#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 164160814Ssimon /* async callback mechanisms */ 165160814Ssimon /* swiftCallbackLevel */ 166280304Sjkim# define SW_MAC_CALLBACK_LEVEL_NO 0 167280304Sjkim# define SW_MAC_CALLBACK_LEVEL_HARDWARE 1/* from the hardware ISR */ 168280304Sjkim# define SW_MAC_CALLBACK_LEVEL_SECONDARY 2/* as secondary ISR */ 169280304Sjkim typedef int SW_MAC_CALLBACK_LEVEL; 170280304Sjkim typedef int SW_OSHANDLE; 171280304Sjkim# define SW_OS_INVALID_HANDLE (-1) 172280304Sjkim# define SW_CALLCONV 173280304Sjkim#else /* Unix variants */ 174280304Sjkim typedef int SW_OSHANDLE; /* handle to driver */ 175280304Sjkim# define SW_OS_INVALID_HANDLE (-1) 176280304Sjkim# define SW_CALLCONV 177280304Sjkim#endif 178160814Ssimon 179280304Sjkim typedef struct _SW_CRT { 180280304Sjkim SW_LARGENUMBER p; /* prime number p */ 181280304Sjkim SW_LARGENUMBER q; /* prime number q */ 182280304Sjkim SW_LARGENUMBER dmp1; /* exponent1 */ 183280304Sjkim SW_LARGENUMBER dmq1; /* exponent2 */ 184280304Sjkim SW_LARGENUMBER iqmp; /* CRT coefficient */ 185280304Sjkim } SW_CRT; 186160814Ssimon 187280304Sjkim typedef struct _SW_EXP { 188280304Sjkim SW_LARGENUMBER modulus; /* modulus */ 189280304Sjkim SW_LARGENUMBER exponent; /* exponent */ 190280304Sjkim } SW_EXP; 191160814Ssimon 192280304Sjkim typedef struct _SW_DSA { 193280304Sjkim SW_LARGENUMBER p; /* */ 194280304Sjkim SW_LARGENUMBER q; /* */ 195280304Sjkim SW_LARGENUMBER g; /* */ 196280304Sjkim SW_LARGENUMBER key; /* private/public key */ 197280304Sjkim } SW_DSA; 198160814Ssimon 199280304Sjkim typedef struct _SW_NVDATA { 200280304Sjkim SW_U32 accnum; /* accelerator board number */ 201280304Sjkim SW_U32 offset; /* offset in byte */ 202280304Sjkim } SW_NVDATA; 203160814Ssimon 204280304Sjkim typedef struct _SW_PARAM { 205280304Sjkim SW_ALGTYPE type; /* type of the alogrithm */ 206280304Sjkim union { 207280304Sjkim SW_CRT crt; 208280304Sjkim SW_EXP exp; 209280304Sjkim SW_DSA dsa; 210280304Sjkim SW_NVDATA nvdata; 211280304Sjkim } up; 212280304Sjkim } SW_PARAM; 213160814Ssimon 214280304Sjkim typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ 215160814Ssimon 216280304Sjkim /* 217280304Sjkim * Now the OpenSSL bits, these function types are the for the function 218280304Sjkim * pointers that will bound into the Rainbow shared libraries. 219280304Sjkim */ 220280304Sjkim typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE 221280304Sjkim *hac); 222280304Sjkim typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, 223280304Sjkim SW_PARAM *key_params); 224280304Sjkim typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac, 225280304Sjkim SW_COMMAND_CODE cmd, 226280304Sjkim SW_LARGENUMBER pin[], 227280304Sjkim SW_U32 pin_count, 228280304Sjkim SW_LARGENUMBER pout[], 229280304Sjkim SW_U32 pout_count); 230280304Sjkim typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE 231280304Sjkim hac); 232160814Ssimon 233160814Ssimon#ifdef __cplusplus 234160814Ssimon} 235280304Sjkim#endif /* __cplusplus */ 236