summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/evp.h')
-rw-r--r--src/lib/libcrypto/evp/evp.h133
1 files changed, 105 insertions, 28 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 54215b0905..f5b938d2f8 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -59,13 +59,23 @@
59#ifndef HEADER_ENVELOPE_H 59#ifndef HEADER_ENVELOPE_H
60#define HEADER_ENVELOPE_H 60#define HEADER_ENVELOPE_H
61 61
62#ifdef __cplusplus 62#ifdef OPENSSL_ALGORITHM_DEFINES
63extern "C" { 63# include <openssl/opensslconf.h>
64#else
65# define OPENSSL_ALGORITHM_DEFINES
66# include <openssl/opensslconf.h>
67# undef OPENSSL_ALGORITHM_DEFINES
64#endif 68#endif
65 69
70#ifndef NO_BIO
71#include <openssl/bio.h>
72#endif
66#ifndef NO_MD2 73#ifndef NO_MD2
67#include <openssl/md2.h> 74#include <openssl/md2.h>
68#endif 75#endif
76#ifndef NO_MD4
77#include <openssl/md4.h>
78#endif
69#ifndef NO_MD5 79#ifndef NO_MD5
70#include <openssl/md5.h> 80#include <openssl/md5.h>
71#endif 81#endif
@@ -147,6 +157,10 @@ extern "C" {
147#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 157#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
148#define EVP_PKEY_DH NID_dhKeyAgreement 158#define EVP_PKEY_DH NID_dhKeyAgreement
149 159
160#ifdef __cplusplus
161extern "C" {
162#endif
163
150/* Type needs to be a bit field 164/* Type needs to be a bit field
151 * Sub-type needs to be for variations on the method, as in, can it do 165 * Sub-type needs to be for variations on the method, as in, can it do
152 * arbitrary encryption.... */ 166 * arbitrary encryption.... */
@@ -168,7 +182,7 @@ typedef struct evp_pkey_st
168#endif 182#endif
169 } pkey; 183 } pkey;
170 int save_parameters; 184 int save_parameters;
171 STACK /*X509_ATTRIBUTE*/ *attributes; /* [ 0 ] */ 185 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
172 } EVP_PKEY; 186 } EVP_PKEY;
173 187
174#define EVP_PKEY_MO_SIGN 0x0001 188#define EVP_PKEY_MO_SIGN 0x0001
@@ -298,6 +312,9 @@ typedef struct env_md_ctx_st
298#ifndef NO_MD5 312#ifndef NO_MD5
299 MD5_CTX md5; 313 MD5_CTX md5;
300#endif 314#endif
315#ifndef NO_MD4
316 MD4_CTX md4;
317#endif
301#ifndef NO_RIPEMD 318#ifndef NO_RIPEMD
302 RIPEMD160_CTX ripemd160; 319 RIPEMD160_CTX ripemd160;
303#endif 320#endif
@@ -310,21 +327,57 @@ typedef struct env_md_ctx_st
310 } md; 327 } md;
311 } EVP_MD_CTX; 328 } EVP_MD_CTX;
312 329
313typedef struct evp_cipher_st 330typedef struct evp_cipher_st EVP_CIPHER;
331typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
332
333struct evp_cipher_st
314 { 334 {
315 int nid; 335 int nid;
316 int block_size; 336 int block_size;
317 int key_len; 337 int key_len; /* Default value for variable length ciphers */
318 int iv_len; 338 int iv_len;
319 void (*init)(); /* init for encryption */ 339 unsigned long flags; /* Various flags */
320 void (*do_cipher)(); /* encrypt data */ 340 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
321 void (*cleanup)(); /* used by cipher method */ 341 const unsigned char *iv, int enc); /* init key */
342 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
343 const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
344 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
322 int ctx_size; /* how big the ctx needs to be */ 345 int ctx_size; /* how big the ctx needs to be */
323 /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ 346 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
324 int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */ 347 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
325 /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ 348 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
326 int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */ 349 void *app_data; /* Application data */
327 } EVP_CIPHER; 350 };
351
352/* Values for cipher flags */
353
354/* Modes for ciphers */
355
356#define EVP_CIPH_STREAM_CIPHER 0x0
357#define EVP_CIPH_ECB_MODE 0x1
358#define EVP_CIPH_CBC_MODE 0x2
359#define EVP_CIPH_CFB_MODE 0x3
360#define EVP_CIPH_OFB_MODE 0x4
361#define EVP_CIPH_MODE 0x7
362/* Set if variable length cipher */
363#define EVP_CIPH_VARIABLE_LENGTH 0x8
364/* Set if the iv handling should be done by the cipher itself */
365#define EVP_CIPH_CUSTOM_IV 0x10
366/* Set if the cipher's init() function should be called if key is NULL */
367#define EVP_CIPH_ALWAYS_CALL_INIT 0x20
368/* Call ctrl() to init cipher parameters */
369#define EVP_CIPH_CTRL_INIT 0x40
370/* Don't use standard key length function */
371#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
372
373/* ctrl() values */
374
375#define EVP_CTRL_INIT 0x0
376#define EVP_CTRL_SET_KEY_LENGTH 0x1
377#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
378#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
379#define EVP_CTRL_GET_RC5_ROUNDS 0x4
380#define EVP_CTRL_SET_RC5_ROUNDS 0x5
328 381
329typedef struct evp_cipher_info_st 382typedef struct evp_cipher_info_st
330 { 383 {
@@ -332,7 +385,7 @@ typedef struct evp_cipher_info_st
332 unsigned char iv[EVP_MAX_IV_LENGTH]; 385 unsigned char iv[EVP_MAX_IV_LENGTH];
333 } EVP_CIPHER_INFO; 386 } EVP_CIPHER_INFO;
334 387
335typedef struct evp_cipher_ctx_st 388struct evp_cipher_ctx_st
336 { 389 {
337 const EVP_CIPHER *cipher; 390 const EVP_CIPHER *cipher;
338 int encrypt; /* encrypt or decrypt */ 391 int encrypt; /* encrypt or decrypt */
@@ -343,7 +396,8 @@ typedef struct evp_cipher_ctx_st
343 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */ 396 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */
344 int num; /* used by cfb/ofb mode */ 397 int num; /* used by cfb/ofb mode */
345 398
346 char *app_data; /* application stuff */ 399 void *app_data; /* application stuff */
400 int key_len; /* May change for variable length cipher */
347 union { 401 union {
348#ifndef NO_RC4 402#ifndef NO_RC4
349 struct 403 struct
@@ -371,10 +425,16 @@ typedef struct evp_cipher_ctx_st
371 IDEA_KEY_SCHEDULE idea_ks;/* key schedule */ 425 IDEA_KEY_SCHEDULE idea_ks;/* key schedule */
372#endif 426#endif
373#ifndef NO_RC2 427#ifndef NO_RC2
374 RC2_KEY rc2_ks;/* key schedule */ 428 struct {
429 int key_bits; /* effective key bits */
430 RC2_KEY ks;/* key schedule */
431 } rc2;
375#endif 432#endif
376#ifndef NO_RC5 433#ifndef NO_RC5
377 RC5_32_KEY rc5_ks;/* key schedule */ 434 struct {
435 int rounds; /* number of rounds */
436 RC5_32_KEY ks;/* key schedule */
437 } rc5;
378#endif 438#endif
379#ifndef NO_BF 439#ifndef NO_BF
380 BF_KEY bf_ks;/* key schedule */ 440 BF_KEY bf_ks;/* key schedule */
@@ -383,7 +443,7 @@ typedef struct evp_cipher_ctx_st
383 CAST_KEY cast_ks;/* key schedule */ 443 CAST_KEY cast_ks;/* key schedule */
384#endif 444#endif
385 } c; 445 } c;
386 } EVP_CIPHER_CTX; 446 };
387 447
388typedef struct evp_Encode_Ctx_st 448typedef struct evp_Encode_Ctx_st
389 { 449 {
@@ -430,15 +490,19 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
430#define EVP_CIPHER_block_size(e) ((e)->block_size) 490#define EVP_CIPHER_block_size(e) ((e)->block_size)
431#define EVP_CIPHER_key_length(e) ((e)->key_len) 491#define EVP_CIPHER_key_length(e) ((e)->key_len)
432#define EVP_CIPHER_iv_length(e) ((e)->iv_len) 492#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
493#define EVP_CIPHER_flags(e) ((e)->flags)
494#define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE)
433 495
434#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) 496#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
435#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) 497#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
436#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) 498#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
437#define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len) 499#define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
438#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) 500#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
439#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) 501#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
440#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) 502#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
441#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) 503#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
504#define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
505#define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
442 506
443#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) 507#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
444#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) 508#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
@@ -486,21 +550,21 @@ int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
486 unsigned char *data, int datal, int count, 550 unsigned char *data, int datal, int count,
487 unsigned char *key,unsigned char *iv); 551 unsigned char *key,unsigned char *iv);
488 552
489void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, 553int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
490 unsigned char *key, unsigned char *iv); 554 unsigned char *key, unsigned char *iv);
491void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 555int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
492 int *outl, unsigned char *in, int inl); 556 int *outl, unsigned char *in, int inl);
493void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 557int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
494 558
495void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, 559int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
496 unsigned char *key, unsigned char *iv); 560 unsigned char *key, unsigned char *iv);
497void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 561int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
498 int *outl, unsigned char *in, int inl); 562 int *outl, unsigned char *in, int inl);
499int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 563int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
500 564
501void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, 565int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
502 unsigned char *key,unsigned char *iv,int enc); 566 unsigned char *key,unsigned char *iv,int enc);
503void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 567int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
504 int *outl, unsigned char *in, int inl); 568 int *outl, unsigned char *in, int inl);
505int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 569int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
506 570
@@ -534,9 +598,11 @@ int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
534void ERR_load_EVP_strings(void ); 598void ERR_load_EVP_strings(void );
535 599
536void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); 600void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
537void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); 601int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
602int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
603int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
538 604
539#ifdef HEADER_BIO_H 605#ifndef NO_BIO
540BIO_METHOD *BIO_f_md(void); 606BIO_METHOD *BIO_f_md(void);
541BIO_METHOD *BIO_f_base64(void); 607BIO_METHOD *BIO_f_base64(void);
542BIO_METHOD *BIO_f_cipher(void); 608BIO_METHOD *BIO_f_cipher(void);
@@ -547,6 +613,7 @@ void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
547 613
548EVP_MD *EVP_md_null(void); 614EVP_MD *EVP_md_null(void);
549EVP_MD *EVP_md2(void); 615EVP_MD *EVP_md2(void);
616EVP_MD *EVP_md4(void);
550EVP_MD *EVP_md5(void); 617EVP_MD *EVP_md5(void);
551EVP_MD *EVP_sha(void); 618EVP_MD *EVP_sha(void);
552EVP_MD *EVP_sha1(void); 619EVP_MD *EVP_sha1(void);
@@ -683,6 +750,9 @@ void EVP_PBE_cleanup(void);
683 750
684/* Function codes. */ 751/* Function codes. */
685#define EVP_F_D2I_PKEY 100 752#define EVP_F_D2I_PKEY 100
753#define EVP_F_EVP_CIPHERINIT 123
754#define EVP_F_EVP_CIPHER_CTX_CTRL 124
755#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
686#define EVP_F_EVP_DECRYPTFINAL 101 756#define EVP_F_EVP_DECRYPTFINAL 101
687#define EVP_F_EVP_MD_CTX_COPY 110 757#define EVP_F_EVP_MD_CTX_COPY 110
688#define EVP_F_EVP_OPENINIT 102 758#define EVP_F_EVP_OPENINIT 102
@@ -703,12 +773,15 @@ void EVP_PBE_cleanup(void);
703#define EVP_F_PKCS5_PBE_KEYIVGEN 117 773#define EVP_F_PKCS5_PBE_KEYIVGEN 117
704#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 774#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
705#define EVP_F_RC2_MAGIC_TO_METH 109 775#define EVP_F_RC2_MAGIC_TO_METH 109
776#define EVP_F_RC5_CTRL 125
706 777
707/* Reason codes. */ 778/* Reason codes. */
708#define EVP_R_BAD_DECRYPT 100 779#define EVP_R_BAD_DECRYPT 100
709#define EVP_R_BN_DECODE_ERROR 112 780#define EVP_R_BN_DECODE_ERROR 112
710#define EVP_R_BN_PUBKEY_ERROR 113 781#define EVP_R_BN_PUBKEY_ERROR 113
711#define EVP_R_CIPHER_PARAMETER_ERROR 122 782#define EVP_R_CIPHER_PARAMETER_ERROR 122
783#define EVP_R_CTRL_NOT_IMPLEMENTED 132
784#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
712#define EVP_R_DECODE_ERROR 114 785#define EVP_R_DECODE_ERROR 114
713#define EVP_R_DIFFERENT_KEY_TYPES 101 786#define EVP_R_DIFFERENT_KEY_TYPES 101
714#define EVP_R_ENCODE_ERROR 115 787#define EVP_R_ENCODE_ERROR 115
@@ -716,16 +789,20 @@ void EVP_PBE_cleanup(void);
716#define EVP_R_EXPECTING_AN_RSA_KEY 127 789#define EVP_R_EXPECTING_AN_RSA_KEY 127
717#define EVP_R_EXPECTING_A_DH_KEY 128 790#define EVP_R_EXPECTING_A_DH_KEY 128
718#define EVP_R_EXPECTING_A_DSA_KEY 129 791#define EVP_R_EXPECTING_A_DSA_KEY 129
792#define EVP_R_INITIALIZATION_ERROR 134
719#define EVP_R_INPUT_NOT_INITIALIZED 111 793#define EVP_R_INPUT_NOT_INITIALIZED 111
794#define EVP_R_INVALID_KEY_LENGTH 130
720#define EVP_R_IV_TOO_LARGE 102 795#define EVP_R_IV_TOO_LARGE 102
721#define EVP_R_KEYGEN_FAILURE 120 796#define EVP_R_KEYGEN_FAILURE 120
722#define EVP_R_MISSING_PARAMETERS 103 797#define EVP_R_MISSING_PARAMETERS 103
798#define EVP_R_NO_CIPHER_SET 131
723#define EVP_R_NO_DSA_PARAMETERS 116 799#define EVP_R_NO_DSA_PARAMETERS 116
724#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 800#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
725#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 801#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
726#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117 802#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
727#define EVP_R_PUBLIC_KEY_NOT_RSA 106 803#define EVP_R_PUBLIC_KEY_NOT_RSA 106
728#define EVP_R_UNKNOWN_PBE_ALGORITHM 121 804#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
805#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135
729#define EVP_R_UNSUPPORTED_CIPHER 107 806#define EVP_R_UNSUPPORTED_CIPHER 107
730#define EVP_R_UNSUPPORTED_KEYLENGTH 123 807#define EVP_R_UNSUPPORTED_KEYLENGTH 123
731#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 808#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124