summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/mem.c
diff options
context:
space:
mode:
authordjm <>2010-10-01 22:59:01 +0000
committerdjm <>2010-10-01 22:59:01 +0000
commitfe047d8b632246cb2db3234a0a4f32e5c318857b (patch)
tree939b752540947d33507b3acc48d76a8bfb7c3dc3 /src/lib/libcrypto/mem.c
parent2ea67f4aa254b09ded62e6e14fc893bbe6381579 (diff)
downloadopenbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.gz
openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.bz2
openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.zip
resolve conflicts, fix local changes
Diffstat (limited to 'src/lib/libcrypto/mem.c')
-rw-r--r--src/lib/libcrypto/mem.c65
1 files changed, 17 insertions, 48 deletions
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
index 00ebaf0b9b..8f06d190a1 100644
--- a/src/lib/libcrypto/mem.c
+++ b/src/lib/libcrypto/mem.c
@@ -101,7 +101,7 @@ static void (*free_locked_func)(void *) = free;
101 101
102/* may be changed as long as 'allow_customize_debug' is set */ 102/* may be changed as long as 'allow_customize_debug' is set */
103/* XXX use correct function pointer types */ 103/* XXX use correct function pointer types */
104#if defined(CRYPTO_MDEBUG) && !defined(OPENSSL_FIPS) 104#ifdef CRYPTO_MDEBUG
105/* use default functions from mem_dbg.c */ 105/* use default functions from mem_dbg.c */
106static void (*malloc_debug_func)(void *,int,const char *,int,int) 106static void (*malloc_debug_func)(void *,int,const char *,int,int)
107 = CRYPTO_dbg_malloc; 107 = CRYPTO_dbg_malloc;
@@ -110,14 +110,6 @@ static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
110static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free; 110static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free;
111static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options; 111static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options;
112static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options; 112static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options;
113
114static int (*push_info_func)(const char *info, const char *file, int line)
115 = CRYPTO_dbg_push_info;
116static int (*pop_info_func)(void)
117 = CRYPTO_dbg_pop_info;
118static int (*remove_all_info_func)(void)
119 = CRYPTO_dbg_remove_all_info;
120
121#else 113#else
122/* applications can use CRYPTO_malloc_debug_init() to select above case 114/* applications can use CRYPTO_malloc_debug_init() to select above case
123 * at run-time */ 115 * at run-time */
@@ -127,13 +119,6 @@ static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
127static void (*free_debug_func)(void *,int) = NULL; 119static void (*free_debug_func)(void *,int) = NULL;
128static void (*set_debug_options_func)(long) = NULL; 120static void (*set_debug_options_func)(long) = NULL;
129static long (*get_debug_options_func)(void) = NULL; 121static long (*get_debug_options_func)(void) = NULL;
130
131
132static int (*push_info_func)(const char *info, const char *file, int line)
133 = NULL;
134static int (*pop_info_func)(void) = NULL;
135static int (*remove_all_info_func)(void) = NULL;
136
137#endif 122#endif
138 123
139 124
@@ -209,15 +194,6 @@ int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
209 return 1; 194 return 1;
210 } 195 }
211 196
212void CRYPTO_set_mem_info_functions(
213 int (*push_info_fn)(const char *info, const char *file, int line),
214 int (*pop_info_fn)(void),
215 int (*remove_all_info_fn)(void))
216 {
217 push_info_func = push_info_fn;
218 pop_info_func = pop_info_fn;
219 remove_all_info_func = remove_all_info_fn;
220 }
221 197
222void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t), 198void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
223 void (**f)(void *)) 199 void (**f)(void *))
@@ -274,7 +250,6 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
274void *CRYPTO_malloc_locked(int num, const char *file, int line) 250void *CRYPTO_malloc_locked(int num, const char *file, int line)
275 { 251 {
276 void *ret = NULL; 252 void *ret = NULL;
277 extern unsigned char cleanse_ctr;
278 253
279 if (num <= 0) return NULL; 254 if (num <= 0) return NULL;
280 255
@@ -291,11 +266,15 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
291 if (malloc_debug_func != NULL) 266 if (malloc_debug_func != NULL)
292 malloc_debug_func(ret, num, file, line, 1); 267 malloc_debug_func(ret, num, file, line, 1);
293 268
269#ifndef OPENSSL_CPUID_OBJ
294 /* Create a dependency on the value of 'cleanse_ctr' so our memory 270 /* Create a dependency on the value of 'cleanse_ctr' so our memory
295 * sanitisation function can't be optimised out. NB: We only do 271 * sanitisation function can't be optimised out. NB: We only do
296 * this for >2Kb so the overhead doesn't bother us. */ 272 * this for >2Kb so the overhead doesn't bother us. */
297 if(ret && (num > 2048)) 273 if(ret && (num > 2048))
274 { extern unsigned char cleanse_ctr;
298 ((unsigned char *)ret)[0] = cleanse_ctr; 275 ((unsigned char *)ret)[0] = cleanse_ctr;
276 }
277#endif
299 278
300 return ret; 279 return ret;
301 } 280 }
@@ -315,7 +294,6 @@ void CRYPTO_free_locked(void *str)
315void *CRYPTO_malloc(int num, const char *file, int line) 294void *CRYPTO_malloc(int num, const char *file, int line)
316 { 295 {
317 void *ret = NULL; 296 void *ret = NULL;
318 extern unsigned char cleanse_ctr;
319 297
320 if (num <= 0) return NULL; 298 if (num <= 0) return NULL;
321 299
@@ -332,12 +310,24 @@ void *CRYPTO_malloc(int num, const char *file, int line)
332 if (malloc_debug_func != NULL) 310 if (malloc_debug_func != NULL)
333 malloc_debug_func(ret, num, file, line, 1); 311 malloc_debug_func(ret, num, file, line, 1);
334 312
313#ifndef OPENSSL_CPUID_OBJ
335 /* Create a dependency on the value of 'cleanse_ctr' so our memory 314 /* Create a dependency on the value of 'cleanse_ctr' so our memory
336 * sanitisation function can't be optimised out. NB: We only do 315 * sanitisation function can't be optimised out. NB: We only do
337 * this for >2Kb so the overhead doesn't bother us. */ 316 * this for >2Kb so the overhead doesn't bother us. */
338 if(ret && (num > 2048)) 317 if(ret && (num > 2048))
318 { extern unsigned char cleanse_ctr;
339 ((unsigned char *)ret)[0] = cleanse_ctr; 319 ((unsigned char *)ret)[0] = cleanse_ctr;
320 }
321#endif
322
323 return ret;
324 }
325char *CRYPTO_strdup(const char *str, const char *file, int line)
326 {
327 size_t len = strlen(str)+1;
328 char *ret = CRYPTO_malloc(len, file, line);
340 329
330 memcpy(ret, str, len);
341 return ret; 331 return ret;
342 } 332 }
343 333
@@ -423,24 +413,3 @@ long CRYPTO_get_mem_debug_options(void)
423 return get_debug_options_func(); 413 return get_debug_options_func();
424 return 0; 414 return 0;
425 } 415 }
426
427int CRYPTO_push_info_(const char *info, const char *file, int line)
428 {
429 if (push_info_func)
430 return push_info_func(info, file, line);
431 return 1;
432 }
433
434int CRYPTO_pop_info(void)
435 {
436 if (pop_info_func)
437 return pop_info_func();
438 return 1;
439 }
440
441int CRYPTO_remove_all_info(void)
442 {
443 if (remove_all_info_func)
444 return remove_all_info_func();
445 return 1;
446 }