'typo'
[openssl.git] / crypto / evp / evp_enc.c
index 22cb6131be2e409027ed2006dabac213751fbaf0..bead6a2170a0a3d7b6e17caec288cc61edd69ed0 100644 (file)
@@ -66,7 +66,7 @@
 #endif
 #include "evp_locl.h"
 
-const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
+const char EVP_version[]="EVP" OPENSSL_VERSION_PTEXT;
 
 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
        {
@@ -74,6 +74,13 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
        /* ctx->cipher=NULL; */
        }
 
+EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
+       {
+       EVP_CIPHER_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
+       if (ctx)
+               EVP_CIPHER_CTX_init(ctx);
+       return ctx;
+       }
 
 int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
             const unsigned char *key, const unsigned char *iv, int enc)
@@ -272,7 +279,12 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
        {
        int i,j,bl;
 
-       OPENSSL_assert(inl > 0);
+       if (inl <= 0)
+               {
+               *outl = 0;
+               return inl == 0;
+               }
+
        if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
                {
                if(ctx->cipher->do_cipher(ctx,out,in,inl))
@@ -374,10 +386,10 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
        int fix_len;
        unsigned int b;
 
-       if (inl == 0)
+       if (inl <= 0)
                {
-               *outl=0;
-               return 1;
+               *outl = 0;
+               return inl == 0;
                }
 
        if (ctx->flags & EVP_CIPH_NO_PADDING)
@@ -472,6 +484,15 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
        return(1);
        }
 
+void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
+       {
+       if (ctx)
+               {
+               EVP_CIPHER_CTX_cleanup(ctx);
+               OPENSSL_free(ctx);
+               }
+       }
+
 int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
        {
        if (c->cipher != NULL)
@@ -545,3 +566,38 @@ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
        return 1;
        }
 
+int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
+       {
+       if ((in == NULL) || (in->cipher == NULL))
+               {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
+               return 0;
+               }
+#ifndef OPENSSL_NO_ENGINE
+       /* Make sure it's safe to copy a cipher context using an ENGINE */
+       if (in->engine && !ENGINE_init(in->engine))
+               {
+               EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_ENGINE_LIB);
+               return 0;
+               }
+#endif
+
+       EVP_CIPHER_CTX_cleanup(out);
+       memcpy(out,in,sizeof *out);
+
+       if (in->cipher_data && in->cipher->ctx_size)
+               {
+               out->cipher_data=OPENSSL_malloc(in->cipher->ctx_size);
+               if (!out->cipher_data)
+                       {
+                       EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_MALLOC_FAILURE);
+                       return 0;
+                       }
+               memcpy(out->cipher_data,in->cipher_data,in->cipher->ctx_size);
+               }
+
+       if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY)
+               return in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out);
+       return 1;
+       }
+