1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#include <grub/gcrypt/g10lib.h>
#include <grub/gcrypt/gpg-error.h>
#include <grub/term.h>
#include <grub/crypto.h>
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/safemath.h>
GRUB_MOD_LICENSE ("GPLv3+");
void *
gcry_malloc (size_t n)
{
return grub_malloc (n);
}
void *
gcry_malloc_secure (size_t n)
{
return grub_malloc (n);
}
void
gcry_free (void *a)
{
grub_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;
size_t sz;
if (grub_mul (n, m, &sz))
grub_fatal ("gcry_xcalloc would overflow");
ret = grub_zalloc (sz);
if (!ret)
grub_fatal ("gcry_xcalloc failed");
return ret;
}
void *
gcry_xmalloc_secure (size_t n)
{
void *ret;
ret = grub_malloc (n);
if (!ret)
grub_fatal ("gcry_xmalloc failed");
return ret;
}
void *
gcry_xcalloc_secure (size_t n, size_t m)
{
void *ret;
size_t sz;
if (grub_mul (n, m, &sz))
grub_fatal ("gcry_xcalloc would overflow");
ret = grub_zalloc (sz);
if (!ret)
grub_fatal ("gcry_xcalloc failed");
return ret;
}
void *
gcry_xmalloc (size_t n)
{
void *ret;
ret = grub_malloc (n);
if (!ret)
grub_fatal ("gcry_xmalloc failed");
return ret;
}
void *
gcry_xrealloc (void *a, size_t n)
{
void *ret;
ret = grub_realloc (a, n);
if (!ret)
grub_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 = grub_env_get ("debug");
if (! debug)
return;
if (grub_strword (debug, "all") || grub_strword (debug, "gcrypt"))
{
grub_printf ("gcrypt: ");
va_start (args, fmt);
grub_vprintf (fmt, args);
va_end (args);
grub_refresh ();
}
}
void _gcry_log_bug (const char *fmt, ...)
{
va_list args;
grub_printf ("gcrypt bug: ");
va_start (args, fmt);
grub_vprintf (fmt, args);
va_end (args);
grub_refresh ();
grub_fatal ("gcrypt bug");
}
gcry_err_code_t
gpg_error_from_syserror (void)
{
switch (grub_errno)
{
case GRUB_ERR_NONE:
return GPG_ERR_NO_ERROR;
case GRUB_ERR_OUT_OF_MEMORY:
return GPG_ERR_OUT_OF_MEMORY;
default:
return GPG_ERR_GENERAL;
}
}
|