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