vaseboot/VasEBoot-core/lib/libgcrypt_wrap/mem.c

134 lines
2.2 KiB
C

#include <VasEBoot/gcrypt/g10lib.h>
#include <VasEBoot/gcrypt/gpg-error.h>
#include <VasEBoot/term.h>
#include <VasEBoot/crypto.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/env.h>
VasEBoot_MOD_LICENSE ("GPLv3+");
void *
gcry_malloc (size_t n)
{
return VasEBoot_malloc (n);
}
void *
gcry_malloc_secure (size_t n)
{
return VasEBoot_malloc (n);
}
void
gcry_free (void *a)
{
VasEBoot_free (a);
}
int
gcry_is_secure (const void *a __attribute__ ((unused)))
{
return 0;
}
/* FIXME: implement "exit". */
void *
gcry_xcalloc (size_t n, size_t m)
{
void *ret;
ret = VasEBoot_zalloc (n * m);
if (!ret)
VasEBoot_fatal ("gcry_xcalloc failed");
return ret;
}
void *
gcry_xmalloc_secure (size_t n)
{
void *ret;
ret = VasEBoot_malloc (n);
if (!ret)
VasEBoot_fatal ("gcry_xmalloc failed");
return ret;
}
void *
gcry_xcalloc_secure (size_t n, size_t m)
{
void *ret;
ret = VasEBoot_zalloc (n * m);
if (!ret)
VasEBoot_fatal ("gcry_xcalloc failed");
return ret;
}
void *
gcry_xmalloc (size_t n)
{
void *ret;
ret = VasEBoot_malloc (n);
if (!ret)
VasEBoot_fatal ("gcry_xmalloc failed");
return ret;
}
void *
gcry_xrealloc (void *a, size_t n)
{
void *ret;
ret = VasEBoot_realloc (a, n);
if (!ret)
VasEBoot_fatal ("gcry_xrealloc failed");
return ret;
}
void
_gcry_check_heap (const void *a __attribute__ ((unused)))
{
}
void _gcry_log_printf (const char *fmt, ...)
{
va_list args;
const char *debug = VasEBoot_env_get ("debug");
if (! debug)
return;
if (VasEBoot_strword (debug, "all") || VasEBoot_strword (debug, "gcrypt"))
{
VasEBoot_printf ("gcrypt: ");
va_start (args, fmt);
VasEBoot_vprintf (fmt, args);
va_end (args);
VasEBoot_refresh ();
}
}
void _gcry_log_bug (const char *fmt, ...)
{
va_list args;
VasEBoot_printf ("gcrypt bug: ");
va_start (args, fmt);
VasEBoot_vprintf (fmt, args);
va_end (args);
VasEBoot_refresh ();
VasEBoot_fatal ("gcrypt bug");
}
gcry_err_code_t
gpg_error_from_syserror (void)
{
switch (VasEBoot_errno)
{
case VasEBoot_ERR_NONE:
return GPG_ERR_NO_ERROR;
case VasEBoot_ERR_OUT_OF_MEMORY:
return GPG_ERR_OUT_OF_MEMORY;
default:
return GPG_ERR_GENERAL;
}
}