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