]> git.proxmox.com Git - grub2.git/blob - grub-core/lib/libgcrypt/src/g10lib.h
Import grub2_2.02+dfsg1.orig.tar.xz
[grub2.git] / grub-core / lib / libgcrypt / src / g10lib.h
1 /* g10lib.h - Internal definitions for libgcrypt
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
3 * 2007, 2011 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser general Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /* This header is to be used inside of libgcrypt in place of gcrypt.h.
22 This way we can better distinguish between internal and external
23 usage of gcrypt.h. */
24
25 #ifndef G10LIB_H
26 #define G10LIB_H 1
27
28 #ifdef _GCRYPT_H
29 #error gcrypt.h already included
30 #endif
31
32 #ifndef _GCRYPT_IN_LIBGCRYPT
33 #error something is wrong with config.h
34 #endif
35
36 #include <stdio.h>
37 #include <stdarg.h>
38
39 #include "visibility.h"
40 #include "types.h"
41
42
43 \f
44
45 /* Attribute handling macros. */
46
47 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
48 #define JNLIB_GCC_M_FUNCTION 1
49 #define JNLIB_GCC_A_NR __attribute__ ((noreturn))
50 #define JNLIB_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
51 #define JNLIB_GCC_A_NR_PRINTF( f, a ) \
52 __attribute__ ((noreturn, format (printf,f,a)))
53 #define GCC_ATTR_NORETURN __attribute__ ((__noreturn__))
54 #else
55 #define JNLIB_GCC_A_NR
56 #define JNLIB_GCC_A_PRINTF( f, a )
57 #define JNLIB_GCC_A_NR_PRINTF( f, a )
58 #define GCC_ATTR_NORETURN
59 #endif
60
61 #if __GNUC__ >= 3
62 /* According to glibc this attribute is available since 2.8 however we
63 better play safe and use it only with gcc 3 or newer. */
64 #define GCC_ATTR_FORMAT_ARG(a) __attribute__ ((format_arg (a)))
65 #else
66 #define GCC_ATTR_FORMAT_ARG(a)
67 #endif
68
69
70 /* Gettext macros. */
71
72 /* Some handy macros */
73 #ifndef STR
74 #define STR(v) #v
75 #endif
76 #define STR2(v) STR(v)
77 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
78 #define DIMof(type,member) DIM(((type *)0)->member)
79
80 \f
81
82 /*-- src/global.c -*/
83 int _gcry_global_is_operational (void);
84 gcry_error_t _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr);
85 void _gcry_check_heap (const void *a);
86 int _gcry_get_debug_flag (unsigned int mask);
87
88
89 /*-- src/misc.c --*/
90
91 #if defined(JNLIB_GCC_M_FUNCTION) || __STDC_VERSION__ >= 199901L
92 void _gcry_bug (const char *file, int line,
93 const char *func) GCC_ATTR_NORETURN;
94 void _gcry_assert_failed (const char *expr, const char *file, int line,
95 const char *func) GCC_ATTR_NORETURN;
96 #else
97 void _gcry_bug (const char *file, int line);
98 void _gcry_assert_failed (const char *expr, const char *file, int line);
99 #endif
100
101 const char *_gcry_gettext (const char *key) GCC_ATTR_FORMAT_ARG(1);
102 void _gcry_fatal_error(int rc, const char *text ) JNLIB_GCC_A_NR;
103 void _gcry_log( int level, const char *fmt, ... ) JNLIB_GCC_A_PRINTF(2,3);
104 void _gcry_log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
105 void _gcry_log_fatal( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
106 void _gcry_log_error( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
107 void _gcry_log_info( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
108 int _gcry_log_info_with_dummy_fp (FILE *fp, const char *fmt, ... )
109 JNLIB_GCC_A_PRINTF(2,3);
110 void _gcry_log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
111 void _gcry_log_printf ( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
112 void _gcry_log_printhex (const char *text, const void *buffer, size_t length);
113
114 void _gcry_set_log_verbosity( int level );
115 int _gcry_log_verbosity( int level );
116
117 #ifdef JNLIB_GCC_M_FUNCTION
118 #define BUG() _gcry_bug( __FILE__ , __LINE__, __FUNCTION__ )
119 #define gcry_assert(expr) ((expr)? (void)0 \
120 : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __FUNCTION__))
121 #elif __STDC_VERSION__ >= 199901L
122 #define BUG() _gcry_bug( __FILE__ , __LINE__, __func__ )
123 #define gcry_assert(expr) ((expr)? (void)0 \
124 : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __func__))
125 #else
126 #define BUG() _gcry_bug( __FILE__ , __LINE__ )
127 #define gcry_assert(expr) ((expr)? (void)0 \
128 : _gcry_assert_failed (STR(expr), __FILE__, __LINE__))
129 #endif
130
131
132 #define log_bug _gcry_log_bug
133 #define log_fatal _gcry_log_fatal
134 #define log_error _gcry_log_error
135 #define log_info _gcry_log_info
136 #define log_debug _gcry_log_debug
137 #define log_printf _gcry_log_printf
138 #define log_printhex _gcry_log_printhex
139
140
141 /*-- src/hwfeatures.c --*/
142 /* (Do not change these values unless synced with the asm code.) */
143 #define HWF_PADLOCK_RNG 1
144 #define HWF_PADLOCK_AES 2
145 #define HWF_PADLOCK_SHA 4
146 #define HWF_PADLOCK_MMUL 8
147
148 #define HWF_INTEL_AESNI 256
149
150
151 unsigned int _gcry_get_hw_features (void);
152 void _gcry_detect_hw_features (unsigned int);
153
154
155 /*-- mpi/mpiutil.c --*/
156 const char *_gcry_mpi_get_hw_config (void);
157
158
159 /*-- cipher/pubkey.c --*/
160
161 /* FIXME: shouldn't this go into mpi.h? */
162 #ifndef mpi_powm
163 #define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
164 #endif
165
166 /*-- primegen.c --*/
167 gcry_mpi_t _gcry_generate_secret_prime (unsigned int nbits,
168 gcry_random_level_t random_level,
169 int (*extra_check)(void*, gcry_mpi_t),
170 void *extra_check_arg);
171 gcry_mpi_t _gcry_generate_public_prime (unsigned int nbits,
172 gcry_random_level_t random_level,
173 int (*extra_check)(void*, gcry_mpi_t),
174 void *extra_check_arg);
175 gcry_mpi_t _gcry_generate_elg_prime (int mode,
176 unsigned int pbits, unsigned int qbits,
177 gcry_mpi_t g, gcry_mpi_t **factors);
178 gcry_mpi_t _gcry_derive_x931_prime (const gcry_mpi_t xp,
179 const gcry_mpi_t xp1, const gcry_mpi_t xp2,
180 const gcry_mpi_t e,
181 gcry_mpi_t *r_p1, gcry_mpi_t *r_p2);
182 gpg_err_code_t _gcry_generate_fips186_2_prime
183 (unsigned int pbits, unsigned int qbits,
184 const void *seed, size_t seedlen,
185 gcry_mpi_t *r_q, gcry_mpi_t *r_p,
186 int *r_counter,
187 void **r_seed, size_t *r_seedlen);
188 gpg_err_code_t _gcry_generate_fips186_3_prime
189 (unsigned int pbits, unsigned int qbits,
190 const void *seed, size_t seedlen,
191 gcry_mpi_t *r_q, gcry_mpi_t *r_p,
192 int *r_counter,
193 void **r_seed, size_t *r_seedlen, int *r_hashalgo);
194
195
196 /* Replacements of missing functions (missing-string.c). */
197 #ifndef HAVE_STPCPY
198 char *stpcpy (char *a, const char *b);
199 #endif
200 #ifndef HAVE_STRCASECMP
201 int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE;
202 #endif
203
204
205 /* Macros used to rename missing functions. */
206 #ifndef HAVE_STRTOUL
207 #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
208 #endif
209 #ifndef HAVE_MEMMOVE
210 #define memmove(d, s, n) bcopy((s), (d), (n))
211 #endif
212 #ifndef HAVE_STRICMP
213 #define stricmp(a,b) strcasecmp( (a), (b) )
214 #endif
215 #ifndef HAVE_ATEXIT
216 #define atexit(a) (on_exit((a),0))
217 #endif
218 #ifndef HAVE_RAISE
219 #define raise(a) kill(getpid(), (a))
220 #endif
221
222
223 /* Stack burning. */
224
225 void _gcry_burn_stack (int bytes);
226
227
228 /* To avoid that a compiler optimizes certain memset calls away, these
229 macros may be used instead. */
230 #define wipememory2(_ptr,_set,_len) do { \
231 volatile char *_vptr=(volatile char *)(_ptr); \
232 size_t _vlen=(_len); \
233 while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
234 } while(0)
235 #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
236
237
238
239 /* Digit predicates. */
240
241 #define digitp(p) (*(p) >= '0' && *(p) <= '9')
242 #define octdigitp(p) (*(p) >= '0' && *(p) <= '7')
243 #define alphap(a) ( (*(a) >= 'A' && *(a) <= 'Z') \
244 || (*(a) >= 'a' && *(a) <= 'z'))
245 #define hexdigitp(a) (digitp (a) \
246 || (*(a) >= 'A' && *(a) <= 'F') \
247 || (*(a) >= 'a' && *(a) <= 'f'))
248
249
250 /*-- sexp.c --*/
251 gcry_error_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
252 const char *format, va_list arg_ptr);
253 char *_gcry_sexp_nth_string (const gcry_sexp_t list, int number);
254
255
256 /*-- fips.c --*/
257
258 void _gcry_initialize_fips_mode (int force);
259
260 int _gcry_fips_mode (void);
261 #define fips_mode() _gcry_fips_mode ()
262
263 int _gcry_enforced_fips_mode (void);
264
265 void _gcry_set_enforced_fips_mode (void);
266
267 void _gcry_inactivate_fips_mode (const char *text);
268 int _gcry_is_fips_mode_inactive (void);
269
270
271 void _gcry_fips_signal_error (const char *srcfile,
272 int srcline,
273 const char *srcfunc,
274 int is_fatal,
275 const char *description);
276 #ifdef JNLIB_GCC_M_FUNCTION
277 # define fips_signal_error(a) \
278 _gcry_fips_signal_error (__FILE__, __LINE__, __FUNCTION__, 0, (a))
279 # define fips_signal_fatal_error(a) \
280 _gcry_fips_signal_error (__FILE__, __LINE__, __FUNCTION__, 1, (a))
281 #else
282 # define fips_signal_error(a) \
283 _gcry_fips_signal_error (__FILE__, __LINE__, NULL, 0, (a))
284 # define fips_signal_fatal_error(a) \
285 _gcry_fips_signal_error (__FILE__, __LINE__, NULL, 1, (a))
286 #endif
287
288 int _gcry_fips_is_operational (void);
289 #define fips_is_operational() (_gcry_global_is_operational ())
290 #define fips_not_operational() (GCRY_GPG_ERR_NOT_OPERATIONAL)
291
292 int _gcry_fips_test_operational (void);
293 int _gcry_fips_test_error_or_operational (void);
294
295 gpg_err_code_t _gcry_fips_run_selftests (int extended);
296
297 void _gcry_fips_noreturn (void);
298 #define fips_noreturn() (_gcry_fips_noreturn ())
299
300
301
302 #endif /* G10LIB_H */