1ebfedea0SLionel Sambuc /* File : /crypto/engine/vendor_defns/hw_zencod.h */ 2ebfedea0SLionel Sambuc /* ==================================================================== 3ebfedea0SLionel Sambuc * Written by Donnat Frederic (frederic.donnat@zencod.com) from ZENCOD 4ebfedea0SLionel Sambuc * for "zencod" ENGINE integration in OpenSSL project. 5ebfedea0SLionel Sambuc */ 6ebfedea0SLionel Sambuc 7ebfedea0SLionel Sambuc #ifndef _HW_ZENCOD_H_ 8ebfedea0SLionel Sambuc # define _HW_ZENCOD_H_ 9ebfedea0SLionel Sambuc 10ebfedea0SLionel Sambuc # include <stdio.h> 11ebfedea0SLionel Sambuc 12ebfedea0SLionel Sambuc # ifdef __cplusplus 13ebfedea0SLionel Sambuc extern "C" { 14ebfedea0SLionel Sambuc # endif /* __cplusplus */ 15ebfedea0SLionel Sambuc 16ebfedea0SLionel Sambuc # define ZENBRIDGE_MAX_KEYSIZE_RSA 2048 17ebfedea0SLionel Sambuc # define ZENBRIDGE_MAX_KEYSIZE_RSA_CRT 1024 18ebfedea0SLionel Sambuc # define ZENBRIDGE_MAX_KEYSIZE_DSA_SIGN 1024 19ebfedea0SLionel Sambuc # define ZENBRIDGE_MAX_KEYSIZE_DSA_VRFY 1024 20ebfedea0SLionel Sambuc 21ebfedea0SLionel Sambuc /* Library version computation */ 22ebfedea0SLionel Sambuc # define ZENBRIDGE_VERSION_MAJOR(x) (((x) >> 16) | 0xff) 23ebfedea0SLionel Sambuc # define ZENBRIDGE_VERSION_MINOR(x) (((x) >> 8) | 0xff) 24ebfedea0SLionel Sambuc # define ZENBRIDGE_VERSION_PATCH(x) (((x) >> 0) | 0xff) 25ebfedea0SLionel Sambuc # define ZENBRIDGE_VERSION(x, y, z) ((x) << 16 | (y) << 8 | (z)) 26ebfedea0SLionel Sambuc 27ebfedea0SLionel Sambuc /* 28ebfedea0SLionel Sambuc * Memory type 29ebfedea0SLionel Sambuc */ 30ebfedea0SLionel Sambuc typedef struct zencod_number_s { 31ebfedea0SLionel Sambuc unsigned long len; 32ebfedea0SLionel Sambuc unsigned char *data; 33ebfedea0SLionel Sambuc } zen_nb_t; 34ebfedea0SLionel Sambuc 35ebfedea0SLionel Sambuc # define KEY zen_nb_t 36ebfedea0SLionel Sambuc 37ebfedea0SLionel Sambuc /* 38ebfedea0SLionel Sambuc * Misc 39ebfedea0SLionel Sambuc */ 40ebfedea0SLionel Sambuc typedef int t_zencod_lib_version(void); 41ebfedea0SLionel Sambuc typedef int t_zencod_hw_version(void); 42ebfedea0SLionel Sambuc typedef int t_zencod_test(void); 43ebfedea0SLionel Sambuc typedef int t_zencod_dump_key(FILE *stream, char *msg, KEY * key); 44ebfedea0SLionel Sambuc 45ebfedea0SLionel Sambuc /* 46ebfedea0SLionel Sambuc * Key management tools 47ebfedea0SLionel Sambuc */ 48ebfedea0SLionel Sambuc typedef KEY *t_zencod_new_number(unsigned long len, unsigned char *data); 49*0a6a1f1dSLionel Sambuc typedef int t_zencod_init_number(KEY * n, unsigned long len, 50*0a6a1f1dSLionel Sambuc unsigned char *data); 51*0a6a1f1dSLionel Sambuc typedef unsigned long t_zencod_bytes2bits(unsigned char *n, 52*0a6a1f1dSLionel Sambuc unsigned long bytes); 53ebfedea0SLionel Sambuc typedef unsigned long t_zencod_bits2bytes(unsigned long bits); 54ebfedea0SLionel Sambuc 55ebfedea0SLionel Sambuc /* 56ebfedea0SLionel Sambuc * RSA API 57ebfedea0SLionel Sambuc */ 58ebfedea0SLionel Sambuc /* Compute modular exponential : y = x**e | n */ 59ebfedea0SLionel Sambuc typedef int t_zencod_rsa_mod_exp(KEY * y, KEY * x, KEY * n, KEY * e); 60*0a6a1f1dSLionel Sambuc /* 61*0a6a1f1dSLionel Sambuc * Compute modular exponential : y1 = (x | p)**edp | p, y2 = (x | p)**edp 62*0a6a1f1dSLionel Sambuc * | p, y = y2 + (qinv * (y1 - y2) | p) * q 63*0a6a1f1dSLionel Sambuc */ 64ebfedea0SLionel Sambuc typedef int t_zencod_rsa_mod_exp_crt(KEY * y, KEY * x, KEY * p, KEY * q, 65ebfedea0SLionel Sambuc KEY * edp, KEY * edq, KEY * qinv); 66ebfedea0SLionel Sambuc 67ebfedea0SLionel Sambuc /* 68ebfedea0SLionel Sambuc * DSA API 69ebfedea0SLionel Sambuc */ 70*0a6a1f1dSLionel Sambuc typedef int t_zencod_dsa_do_sign(unsigned int hash, KEY * data, 71*0a6a1f1dSLionel Sambuc KEY * random, KEY * p, KEY * q, KEY * g, 72*0a6a1f1dSLionel Sambuc KEY * x, KEY * r, KEY * s); 73*0a6a1f1dSLionel Sambuc typedef int t_zencod_dsa_do_verify(unsigned int hash, KEY * data, KEY * p, 74*0a6a1f1dSLionel Sambuc KEY * q, KEY * g, KEY * y, KEY * r, 75*0a6a1f1dSLionel Sambuc KEY * s, KEY * v); 76ebfedea0SLionel Sambuc 77ebfedea0SLionel Sambuc /* 78ebfedea0SLionel Sambuc * DH API 79ebfedea0SLionel Sambuc */ 80ebfedea0SLionel Sambuc /* Key generation : compute public value y = g**x | n */ 81*0a6a1f1dSLionel Sambuc typedef int t_zencod_dh_generate_key(KEY * y, KEY * x, KEY * g, KEY * n, 82*0a6a1f1dSLionel Sambuc int gen_x); 83ebfedea0SLionel Sambuc typedef int t_zencod_dh_compute_key(KEY * k, KEY * y, KEY * x, KEY * n); 84ebfedea0SLionel Sambuc 85ebfedea0SLionel Sambuc /* 86ebfedea0SLionel Sambuc * RNG API 87ebfedea0SLionel Sambuc */ 88ebfedea0SLionel Sambuc # define ZENBRIDGE_RNG_DIRECT 0 89ebfedea0SLionel Sambuc # define ZENBRIDGE_RNG_SHA1 1 90ebfedea0SLionel Sambuc typedef int t_zencod_rand_bytes(KEY * rand, unsigned int flags); 91ebfedea0SLionel Sambuc 92ebfedea0SLionel Sambuc /* 93ebfedea0SLionel Sambuc * Math API 94ebfedea0SLionel Sambuc */ 95ebfedea0SLionel Sambuc typedef int t_zencod_math_mod_exp(KEY * r, KEY * a, KEY * e, KEY * n); 96ebfedea0SLionel Sambuc 97ebfedea0SLionel Sambuc /* 98ebfedea0SLionel Sambuc * Symetric API 99ebfedea0SLionel Sambuc */ 100ebfedea0SLionel Sambuc /* Define a data structure for digests operations */ 101*0a6a1f1dSLionel Sambuc typedef struct ZEN_data_st { 102ebfedea0SLionel Sambuc unsigned int HashBufferSize; 103ebfedea0SLionel Sambuc unsigned char *HashBuffer; 104ebfedea0SLionel Sambuc } ZEN_MD_DATA; 105ebfedea0SLionel Sambuc 106ebfedea0SLionel Sambuc /* 107ebfedea0SLionel Sambuc * Functions for Digest (MD5, SHA1) stuff 108ebfedea0SLionel Sambuc */ 109ebfedea0SLionel Sambuc /* output : output data buffer */ 110ebfedea0SLionel Sambuc /* input : input data buffer */ 111ebfedea0SLionel Sambuc /* algo : hash algorithm, MD5 or SHA1 */ 112*0a6a1f1dSLionel Sambuc /*- 113*0a6a1f1dSLionel Sambuc * typedef int t_zencod_hash ( KEY *output, const KEY *input, int algo ) ; 114ebfedea0SLionel Sambuc * typedef int t_zencod_sha_hash ( KEY *output, const KEY *input, int algo ) ; 115ebfedea0SLionel Sambuc */ 116ebfedea0SLionel Sambuc /* For now separate this stuff that mad it easier to test */ 117ebfedea0SLionel Sambuc typedef int t_zencod_md5_init(ZEN_MD_DATA *data); 118ebfedea0SLionel Sambuc typedef int t_zencod_md5_update(ZEN_MD_DATA *data, const KEY * input); 119ebfedea0SLionel Sambuc typedef int t_zencod_md5_do_final(ZEN_MD_DATA *data, KEY * output); 120ebfedea0SLionel Sambuc 121ebfedea0SLionel Sambuc typedef int t_zencod_sha1_init(ZEN_MD_DATA *data); 122ebfedea0SLionel Sambuc typedef int t_zencod_sha1_update(ZEN_MD_DATA *data, const KEY * input); 123ebfedea0SLionel Sambuc typedef int t_zencod_sha1_do_final(ZEN_MD_DATA *data, KEY * output); 124ebfedea0SLionel Sambuc 125ebfedea0SLionel Sambuc /* 126ebfedea0SLionel Sambuc * Functions for Cipher (RC4, DES, 3DES) stuff 127ebfedea0SLionel Sambuc */ 128ebfedea0SLionel Sambuc /* output : output data buffer */ 129ebfedea0SLionel Sambuc /* input : input data buffer */ 130ebfedea0SLionel Sambuc /* key : rc4 key data */ 131ebfedea0SLionel Sambuc /* index_1 : value of index x from RC4 key structure */ 132ebfedea0SLionel Sambuc /* index_2 : value of index y from RC4 key structure */ 133*0a6a1f1dSLionel Sambuc /* 134*0a6a1f1dSLionel Sambuc * Be carefull : RC4 key should be expanded before calling this method 135*0a6a1f1dSLionel Sambuc * (Should we provide an expand function ??) 136*0a6a1f1dSLionel Sambuc */ 137*0a6a1f1dSLionel Sambuc typedef int t_zencod_rc4_cipher(KEY * output, const KEY * input, 138*0a6a1f1dSLionel Sambuc const KEY * key, unsigned char *index_1, 139*0a6a1f1dSLionel Sambuc unsigned char *index_2, int mode); 140ebfedea0SLionel Sambuc 141ebfedea0SLionel Sambuc /* output : output data buffer */ 142ebfedea0SLionel Sambuc /* input : input data buffer */ 143ebfedea0SLionel Sambuc /* key_1 : des first key data */ 144ebfedea0SLionel Sambuc /* key_2 : des second key data */ 145ebfedea0SLionel Sambuc /* key_3 : des third key data */ 146ebfedea0SLionel Sambuc /* iv : initial vector */ 147ebfedea0SLionel Sambuc /* mode : xdes mode (encrypt or decrypt) */ 148ebfedea0SLionel Sambuc /* Be carefull : In DES mode key_1 = key_2 = key_3 (as far as i can see !!) */ 149*0a6a1f1dSLionel Sambuc typedef int t_zencod_xdes_cipher(KEY * output, const KEY * input, 150*0a6a1f1dSLionel Sambuc const KEY * key_1, const KEY * key_2, 151*0a6a1f1dSLionel Sambuc const KEY * key_3, const KEY * iv, 152*0a6a1f1dSLionel Sambuc int mode); 153ebfedea0SLionel Sambuc 154ebfedea0SLionel Sambuc # undef KEY 155ebfedea0SLionel Sambuc 156ebfedea0SLionel Sambuc # ifdef __cplusplus 157ebfedea0SLionel Sambuc } 158ebfedea0SLionel Sambuc # endif /* __cplusplus */ 159ebfedea0SLionel Sambuc #endif /* !_HW_ZENCOD_H_ */ 160