Make MD functions take EVP_MD_CTX * instead of void *, add copy() function.
[openssl.git] / crypto / evp / evp.h
index cd5a3406246e68c2a2c68ede3beea76ba0f836d6..7f798388f0d9e16f5ac08fd76a1df170b2c5d5f8 100644 (file)
@@ -137,7 +137,7 @@ struct evp_pkey_st
                } pkey;
        int save_parameters;
        STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
-       };
+       } /* EVP_PKEY */;
 
 #define EVP_PKEY_MO_SIGN       0x0001
 #define EVP_PKEY_MO_VERIFY     0x0002
@@ -217,18 +217,22 @@ struct env_md_st
        int type;
        int pkey_type;
        int md_size;
-       int (*init)();
-       int (*update)();
-       int (*final)();
+       unsigned long flags;
+       int (*init)(EVP_MD_CTX *ctx);
+       int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
+       int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
+       int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
 
+       /* FIXME: prototype these some day */
        int (*sign)();
        int (*verify)();
        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 */;
 
+#define EVP_MD_FLAG_ONESHOT    0x0001 /* digest can only handle a single
+                                       * block */
 
 #define EVP_PKEY_NULL_method   NULL,NULL,{0,0,0,0}
 
@@ -254,11 +258,17 @@ struct env_md_st
 
 #endif /* !EVP_MD */
 
-typedef struct env_md_ctx_st
+struct env_md_ctx_st
        {
        const EVP_MD *digest;
+       unsigned long flags;
        void *md_data;
-       } EVP_MD_CTX;
+       } /* EVP_MD_CTX */;
+
+/* values for EVP_MD_CTX flags */
+
+#define EVP_MD_CTX_FLAG_ONESHOT                0x0001 /* digest update will be called
+                                               * once only */
 
 struct evp_cipher_st
        {
@@ -277,7 +287,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 */
 
@@ -335,7 +345,7 @@ struct evp_cipher_ctx_st
        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
        {
@@ -377,6 +387,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)
@@ -387,6 +399,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)
@@ -435,13 +448,19 @@ 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);
 void   EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
 int     EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);  
+#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
+#ifdef CRYPTO_MDEBUG
+int    EVP_DigestInit_dbg(EVP_MD_CTX *ctx, const EVP_MD *type,
+                          const char *file,int line);
+#define EVP_DigestInit(ctx,type) EVP_DigestInit_dbg(ctx,type,__FILE__,__LINE__)
+#else
 int    EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
+#endif
 int    EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
                         unsigned int cnt);
 int    EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
@@ -457,21 +476,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,
@@ -557,6 +577,8 @@ 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