2 * Written by Corinne Dive-Reclus(cdive@baltimore.com)
4 * Copyright@2001 Baltimore Technologies Ltd.
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
20 #define SW_EXPORT __declspec ( dllexport )
26 * List of exposed SureWare errors
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
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.
40 * SureWare Initialisation function
41 * in param threadsafe, if !=0, thread safe enabled
42 * return SureWareHOOK_ERROR_UNIT_FAILURE if failure, 1 if success
44 typedef int SureWareHook_Init_t(char*const msg,int threadsafe);
45 extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init;
47 * SureWare Finish function
49 typedef void SureWareHook_Finish_t(void);
50 extern SW_EXPORT SureWareHook_Finish_t SureWareHook_Finish;
53 * DO NOT CALL ANY OF THE FOLLOWING FUNCTIONS IN CASE OF INIT FAILURE
56 * SureWare RAND Bytes function
57 * In case of failure, the content of buf is unpredictable.
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
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
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;
71 * SureWare RAND Seed function
72 * Adds some seed to the Hardware Random Number Generator
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
79 * in param buf : the seed to add into the HRNG
80 * in param num : the number of bytes into buf
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;
86 * SureWare Load Private Key function
88 * SureWareHOOK_ERROR_FAILED if error while processing
89 * No hardware is contact for this function.
91 * in param key_id :the name of the private protected key file without the extension
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
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;
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.
106 * in param key_id :the name of the private protected key file without the extension
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
112 typedef int SureWareHook_Info_Pubkey_t(char*const msg,const char *key_id,unsigned long *num,
114 extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey;
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.
122 * in param key_id :the name of the public protected key file without the extension
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
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;
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.
138 * in param key_id :the name of the public protected key file without the extension
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
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,
149 extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey;
152 * SureWare Free function
153 * Destroy the key into the hardware if destroy==1
155 typedef void SureWareHook_Free_t(char *p,int destroy);
156 extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free;
158 #define SUREWARE_PKCS1_PAD 1
159 #define SUREWARE_ISO9796_PAD 2
160 #define SUREWARE_NO_PAD 0
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
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
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;
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
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
196 * SUREWARE_ISO9796_PAD
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;
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
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
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;
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
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)
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,
237 extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp;