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