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