Constify EVP_SealInit, EVP_OpenInit
[openssl.git] / crypto / evp / evp.h
index efcc17c6085ba917b70784b56086c4ff884e42d0..494fa0c65e8320dcc4a592137320fac692e9cdf2 100644 (file)
@@ -217,10 +217,14 @@ 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);
+       int (*cleanup)(EVP_MD_CTX *ctx);
+
+       /* FIXME: prototype these some day */
        int (*sign)();
        int (*verify)();
        int required_pkey_type[5]; /*EVP_PKEY_xxx */
@@ -228,7 +232,8 @@ struct env_md_st
        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 +259,20 @@ struct env_md_st
 
 #endif /* !EVP_MD */
 
-typedef struct env_md_ctx_st
+struct env_md_ctx_st
        {
        const EVP_MD *digest;
+       ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
+       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 */
+#define EVP_MD_CTX_FLAG_CLEANED                0x0002 /* context has already been
+                                               * cleaned */
 
 struct evp_cipher_st
        {
@@ -277,7 +291,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 */
 
@@ -320,6 +334,7 @@ typedef struct evp_cipher_info_st
 struct evp_cipher_ctx_st
        {
        const EVP_CIPHER *cipher;
+       ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
        int encrypt;            /* encrypt or decrypt */
        int buf_len;            /* number we have left */
 
@@ -335,7 +350,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 +392,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 +404,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 +453,16 @@ 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))
+#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
+#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
 int    EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
+int    EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
 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 +478,29 @@ 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_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, ENGINE *impl,
+               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_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, ENGINE *impl,
+               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_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, ENGINE *impl,
+                      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,
@@ -480,11 +509,11 @@ int       EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
 int    EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
                unsigned int siglen,EVP_PKEY *pkey);
 
-int    EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
+int    EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,unsigned char *ek,
                int ekl,unsigned char *iv,EVP_PKEY *priv);
 int    EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
 
-int    EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
+int    EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
                int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
 void   EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
 
@@ -555,10 +584,16 @@ 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);
+/* This should now be supported through the dev_crypto ENGINE. But also, why are
+ * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */
+#if 0
 # 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
+#endif
 #ifndef OPENSSL_NO_RC4
 const EVP_CIPHER *EVP_rc4(void);
 const EVP_CIPHER *EVP_rc4_40(void);
@@ -694,6 +729,7 @@ void EVP_PBE_cleanup(void);
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
  */
+void ERR_load_EVP_strings(void);
 
 /* Error codes for the EVP functions. */
 
@@ -703,6 +739,7 @@ void EVP_PBE_cleanup(void);
 #define EVP_F_EVP_CIPHER_CTX_CTRL                       124
 #define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH             122
 #define EVP_F_EVP_DECRYPTFINAL                          101
+#define EVP_F_EVP_DIGESTINIT                            128
 #define EVP_F_EVP_ENCRYPTFINAL                          127
 #define EVP_F_EVP_MD_CTX_COPY                           110
 #define EVP_F_EVP_OPENINIT                              102
@@ -750,6 +787,7 @@ void EVP_PBE_cleanup(void);
 #define EVP_R_KEYGEN_FAILURE                            120
 #define EVP_R_MISSING_PARAMETERS                        103
 #define EVP_R_NO_CIPHER_SET                             131
+#define EVP_R_NO_DIGEST_SET                             139
 #define EVP_R_NO_DSA_PARAMETERS                                 116
 #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED               104
 #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED             105
@@ -771,4 +809,3 @@ void EVP_PBE_cleanup(void);
 }
 #endif
 #endif
-