Add EVP test program.
[openssl.git] / crypto / evp / evp.h
index df9b2dd0a89b9c94ea613ab3081b6bfd694cfecb..629782c8b8cf41177e39e62ab03c1f232055cf21 100644 (file)
 # undef OPENSSL_ALGORITHM_DEFINES
 #endif
 
+#include <openssl/types.h>
+
 #ifndef OPENSSL_NO_BIO
 #include <openssl/bio.h>
 #endif
-#if 0
-#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
-#endif /* 0 */
 
 /*
 #define EVP_RC2_KEY_SIZE               16
 /* Default PKCS#5 iteration count */
 #define PKCS5_DEFAULT_ITER             2048
 
-#if 0
-#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
-#endif /* 0 */
-
 #include <openssl/objects.h>
 
 #define EVP_PK_RSA     0x0001
@@ -174,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;
@@ -193,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
@@ -268,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;
@@ -282,7 +226,7 @@ typedef struct env_md_st
        int required_pkey_type[5]; /*EVP_PKEY_xxx */
        int block_size;
        int ctx_size; /* how big does the ctx->md_data need to be */
-       } EVP_MD;
+       } /* EVP_MD */;
 
 
 
@@ -313,35 +257,9 @@ typedef struct env_md_st
 typedef struct env_md_ctx_st
        {
        const EVP_MD *digest;
-#if 0
-       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;
-#endif
        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;
@@ -359,7 +277,7 @@ struct evp_cipher_st
        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 */
 
@@ -413,67 +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 */
-#if 0
-       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
-#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
-               struct session_op *dev_crypto;
-#endif
-               } c;
-#endif /* 0 */
        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
        {
@@ -525,6 +387,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)
@@ -573,7 +436,6 @@ 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);
 
-
 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);
@@ -595,21 +457,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,