New flags EVP_CIPH_FLAG_CUSTOM_CIPHER in cipher structures if an underlying
[openssl.git] / crypto / evp / evp_enc.c
index a0bdf9856c1d07edf2a77012ee33399ef4197d4f..3f8473b348a653cb7a59e7921ca6893eb5b7dd13 100644 (file)
@@ -286,6 +286,16 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
        {
        int i,j,bl;
 
+       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER)
+               {
+               i = ctx->cipher->do_cipher(ctx, out, in, inl);
+               if (i < 0)
+                       return 0;
+               else
+                       *outl = i;
+               return 1;
+               }
+
        if (inl <= 0)
                {
                *outl = 0;
@@ -356,6 +366,16 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
        int n,ret;
        unsigned int i, b, bl;
 
+       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER)
+               {
+               i = ctx->cipher->do_cipher(ctx, out, NULL, -1);
+               if (i < 0)
+                       return 0;
+               else
+                       *outl = i;
+               return 1;
+               }
+
        b=ctx->cipher->block_size;
        OPENSSL_assert(b <= sizeof ctx->buf);
        if (b == 1)
@@ -393,6 +413,19 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
        int fix_len;
        unsigned int b;
 
+       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER)
+               {
+               fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
+               if (fix_len < 0)
+                       {
+                       *outl = 0;
+                       return 0;
+                       }
+               else
+                       *outl = fix_len;
+               return 1;
+               }
+
        if (inl <= 0)
                {
                *outl = 0;
@@ -446,8 +479,18 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
        {
        int i,n;
        unsigned int b;
-
        *outl=0;
+
+       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER)
+               {
+               i = ctx->cipher->do_cipher(ctx, out, NULL, -1);
+               if (i < 0)
+                       return 0;
+               else
+                       *outl = i;
+               return 1;
+               }
+
        b=ctx->cipher->block_size;
        if (ctx->flags & EVP_CIPH_NO_PADDING)
                {