cswift.h revision 280304
1193323Sed/* 2193323Sed * Attribution notice: Rainbow have generously allowed me to reproduce the 3193323Sed * necessary definitions here from their API. This means the support can 4193323Sed * build independently of whether application builders have the API or 5193323Sed * hardware. This will allow developers to easily produce software that has 6193323Sed * latent hardware support for any users that have accelertors installed, 7193323Sed * without the developers themselves needing anything extra. I have only 8193323Sed * clipped the parts from the CryptoSwift header files that are (or seem) 9193323Sed * relevant to the CryptoSwift support code. This is simply to keep the file 10193323Sed * sizes reasonable. [Geoff] 11193323Sed */ 12193323Sed 13193323Sed/* 14193323Sed * NB: These type widths do *not* seem right in general, in particular 15193323Sed * they're not terribly friendly to 64-bit architectures (unsigned long) will 16193323Sed * be 64-bit on IA-64 for a start. I'm leaving these alone as they agree with 17193323Sed * Rainbow's API and this will only be called into question on platforms with 18193323Sed * Rainbow support anyway! ;-) 19193323Sed */ 20193323Sed 21193323Sed#ifdef __cplusplus 22193323Sedextern "C" { 23193323Sed#endif /* __cplusplus */ 24193323Sed 25193323Sed typedef long SW_STATUS; /* status */ 26193323Sed typedef unsigned char SW_BYTE; /* 8 bit byte */ 27193323Sed typedef unsigned short SW_U16; /* 16 bit number */ 28193323Sed#if defined(_IRIX) 29193323Sed# include <sgidefs.h> 30193323Sed typedef __uint32_t SW_U32; 31193323Sed#else 32193323Sed typedef unsigned long SW_U32; /* 32 bit integer */ 33193323Sed#endif 34193323Sed 35193323Sed#if defined(OPENSSL_SYS_WIN32) 36193323Sed typedef struct _SW_U64 { 37193323Sed SW_U32 low32; 38193323Sed SW_U32 high32; 39193323Sed } SW_U64; /* 64 bit integer */ 40193323Sed#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 41193323Sed typedef longlong SW_U64 42193323Sed#else /* Unix variants */ 43193323Sed typedef struct _SW_U64 { 44193323Sed SW_U32 low32; 45193323Sed SW_U32 high32; 46193323Sed } SW_U64; /* 64 bit integer */ 47193323Sed#endif 48193323Sed 49193323Sed/* status codes */ 50193323Sed#define SW_OK (0L) 51193323Sed#define SW_ERR_BASE (-10000L) 52193323Sed#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ 53193323Sed#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ 54193323Sed /* up yet */ 55193323Sed#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ 56193323Sed /* time out */ 57193323Sed#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ 58193323Sed /* execute the command */ 59193323Sed#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ 60193323Sed /* NULL */ 61193323Sed#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ 62193323Sed /* small, too large. */ 63193323Sed#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ 64193323Sed /* handle */ 65193323Sed#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ 66193323Sed /* standing at this */ 67193323Sed /* context handle */ 68193323Sed#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ 69193323Sed#define SW_ERR_NO_PENDING (SW_ERR_BASE-10) /* No request is pending. */ 70193323Sed#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11) /* Not enough memory */ 71193323Sed#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12) /* Invalid algorithm type */ 72193323Sed /* in SW_PARAM structure */ 73193323Sed#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13) /* No key is associated with */ 74193323Sed /* context. */ 75193323Sed /* swAttachKeyParam() is */ 76193323Sed /* not called. */ 77193323Sed#define SW_ERR_KEY_CMD_MISMATCH \ 78193323Sed (SW_ERR_BASE-14) /* Cannot perform requested */ 79193323Sed /* SW_COMMAND_CODE since */ 80193323Sed /* key attached via */ 81193323Sed /* swAttachKeyParam() */ 82193323Sed /* cannot be used for this */ 83193323Sed /* SW_COMMAND_CODE. */ 84193323Sed#define SW_ERR_NOT_IMPLEMENTED \ 85193323Sed (SW_ERR_BASE-15) /* Not implemented */ 86193323Sed#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16) /* Bad command code */ 87193323Sed#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17) /* too small or too large in */ 88193323Sed /* the "initems" or */ 89193323Sed /* "outitems". */ 90193323Sed#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18) /* Bad accelerator number */ 91193323Sed#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19) /* At least one of the self */ 92193323Sed /* test fail, look at the */ 93193323Sed /* selfTestBitmap in */ 94193323Sed /* SW_ACCELERATOR_INFO for */ 95193323Sed /* details. */ 96193323Sed#define SW_ERR_MISALIGN (SW_ERR_BASE-20) /* Certain alogrithms require */ 97193323Sed /* key materials aligned */ 98193323Sed /* in certain order, e.g. */ 99193323Sed /* 128 bit for CRT */ 100193323Sed#define SW_ERR_OUTPUT_NULL_PTR \ 101193323Sed (SW_ERR_BASE-21) /* a required pointer is */ 102193323Sed /* NULL */ 103193323Sed#define SW_ERR_OUTPUT_SIZE \ 104193323Sed (SW_ERR_BASE-22) /* size is invalid, too */ 105193323Sed /* small, too large. */ 106193323Sed#define SW_ERR_FIRMWARE_CHECKSUM \ 107193323Sed (SW_ERR_BASE-23) /* firmware checksum mismatch */ 108193323Sed /* download failed. */ 109193323Sed#define SW_ERR_UNKNOWN_FIRMWARE \ 110193323Sed (SW_ERR_BASE-24) /* unknown firmware error */ 111193323Sed#define SW_ERR_INTERRUPT (SW_ERR_BASE-25) /* request is abort when */ 112193323Sed /* it's waiting to be */ 113193323Sed /* completed. */ 114193323Sed#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26) /* error in writing to Non- */ 115193323Sed /* volatile memory */ 116193323Sed#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27) /* out of range error in */ 117193323Sed /* writing to NV memory */ 118193323Sed#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28) /* Random Number Generation */ 119193323Sed /* failure */ 120198090Srdivacky#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29) /* DSS Sign or Verify failure */ 121193323Sed#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30) /* Failure in various math */ 122198090Srdivacky /* calculations */ 123193323Sed#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31) /* Error in accessing on - */ 124193323Sed /* board memory */ 125198090Srdivacky#define SW_ERR_FIRMWARE_VERSION \ 126193323Sed (SW_ERR_BASE-32) /* Wrong version in firmware */ 127198090Srdivacky /* update */ 128193323Sed#define SW_ERR_ZERO_WORKING_ACCELERATOR \ 129193323Sed (SW_ERR_BASE-44) /* All accelerators are bad */ 130198090Srdivacky 131193323Sed /* algorithm type */ 132198090Srdivacky#define SW_ALG_CRT 1 133198892Srdivacky#define SW_ALG_EXP 2 134198090Srdivacky#define SW_ALG_DSA 3 135193323Sed#define SW_ALG_NVDATA 4 136195098Sed 137198090Srdivacky /* command code */ 138198892Srdivacky#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ 139195098Sed /* Chinese Remainder Theorem (CRT) */ 140195098Sed#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ 141198090Srdivacky#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ 142198892Srdivacky#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ 143195098Sed#define SW_CMD_RAND 5 /* perform random number generation */ 144195098Sed#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ 145198090Srdivacky#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ 146198892Srdivacky 147195098Sed typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ 148198090Srdivacky typedef SW_U32 SW_STATE; /* state */ 149198090Srdivacky typedef SW_U32 SW_COMMAND_CODE; /* command code */ 150198892Srdivacky typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ 151198090Srdivacky 152198090Srdivacky typedef struct _SW_LARGENUMBER { 153198090Srdivacky SW_U32 nbytes; /* number of bytes in the buffer "value" */ 154198892Srdivacky SW_BYTE *value; /* the large integer as a string of */ 155198090Srdivacky /* bytes in network (big endian) order */ 156195098Sed } SW_LARGENUMBER; 157198090Srdivacky 158198892Srdivacky#if defined(OPENSSL_SYS_WIN32) 159195098Sed# include <windows.h> 160198090Srdivacky typedef HANDLE SW_OSHANDLE; /* handle to kernel object */ 161198892Srdivacky# define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE 162198090Srdivacky# define SW_CALLCONV _stdcall 163198892Srdivacky#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) 164198090Srdivacky /* async callback mechanisms */ 165198090Srdivacky /* swiftCallbackLevel */ 166198892Srdivacky# define SW_MAC_CALLBACK_LEVEL_NO 0 167198090Srdivacky# define SW_MAC_CALLBACK_LEVEL_HARDWARE 1/* from the hardware ISR */ 168198090Srdivacky# define SW_MAC_CALLBACK_LEVEL_SECONDARY 2/* as secondary ISR */ 169198090Srdivacky typedef int SW_MAC_CALLBACK_LEVEL; 170198892Srdivacky typedef int SW_OSHANDLE; 171198892Srdivacky# define SW_OS_INVALID_HANDLE (-1) 172198090Srdivacky# define SW_CALLCONV 173193323Sed#else /* Unix variants */ 174193323Sed typedef int SW_OSHANDLE; /* handle to driver */ 175193323Sed# define SW_OS_INVALID_HANDLE (-1) 176193323Sed# define SW_CALLCONV 177198090Srdivacky#endif 178198892Srdivacky 179193323Sed typedef struct _SW_CRT { 180198892Srdivacky SW_LARGENUMBER p; /* prime number p */ 181193323Sed SW_LARGENUMBER q; /* prime number q */ 182193323Sed SW_LARGENUMBER dmp1; /* exponent1 */ 183198892Srdivacky SW_LARGENUMBER dmq1; /* exponent2 */ 184198892Srdivacky SW_LARGENUMBER iqmp; /* CRT coefficient */ 185198892Srdivacky } SW_CRT; 186198892Srdivacky 187198892Srdivacky typedef struct _SW_EXP { 188198892Srdivacky SW_LARGENUMBER modulus; /* modulus */ 189193323Sed SW_LARGENUMBER exponent; /* exponent */ 190198090Srdivacky } SW_EXP; 191198090Srdivacky 192198090Srdivacky typedef struct _SW_DSA { 193198892Srdivacky SW_LARGENUMBER p; /* */ 194193323Sed SW_LARGENUMBER q; /* */ 195193323Sed SW_LARGENUMBER g; /* */ 196198090Srdivacky SW_LARGENUMBER key; /* private/public key */ 197198090Srdivacky } SW_DSA; 198198090Srdivacky 199198090Srdivacky typedef struct _SW_NVDATA { 200198090Srdivacky SW_U32 accnum; /* accelerator board number */ 201198090Srdivacky SW_U32 offset; /* offset in byte */ 202198892Srdivacky } SW_NVDATA; 203198090Srdivacky 204198090Srdivacky typedef struct _SW_PARAM { 205198090Srdivacky SW_ALGTYPE type; /* type of the alogrithm */ 206198090Srdivacky union { 207198090Srdivacky SW_CRT crt; 208198892Srdivacky SW_EXP exp; 209198090Srdivacky SW_DSA dsa; 210198090Srdivacky SW_NVDATA nvdata; 211198090Srdivacky } up; 212198090Srdivacky } SW_PARAM; 213198090Srdivacky 214198892Srdivacky typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ 215198090Srdivacky 216198090Srdivacky /* 217198090Srdivacky * Now the OpenSSL bits, these function types are the for the function 218193323Sed * pointers that will bound into the Rainbow shared libraries. 219198090Srdivacky */ 220198892Srdivacky typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE 221198090Srdivacky *hac); 222198090Srdivacky typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, 223193323Sed SW_PARAM *key_params); 224193323Sed typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac, 225198090Srdivacky SW_COMMAND_CODE cmd, 226198090Srdivacky SW_LARGENUMBER pin[], 227198090Srdivacky SW_U32 pin_count, 228198090Srdivacky SW_LARGENUMBER pout[], 229198090Srdivacky SW_U32 pout_count); 230198090Srdivacky typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE 231198090Srdivacky hac); 232198090Srdivacky 233198892Srdivacky#ifdef __cplusplus 234198090Srdivacky} 235198090Srdivacky#endif /* __cplusplus */ 236198090Srdivacky