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