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*/ 44typedef int SureWareHook_Init_t(char *const msg, int threadsafe); 45extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init; 46/*- 47* SureWare Finish function 48*/ 49typedef void SureWareHook_Finish_t(void); 50extern 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*/ 67typedef int SureWareHook_Rand_Bytes_t(char *const msg, unsigned char *buf, 68 int num); 69extern SW_EXPORT SureWareHook_Rand_Bytes_t SureWareHook_Rand_Bytes; 70 71/*- 72* SureWare RAND Seed function 73* Adds some seed to the Hardware Random Number Generator 74* return 1 if success 75* SureWareHOOK_ERROR_FALLBACK if function not available in hardware 76* SureWareHOOK_ERROR_FAILED if error while processing 77* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure 78* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf 79* 80* in param buf : the seed to add into the HRNG 81* in param num : the number of bytes into buf 82*/ 83typedef int SureWareHook_Rand_Seed_t(char *const msg, const void *buf, 84 int num); 85extern SW_EXPORT SureWareHook_Rand_Seed_t SureWareHook_Rand_Seed; 86 87/*- 88* SureWare Load Private Key function 89* return 1 if success 90* SureWareHOOK_ERROR_FAILED if error while processing 91* No hardware is contact for this function. 92* 93* in param key_id :the name of the private protected key file without the extension 94 ".sws" 95* out param hptr : a pointer to a buffer allocated by SureWare_Hook 96* out param num: the effective key length in bytes 97* out param keytype: 1 if RSA 2 if DSA 98*/ 99typedef int SureWareHook_Load_Privkey_t(char *const msg, const char *key_id, 100 char **hptr, unsigned long *num, 101 char *keytype); 102extern SW_EXPORT SureWareHook_Load_Privkey_t SureWareHook_Load_Privkey; 103 104/*- 105* SureWare Info Public Key function 106* return 1 if success 107* SureWareHOOK_ERROR_FAILED if error while processing 108* No hardware is contact for this function. 109* 110* in param key_id :the name of the private protected key file without the extension 111 ".swp" 112* out param hptr : a pointer to a buffer allocated by SureWare_Hook 113* out param num: the effective key length in bytes 114* out param keytype: 1 if RSA 2 if DSA 115*/ 116typedef int SureWareHook_Info_Pubkey_t(char *const msg, const char *key_id, 117 unsigned long *num, char *keytype); 118extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey; 119 120/*- 121* SureWare Load Public Key function 122* return 1 if success 123* SureWareHOOK_ERROR_FAILED if error while processing 124* No hardware is contact for this function. 125* 126* in param key_id :the name of the public protected key file without the extension 127 ".swp" 128* in param num : the bytes size of n and e 129* out param n: where to write modulus in bn format 130* out param e: where to write exponent in bn format 131*/ 132typedef int SureWareHook_Load_Rsa_Pubkey_t(char *const msg, 133 const char *key_id, 134 unsigned long num, 135 unsigned long *n, 136 unsigned long *e); 137extern SW_EXPORT SureWareHook_Load_Rsa_Pubkey_t SureWareHook_Load_Rsa_Pubkey; 138 139/*- 140* SureWare Load DSA Public Key function 141* return 1 if success 142* SureWareHOOK_ERROR_FAILED if error while processing 143* No hardware is contact for this function. 144* 145* in param key_id :the name of the public protected key file without the extension 146 ".swp" 147* in param num : the bytes size of n and e 148* out param pub: where to write pub key in bn format 149* out param p: where to write prime in bn format 150* out param q: where to write sunprime (length 20 bytes) in bn format 151* out param g: where to write base in bn format 152*/ 153typedef int SureWareHook_Load_Dsa_Pubkey_t(char *const msg, 154 const char *key_id, 155 unsigned long num, 156 unsigned long *pub, 157 unsigned long *p, unsigned long *q, 158 unsigned long *g); 159extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey; 160 161/*- 162* SureWare Free function 163* Destroy the key into the hardware if destroy==1 164*/ 165typedef void SureWareHook_Free_t(char *p, int destroy); 166extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free; 167 168#define SUREWARE_PKCS1_PAD 1 169#define SUREWARE_ISO9796_PAD 2 170#define SUREWARE_NO_PAD 0 171/*- 172* SureWare RSA Private Decryption 173* return 1 if success 174* SureWareHOOK_ERROR_FAILED if error while processing 175* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure 176* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf 177* 178* in param flen : byte size of from and to 179* in param from : encrypted data buffer, should be a not-null valid pointer 180* out param tlen: byte size of decrypted data, if error, unexpected value 181* out param to : decrypted data buffer, should be a not-null valid pointer 182* in param prsa: a protected key pointer, should be a not-null valid pointer 183* int padding: padding id as follow 184* SUREWARE_PKCS1_PAD 185* SUREWARE_NO_PAD 186* 187*/ 188typedef int SureWareHook_Rsa_Priv_Dec_t(char *const msg, int flen, 189 unsigned char *from, int *tlen, 190 unsigned char *to, char *prsa, 191 int padding); 192extern SW_EXPORT SureWareHook_Rsa_Priv_Dec_t SureWareHook_Rsa_Priv_Dec; 193/*- 194* SureWare RSA Signature 195* return 1 if success 196* SureWareHOOK_ERROR_FAILED if error while processing 197* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure 198* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf 199* 200* in param flen : byte size of from and to 201* in param from : encrypted data buffer, should be a not-null valid pointer 202* out param tlen: byte size of decrypted data, if error, unexpected value 203* out param to : decrypted data buffer, should be a not-null valid pointer 204* in param prsa: a protected key pointer, should be a not-null valid pointer 205* int padding: padding id as follow 206* SUREWARE_PKCS1_PAD 207* SUREWARE_ISO9796_PAD 208* 209*/ 210typedef int SureWareHook_Rsa_Sign_t(char *const msg, int flen, 211 unsigned char *from, int *tlen, 212 unsigned char *to, char *prsa, 213 int padding); 214extern SW_EXPORT SureWareHook_Rsa_Sign_t SureWareHook_Rsa_Sign; 215/*- 216* SureWare DSA Signature 217* return 1 if success 218* SureWareHOOK_ERROR_FAILED if error while processing 219* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure 220* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf 221* 222* in param flen : byte size of from and to 223* in param from : encrypted data buffer, should be a not-null valid pointer 224* out param to : decrypted data buffer, should be a 40bytes valid pointer 225* in param pdsa: a protected key pointer, should be a not-null valid pointer 226* 227*/ 228typedef int SureWareHook_Dsa_Sign_t(char *const msg, int flen, 229 const unsigned char *from, 230 unsigned long *r, unsigned long *s, 231 char *pdsa); 232extern SW_EXPORT SureWareHook_Dsa_Sign_t SureWareHook_Dsa_Sign; 233 234/*- 235* SureWare Mod Exp 236* return 1 if success 237* SureWareHOOK_ERROR_FAILED if error while processing 238* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure 239* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf 240* 241* mod and res are mlen bytes long. 242* exp is elen bytes long 243* data is dlen bytes long 244* mlen,elen and dlen are all multiple of sizeof(unsigned long) 245*/ 246typedef int SureWareHook_Mod_Exp_t(char *const msg, int mlen, 247 const unsigned long *mod, int elen, 248 const unsigned long *exponent, int dlen, 249 unsigned long *data, unsigned long *res); 250extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp; 251