Optimize OPENSSL_cleanse.
authorAndy Polyakov <appro@openssl.org>
Wed, 20 Jun 2007 17:36:39 +0000 (17:36 +0000)
committerAndy Polyakov <appro@openssl.org>
Wed, 20 Jun 2007 17:36:39 +0000 (17:36 +0000)
crypto/mem_clr.c

index 75cbfb374e3bd4e09af7e9dd0999a7e39a8b0c32..00dfcff0cf046fb0c8d234d6dba9fcce7accc470 100644 (file)
@@ -64,12 +64,13 @@ unsigned char cleanse_ctr = 0;
 void OPENSSL_cleanse(void *ptr, size_t len)
        {
        unsigned char *p = ptr;
-       size_t loop = len;
+       size_t loop = len, ctr = cleanse_ctr;
        while(loop--)
                {
-               *(p++) = cleanse_ctr;
-               cleanse_ctr += (17 + (unsigned char)((unsigned long)p & 0xF));
+               *(p++) = (unsigned char)ctr;
+               ctr += (17 + ((size_t)p & 0xF));
                }
-       if(memchr(ptr, cleanse_ctr, len))
-               cleanse_ctr += 63;
+       if(p=memchr(ptr, (unsigned char)ctr, len))
+               ctr += (63 + (size_t)p);
+       cleanse_ctr = (unsigned char)ctr;
        }