1109998Smarkm/* File : /crypto/engine/vendor_defns/hw_zencod.h */
2109998Smarkm/* ====================================================================
3109998Smarkm * Written by Donnat Frederic (frederic.donnat@zencod.com) from ZENCOD
4109998Smarkm * for "zencod" ENGINE integration in OpenSSL project.
5109998Smarkm */
6109998Smarkm
7296465Sdelphij#ifndef        _HW_ZENCOD_H_
8296465Sdelphij# define _HW_ZENCOD_H_
9109998Smarkm
10296465Sdelphij# include <stdio.h>
11109998Smarkm
12296465Sdelphij# ifdef  __cplusplus
13109998Smarkmextern "C" {
14296465Sdelphij# endif                         /* __cplusplus */
15109998Smarkm
16296465Sdelphij# define ZENBRIDGE_MAX_KEYSIZE_RSA       2048
17296465Sdelphij# define ZENBRIDGE_MAX_KEYSIZE_RSA_CRT   1024
18296465Sdelphij# define ZENBRIDGE_MAX_KEYSIZE_DSA_SIGN  1024
19296465Sdelphij# define ZENBRIDGE_MAX_KEYSIZE_DSA_VRFY  1024
20109998Smarkm
21109998Smarkm/* Library version computation */
22296465Sdelphij# define ZENBRIDGE_VERSION_MAJOR(x)      (((x) >> 16) | 0xff)
23296465Sdelphij# define ZENBRIDGE_VERSION_MINOR(x)      (((x) >>  8) | 0xff)
24296465Sdelphij# define ZENBRIDGE_VERSION_PATCH(x)      (((x) >>  0) | 0xff)
25296465Sdelphij# define ZENBRIDGE_VERSION(x, y, z)              ((x) << 16 | (y) << 8 | (z))
26109998Smarkm
27296465Sdelphij    /*
28296465Sdelphij     * Memory type
29296465Sdelphij     */
30296465Sdelphij    typedef struct zencod_number_s {
31296465Sdelphij        unsigned long len;
32296465Sdelphij        unsigned char *data;
33296465Sdelphij    } zen_nb_t;
34109998Smarkm
35296465Sdelphij# define KEY     zen_nb_t
36109998Smarkm
37296465Sdelphij    /*
38296465Sdelphij     * Misc
39296465Sdelphij     */
40296465Sdelphij    typedef int t_zencod_lib_version(void);
41296465Sdelphij    typedef int t_zencod_hw_version(void);
42296465Sdelphij    typedef int t_zencod_test(void);
43296465Sdelphij    typedef int t_zencod_dump_key(FILE *stream, char *msg, KEY * key);
44109998Smarkm
45296465Sdelphij    /*
46296465Sdelphij     * Key management tools
47296465Sdelphij     */
48296465Sdelphij    typedef KEY *t_zencod_new_number(unsigned long len, unsigned char *data);
49296465Sdelphij    typedef int t_zencod_init_number(KEY * n, unsigned long len,
50296465Sdelphij                                     unsigned char *data);
51296465Sdelphij    typedef unsigned long t_zencod_bytes2bits(unsigned char *n,
52296465Sdelphij                                              unsigned long bytes);
53296465Sdelphij    typedef unsigned long t_zencod_bits2bytes(unsigned long bits);
54109998Smarkm
55296465Sdelphij    /*
56296465Sdelphij     * RSA API
57296465Sdelphij     */
58109998Smarkm/* Compute modular exponential : y = x**e | n */
59296465Sdelphij    typedef int t_zencod_rsa_mod_exp(KEY * y, KEY * x, KEY * n, KEY * e);
60296465Sdelphij    /*
61296465Sdelphij     * Compute modular exponential : y1 = (x | p)**edp | p, y2 = (x | p)**edp
62296465Sdelphij     * | p, y = y2 + (qinv * (y1 - y2) | p) * q
63296465Sdelphij     */
64296465Sdelphij    typedef int t_zencod_rsa_mod_exp_crt(KEY * y, KEY * x, KEY * p, KEY * q,
65296465Sdelphij                                         KEY * edp, KEY * edq, KEY * qinv);
66109998Smarkm
67296465Sdelphij    /*
68296465Sdelphij     * DSA API
69296465Sdelphij     */
70296465Sdelphij    typedef int t_zencod_dsa_do_sign(unsigned int hash, KEY * data,
71296465Sdelphij                                     KEY * random, KEY * p, KEY * q, KEY * g,
72296465Sdelphij                                     KEY * x, KEY * r, KEY * s);
73296465Sdelphij    typedef int t_zencod_dsa_do_verify(unsigned int hash, KEY * data, KEY * p,
74296465Sdelphij                                       KEY * q, KEY * g, KEY * y, KEY * r,
75296465Sdelphij                                       KEY * s, KEY * v);
76109998Smarkm
77296465Sdelphij    /*
78296465Sdelphij     * DH API
79296465Sdelphij     */
80296465Sdelphij    /* Key generation : compute public value y = g**x | n */
81296465Sdelphij    typedef int t_zencod_dh_generate_key(KEY * y, KEY * x, KEY * g, KEY * n,
82296465Sdelphij                                         int gen_x);
83296465Sdelphij    typedef int t_zencod_dh_compute_key(KEY * k, KEY * y, KEY * x, KEY * n);
84109998Smarkm
85296465Sdelphij    /*
86296465Sdelphij     * RNG API
87296465Sdelphij     */
88296465Sdelphij# define ZENBRIDGE_RNG_DIRECT            0
89296465Sdelphij# define ZENBRIDGE_RNG_SHA1              1
90296465Sdelphij    typedef int t_zencod_rand_bytes(KEY * rand, unsigned int flags);
91109998Smarkm
92296465Sdelphij    /*
93296465Sdelphij     * Math API
94296465Sdelphij     */
95296465Sdelphij    typedef int t_zencod_math_mod_exp(KEY * r, KEY * a, KEY * e, KEY * n);
96109998Smarkm
97296465Sdelphij    /*
98296465Sdelphij     * Symetric API
99296465Sdelphij     */
100109998Smarkm/* Define a data structure for digests operations */
101296465Sdelphij    typedef struct ZEN_data_st {
102296465Sdelphij        unsigned int HashBufferSize;
103296465Sdelphij        unsigned char *HashBuffer;
104296465Sdelphij    } ZEN_MD_DATA;
105109998Smarkm
106296465Sdelphij    /*
107296465Sdelphij     * Functions for Digest (MD5, SHA1) stuff
108296465Sdelphij     */
109296465Sdelphij    /* output : output data buffer */
110296465Sdelphij    /* input : input data buffer */
111296465Sdelphij    /* algo : hash algorithm, MD5 or SHA1 */
112296465Sdelphij    /*-
113296465Sdelphij     * typedef int t_zencod_hash ( KEY *output, const KEY *input, int algo ) ;
114296465Sdelphij     * typedef int t_zencod_sha_hash ( KEY *output, const KEY *input, int algo ) ;
115296465Sdelphij     */
116296465Sdelphij    /* For now separate this stuff that mad it easier to test */
117296465Sdelphij    typedef int t_zencod_md5_init(ZEN_MD_DATA *data);
118296465Sdelphij    typedef int t_zencod_md5_update(ZEN_MD_DATA *data, const KEY * input);
119296465Sdelphij    typedef int t_zencod_md5_do_final(ZEN_MD_DATA *data, KEY * output);
120109998Smarkm
121296465Sdelphij    typedef int t_zencod_sha1_init(ZEN_MD_DATA *data);
122296465Sdelphij    typedef int t_zencod_sha1_update(ZEN_MD_DATA *data, const KEY * input);
123296465Sdelphij    typedef int t_zencod_sha1_do_final(ZEN_MD_DATA *data, KEY * output);
124109998Smarkm
125296465Sdelphij    /*
126296465Sdelphij     * Functions for Cipher (RC4, DES, 3DES) stuff
127296465Sdelphij     */
128109998Smarkm/* output : output data buffer */
129109998Smarkm/* input : input data buffer */
130109998Smarkm/* key : rc4 key data */
131109998Smarkm/* index_1 : value of index x from RC4 key structure */
132109998Smarkm/* index_2 : value of index y from RC4 key structure */
133296465Sdelphij    /*
134296465Sdelphij     * Be carefull : RC4 key should be expanded before calling this method
135296465Sdelphij     * (Should we provide an expand function ??)
136296465Sdelphij     */
137296465Sdelphij    typedef int t_zencod_rc4_cipher(KEY * output, const KEY * input,
138296465Sdelphij                                    const KEY * key, unsigned char *index_1,
139296465Sdelphij                                    unsigned char *index_2, int mode);
140109998Smarkm
141109998Smarkm/* output : output data buffer */
142109998Smarkm/* input : input data buffer */
143109998Smarkm/* key_1 : des first key data */
144109998Smarkm/* key_2 : des second key data */
145109998Smarkm/* key_3 : des third key data */
146109998Smarkm/* iv : initial vector */
147109998Smarkm/* mode : xdes mode (encrypt or decrypt) */
148109998Smarkm/* Be carefull : In DES mode key_1 = key_2 = key_3 (as far as i can see !!) */
149296465Sdelphij    typedef int t_zencod_xdes_cipher(KEY * output, const KEY * input,
150296465Sdelphij                                     const KEY * key_1, const KEY * key_2,
151296465Sdelphij                                     const KEY * key_3, const KEY * iv,
152296465Sdelphij                                     int mode);
153109998Smarkm
154296465Sdelphij# undef KEY
155109998Smarkm
156296465Sdelphij# ifdef  __cplusplus
157109998Smarkm}
158296465Sdelphij# endif                         /* __cplusplus */
159296465Sdelphij#endif                          /* !_HW_ZENCOD_H_ */
160