1107120Sjulian/* 2107120Sjulian * Attribution notice: Rainbow have generously allowed me to reproduce the 3139823Simp * necessary definitions here from their API. This means the support can 4139823Simp * build independently of whether application builders have the API or 5139823Simp * hardware. This will allow developers to easily produce software that has 6107120Sjulian * latent hardware support for any users that have accelertors installed, 7107120Sjulian * without the developers themselves needing anything extra. I have only 8107120Sjulian * clipped the parts from the CryptoSwift header files that are (or seem) 9107120Sjulian * relevant to the CryptoSwift support code. This is simply to keep the file 10107120Sjulian * sizes reasonable. [Geoff] 11107120Sjulian */ 12107120Sjulian 13107120Sjulian/* 14107120Sjulian * NB: These type widths do *not* seem right in general, in particular 15107120Sjulian * they're not terribly friendly to 64-bit architectures (unsigned long) will 16107120Sjulian * be 64-bit on IA-64 for a start. I'm leaving these alone as they agree with 17107120Sjulian * Rainbow's API and this will only be called into question on platforms with 18107120Sjulian * Rainbow support anyway! ;-) 19107120Sjulian */ 20107120Sjulian 21107120Sjulian#ifdef __cplusplus 22107120Sjulianextern "C" { 23107120Sjulian#endif /* __cplusplus */ 24107120Sjulian 25107120Sjulian typedef long SW_STATUS; /* status */ 26107120Sjulian typedef unsigned char SW_BYTE; /* 8 bit byte */ 27107120Sjulian typedef unsigned short SW_U16; /* 16 bit number */ 28107120Sjulian#if defined(_IRIX) 29107120Sjulian# include <sgidefs.h> 30114878Sjulian typedef __uint32_t SW_U32; 31107120Sjulian#else 32107120Sjulian typedef unsigned long SW_U32; /* 32 bit integer */ 33107120Sjulian#endif 34107120Sjulian 35107120Sjulian#if defined(OPENSSL_SYS_WIN32) 36107120Sjulian typedef struct _SW_U64 { 37107120Sjulian SW_U32 low32; 38107120Sjulian SW_U32 high32; 39107120Sjulian } SW_U64; /* 64 bit integer */ 40107120Sjulian#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 41107120Sjulian typedef longlong SW_U64 42107120Sjulian#else /* Unix variants */ 43107120Sjulian typedef struct _SW_U64 { 44107120Sjulian SW_U32 low32; 45107120Sjulian SW_U32 high32; 46107120Sjulian } SW_U64; /* 64 bit integer */ 47107120Sjulian#endif 48107120Sjulian 49107120Sjulian/* status codes */ 50107120Sjulian#define SW_OK (0L) 51107120Sjulian#define SW_ERR_BASE (-10000L) 52107120Sjulian#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ 53107120Sjulian#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ 54107120Sjulian /* up yet */ 55107120Sjulian#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ 56107120Sjulian /* time out */ 57107120Sjulian#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ 58107120Sjulian /* execute the command */ 59243882Sglebius#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ 60107120Sjulian /* NULL */ 61107120Sjulian#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ 62107120Sjulian /* small, too large. */ 63107120Sjulian#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ 64107120Sjulian /* handle */ 65107120Sjulian#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ 66107120Sjulian /* standing at this */ 67107120Sjulian /* context handle */ 68107120Sjulian#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ 69107120Sjulian#define SW_ERR_NO_PENDING (SW_ERR_BASE-10) /* No request is pending. */ 70107120Sjulian#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11) /* Not enough memory */ 71107120Sjulian#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12) /* Invalid algorithm type */ 72107120Sjulian /* in SW_PARAM structure */ 73107120Sjulian#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13) /* No key is associated with */ 74107120Sjulian /* context. */ 75107120Sjulian /* swAttachKeyParam() is */ 76107120Sjulian /* not called. */ 77107120Sjulian#define SW_ERR_KEY_CMD_MISMATCH \ 78107120Sjulian (SW_ERR_BASE-14) /* Cannot perform requested */ 79107120Sjulian /* SW_COMMAND_CODE since */ 80107120Sjulian /* key attached via */ 81107120Sjulian /* swAttachKeyParam() */ 82107120Sjulian /* cannot be used for this */ 83107120Sjulian /* SW_COMMAND_CODE. */ 84107120Sjulian#define SW_ERR_NOT_IMPLEMENTED \ 85107120Sjulian (SW_ERR_BASE-15) /* Not implemented */ 86107120Sjulian#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16) /* Bad command code */ 87107120Sjulian#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17) /* too small or too large in */ 88107120Sjulian /* the "initems" or */ 89107120Sjulian /* "outitems". */ 90107120Sjulian#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18) /* Bad accelerator number */ 91107120Sjulian#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19) /* At least one of the self */ 92107120Sjulian /* test fail, look at the */ 93243882Sglebius /* selfTestBitmap in */ 94107120Sjulian /* SW_ACCELERATOR_INFO for */ 95107120Sjulian /* details. */ 96107120Sjulian#define SW_ERR_MISALIGN (SW_ERR_BASE-20) /* Certain alogrithms require */ 97107120Sjulian /* key materials aligned */ 98107120Sjulian /* in certain order, e.g. */ 99107120Sjulian /* 128 bit for CRT */ 100107120Sjulian#define SW_ERR_OUTPUT_NULL_PTR \ 101107120Sjulian (SW_ERR_BASE-21) /* a required pointer is */ 102107120Sjulian /* NULL */ 103107120Sjulian#define SW_ERR_OUTPUT_SIZE \ 104107120Sjulian (SW_ERR_BASE-22) /* size is invalid, too */ 105107120Sjulian /* small, too large. */ 106107120Sjulian#define SW_ERR_FIRMWARE_CHECKSUM \ 107107120Sjulian (SW_ERR_BASE-23) /* firmware checksum mismatch */ 108107120Sjulian /* download failed. */ 109107120Sjulian#define SW_ERR_UNKNOWN_FIRMWARE \ 110107120Sjulian (SW_ERR_BASE-24) /* unknown firmware error */ 111107120Sjulian#define SW_ERR_INTERRUPT (SW_ERR_BASE-25) /* request is abort when */ 112107120Sjulian /* it's waiting to be */ 113107120Sjulian /* completed. */ 114107120Sjulian#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26) /* error in writing to Non- */ 115107120Sjulian /* volatile memory */ 116243882Sglebius#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27) /* out of range error in */ 117107120Sjulian /* writing to NV memory */ 118107120Sjulian#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28) /* Random Number Generation */ 119107120Sjulian /* failure */ 120107120Sjulian#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29) /* DSS Sign or Verify failure */ 121107120Sjulian#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30) /* Failure in various math */ 122107120Sjulian /* calculations */ 123107120Sjulian#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31) /* Error in accessing on - */ 124107120Sjulian /* board memory */ 125107120Sjulian#define SW_ERR_FIRMWARE_VERSION \ 126107120Sjulian (SW_ERR_BASE-32) /* Wrong version in firmware */ 127107120Sjulian /* update */ 128107120Sjulian#define SW_ERR_ZERO_WORKING_ACCELERATOR \ 129107120Sjulian (SW_ERR_BASE-44) /* All accelerators are bad */ 130107120Sjulian 131107120Sjulian /* algorithm type */ 132107120Sjulian#define SW_ALG_CRT 1 133107120Sjulian#define SW_ALG_EXP 2 134107120Sjulian#define SW_ALG_DSA 3 135107120Sjulian#define SW_ALG_NVDATA 4 136107120Sjulian 137107120Sjulian /* command code */ 138107120Sjulian#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ 139107120Sjulian /* Chinese Remainder Theorem (CRT) */ 140107120Sjulian#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ 141243882Sglebius#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ 142107120Sjulian#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ 143107120Sjulian#define SW_CMD_RAND 5 /* perform random number generation */ 144107120Sjulian#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ 145107120Sjulian#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ 146107120Sjulian 147107120Sjulian typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ 148107120Sjulian typedef SW_U32 SW_STATE; /* state */ 149107120Sjulian typedef SW_U32 SW_COMMAND_CODE; /* command code */ 150107120Sjulian typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ 151107120Sjulian 152107120Sjulian typedef struct _SW_LARGENUMBER { 153107120Sjulian SW_U32 nbytes; /* number of bytes in the buffer "value" */ 154107120Sjulian SW_BYTE *value; /* the large integer as a string of */ 155107120Sjulian /* bytes in network (big endian) order */ 156107120Sjulian } SW_LARGENUMBER; 157114878Sjulian 158114878Sjulian#if defined(OPENSSL_SYS_WIN32) 159107120Sjulian# include <windows.h> 160114878Sjulian typedef HANDLE SW_OSHANDLE; /* handle to kernel object */ 161114878Sjulian# define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE 162107120Sjulian# define SW_CALLCONV _stdcall 163107120Sjulian#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 164107120Sjulian /* async callback mechanisms */ 165107120Sjulian /* swiftCallbackLevel */ 166107120Sjulian# define SW_MAC_CALLBACK_LEVEL_NO 0 167107120Sjulian# define SW_MAC_CALLBACK_LEVEL_HARDWARE 1/* from the hardware ISR */ 168107120Sjulian# define SW_MAC_CALLBACK_LEVEL_SECONDARY 2/* as secondary ISR */ 169107120Sjulian typedef int SW_MAC_CALLBACK_LEVEL; 170107120Sjulian typedef int SW_OSHANDLE; 171107120Sjulian# define SW_OS_INVALID_HANDLE (-1) 172107120Sjulian# define SW_CALLCONV 173107120Sjulian#else /* Unix variants */ 174107120Sjulian typedef int SW_OSHANDLE; /* handle to driver */ 175243882Sglebius# define SW_OS_INVALID_HANDLE (-1) 176107120Sjulian# define SW_CALLCONV 177107120Sjulian#endif 178107120Sjulian 179107120Sjulian typedef struct _SW_CRT { 180107120Sjulian SW_LARGENUMBER p; /* prime number p */ 181107120Sjulian SW_LARGENUMBER q; /* prime number q */ 182107120Sjulian SW_LARGENUMBER dmp1; /* exponent1 */ 183107120Sjulian SW_LARGENUMBER dmq1; /* exponent2 */ 184107120Sjulian SW_LARGENUMBER iqmp; /* CRT coefficient */ 185107120Sjulian } SW_CRT; 186107120Sjulian 187107120Sjulian typedef struct _SW_EXP { 188107120Sjulian SW_LARGENUMBER modulus; /* modulus */ 189107120Sjulian SW_LARGENUMBER exponent; /* exponent */ 190107120Sjulian } SW_EXP; 191107120Sjulian 192114878Sjulian typedef struct _SW_DSA { 193114878Sjulian SW_LARGENUMBER p; /* */ 194107120Sjulian SW_LARGENUMBER q; /* */ 195114878Sjulian SW_LARGENUMBER g; /* */ 196114878Sjulian SW_LARGENUMBER key; /* private/public key */ 197107120Sjulian } SW_DSA; 198107120Sjulian 199107120Sjulian typedef struct _SW_NVDATA { 200107120Sjulian SW_U32 accnum; /* accelerator board number */ 201107120Sjulian SW_U32 offset; /* offset in byte */ 202107120Sjulian } SW_NVDATA; 203107120Sjulian 204107120Sjulian typedef struct _SW_PARAM { 205107120Sjulian SW_ALGTYPE type; /* type of the alogrithm */ 206107120Sjulian union { 207243882Sglebius SW_CRT crt; 208107120Sjulian SW_EXP exp; 209107120Sjulian SW_DSA dsa; 210107120Sjulian SW_NVDATA nvdata; 211107120Sjulian } up; 212107120Sjulian } SW_PARAM; 213107120Sjulian 214107120Sjulian typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ 215107120Sjulian 216107120Sjulian /* 217107120Sjulian * Now the OpenSSL bits, these function types are the for the function 218107120Sjulian * pointers that will bound into the Rainbow shared libraries. 219107120Sjulian */ 220107120Sjulian typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE 221107120Sjulian *hac); 222107120Sjulian typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, 223107120Sjulian SW_PARAM *key_params); 224107120Sjulian typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac, 225107120Sjulian SW_COMMAND_CODE cmd, 226107120Sjulian SW_LARGENUMBER pin[], 227107120Sjulian SW_U32 pin_count, 228107120Sjulian SW_LARGENUMBER pout[], 229107120Sjulian SW_U32 pout_count); 230107120Sjulian typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE 231107120Sjulian hac); 232107120Sjulian 233107120Sjulian#ifdef __cplusplus 234107120Sjulian} 235107120Sjulian#endif /* __cplusplus */ 236107120Sjulian