~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/heimdal/lib/hcrypto/evp.h

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005 - 2008 Kungliga Tekniska Högskolan
 
3
 * (Royal Institute of Technology, Stockholm, Sweden).
 
4
 * All rights reserved.
 
5
 *
 
6
 * Redistribution and use in source and binary forms, with or without
 
7
 * modification, are permitted provided that the following conditions
 
8
 * are met:
 
9
 *
 
10
 * 1. Redistributions of source code must retain the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer.
 
12
 *
 
13
 * 2. Redistributions in binary form must reproduce the above copyright
 
14
 *    notice, this list of conditions and the following disclaimer in the
 
15
 *    documentation and/or other materials provided with the distribution.
 
16
 *
 
17
 * 3. Neither the name of the Institute nor the names of its contributors
 
18
 *    may be used to endorse or promote products derived from this software
 
19
 *    without specific prior written permission.
 
20
 *
 
21
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 
22
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
24
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 
25
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
26
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
27
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
28
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
29
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
30
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
31
 * SUCH DAMAGE.
 
32
 */
 
33
 
 
34
/* $Id$ */
 
35
 
 
36
#ifndef HEIM_EVP_H
 
37
#define HEIM_EVP_H 1
 
38
 
 
39
#include <hcrypto/engine.h>
 
40
 
 
41
/* symbol renaming */
 
42
#define EVP_CIPHER_CTX_block_size hc_EVP_CIPHER_CTX_block_size
 
43
#define EVP_CIPHER_CTX_cipher hc_EVP_CIPHER_CTX_cipher
 
44
#define EVP_CIPHER_CTX_cleanup hc_EVP_CIPHER_CTX_cleanup
 
45
#define EVP_CIPHER_CTX_flags hc_EVP_CIPHER_CTX_flags
 
46
#define EVP_CIPHER_CTX_get_app_data hc_EVP_CIPHER_CTX_get_app_data
 
47
#define EVP_CIPHER_CTX_init hc_EVP_CIPHER_CTX_init
 
48
#define EVP_CIPHER_CTX_iv_length hc_EVP_CIPHER_CTX_iv_length
 
49
#define EVP_CIPHER_CTX_key_length hc_EVP_CIPHER_CTX_key_length
 
50
#define EVP_CIPHER_CTX_mode hc_EVP_CIPHER_CTX_mode
 
51
#define EVP_CIPHER_CTX_set_app_data hc_EVP_CIPHER_CTX_set_app_data
 
52
#define EVP_CIPHER_CTX_set_key_length hc_EVP_CIPHER_CTX_set_key_length
 
53
#define EVP_CIPHER_CTX_set_padding hc_EVP_CIPHER_CTX_set_padding
 
54
#define EVP_CIPHER_block_size hc_EVP_CIPHER_block_size
 
55
#define EVP_CIPHER_iv_length hc_EVP_CIPHER_iv_length
 
56
#define EVP_CIPHER_key_length hc_EVP_CIPHER_key_length
 
57
#define EVP_Cipher hc_EVP_Cipher
 
58
#define EVP_CipherInit_ex hc_EVP_CipherInit_ex
 
59
#define EVP_CipherUpdate hc_EVP_CipherUpdate
 
60
#define EVP_CipherFinal_ex hc_EVP_CipherFinal_ex
 
61
#define EVP_Digest hc_EVP_Digest
 
62
#define EVP_DigestFinal_ex hc_EVP_DigestFinal_ex
 
63
#define EVP_DigestInit_ex hc_EVP_DigestInit_ex
 
64
#define EVP_DigestUpdate hc_EVP_DigestUpdate
 
65
#define EVP_MD_CTX_block_size hc_EVP_MD_CTX_block_size
 
66
#define EVP_MD_CTX_cleanup hc_EVP_MD_CTX_cleanup
 
67
#define EVP_MD_CTX_create hc_EVP_MD_CTX_create
 
68
#define EVP_MD_CTX_init hc_EVP_MD_CTX_init
 
69
#define EVP_MD_CTX_destroy hc_EVP_MD_CTX_destroy
 
70
#define EVP_MD_CTX_md hc_EVP_MD_CTX_md
 
71
#define EVP_MD_CTX_size hc_EVP_MD_CTX_size
 
72
#define EVP_MD_block_size hc_EVP_MD_block_size
 
73
#define EVP_MD_size hc_EVP_MD_size
 
74
#define EVP_aes_128_cbc hc_EVP_aes_128_cbc
 
75
#define EVP_aes_192_cbc hc_EVP_aes_192_cbc
 
76
#define EVP_aes_256_cbc hc_EVP_aes_256_cbc
 
77
#define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc
 
78
#define EVP_hcrypto_aes_192_cbc hc_EVP_hcrypto_aes_192_cbc
 
79
#define EVP_hcrypto_aes_256_cbc hc_EVP_hcrypto_aes_256_cbc
 
80
#define EVP_hcrypto_aes_128_cts hc_EVP_hcrypto_aes_128_cts
 
81
#define EVP_hcrypto_aes_192_cts hc_EVP_hcrypto_aes_192_cts
 
82
#define EVP_hcrypto_aes_256_cts hc_EVP_hcrypto_aes_256_cts
 
83
#define EVP_des_cbc hc_EVP_des_cbc
 
84
#define EVP_des_ede3_cbc hc_EVP_des_ede3_cbc
 
85
#define EVP_enc_null hc_EVP_enc_null
 
86
#define EVP_md2 hc_EVP_md2
 
87
#define EVP_md4 hc_EVP_md4
 
88
#define EVP_md5 hc_EVP_md5
 
89
#define EVP_md_null hc_EVP_md_null
 
90
#define EVP_rc2_40_cbc hc_EVP_rc2_40_cbc
 
91
#define EVP_rc2_64_cbc hc_EVP_rc2_64_cbc
 
92
#define EVP_rc2_cbc hc_EVP_rc2_cbc
 
93
#define EVP_rc4 hc_EVP_rc4
 
94
#define EVP_rc4_40 hc_EVP_rc4_40
 
95
#define EVP_camellia_128_cbc hc_EVP_camellia_128_cbc
 
96
#define EVP_camellia_192_cbc hc_EVP_camellia_192_cbc
 
97
#define EVP_camellia_256_cbc hc_EVP_camellia_256_cbc
 
98
#define EVP_sha hc_EVP_sha
 
99
#define EVP_sha1 hc_EVP_sha1
 
100
#define EVP_sha256 hc_EVP_sha256
 
101
#define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1
 
102
#define EVP_BytesToKey hc_EVP_BytesToKey
 
103
#define EVP_get_cipherbyname hc_EVP_get_cipherbyname
 
104
#define OpenSSL_add_all_algorithms hc_OpenSSL_add_all_algorithms
 
105
#define OpenSSL_add_all_algorithms_conf hc_OpenSSL_add_all_algorithms_conf
 
106
#define OpenSSL_add_all_algorithms_noconf hc_OpenSSL_add_all_algorithms_noconf
 
107
#define EVP_CIPHER_CTX_ctrl hc_EVP_CIPHER_CTX_ctrl
 
108
#define EVP_CIPHER_CTX_rand_key hc_EVP_CIPHER_CTX_rand_key
 
109
 
 
110
/*
 
111
 *
 
112
 */
 
113
 
 
114
typedef struct hc_EVP_MD_CTX EVP_MD_CTX;
 
115
typedef struct hc_evp_pkey EVP_PKEY;
 
116
typedef struct hc_evp_md EVP_MD;
 
117
typedef struct hc_CIPHER EVP_CIPHER;
 
118
typedef struct hc_CIPHER_CTX EVP_CIPHER_CTX;
 
119
 
 
120
#define EVP_MAX_IV_LENGTH       16
 
121
#define EVP_MAX_BLOCK_LENGTH    32
 
122
 
 
123
#define EVP_MAX_MD_SIZE         64
 
124
 
 
125
struct hc_CIPHER {
 
126
    int nid;
 
127
    int block_size;
 
128
    int key_len;
 
129
    int iv_len;
 
130
    unsigned long flags;
 
131
    /* The lowest 3 bits is used as integer field for the mode the
 
132
     * cipher is used in (use EVP_CIPHER.._mode() to extract the
 
133
     * mode). The rest of the flag field is a bitfield.
 
134
     */
 
135
#define EVP_CIPH_STREAM_CIPHER          0
 
136
#define EVP_CIPH_CBC_MODE               2
 
137
#define EVP_CIPH_MODE                   0x7
 
138
 
 
139
#define EVP_CIPH_ALWAYS_CALL_INIT       0x020
 
140
#define EVP_CIPH_RAND_KEY               0x200
 
141
 
 
142
    int (*init)(EVP_CIPHER_CTX*,const unsigned char*,const unsigned char*,int);
 
143
    int (*do_cipher)(EVP_CIPHER_CTX *, unsigned char *,
 
144
                     const unsigned char *, unsigned int);
 
145
    int (*cleanup)(EVP_CIPHER_CTX *);
 
146
    int ctx_size;
 
147
    void *set_asn1_parameters;
 
148
    void *get_asn1_parameters;
 
149
    int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr);
 
150
#define EVP_CTRL_RAND_KEY               0x6
 
151
 
 
152
    void *app_data;
 
153
};
 
154
 
 
155
struct hc_CIPHER_CTX {
 
156
    const EVP_CIPHER *cipher;
 
157
    ENGINE *engine;
 
158
    int encrypt;
 
159
    int buf_len; /* bytes stored in buf for EVP_CipherUpdate */
 
160
    unsigned char oiv[EVP_MAX_IV_LENGTH];
 
161
    unsigned char iv[EVP_MAX_IV_LENGTH];
 
162
    unsigned char buf[EVP_MAX_BLOCK_LENGTH];
 
163
    int num;
 
164
    void *app_data;
 
165
    int key_len;
 
166
    unsigned long flags;
 
167
    void *cipher_data;
 
168
    int final_used;
 
169
    int block_mask;
 
170
    unsigned char final[EVP_MAX_BLOCK_LENGTH];
 
171
};
 
172
 
 
173
typedef int (*hc_evp_md_init)(EVP_MD_CTX *);
 
174
typedef int (*hc_evp_md_update)(EVP_MD_CTX *,const void *, size_t);
 
175
typedef int (*hc_evp_md_final)(void *, EVP_MD_CTX *);
 
176
typedef int (*hc_evp_md_cleanup)(EVP_MD_CTX *);
 
177
 
 
178
struct hc_evp_md {
 
179
    int hash_size;
 
180
    int block_size;
 
181
    int ctx_size;
 
182
    hc_evp_md_init init;
 
183
    hc_evp_md_update update;
 
184
    hc_evp_md_final final;
 
185
    hc_evp_md_cleanup cleanup;
 
186
};
 
187
 
 
188
#if !defined(__GNUC__) && !defined(__attribute__)
 
189
#define __attribute__(x)
 
190
#endif
 
191
 
 
192
#ifndef HC_DEPRECATED
 
193
#define HC_DEPRECATED __attribute__((deprecated))
 
194
#endif
 
195
#ifndef HC_DEPRECATED_CRYPTO
 
196
#define HC_DEPRECATED_CRYPTO __attribute__((deprecated))
 
197
#endif
 
198
 
 
199
 
 
200
#ifdef  __cplusplus
 
201
extern "C" {
 
202
#endif
 
203
 
 
204
/*
 
205
 * Avaible crypto algs
 
206
 */
 
207
 
 
208
const EVP_MD *EVP_md_null(void);
 
209
const EVP_MD *EVP_md2(void) HC_DEPRECATED_CRYPTO;
 
210
const EVP_MD *EVP_md4(void) HC_DEPRECATED_CRYPTO;
 
211
const EVP_MD *EVP_md5(void) HC_DEPRECATED_CRYPTO;
 
212
const EVP_MD *EVP_sha(void);
 
213
const EVP_MD *EVP_sha1(void);
 
214
const EVP_MD *EVP_sha256(void);
 
215
 
 
216
const EVP_CIPHER * EVP_aes_128_cbc(void);
 
217
const EVP_CIPHER * EVP_aes_192_cbc(void);
 
218
const EVP_CIPHER * EVP_aes_256_cbc(void);
 
219
const EVP_CIPHER * EVP_hcrypto_aes_128_cbc(void);
 
220
const EVP_CIPHER * EVP_hcrypto_aes_192_cbc(void);
 
221
const EVP_CIPHER * EVP_hcrypto_aes_256_cbc(void);
 
222
const EVP_CIPHER * EVP_hcrypto_aes_128_cts(void);
 
223
const EVP_CIPHER * EVP_hcrypto_aes_192_cts(void);
 
224
const EVP_CIPHER * EVP_hcrypto_aes_256_cts(void);
 
225
const EVP_CIPHER * EVP_des_cbc(void) HC_DEPRECATED_CRYPTO;
 
226
const EVP_CIPHER * EVP_des_ede3_cbc(void);
 
227
const EVP_CIPHER * EVP_enc_null(void);
 
228
const EVP_CIPHER * EVP_rc2_40_cbc(void) HC_DEPRECATED_CRYPTO;
 
229
const EVP_CIPHER * EVP_rc2_64_cbc(void) HC_DEPRECATED_CRYPTO;
 
230
const EVP_CIPHER * EVP_rc2_cbc(void) HC_DEPRECATED_CRYPTO;
 
231
const EVP_CIPHER * EVP_rc4(void);
 
232
const EVP_CIPHER * EVP_rc4_40(void) HC_DEPRECATED_CRYPTO;
 
233
const EVP_CIPHER * EVP_camellia_128_cbc(void);
 
234
const EVP_CIPHER * EVP_camellia_192_cbc(void);
 
235
const EVP_CIPHER * EVP_camellia_256_cbc(void);
 
236
 
 
237
/*
 
238
 *
 
239
 */
 
240
 
 
241
size_t  EVP_MD_size(const EVP_MD *);
 
242
size_t  EVP_MD_block_size(const EVP_MD *);
 
243
 
 
244
const EVP_MD *
 
245
        EVP_MD_CTX_md(EVP_MD_CTX *);
 
246
size_t  EVP_MD_CTX_size(EVP_MD_CTX *);
 
247
size_t  EVP_MD_CTX_block_size(EVP_MD_CTX *);
 
248
 
 
249
EVP_MD_CTX *
 
250
        EVP_MD_CTX_create(void);
 
251
void    HC_DEPRECATED EVP_MD_CTX_init(EVP_MD_CTX *);
 
252
void    EVP_MD_CTX_destroy(EVP_MD_CTX *);
 
253
int     HC_DEPRECATED EVP_MD_CTX_cleanup(EVP_MD_CTX *);
 
254
 
 
255
int     EVP_DigestInit_ex(EVP_MD_CTX *, const EVP_MD *, ENGINE *);
 
256
int     EVP_DigestUpdate(EVP_MD_CTX *,const void *, size_t);
 
257
int     EVP_DigestFinal_ex(EVP_MD_CTX *, void *, unsigned int *);
 
258
int     EVP_Digest(const void *, size_t, void *, unsigned int *,
 
259
                   const EVP_MD *, ENGINE *);
 
260
/*
 
261
 *
 
262
 */
 
263
 
 
264
const EVP_CIPHER *
 
265
        EVP_get_cipherbyname(const char *);
 
266
 
 
267
size_t  EVP_CIPHER_block_size(const EVP_CIPHER *);
 
268
size_t  EVP_CIPHER_key_length(const EVP_CIPHER *);
 
269
size_t  EVP_CIPHER_iv_length(const EVP_CIPHER *);
 
270
 
 
271
void    EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *);
 
272
int     EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
 
273
int     EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *, int);
 
274
int     EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int);
 
275
unsigned long
 
276
        EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *);
 
277
int     EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *);
 
278
 
 
279
const EVP_CIPHER *
 
280
        EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *);
 
281
size_t  EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *);
 
282
size_t  EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *);
 
283
size_t  EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *);
 
284
void *  EVP_CIPHER_CTX_get_app_data(EVP_CIPHER_CTX *);
 
285
void    EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *, void *);
 
286
 
 
287
int     EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *, int, int, void *);
 
288
int     EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *, void *);
 
289
 
 
290
 
 
291
int     EVP_CipherInit_ex(EVP_CIPHER_CTX *,const EVP_CIPHER *, ENGINE *,
 
292
                          const void *, const void *, int);
 
293
int     EVP_CipherUpdate(EVP_CIPHER_CTX *, void *, int *, void *, size_t);
 
294
int     EVP_CipherFinal_ex(EVP_CIPHER_CTX *, void *, int *);
 
295
 
 
296
int     EVP_Cipher(EVP_CIPHER_CTX *,void *,const void *,size_t);
 
297
 
 
298
int     PKCS5_PBKDF2_HMAC_SHA1(const void *, size_t, const void *, size_t,
 
299
                               unsigned long, size_t, void *);
 
300
 
 
301
int     EVP_BytesToKey(const EVP_CIPHER *, const EVP_MD *,
 
302
                       const void *, const void *, size_t,
 
303
                       unsigned int, void *, void *);
 
304
 
 
305
 
 
306
/*
 
307
 *
 
308
 */
 
309
 
 
310
void    OpenSSL_add_all_algorithms(void);
 
311
void    OpenSSL_add_all_algorithms_conf(void);
 
312
void    OpenSSL_add_all_algorithms_noconf(void);
 
313
 
 
314
#ifdef  __cplusplus
 
315
}
 
316
#endif
 
317
 
 
318
#endif /* HEIM_EVP_H */