X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fmem_clr.c;h=579e9d18251d51b5a4b026fcde08267b913d95e0;hb=d8908c3310240bb0efd9b17c663a8b9e47bf31dc;hp=e4b7f540b0bd12dd03608b52e8214332cb1a8b72;hpb=470799152037586dd51e9ec7d39304ddca873b22;p=oweals%2Fopenssl.git diff --git a/crypto/mem_clr.c b/crypto/mem_clr.c index e4b7f540b0..579e9d1825 100644 --- a/crypto/mem_clr.c +++ b/crypto/mem_clr.c @@ -1,6 +1,7 @@ -/* crypto/mem_clr.c -*- mode:C; c-file-style: "eay" -*- */ -/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL - * project 2002. +/* crypto/mem_clr.c */ +/* + * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project + * 2002. */ /* ==================================================================== * Copyright (c) 2001 The OpenSSL Project. All rights reserved. @@ -10,7 +11,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -59,17 +60,16 @@ #include #include -unsigned char cleanse_ctr = 0; +/* + * Pointer to memset is volatile so that compiler must de-reference + * the pointer and can't assume that it points to any function in + * particular (such as memset, which it then might further "optimize") + */ +typedef void *(*memset_t)(void *,int,size_t); + +static volatile memset_t memset_func = memset; void OPENSSL_cleanse(void *ptr, size_t len) - { - unsigned char *p = ptr; - size_t loop = len; - while(loop--) - { - *(p++) = cleanse_ctr; - cleanse_ctr += (17 + (unsigned char)((int)p & 0xF)); - } - if(memchr(ptr, cleanse_ctr, len)) - cleanse_ctr += 63; - } +{ + memset_func(ptr, 0, len); +}