summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/mem.c
diff options
context:
space:
mode:
authormarkus <>2003-05-11 21:36:59 +0000
committermarkus <>2003-05-11 21:36:59 +0000
commit9cea7b85baecb1a02a3ea617de73d9693a9792eb (patch)
treeb0ca83a03e35572831c5818cd2011868d462a5d1 /src/lib/libcrypto/mem.c
parentf8f1d7fabf136ce9810602509c477d2c42bf6d1c (diff)
downloadopenbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.tar.gz
openbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.tar.bz2
openbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.zip
import 0.9.7b (without idea and rc5)
Diffstat (limited to 'src/lib/libcrypto/mem.c')
-rw-r--r--src/lib/libcrypto/mem.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
index a7826908e6..29df7d35b2 100644
--- a/src/lib/libcrypto/mem.c
+++ b/src/lib/libcrypto/mem.c
@@ -250,6 +250,9 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
250void *CRYPTO_malloc_locked(int num, const char *file, int line) 250void *CRYPTO_malloc_locked(int num, const char *file, int line)
251 { 251 {
252 void *ret = NULL; 252 void *ret = NULL;
253 extern unsigned char cleanse_ctr;
254
255 if (num < 0) return NULL;
253 256
254 allow_customize = 0; 257 allow_customize = 0;
255 if (malloc_debug_func != NULL) 258 if (malloc_debug_func != NULL)
@@ -264,6 +267,12 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
264 if (malloc_debug_func != NULL) 267 if (malloc_debug_func != NULL)
265 malloc_debug_func(ret, num, file, line, 1); 268 malloc_debug_func(ret, num, file, line, 1);
266 269
270 /* Create a dependency on the value of 'cleanse_ctr' so our memory
271 * sanitisation function can't be optimised out. NB: We only do
272 * this for >2Kb so the overhead doesn't bother us. */
273 if(ret && (num > 2048))
274 ((unsigned char *)ret)[0] = cleanse_ctr;
275
267 return ret; 276 return ret;
268 } 277 }
269 278
@@ -282,6 +291,9 @@ void CRYPTO_free_locked(void *str)
282void *CRYPTO_malloc(int num, const char *file, int line) 291void *CRYPTO_malloc(int num, const char *file, int line)
283 { 292 {
284 void *ret = NULL; 293 void *ret = NULL;
294 extern unsigned char cleanse_ctr;
295
296 if (num < 0) return NULL;
285 297
286 allow_customize = 0; 298 allow_customize = 0;
287 if (malloc_debug_func != NULL) 299 if (malloc_debug_func != NULL)
@@ -296,6 +308,12 @@ void *CRYPTO_malloc(int num, const char *file, int line)
296 if (malloc_debug_func != NULL) 308 if (malloc_debug_func != NULL)
297 malloc_debug_func(ret, num, file, line, 1); 309 malloc_debug_func(ret, num, file, line, 1);
298 310
311 /* Create a dependency on the value of 'cleanse_ctr' so our memory
312 * sanitisation function can't be optimised out. NB: We only do
313 * this for >2Kb so the overhead doesn't bother us. */
314 if(ret && (num > 2048))
315 ((unsigned char *)ret)[0] = cleanse_ctr;
316
299 return ret; 317 return ret;
300 } 318 }
301 319
@@ -306,6 +324,8 @@ void *CRYPTO_realloc(void *str, int num, const char *file, int line)
306 if (str == NULL) 324 if (str == NULL)
307 return CRYPTO_malloc(num, file, line); 325 return CRYPTO_malloc(num, file, line);
308 326
327 if (num < 0) return NULL;
328
309 if (realloc_debug_func != NULL) 329 if (realloc_debug_func != NULL)
310 realloc_debug_func(str, NULL, num, file, line, 0); 330 realloc_debug_func(str, NULL, num, file, line, 0);
311 ret = realloc_ex_func(str,num,file,line); 331 ret = realloc_ex_func(str,num,file,line);
@@ -318,6 +338,32 @@ void *CRYPTO_realloc(void *str, int num, const char *file, int line)
318 return ret; 338 return ret;
319 } 339 }
320 340
341void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file,
342 int line)
343 {
344 void *ret = NULL;
345
346 if (str == NULL)
347 return CRYPTO_malloc(num, file, line);
348
349 if (num < 0) return NULL;
350
351 if (realloc_debug_func != NULL)
352 realloc_debug_func(str, NULL, num, file, line, 0);
353 ret=malloc_ex_func(num,file,line);
354 if(ret)
355 memcpy(ret,str,old_len);
356 OPENSSL_cleanse(str,old_len);
357 free_func(str);
358#ifdef LEVITTE_DEBUG_MEM
359 fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num);
360#endif
361 if (realloc_debug_func != NULL)
362 realloc_debug_func(str, ret, num, file, line, 1);
363
364 return ret;
365 }
366
321void CRYPTO_free(void *str) 367void CRYPTO_free(void *str)
322 { 368 {
323 if (free_debug_func != NULL) 369 if (free_debug_func != NULL)
@@ -337,7 +383,6 @@ void *CRYPTO_remalloc(void *a, int num, const char *file, int line)
337 return(a); 383 return(a);
338 } 384 }
339 385
340
341void CRYPTO_set_mem_debug_options(long bits) 386void CRYPTO_set_mem_debug_options(long bits)
342 { 387 {
343 if (set_debug_options_func != NULL) 388 if (set_debug_options_func != NULL)