mark all block comments that need format preserving so that
[openssl.git] / engines / vendor_defns / sureware.h
1 /*-
2  * Written by Corinne Dive-Reclus(cdive@baltimore.com)
3  *
4  * Copyright@2001 Baltimore Technologies Ltd.
5  *
6  * THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND
7  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9  * ARE DISCLAIMED.  IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE
10  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16  * SUCH DAMAGE.
17  */
18
19 #ifdef WIN32
20 #define SW_EXPORT       __declspec ( dllexport )
21 #else
22 #define SW_EXPORT
23 #endif
24
25 /*
26 *       List of exposed SureWare errors
27 */
28 #define SUREWAREHOOK_ERROR_FAILED               -1
29 #define SUREWAREHOOK_ERROR_FALLBACK             -2
30 #define SUREWAREHOOK_ERROR_UNIT_FAILURE -3
31 #define SUREWAREHOOK_ERROR_DATA_SIZE -4
32 #define SUREWAREHOOK_ERROR_INVALID_PAD -5
33 /*-
34 * -----------------WARNING-----------------------------------
35 * In all the following functions:
36 * msg is a string with at least 24 bytes free.
37 * A 24 bytes string will be concatenated to the existing content of msg. 
38 */
39 /*-
40 *       SureWare Initialisation function
41 *       in param threadsafe, if !=0, thread safe enabled
42 *       return SureWareHOOK_ERROR_UNIT_FAILURE if failure, 1 if success
43 */
44 typedef int SureWareHook_Init_t(char*const msg,int threadsafe);
45 extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init;
46 /*-
47 *       SureWare Finish function
48 */
49 typedef void SureWareHook_Finish_t(void);
50 extern SW_EXPORT SureWareHook_Finish_t SureWareHook_Finish;
51 /*-
52 *        PRE_CONDITION:
53 *               DO NOT CALL ANY OF THE FOLLOWING FUNCTIONS IN CASE OF INIT FAILURE
54 */
55 /*-
56 *       SureWare RAND Bytes function
57 *       In case of failure, the content of buf is unpredictable.
58 *       return 1 if success
59 *                       SureWareHOOK_ERROR_FALLBACK if function not available in hardware
60 *                       SureWareHOOK_ERROR_FAILED if error while processing
61 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
62 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
63 *
64 *       in/out param buf : a num bytes long buffer where random bytes will be put
65 *       in param num : the number of bytes into buf
66 */
67 typedef int SureWareHook_Rand_Bytes_t(char*const msg,unsigned char *buf, int num);
68 extern SW_EXPORT SureWareHook_Rand_Bytes_t SureWareHook_Rand_Bytes;
69
70 /*-
71 *       SureWare RAND Seed function
72 *       Adds some seed to the Hardware Random Number Generator
73 *       return 1 if success
74 *                       SureWareHOOK_ERROR_FALLBACK if function not available in hardware
75 *                       SureWareHOOK_ERROR_FAILED if error while processing
76 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
77 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
78 *
79 *       in param buf : the seed to add into the HRNG
80 *       in param num : the number of bytes into buf
81 */
82 typedef int SureWareHook_Rand_Seed_t(char*const msg,const void *buf, int num);
83 extern SW_EXPORT SureWareHook_Rand_Seed_t SureWareHook_Rand_Seed;
84
85 /*-
86 *       SureWare Load Private Key function
87 *       return 1 if success
88 *                       SureWareHOOK_ERROR_FAILED if error while processing
89 *       No hardware is contact for this function.
90 *
91 *       in param key_id :the name of the private protected key file without the extension
92                                                 ".sws"
93 *       out param hptr : a pointer to a buffer allocated by SureWare_Hook
94 *       out param num: the effective key length in bytes
95 *       out param keytype: 1 if RSA 2 if DSA
96 */
97 typedef int SureWareHook_Load_Privkey_t(char*const msg,const char *key_id,char **hptr,unsigned long *num,char *keytype);
98 extern SW_EXPORT SureWareHook_Load_Privkey_t SureWareHook_Load_Privkey;
99
100 /*-
101 *       SureWare Info Public Key function
102 *       return 1 if success
103 *                       SureWareHOOK_ERROR_FAILED if error while processing
104 *       No hardware is contact for this function.
105 *
106 *       in param key_id :the name of the private protected key file without the extension
107                                                 ".swp"
108 *       out param hptr : a pointer to a buffer allocated by SureWare_Hook
109 *       out param num: the effective key length in bytes
110 *       out param keytype: 1 if RSA 2 if DSA
111 */
112 typedef int SureWareHook_Info_Pubkey_t(char*const msg,const char *key_id,unsigned long *num,
113                                                                                 char *keytype);
114 extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey;
115
116 /*-
117 *       SureWare Load Public Key function
118 *       return 1 if success
119 *                       SureWareHOOK_ERROR_FAILED if error while processing
120 *       No hardware is contact for this function.
121 *
122 *       in param key_id :the name of the public protected key file without the extension
123                                                 ".swp"
124 *       in param num : the bytes size of n and e
125 *       out param n: where to write modulus in bn format
126 *       out param e: where to write exponent in bn format
127 */
128 typedef int SureWareHook_Load_Rsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num,
129                                                                                 unsigned long *n, unsigned long *e);
130 extern SW_EXPORT SureWareHook_Load_Rsa_Pubkey_t SureWareHook_Load_Rsa_Pubkey;
131
132 /*-
133 *       SureWare Load DSA Public Key function
134 *       return 1 if success
135 *                       SureWareHOOK_ERROR_FAILED if error while processing
136 *       No hardware is contact for this function.
137 *
138 *       in param key_id :the name of the public protected key file without the extension
139                                                 ".swp"
140 *       in param num : the bytes size of n and e
141 *       out param pub: where to write pub key in bn format
142 *       out param p: where to write prime in bn format
143 *       out param q: where to write sunprime (length 20 bytes) in bn format
144 *       out param g: where to write base in bn format
145 */
146 typedef int SureWareHook_Load_Dsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num,
147                                                                                 unsigned long *pub, unsigned long *p,unsigned long*q,
148                                                                                 unsigned long *g);
149 extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey;
150
151 /*-
152 *       SureWare Free function
153 *       Destroy the key into the hardware if destroy==1
154 */
155 typedef void SureWareHook_Free_t(char *p,int destroy);
156 extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free;
157
158 #define SUREWARE_PKCS1_PAD 1
159 #define SUREWARE_ISO9796_PAD 2
160 #define SUREWARE_NO_PAD 0
161 /*-
162 * SureWare RSA Private Decryption
163 * return 1 if success
164 *                       SureWareHOOK_ERROR_FAILED if error while processing
165 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
166 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
167 *
168 *       in param flen : byte size of from and to
169 *       in param from : encrypted data buffer, should be a not-null valid pointer
170 *       out param tlen: byte size of decrypted data, if error, unexpected value
171 *       out param to : decrypted data buffer, should be a not-null valid pointer
172 *   in param prsa: a protected key pointer, should be a not-null valid pointer
173 *   int padding: padding id as follow
174 *                                       SUREWARE_PKCS1_PAD
175 *                                       SUREWARE_NO_PAD
176 *
177 */
178 typedef int SureWareHook_Rsa_Priv_Dec_t(char*const msg,int flen,unsigned char *from,
179                                                                                 int *tlen,unsigned char *to,
180                                                                                 char *prsa,int padding);
181 extern SW_EXPORT SureWareHook_Rsa_Priv_Dec_t SureWareHook_Rsa_Priv_Dec;
182 /*-
183 * SureWare RSA Signature
184 * return 1 if success
185 *                       SureWareHOOK_ERROR_FAILED if error while processing
186 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
187 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
188 *
189 *       in param flen : byte size of from and to
190 *       in param from : encrypted data buffer, should be a not-null valid pointer
191 *       out param tlen: byte size of decrypted data, if error, unexpected value
192 *       out param to : decrypted data buffer, should be a not-null valid pointer
193 *   in param prsa: a protected key pointer, should be a not-null valid pointer
194 *   int padding: padding id as follow
195 *                                       SUREWARE_PKCS1_PAD
196 *                                       SUREWARE_ISO9796_PAD
197 *
198 */
199 typedef int SureWareHook_Rsa_Sign_t(char*const msg,int flen,unsigned char *from,
200                                                                                 int *tlen,unsigned char *to,
201                                                                                 char *prsa,int padding);
202 extern SW_EXPORT SureWareHook_Rsa_Sign_t SureWareHook_Rsa_Sign;
203 /*-
204 * SureWare DSA Signature
205 * return 1 if success
206 *                       SureWareHOOK_ERROR_FAILED if error while processing
207 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
208 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
209 *
210 *       in param flen : byte size of from and to
211 *       in param from : encrypted data buffer, should be a not-null valid pointer
212 *       out param to : decrypted data buffer, should be a 40bytes valid pointer
213 *   in param pdsa: a protected key pointer, should be a not-null valid pointer
214 *
215 */
216 typedef int SureWareHook_Dsa_Sign_t(char*const msg,int flen,const unsigned char *from,
217                                                                                 unsigned long *r,unsigned long *s,char *pdsa);
218 extern SW_EXPORT SureWareHook_Dsa_Sign_t SureWareHook_Dsa_Sign;
219
220
221 /*-
222 * SureWare Mod Exp
223 * return 1 if success
224 *                       SureWareHOOK_ERROR_FAILED if error while processing
225 *                       SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
226 *                       SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
227 *
228 *       mod and res are mlen bytes long.
229 *       exp is elen bytes long
230 *       data is dlen bytes long
231 *       mlen,elen and dlen are all multiple of sizeof(unsigned long)
232 */
233 typedef int SureWareHook_Mod_Exp_t(char*const msg,int mlen,const unsigned long *mod,
234                                                                         int elen,const unsigned long *exponent,
235                                                                         int dlen,unsigned long *data,
236                                                                         unsigned long *res);
237 extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp;
238