+ return ret;
+}
+
+void *CRYPTO_zalloc(size_t num, const char *file, int line)
+{
+ void *ret = CRYPTO_malloc(num, file, line);
+
+ if (ret != NULL)
+ memset(ret, 0, num);
+ return ret;
+}
+
+void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
+{
+ if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)
+ return realloc_impl(str, num, file, line);
+
+ if (str == NULL)
+ return CRYPTO_malloc(num, file, line);
+
+ if (num == 0) {
+ CRYPTO_free(str, file, line);
+ return NULL;
+ }
+
+ allow_customize = 0;
+#ifndef OPENSSL_NO_CRYPTO_MDEBUG
+ if (call_malloc_debug) {
+ void *ret;
+ CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);
+ ret = realloc(str, num);
+ CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);
+ return ret;
+ }
+#else
+ osslargused(file); osslargused(line);
+#endif
+ return realloc(str, num);
+
+}
+
+void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
+ const char *file, int line)
+{
+ void *ret = NULL;
+
+ if (str == NULL)
+ return CRYPTO_malloc(num, file, line);
+
+ if (num == 0) {
+ CRYPTO_clear_free(str, old_len, file, line);
+ return NULL;
+ }
+
+ /* Can't shrink the buffer since memcpy below copies |old_len| bytes. */
+ if (num < old_len) {
+ memset((char*)str + num, 0, old_len - num);
+ return str;
+ }
+
+ ret = CRYPTO_malloc(num, file, line);
+ if (ret != NULL) {
+ memcpy(ret, str, old_len);
+ CRYPTO_clear_free(str, old_len, file, line);
+ }
+ return ret;
+}
+
+void CRYPTO_free(void *str, const char *file, int line)
+{
+ if (free_impl != NULL && free_impl != &CRYPTO_free) {
+ free_impl(str, file, line);
+ return;
+ }
+
+#ifndef OPENSSL_NO_CRYPTO_MDEBUG
+ if (call_malloc_debug) {
+ CRYPTO_mem_debug_free(str, 0, file, line);
+ free(str);
+ CRYPTO_mem_debug_free(str, 1, file, line);
+ } else {
+ free(str);
+ }
+#else
+ free(str);
+#endif
+}
+
+void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
+{
+ if (str == NULL)
+ return;
+ if (num)
+ OPENSSL_cleanse(str, num);
+ CRYPTO_free(str, file, line);
+}