Use & instead of % - worth about 4% for 8 byte blocks.
authorBen Laurie <ben@openssl.org>
Sun, 8 Jul 2001 17:27:32 +0000 (17:27 +0000)
committerBen Laurie <ben@openssl.org>
Sun, 8 Jul 2001 17:27:32 +0000 (17:27 +0000)
CHANGES
crypto/evp/evp_enc.c

diff --git a/CHANGES b/CHANGES
index 94acfc526888e3361c7e0273b63381c6defddc50..78a894d443f8935593fc07467505406783224855 100644 (file)
--- a/CHANGES
+++ b/CHANGES
          *) applies to 0.9.6a (/0.9.6b) and 0.9.7
          +) applies to 0.9.7 only
 
+  +) Speed up EVP routines.
+     Before:
+encrypt
+type              8 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
+des-cbc           4408.85k     5560.51k     5778.46k     5862.20k     5825.16k
+des-cbc           4389.55k     5571.17k     5792.23k     5846.91k     5832.11k
+des-cbc           4394.32k     5575.92k     5807.44k     5848.37k     5841.30k
+decrypt
+des-cbc           3482.66k     5069.49k     5496.39k     5614.16k     5639.28k
+des-cbc           3480.74k     5068.76k     5510.34k     5609.87k     5635.52k
+des-cbc           3483.72k     5067.62k     5504.60k     5708.01k     5724.80k
+     After:
+encrypt
+des-cbc           4581.64k     5666.39k     5811.23k     5871.60k     5833.23k
+decrypt
+des-cbc           3615.18k     5102.53k     5501.58k     5631.13k     5635.52k
+     [Ben Laurie]
+
   *) Fix crypto/bn/asm/mips3.s.
      [Andy Polyakov]
 
index 14c8506e80c973e5a62393232353ede9d9c57ba5..ae1a22ebb805b1fd8786810ad97fcbb31ac3d97d 100644 (file)
@@ -62,6 +62,8 @@
 #include <openssl/err.h>
 #include "evp_locl.h"
 
+#include <assert.h>
+
 const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
 
 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
@@ -88,6 +90,12 @@ int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
                EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);
                return 0;
        }
+
+       /* we assume block size is a power of 2 in *cryptUpdate */
+       assert(ctx->cipher->block_size == 1
+              || ctx->cipher->block_size == 8
+              || ctx->cipher->block_size == 16);
+
        if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
                switch(EVP_CIPHER_CTX_mode(ctx)) {
 
@@ -147,7 +155,6 @@ int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
        return EVP_CipherInit(ctx, cipher, key, iv, 0);
        }
 
-
 int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
             unsigned char *in, int inl)
        {
@@ -176,7 +183,8 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
                        *outl+=bl;
                        }
                }
-       i=inl%bl; /* how much is left */
+       //      i=inl%bl; /* how much is left */
+       i=inl&(bl-1);
        inl-=i;
        if (inl > 0)
                {