Test digests.
[openssl.git] / crypto / evp / evp.h
index ecd221fb06af5439a46107634f44228159c2b968..435f2b36e663fa943dce913019be12acc46c990b 100644 (file)
 # undef OPENSSL_ALGORITHM_DEFINES
 #endif
 
+#include <openssl/types.h>
+
 #ifndef OPENSSL_NO_BIO
 #include <openssl/bio.h>
 #endif
-#ifndef OPENSSL_NO_MD2
-#include <openssl/md2.h>
-#endif
-#ifndef OPENSSL_NO_MD4
-#include <openssl/md4.h>
-#endif
-#ifndef OPENSSL_NO_MD5
-#include <openssl/md5.h>
-#endif
-#ifndef OPENSSL_NO_SHA
-#include <openssl/sha.h>
-#endif
-#ifndef OPENSSL_NO_RIPEMD
-#include <openssl/ripemd.h>
-#endif
-#ifndef OPENSSL_NO_DES
-#include <openssl/des.h>
-#endif
-#ifndef OPENSSL_NO_RC4
-#include <openssl/rc4.h>
-#endif
-#ifndef OPENSSL_NO_RC2
-#include <openssl/rc2.h>
-#endif
-#ifndef OPENSSL_NO_RC5
-#include <openssl/rc5.h>
-#endif
-#ifndef OPENSSL_NO_BF
-#include <openssl/blowfish.h>
-#endif
-#ifndef OPENSSL_NO_CAST
-#include <openssl/cast.h>
-#endif
-#ifndef OPENSSL_NO_IDEA
-#include <openssl/idea.h>
-#endif
-#ifndef OPENSSL_NO_MDC2
-#include <openssl/mdc2.h>
-#endif
-#ifndef OPENSSL_NO_AES
-#include <openssl/rijndael.h>
-#endif
 
+/*
 #define EVP_RC2_KEY_SIZE               16
 #define EVP_RC4_KEY_SIZE               16
 #define EVP_BLOWFISH_KEY_SIZE          16
 #define EVP_CAST5_KEY_SIZE             16
 #define EVP_RC5_32_12_16_KEY_SIZE      16
+*/
 #define EVP_MAX_MD_SIZE                        (16+20) /* The SSLv3 md5+sha1 type */
 #define EVP_MAX_KEY_LENGTH             32
 #define EVP_MAX_IV_LENGTH              16
 /* Default PKCS#5 iteration count */
 #define PKCS5_DEFAULT_ITER             2048
 
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-
-#ifndef OPENSSL_NO_DH
-#include <openssl/dh.h>
-#endif
-
 #include <openssl/objects.h>
 
 #define EVP_PK_RSA     0x0001
@@ -168,7 +118,7 @@ extern "C" {
 /* Type needs to be a bit field
  * Sub-type needs to be for variations on the method, as in, can it do
  * arbitrary encryption.... */
-typedef struct evp_pkey_st
+struct evp_pkey_st
        {
        int type;
        int save_type;
@@ -187,7 +137,7 @@ typedef struct evp_pkey_st
                } pkey;
        int save_parameters;
        STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
-       } EVP_PKEY;
+       } /* EVP_PKEY */;
 
 #define EVP_PKEY_MO_SIGN       0x0001
 #define EVP_PKEY_MO_VERIFY     0x0002
@@ -262,7 +212,7 @@ typedef struct evp_pkey_method_st
 #endif
 
 #ifndef EVP_MD
-typedef struct env_md_st
+struct env_md_st
        {
        int type;
        int pkey_type;
@@ -275,8 +225,8 @@ typedef struct env_md_st
        int (*verify)();
        int required_pkey_type[5]; /*EVP_PKEY_xxx */
        int block_size;
-       int ctx_size; /* how big does the ctx need to be */
-       } EVP_MD;
+       int ctx_size; /* how big does the ctx->md_data need to be */
+       } /* EVP_MD */;
 
 
 
@@ -307,32 +257,9 @@ typedef struct env_md_st
 typedef struct env_md_ctx_st
        {
        const EVP_MD *digest;
-       union   {
-               unsigned char base[4];
-#ifndef OPENSSL_NO_MD2
-               MD2_CTX md2;
-#endif
-#ifndef OPENSSL_NO_MD5
-               MD5_CTX md5;
-#endif
-#ifndef OPENSSL_NO_MD4
-               MD4_CTX md4;
-#endif
-#ifndef OPENSSL_NO_RIPEMD
-               RIPEMD160_CTX ripemd160;
-#endif
-#ifndef OPENSSL_NO_SHA
-               SHA_CTX sha;
-#endif
-#ifndef OPENSSL_NO_MDC2
-               MDC2_CTX mdc2;
-#endif
-               } md;
+       void *md_data;
        } EVP_MD_CTX;
 
-typedef struct evp_cipher_st EVP_CIPHER;
-typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
-
 struct evp_cipher_st
        {
        int nid;
@@ -345,12 +272,12 @@ struct evp_cipher_st
        int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
                         const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
        int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
-       int ctx_size;           /* how big the ctx needs to be */
+       int ctx_size;           /* how big ctx->cipher_data needs to be */
        int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
        int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
        int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
        void *app_data;         /* Application data */
-       };
+       } /* EVP_CIPHER */;
 
 /* Values for cipher flags */
 
@@ -404,58 +331,11 @@ struct evp_cipher_ctx_st
        void *app_data;         /* application stuff */
        int key_len;            /* May change for variable length cipher */
        unsigned long flags;    /* Various flags */
-       union
-               {
-#ifndef OPENSSL_NO_RC4
-               struct
-                       {
-                       unsigned char key[EVP_RC4_KEY_SIZE];
-                       RC4_KEY ks;     /* working key */
-                       } rc4;
-#endif
-#ifndef OPENSSL_NO_DES
-               des_key_schedule des_ks;/* key schedule */
-               struct
-                       {
-                       des_key_schedule ks;/* key schedule */
-                       des_cblock inw;
-                       des_cblock outw;
-                       } desx_cbc;
-               struct
-                       {
-                       des_key_schedule ks1;/* key schedule */
-                       des_key_schedule ks2;/* key schedule (for ede) */
-                       des_key_schedule ks3;/* key schedule (for ede3) */
-                       } des_ede;
-#endif
-#ifndef OPENSSL_NO_IDEA
-               IDEA_KEY_SCHEDULE idea_ks;/* key schedule */
-#endif
-#ifndef OPENSSL_NO_RC2
-               struct
-                       {
-                       int key_bits;   /* effective key bits */
-                       RC2_KEY ks;/* key schedule */
-                       } rc2;
-#endif
-#ifndef OPENSSL_NO_RC5
-               struct
-                       {
-                       int rounds;     /* number of rounds */
-                       RC5_32_KEY ks;/* key schedule */
-                       } rc5;
-#endif
-#ifndef OPENSSL_NO_BF
-               BF_KEY bf_ks;/* key schedule */
-#endif
-#ifndef OPENSSL_NO_CAST
-               CAST_KEY cast_ks;/* key schedule */
-#endif
-#ifndef OPENSSL_NO_AES
-               RIJNDAEL_KEY rijndael;
-#endif
-               } c;
-       };
+       void *cipher_data; /* per EVP data */
+       int final_used;
+       int block_mask;
+       unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
+       } /* EVP_CIPHER_CTX */;
 
 typedef struct evp_Encode_Ctx_st
        {
@@ -497,6 +377,8 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
 
 #define EVP_MD_type(e)                 ((e)->type)
+#define EVP_MD_nid(e)                  EVP_MD_type(e)
+#define EVP_MD_name(e)                 OBJ_nid2sn(EVP_MD_nid(e))
 #define EVP_MD_pkey_type(e)            ((e)->pkey_type)
 #define EVP_MD_size(e)                 ((e)->md_size)
 #define EVP_MD_block_size(e)           ((e)->block_size)
@@ -507,6 +389,7 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
 #define EVP_MD_CTX_type(e)             EVP_MD_type((e)->digest)
 
 #define EVP_CIPHER_nid(e)              ((e)->nid)
+#define EVP_CIPHER_name(e)             OBJ_nid2sn(EVP_CIPHER_nid(e))
 #define EVP_CIPHER_block_size(e)       ((e)->block_size)
 #define EVP_CIPHER_key_length(e)       ((e)->key_len)
 #define EVP_CIPHER_iv_length(e)                ((e)->iv_len)
@@ -555,8 +438,11 @@ void BIO_set_md(BIO *,const EVP_MD *md);
 #define EVP_delete_digest_alias(alias) \
        OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
 
-
-int     EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);  
+void   EVP_MD_CTX_init(EVP_MD_CTX *ctx);
+int    EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
+EVP_MD_CTX *EVP_MD_CTX_create(void);
+void   EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
+int     EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);  
 int    EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
 int    EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
                         unsigned int cnt);
@@ -573,21 +459,22 @@ int       EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
                int datal, int count, unsigned char *key,unsigned char *iv);
 
 int    EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
-               unsigned char *key, unsigned char *iv);
+               const unsigned char *key, const unsigned char *iv);
 int    EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
-               int *outl, unsigned char *in, int inl);
+               int *outl, const unsigned char *in, int inl);
 int    EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
 
 int    EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
-               unsigned char *key, unsigned char *iv);
+               const unsigned char *key, const unsigned char *iv);
 int    EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
-               int *outl, unsigned char *in, int inl);
+               int *outl, const unsigned char *in, int inl);
 int    EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
 
 int    EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
-                      unsigned char *key,unsigned char *iv,int enc);
+                      const unsigned char *key,const unsigned char *iv,
+                      int enc);
 int    EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
-               int *outl, unsigned char *in, int inl);
+               int *outl, const unsigned char *in, int inl);
 int    EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
 
 int    EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
@@ -671,6 +558,11 @@ const EVP_CIPHER *EVP_des_cbc(void);
 const EVP_CIPHER *EVP_des_ede_cbc(void);
 const EVP_CIPHER *EVP_des_ede3_cbc(void);
 const EVP_CIPHER *EVP_desx_cbc(void);
+# ifdef OPENSSL_OPENBSD_DEV_CRYPTO
+const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
+const EVP_CIPHER *EVP_dev_crypto_rc4(void);
+const EVP_MD *EVP_dev_crypto_md5(void);
+# endif
 #endif
 #ifndef OPENSSL_NO_RC4
 const EVP_CIPHER *EVP_rc4(void);
@@ -739,18 +631,24 @@ int               EVP_PKEY_type(int type);
 int            EVP_PKEY_bits(EVP_PKEY *pkey);
 int            EVP_PKEY_size(EVP_PKEY *pkey);
 int            EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
+
 #ifndef OPENSSL_NO_RSA
-int            EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
-RSA *          EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
+struct rsa_st;
+int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);
+struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
 #endif
 #ifndef OPENSSL_NO_DSA
-int            EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
-DSA *          EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
+struct dsa_st;
+int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);
+struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
 #endif
 #ifndef OPENSSL_NO_DH
-int            EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
-DH *           EVP_PKEY_get1_DH(EVP_PKEY *pkey);
+struct dh_st;
+int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
+struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
 #endif
+
+
 EVP_PKEY *     EVP_PKEY_new(void);
 void           EVP_PKEY_free(EVP_PKEY *pkey);
 EVP_PKEY *     d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,