1 /* visibility.c - Wrapper for all public functions.
2 * Copyright (C) 2007, 2008, 2011 Free Software Foundation, Inc.
3 * Copyright (C) 2013 g10 Code GmbH
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 #include <config.h>
22 #include <stdarg.h>
23
24 #define _GCRY_INCLUDED_BY_VISIBILITY_C
25 #include "g10lib.h"
26 #include "cipher-proto.h"
27 #include "context.h"
28 #include "mpi.h"
29 #include "ec-context.h"
30
31 const char *
gcry_strerror(gcry_error_t err)32 gcry_strerror (gcry_error_t err)
33 {
34 return _gcry_strerror (err);
35 }
36
37 const char *
gcry_strsource(gcry_error_t err)38 gcry_strsource (gcry_error_t err)
39 {
40 return _gcry_strsource (err);
41 }
42
43 gcry_err_code_t
gcry_err_code_from_errno(int err)44 gcry_err_code_from_errno (int err)
45 {
46 return _gcry_err_code_from_errno (err);
47 }
48
49 int
gcry_err_code_to_errno(gcry_err_code_t code)50 gcry_err_code_to_errno (gcry_err_code_t code)
51 {
52 return _gcry_err_code_to_errno (code);
53 }
54
55 gcry_error_t
gcry_err_make_from_errno(gcry_err_source_t source,int err)56 gcry_err_make_from_errno (gcry_err_source_t source, int err)
57 {
58 return _gcry_err_make_from_errno (source, err);
59 }
60
61 gcry_error_t
gcry_error_from_errno(int err)62 gcry_error_from_errno (int err)
63 {
64 return _gcry_error_from_errno (err);
65 }
66
67 const char *
gcry_check_version(const char * req_version)68 gcry_check_version (const char *req_version)
69 {
70 return _gcry_check_version (req_version);
71 }
72
73 gcry_error_t
gcry_control(enum gcry_ctl_cmds cmd,...)74 gcry_control (enum gcry_ctl_cmds cmd, ...)
75 {
76 gcry_error_t err;
77 va_list arg_ptr;
78
79 va_start (arg_ptr, cmd);
80 err = gpg_error (_gcry_vcontrol (cmd, arg_ptr));
81 va_end(arg_ptr);
82 return err;
83 }
84
85 gcry_error_t
gcry_sexp_new(gcry_sexp_t * retsexp,const void * buffer,size_t length,int autodetect)86 gcry_sexp_new (gcry_sexp_t *retsexp,
87 const void *buffer, size_t length,
88 int autodetect)
89 {
90 return gpg_error (_gcry_sexp_new (retsexp, buffer, length, autodetect));
91 }
92
93 gcry_error_t
gcry_sexp_create(gcry_sexp_t * retsexp,void * buffer,size_t length,int autodetect,void (* freefnc)(void *))94 gcry_sexp_create (gcry_sexp_t *retsexp,
95 void *buffer, size_t length,
96 int autodetect, void (*freefnc) (void *))
97 {
98 return gpg_error (_gcry_sexp_create (retsexp, buffer, length,
99 autodetect, freefnc));
100 }
101
102 gcry_error_t
gcry_sexp_sscan(gcry_sexp_t * retsexp,size_t * erroff,const char * buffer,size_t length)103 gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
104 const char *buffer, size_t length)
105 {
106 return gpg_error (_gcry_sexp_sscan (retsexp, erroff, buffer, length));
107 }
108
109 gcry_error_t
gcry_sexp_build(gcry_sexp_t * retsexp,size_t * erroff,const char * format,...)110 gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff,
111 const char *format, ...)
112 {
113 gcry_err_code_t rc;
114 va_list arg_ptr;
115
116 va_start (arg_ptr, format);
117 rc = _gcry_sexp_vbuild (retsexp, erroff, format, arg_ptr);
118 va_end (arg_ptr);
119 return gpg_error (rc);
120 }
121
122 gcry_error_t
gcry_sexp_build_array(gcry_sexp_t * retsexp,size_t * erroff,const char * format,void ** arg_list)123 gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
124 const char *format, void **arg_list)
125 {
126 return gpg_error (_gcry_sexp_build_array (retsexp, erroff, format, arg_list));
127 }
128
129 void
gcry_sexp_release(gcry_sexp_t sexp)130 gcry_sexp_release (gcry_sexp_t sexp)
131 {
132 _gcry_sexp_release (sexp);
133 }
134
135 size_t
gcry_sexp_canon_len(const unsigned char * buffer,size_t length,size_t * erroff,gcry_error_t * errcode)136 gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
137 size_t *erroff, gcry_error_t *errcode)
138 {
139 size_t n;
140 gpg_err_code_t rc;
141
142 n = _gcry_sexp_canon_len (buffer, length, erroff, &rc);
143 if (errcode)
144 *errcode = gpg_error (rc);
145 return n;
146 }
147
148 size_t
gcry_sexp_sprint(gcry_sexp_t sexp,int mode,void * buffer,size_t maxlength)149 gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer, size_t maxlength)
150 {
151 return _gcry_sexp_sprint (sexp, mode, buffer, maxlength);
152 }
153
154 void
gcry_sexp_dump(const gcry_sexp_t a)155 gcry_sexp_dump (const gcry_sexp_t a)
156 {
157 _gcry_sexp_dump (a);
158 }
159
160 gcry_sexp_t
gcry_sexp_cons(const gcry_sexp_t a,const gcry_sexp_t b)161 gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b)
162 {
163 return _gcry_sexp_cons (a, b);
164 }
165
166 gcry_sexp_t
gcry_sexp_alist(const gcry_sexp_t * array)167 gcry_sexp_alist (const gcry_sexp_t *array)
168 {
169 return _gcry_sexp_alist (array);
170 }
171
172 gcry_sexp_t
gcry_sexp_vlist(const gcry_sexp_t a,...)173 gcry_sexp_vlist (const gcry_sexp_t a, ...)
174 {
175 /* This is not yet implemented in sexp.c. */
176 (void)a;
177 BUG ();
178 return NULL;
179 }
180
181 gcry_sexp_t
gcry_sexp_append(const gcry_sexp_t a,const gcry_sexp_t n)182 gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n)
183 {
184 return _gcry_sexp_append (a, n);
185 }
186
187 gcry_sexp_t
gcry_sexp_prepend(const gcry_sexp_t a,const gcry_sexp_t n)188 gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n)
189 {
190 return _gcry_sexp_prepend (a, n);
191 }
192
193
194 gcry_sexp_t
gcry_sexp_find_token(gcry_sexp_t list,const char * tok,size_t toklen)195 gcry_sexp_find_token (gcry_sexp_t list, const char *tok, size_t toklen)
196 {
197 return _gcry_sexp_find_token (list, tok, toklen);
198 }
199
200 int
gcry_sexp_length(const gcry_sexp_t list)201 gcry_sexp_length (const gcry_sexp_t list)
202 {
203 return _gcry_sexp_length (list);
204 }
205
206 gcry_sexp_t
gcry_sexp_nth(const gcry_sexp_t list,int number)207 gcry_sexp_nth (const gcry_sexp_t list, int number)
208 {
209 return _gcry_sexp_nth (list, number);
210 }
211
212 gcry_sexp_t
gcry_sexp_car(const gcry_sexp_t list)213 gcry_sexp_car (const gcry_sexp_t list)
214 {
215 return _gcry_sexp_car (list);
216 }
217
218 gcry_sexp_t
gcry_sexp_cdr(const gcry_sexp_t list)219 gcry_sexp_cdr (const gcry_sexp_t list)
220 {
221 return _gcry_sexp_cdr (list);
222 }
223
224 gcry_sexp_t
gcry_sexp_cadr(const gcry_sexp_t list)225 gcry_sexp_cadr (const gcry_sexp_t list)
226 {
227 return _gcry_sexp_cadr (list);
228 }
229
230 const char *
gcry_sexp_nth_data(const gcry_sexp_t list,int number,size_t * datalen)231 gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen)
232 {
233 return _gcry_sexp_nth_data (list, number, datalen);
234 }
235
236 void *
gcry_sexp_nth_buffer(const gcry_sexp_t list,int number,size_t * rlength)237 gcry_sexp_nth_buffer (const gcry_sexp_t list, int number, size_t *rlength)
238 {
239 return _gcry_sexp_nth_buffer (list, number, rlength);
240 }
241
242 char *
gcry_sexp_nth_string(gcry_sexp_t list,int number)243 gcry_sexp_nth_string (gcry_sexp_t list, int number)
244 {
245 return _gcry_sexp_nth_string (list, number);
246 }
247
248 gcry_mpi_t
gcry_sexp_nth_mpi(gcry_sexp_t list,int number,int mpifmt)249 gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt)
250 {
251 return _gcry_sexp_nth_mpi (list, number, mpifmt);
252 }
253
254 gpg_error_t
gcry_sexp_extract_param(gcry_sexp_t sexp,const char * path,const char * list,...)255 gcry_sexp_extract_param (gcry_sexp_t sexp, const char *path,
256 const char *list, ...)
257 {
258 gcry_err_code_t rc;
259 va_list arg_ptr;
260
261 va_start (arg_ptr, list);
262 rc = _gcry_sexp_vextract_param (sexp, path, list, arg_ptr);
263 va_end (arg_ptr);
264 return gpg_error (rc);
265 }
266
267
268
269 gcry_mpi_t
gcry_mpi_new(unsigned int nbits)270 gcry_mpi_new (unsigned int nbits)
271 {
272 return _gcry_mpi_new (nbits);
273 }
274
275 gcry_mpi_t
gcry_mpi_snew(unsigned int nbits)276 gcry_mpi_snew (unsigned int nbits)
277 {
278 return _gcry_mpi_snew (nbits);
279 }
280
281 void
gcry_mpi_release(gcry_mpi_t a)282 gcry_mpi_release (gcry_mpi_t a)
283 {
284 _gcry_mpi_release (a);
285 }
286
287 gcry_mpi_t
gcry_mpi_copy(const gcry_mpi_t a)288 gcry_mpi_copy (const gcry_mpi_t a)
289 {
290 return _gcry_mpi_copy (a);
291 }
292
293 void
gcry_mpi_snatch(gcry_mpi_t w,const gcry_mpi_t u)294 gcry_mpi_snatch (gcry_mpi_t w, const gcry_mpi_t u)
295 {
296 _gcry_mpi_snatch (w, u);
297 }
298
299 gcry_mpi_t
gcry_mpi_set(gcry_mpi_t w,const gcry_mpi_t u)300 gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u)
301 {
302 return _gcry_mpi_set (w, u);
303 }
304
305 gcry_mpi_t
gcry_mpi_set_ui(gcry_mpi_t w,unsigned long u)306 gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u)
307 {
308 return _gcry_mpi_set_ui (w, u);
309 }
310
311 gcry_error_t
gcry_mpi_get_ui(unsigned int * w,gcry_mpi_t u)312 gcry_mpi_get_ui (unsigned int *w, gcry_mpi_t u)
313 {
314 return gpg_error (_gcry_mpi_get_ui (w, u));
315 }
316
317 void
gcry_mpi_swap(gcry_mpi_t a,gcry_mpi_t b)318 gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b)
319 {
320 _gcry_mpi_swap (a, b);
321 }
322
323 int
gcry_mpi_is_neg(gcry_mpi_t a)324 gcry_mpi_is_neg (gcry_mpi_t a)
325 {
326 return _gcry_mpi_is_neg (a);
327 }
328
329 void
gcry_mpi_neg(gcry_mpi_t w,gcry_mpi_t u)330 gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u)
331 {
332 _gcry_mpi_neg (w, u);
333 }
334
335 void
gcry_mpi_abs(gcry_mpi_t w)336 gcry_mpi_abs (gcry_mpi_t w)
337 {
338 _gcry_mpi_abs (w);
339 }
340
341 int
gcry_mpi_cmp(const gcry_mpi_t u,const gcry_mpi_t v)342 gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v)
343 {
344 return _gcry_mpi_cmp (u, v);
345 }
346
347 int
gcry_mpi_cmp_ui(const gcry_mpi_t u,unsigned long v)348 gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v)
349 {
350 return _gcry_mpi_cmp_ui (u, v);
351 }
352
353 gcry_error_t
gcry_mpi_scan(gcry_mpi_t * ret_mpi,enum gcry_mpi_format format,const void * buffer,size_t buflen,size_t * nscanned)354 gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format,
355 const void *buffer, size_t buflen,
356 size_t *nscanned)
357 {
358 return gpg_error (_gcry_mpi_scan (ret_mpi, format, buffer, buflen, nscanned));
359 }
360
361 gcry_error_t
gcry_mpi_print(enum gcry_mpi_format format,unsigned char * buffer,size_t buflen,size_t * nwritten,const gcry_mpi_t a)362 gcry_mpi_print (enum gcry_mpi_format format,
363 unsigned char *buffer, size_t buflen,
364 size_t *nwritten,
365 const gcry_mpi_t a)
366 {
367 return gpg_error (_gcry_mpi_print (format, buffer, buflen, nwritten, a));
368 }
369
370 gcry_error_t
gcry_mpi_aprint(enum gcry_mpi_format format,unsigned char ** buffer,size_t * nwritten,const gcry_mpi_t a)371 gcry_mpi_aprint (enum gcry_mpi_format format,
372 unsigned char **buffer, size_t *nwritten,
373 const gcry_mpi_t a)
374 {
375 return gpg_error (_gcry_mpi_aprint (format, buffer, nwritten, a));
376 }
377
378 void
gcry_mpi_dump(const gcry_mpi_t a)379 gcry_mpi_dump (const gcry_mpi_t a)
380 {
381 _gcry_log_printmpi (NULL, a);
382 }
383
384 void
gcry_mpi_add(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v)385 gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
386 {
387 _gcry_mpi_add (w, u, v);
388 }
389
390 void
gcry_mpi_add_ui(gcry_mpi_t w,gcry_mpi_t u,unsigned long v)391 gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v)
392 {
393 _gcry_mpi_add_ui (w, u, v);
394 }
395
396 void
gcry_mpi_addm(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v,gcry_mpi_t m)397 gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
398 {
399 _gcry_mpi_addm (w, u, v, m);
400 }
401
402 void
gcry_mpi_sub(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v)403 gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
404 {
405 _gcry_mpi_sub (w, u, v);
406 }
407
408 void
gcry_mpi_sub_ui(gcry_mpi_t w,gcry_mpi_t u,unsigned long v)409 gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
410 {
411 _gcry_mpi_sub_ui (w, u, v);
412 }
413
414 void
gcry_mpi_subm(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v,gcry_mpi_t m)415 gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
416 {
417 _gcry_mpi_subm (w, u, v, m);
418 }
419
420 void
gcry_mpi_mul(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v)421 gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v)
422 {
423 _gcry_mpi_mul (w, u, v);
424 }
425
426 void
gcry_mpi_mul_ui(gcry_mpi_t w,gcry_mpi_t u,unsigned long v)427 gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v )
428 {
429 _gcry_mpi_mul_ui (w, u, v);
430 }
431
432 void
gcry_mpi_mulm(gcry_mpi_t w,gcry_mpi_t u,gcry_mpi_t v,gcry_mpi_t m)433 gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
434 {
435 _gcry_mpi_mulm (w, u, v, m);
436 }
437
438 void
gcry_mpi_mul_2exp(gcry_mpi_t w,gcry_mpi_t u,unsigned long cnt)439 gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt)
440 {
441 _gcry_mpi_mul_2exp (w, u, cnt);
442 }
443
444 void
gcry_mpi_div(gcry_mpi_t q,gcry_mpi_t r,gcry_mpi_t dividend,gcry_mpi_t divisor,int round)445 gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r,
446 gcry_mpi_t dividend, gcry_mpi_t divisor, int round)
447 {
448 _gcry_mpi_div (q, r, dividend, divisor, round);
449 }
450
451 void
gcry_mpi_mod(gcry_mpi_t r,gcry_mpi_t dividend,gcry_mpi_t divisor)452 gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor)
453 {
454 _gcry_mpi_mod (r, dividend, divisor);
455 }
456
457 void
gcry_mpi_powm(gcry_mpi_t w,const gcry_mpi_t b,const gcry_mpi_t e,const gcry_mpi_t m)458 gcry_mpi_powm (gcry_mpi_t w, const gcry_mpi_t b, const gcry_mpi_t e,
459 const gcry_mpi_t m)
460 {
461 _gcry_mpi_powm (w, b, e, m);
462 }
463
464 int
gcry_mpi_gcd(gcry_mpi_t g,gcry_mpi_t a,gcry_mpi_t b)465 gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b)
466 {
467 return _gcry_mpi_gcd (g, a, b);
468 }
469
470 int
gcry_mpi_invm(gcry_mpi_t x,gcry_mpi_t a,gcry_mpi_t m)471 gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m)
472 {
473 return _gcry_mpi_invm (x, a, m);
474 }
475
476 gcry_mpi_point_t
gcry_mpi_point_new(unsigned int nbits)477 gcry_mpi_point_new (unsigned int nbits)
478 {
479 return _gcry_mpi_point_new (nbits);
480 }
481
482 void
gcry_mpi_point_release(gcry_mpi_point_t point)483 gcry_mpi_point_release (gcry_mpi_point_t point)
484 {
485 _gcry_mpi_point_release (point);
486 }
487
488 gcry_mpi_point_t
gcry_mpi_point_copy(gcry_mpi_point_t point)489 gcry_mpi_point_copy (gcry_mpi_point_t point)
490 {
491 return _gcry_mpi_point_copy (point);
492 }
493
494 void
gcry_mpi_point_get(gcry_mpi_t x,gcry_mpi_t y,gcry_mpi_t z,gcry_mpi_point_t point)495 gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
496 gcry_mpi_point_t point)
497 {
498 _gcry_mpi_point_get (x, y, z, point);
499 }
500
501 void
gcry_mpi_point_snatch_get(gcry_mpi_t x,gcry_mpi_t y,gcry_mpi_t z,gcry_mpi_point_t point)502 gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
503 gcry_mpi_point_t point)
504 {
505 _gcry_mpi_point_snatch_get (x, y, z, point);
506 }
507
508 gcry_mpi_point_t
gcry_mpi_point_set(gcry_mpi_point_t point,gcry_mpi_t x,gcry_mpi_t y,gcry_mpi_t z)509 gcry_mpi_point_set (gcry_mpi_point_t point,
510 gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
511 {
512 return _gcry_mpi_point_set (point, x, y, z);
513 }
514
515 gcry_mpi_point_t
gcry_mpi_point_snatch_set(gcry_mpi_point_t point,gcry_mpi_t x,gcry_mpi_t y,gcry_mpi_t z)516 gcry_mpi_point_snatch_set (gcry_mpi_point_t point,
517 gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z)
518 {
519 return _gcry_mpi_point_snatch_set (point, x, y, z);
520 }
521
522 gpg_error_t
gcry_mpi_ec_new(gcry_ctx_t * r_ctx,gcry_sexp_t keyparam,const char * curvename)523 gcry_mpi_ec_new (gcry_ctx_t *r_ctx,
524 gcry_sexp_t keyparam, const char *curvename)
525 {
526 return gpg_error (_gcry_mpi_ec_new (r_ctx, keyparam, curvename));
527 }
528
529 gcry_mpi_t
gcry_mpi_ec_get_mpi(const char * name,gcry_ctx_t ctx,int copy)530 gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy)
531 {
532 return _gcry_mpi_ec_get_mpi (name, ctx, copy);
533 }
534
535 gcry_mpi_point_t
gcry_mpi_ec_get_point(const char * name,gcry_ctx_t ctx,int copy)536 gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy)
537 {
538 return _gcry_mpi_ec_get_point (name, ctx, copy);
539 }
540
541 gpg_error_t
gcry_mpi_ec_set_mpi(const char * name,gcry_mpi_t newvalue,gcry_ctx_t ctx)542 gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, gcry_ctx_t ctx)
543 {
544 return gpg_error (_gcry_mpi_ec_set_mpi (name, newvalue, ctx));
545 }
546
547 gpg_error_t
gcry_mpi_ec_set_point(const char * name,gcry_mpi_point_t newvalue,gcry_ctx_t ctx)548 gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue,
549 gcry_ctx_t ctx)
550 {
551 return gpg_error (_gcry_mpi_ec_set_point (name, newvalue, ctx));
552 }
553
554 gpg_error_t
gcry_mpi_ec_decode_point(gcry_mpi_point_t result,gcry_mpi_t value,gcry_ctx_t ctx)555 gcry_mpi_ec_decode_point (gcry_mpi_point_t result, gcry_mpi_t value,
556 gcry_ctx_t ctx)
557 {
558 return gpg_error (_gcry_mpi_ec_decode_point
559 (result, value,
560 ctx? _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC) : NULL));
561 }
562
563 int
gcry_mpi_ec_get_affine(gcry_mpi_t x,gcry_mpi_t y,gcry_mpi_point_t point,gcry_ctx_t ctx)564 gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point,
565 gcry_ctx_t ctx)
566 {
567 return _gcry_mpi_ec_get_affine (x, y, point,
568 _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC));
569 }
570
571 void
gcry_mpi_ec_dup(gcry_mpi_point_t w,gcry_mpi_point_t u,gcry_ctx_t ctx)572 gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx)
573 {
574 mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC);
575
576 if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY)
577 {
578 mpi_point_resize (w, ec);
579 mpi_point_resize (u, ec);
580 }
581
582 _gcry_mpi_ec_dup_point (w, u, ec);
583 }
584
585 void
gcry_mpi_ec_add(gcry_mpi_point_t w,gcry_mpi_point_t u,gcry_mpi_point_t v,gcry_ctx_t ctx)586 gcry_mpi_ec_add (gcry_mpi_point_t w,
587 gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx)
588 {
589 mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC);
590
591 if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY)
592 {
593 mpi_point_resize (w, ec);
594 mpi_point_resize (u, ec);
595 mpi_point_resize (v, ec);
596 }
597
598 _gcry_mpi_ec_add_points (w, u, v, ec);
599 }
600
601 void
gcry_mpi_ec_sub(gcry_mpi_point_t w,gcry_mpi_point_t u,gcry_mpi_point_t v,gcry_ctx_t ctx)602 gcry_mpi_ec_sub (gcry_mpi_point_t w,
603 gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx)
604 {
605 mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC);
606
607 if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY)
608 {
609 mpi_point_resize (w, ec);
610 mpi_point_resize (u, ec);
611 mpi_point_resize (v, ec);
612 }
613
614 _gcry_mpi_ec_sub_points (w, u, v, ec);
615 }
616
617 void
gcry_mpi_ec_mul(gcry_mpi_point_t w,gcry_mpi_t n,gcry_mpi_point_t u,gcry_ctx_t ctx)618 gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u,
619 gcry_ctx_t ctx)
620 {
621 _gcry_mpi_ec_mul_point (w, n, u,
622 _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC));
623 }
624
625 int
gcry_mpi_ec_curve_point(gcry_mpi_point_t point,gcry_ctx_t ctx)626 gcry_mpi_ec_curve_point (gcry_mpi_point_t point, gcry_ctx_t ctx)
627 {
628 return _gcry_mpi_ec_curve_point
629 (point, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC));
630 }
631
632 unsigned int
gcry_mpi_get_nbits(gcry_mpi_t a)633 gcry_mpi_get_nbits (gcry_mpi_t a)
634 {
635 return _gcry_mpi_get_nbits (a);
636 }
637
638 int
gcry_mpi_test_bit(gcry_mpi_t a,unsigned int n)639 gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n)
640 {
641 return _gcry_mpi_test_bit (a, n);
642 }
643
644 void
gcry_mpi_set_bit(gcry_mpi_t a,unsigned int n)645 gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n)
646 {
647 _gcry_mpi_set_bit (a, n);
648 }
649
650 void
gcry_mpi_clear_bit(gcry_mpi_t a,unsigned int n)651 gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n)
652 {
653 _gcry_mpi_clear_bit (a, n);
654 }
655
656 void
gcry_mpi_set_highbit(gcry_mpi_t a,unsigned int n)657 gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n)
658 {
659 _gcry_mpi_set_highbit (a, n);
660 }
661
662 void
gcry_mpi_clear_highbit(gcry_mpi_t a,unsigned int n)663 gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n)
664 {
665 _gcry_mpi_clear_highbit (a, n);
666 }
667
668 void
gcry_mpi_rshift(gcry_mpi_t x,gcry_mpi_t a,unsigned int n)669 gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n)
670 {
671 _gcry_mpi_rshift (x, a, n);
672 }
673
674 void
gcry_mpi_lshift(gcry_mpi_t x,gcry_mpi_t a,unsigned int n)675 gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n)
676 {
677 _gcry_mpi_lshift (x, a, n);
678 }
679
680 gcry_mpi_t
gcry_mpi_set_opaque(gcry_mpi_t a,void * p,unsigned int nbits)681 gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits)
682 {
683 return _gcry_mpi_set_opaque (a, p, nbits);
684 }
685
686 gcry_mpi_t
gcry_mpi_set_opaque_copy(gcry_mpi_t a,const void * p,unsigned int nbits)687 gcry_mpi_set_opaque_copy (gcry_mpi_t a, const void *p, unsigned int nbits)
688 {
689 return _gcry_mpi_set_opaque_copy (a, p, nbits);
690 }
691
692 void *
gcry_mpi_get_opaque(gcry_mpi_t a,unsigned int * nbits)693 gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits)
694 {
695 return _gcry_mpi_get_opaque (a, nbits);
696 }
697
698 void
gcry_mpi_set_flag(gcry_mpi_t a,enum gcry_mpi_flag flag)699 gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
700 {
701 _gcry_mpi_set_flag (a, flag);
702 }
703
704 void
gcry_mpi_clear_flag(gcry_mpi_t a,enum gcry_mpi_flag flag)705 gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
706 {
707 _gcry_mpi_clear_flag (a, flag);
708 }
709
710 int
gcry_mpi_get_flag(gcry_mpi_t a,enum gcry_mpi_flag flag)711 gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
712 {
713 return _gcry_mpi_get_flag (a, flag);
714 }
715
716 gcry_mpi_t
_gcry_mpi_get_const(int no)717 _gcry_mpi_get_const (int no)
718 {
719 switch (no)
720 {
721 case 1: return _gcry_mpi_const (MPI_C_ONE);
722 case 2: return _gcry_mpi_const (MPI_C_TWO);
723 case 3: return _gcry_mpi_const (MPI_C_THREE);
724 case 4: return _gcry_mpi_const (MPI_C_FOUR);
725 case 8: return _gcry_mpi_const (MPI_C_EIGHT);
726 default: log_bug("unsupported GCRYMPI_CONST_ macro used\n");
727 }
728 }
729
730 gcry_error_t
gcry_cipher_open(gcry_cipher_hd_t * handle,int algo,int mode,unsigned int flags)731 gcry_cipher_open (gcry_cipher_hd_t *handle,
732 int algo, int mode, unsigned int flags)
733 {
734 if (!fips_is_operational ())
735 {
736 *handle = NULL;
737 return gpg_error (fips_not_operational ());
738 }
739
740 return gpg_error (_gcry_cipher_open (handle, algo, mode, flags));
741 }
742
743 void
gcry_cipher_close(gcry_cipher_hd_t h)744 gcry_cipher_close (gcry_cipher_hd_t h)
745 {
746 _gcry_cipher_close (h);
747 }
748
749 gcry_error_t
gcry_cipher_setkey(gcry_cipher_hd_t hd,const void * key,size_t keylen)750 gcry_cipher_setkey (gcry_cipher_hd_t hd, const void *key, size_t keylen)
751 {
752 if (!fips_is_operational ())
753 return gpg_error (fips_not_operational ());
754
755 return gcry_error (_gcry_cipher_setkey (hd, key, keylen));
756 }
757
758 gcry_error_t
gcry_cipher_setiv(gcry_cipher_hd_t hd,const void * iv,size_t ivlen)759 gcry_cipher_setiv (gcry_cipher_hd_t hd, const void *iv, size_t ivlen)
760 {
761 if (!fips_is_operational ())
762 return gpg_error (fips_not_operational ());
763
764 return gcry_error (_gcry_cipher_setiv (hd, iv, ivlen));
765 }
766
767 gpg_error_t
gcry_cipher_setctr(gcry_cipher_hd_t hd,const void * ctr,size_t ctrlen)768 gcry_cipher_setctr (gcry_cipher_hd_t hd, const void *ctr, size_t ctrlen)
769 {
770 if (!fips_is_operational ())
771 return gpg_error (fips_not_operational ());
772
773 return gcry_error (_gcry_cipher_setctr (hd, ctr, ctrlen));
774 }
775
776 gcry_error_t
gcry_cipher_authenticate(gcry_cipher_hd_t hd,const void * abuf,size_t abuflen)777 gcry_cipher_authenticate (gcry_cipher_hd_t hd, const void *abuf, size_t abuflen)
778 {
779 if (!fips_is_operational ())
780 return gpg_error (fips_not_operational ());
781
782 return gpg_error (_gcry_cipher_authenticate (hd, abuf, abuflen));
783 }
784
785 gcry_error_t
gcry_cipher_gettag(gcry_cipher_hd_t hd,void * outtag,size_t taglen)786 gcry_cipher_gettag (gcry_cipher_hd_t hd, void *outtag, size_t taglen)
787 {
788 if (!fips_is_operational ())
789 return gpg_error (fips_not_operational ());
790
791 return gpg_error (_gcry_cipher_gettag (hd, outtag, taglen));
792 }
793
794 gcry_error_t
gcry_cipher_checktag(gcry_cipher_hd_t hd,const void * intag,size_t taglen)795 gcry_cipher_checktag (gcry_cipher_hd_t hd, const void *intag, size_t taglen)
796 {
797 if (!fips_is_operational ())
798 return gpg_error (fips_not_operational ());
799
800 return gpg_error (_gcry_cipher_checktag (hd, intag, taglen));
801 }
802
803
804 gcry_error_t
gcry_cipher_ctl(gcry_cipher_hd_t h,int cmd,void * buffer,size_t buflen)805 gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen)
806 {
807 if (!fips_is_operational ())
808 return gpg_error (fips_not_operational ());
809
810 return gpg_error (_gcry_cipher_ctl (h, cmd, buffer, buflen));
811 }
812
813 gcry_error_t
gcry_cipher_info(gcry_cipher_hd_t h,int what,void * buffer,size_t * nbytes)814 gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer, size_t *nbytes)
815 {
816 return gpg_error (_gcry_cipher_info (h, what, buffer, nbytes));
817 }
818
819 gcry_error_t
gcry_cipher_algo_info(int algo,int what,void * buffer,size_t * nbytes)820 gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes)
821 {
822 if (!fips_is_operational ())
823 return gpg_error (fips_not_operational ());
824
825 return gpg_error (_gcry_cipher_algo_info (algo, what, buffer, nbytes));
826 }
827
828 const char *
gcry_cipher_algo_name(int algorithm)829 gcry_cipher_algo_name (int algorithm)
830 {
831 return _gcry_cipher_algo_name (algorithm);
832 }
833
834 int
gcry_cipher_map_name(const char * name)835 gcry_cipher_map_name (const char *name)
836 {
837 return _gcry_cipher_map_name (name);
838 }
839
840 int
gcry_cipher_mode_from_oid(const char * string)841 gcry_cipher_mode_from_oid (const char *string)
842 {
843 return _gcry_cipher_mode_from_oid (string);
844 }
845
846 gcry_error_t
gcry_cipher_encrypt(gcry_cipher_hd_t h,void * out,size_t outsize,const void * in,size_t inlen)847 gcry_cipher_encrypt (gcry_cipher_hd_t h,
848 void *out, size_t outsize,
849 const void *in, size_t inlen)
850 {
851 if (!fips_is_operational ())
852 {
853 /* Make sure that the plaintext will never make it to OUT. */
854 if (out)
855 memset (out, 0x42, outsize);
856 return gpg_error (fips_not_operational ());
857 }
858
859 return gpg_error (_gcry_cipher_encrypt (h, out, outsize, in, inlen));
860 }
861
862 gcry_error_t
gcry_cipher_decrypt(gcry_cipher_hd_t h,void * out,size_t outsize,const void * in,size_t inlen)863 gcry_cipher_decrypt (gcry_cipher_hd_t h,
864 void *out, size_t outsize,
865 const void *in, size_t inlen)
866 {
867 if (!fips_is_operational ())
868 return gpg_error (fips_not_operational ());
869
870 return gpg_error (_gcry_cipher_decrypt (h, out, outsize, in, inlen));
871 }
872
873 size_t
gcry_cipher_get_algo_keylen(int algo)874 gcry_cipher_get_algo_keylen (int algo)
875 {
876 return _gcry_cipher_get_algo_keylen (algo);
877 }
878
879 size_t
gcry_cipher_get_algo_blklen(int algo)880 gcry_cipher_get_algo_blklen (int algo)
881 {
882 return _gcry_cipher_get_algo_blklen (algo);
883 }
884
885 gcry_error_t
gcry_mac_algo_info(int algo,int what,void * buffer,size_t * nbytes)886 gcry_mac_algo_info (int algo, int what, void *buffer, size_t *nbytes)
887 {
888 if (!fips_is_operational ())
889 return gpg_error (fips_not_operational ());
890
891 return gpg_error (_gcry_mac_algo_info (algo, what, buffer, nbytes));
892 }
893
894 const char *
gcry_mac_algo_name(int algorithm)895 gcry_mac_algo_name (int algorithm)
896 {
897 return _gcry_mac_algo_name (algorithm);
898 }
899
900 int
gcry_mac_map_name(const char * string)901 gcry_mac_map_name (const char *string)
902 {
903 return _gcry_mac_map_name (string);
904 }
905
906 int
gcry_mac_get_algo(gcry_mac_hd_t hd)907 gcry_mac_get_algo (gcry_mac_hd_t hd)
908 {
909 return _gcry_mac_get_algo (hd);
910 }
911
912 unsigned int
gcry_mac_get_algo_maclen(int algo)913 gcry_mac_get_algo_maclen (int algo)
914 {
915 return _gcry_mac_get_algo_maclen (algo);
916 }
917
918 unsigned int
gcry_mac_get_algo_keylen(int algo)919 gcry_mac_get_algo_keylen (int algo)
920 {
921 return _gcry_mac_get_algo_keylen (algo);
922 }
923
924 gcry_error_t
gcry_mac_open(gcry_mac_hd_t * handle,int algo,unsigned int flags,gcry_ctx_t ctx)925 gcry_mac_open (gcry_mac_hd_t *handle, int algo, unsigned int flags,
926 gcry_ctx_t ctx)
927 {
928 if (!fips_is_operational ())
929 {
930 *handle = NULL;
931 return gpg_error (fips_not_operational ());
932 }
933
934 return gpg_error (_gcry_mac_open (handle, algo, flags, ctx));
935 }
936
937 void
gcry_mac_close(gcry_mac_hd_t hd)938 gcry_mac_close (gcry_mac_hd_t hd)
939 {
940 _gcry_mac_close (hd);
941 }
942
943 gcry_error_t
gcry_mac_setkey(gcry_mac_hd_t hd,const void * key,size_t keylen)944 gcry_mac_setkey (gcry_mac_hd_t hd, const void *key, size_t keylen)
945 {
946 if (!fips_is_operational ())
947 return gpg_error (fips_not_operational ());
948
949 return gpg_error (_gcry_mac_setkey (hd, key, keylen));
950 }
951
952 gcry_error_t
gcry_mac_setiv(gcry_mac_hd_t hd,const void * iv,size_t ivlen)953 gcry_mac_setiv (gcry_mac_hd_t hd, const void *iv, size_t ivlen)
954 {
955 if (!fips_is_operational ())
956 return gpg_error (fips_not_operational ());
957
958 return gpg_error (_gcry_mac_setiv (hd, iv, ivlen));
959 }
960
961 gcry_error_t
gcry_mac_write(gcry_mac_hd_t hd,const void * buf,size_t buflen)962 gcry_mac_write (gcry_mac_hd_t hd, const void *buf, size_t buflen)
963 {
964 if (!fips_is_operational ())
965 return gpg_error (fips_not_operational ());
966
967 return gpg_error (_gcry_mac_write (hd, buf, buflen));
968 }
969
970 gcry_error_t
gcry_mac_read(gcry_mac_hd_t hd,void * outbuf,size_t * outlen)971 gcry_mac_read (gcry_mac_hd_t hd, void *outbuf, size_t *outlen)
972 {
973 if (!fips_is_operational ())
974 return gpg_error (fips_not_operational ());
975
976 return gpg_error (_gcry_mac_read (hd, outbuf, outlen));
977 }
978
979 gcry_error_t
gcry_mac_verify(gcry_mac_hd_t hd,const void * buf,size_t buflen)980 gcry_mac_verify (gcry_mac_hd_t hd, const void *buf, size_t buflen)
981 {
982 if (!fips_is_operational ())
983 return gpg_error (fips_not_operational ());
984
985 return gpg_error (_gcry_mac_verify (hd, buf, buflen));
986 }
987
988 gcry_error_t
gcry_mac_ctl(gcry_mac_hd_t h,int cmd,void * buffer,size_t buflen)989 gcry_mac_ctl (gcry_mac_hd_t h, int cmd, void *buffer, size_t buflen)
990 {
991 if (!fips_is_operational ())
992 return gpg_error (fips_not_operational ());
993
994 return gpg_error (_gcry_mac_ctl (h, cmd, buffer, buflen));
995 }
996
997 gcry_error_t
gcry_pk_encrypt(gcry_sexp_t * result,gcry_sexp_t data,gcry_sexp_t pkey)998 gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey)
999 {
1000 if (!fips_is_operational ())
1001 {
1002 *result = NULL;
1003 return gpg_error (fips_not_operational ());
1004 }
1005 return gpg_error (_gcry_pk_encrypt (result, data, pkey));
1006 }
1007
1008 gcry_error_t
gcry_pk_decrypt(gcry_sexp_t * result,gcry_sexp_t data,gcry_sexp_t skey)1009 gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey)
1010 {
1011 if (!fips_is_operational ())
1012 {
1013 *result = NULL;
1014 return gpg_error (fips_not_operational ());
1015 }
1016 return gpg_error (_gcry_pk_decrypt (result, data, skey));
1017 }
1018
1019 gcry_error_t
gcry_pk_sign(gcry_sexp_t * result,gcry_sexp_t data,gcry_sexp_t skey)1020 gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey)
1021 {
1022 if (!fips_is_operational ())
1023 {
1024 *result = NULL;
1025 return gpg_error (fips_not_operational ());
1026 }
1027 return gpg_error (_gcry_pk_sign (result, data, skey));
1028 }
1029
1030 gcry_error_t
gcry_pk_verify(gcry_sexp_t sigval,gcry_sexp_t data,gcry_sexp_t pkey)1031 gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey)
1032 {
1033 if (!fips_is_operational ())
1034 return gpg_error (fips_not_operational ());
1035 return gpg_error (_gcry_pk_verify (sigval, data, pkey));
1036 }
1037
1038 gcry_error_t
gcry_pk_testkey(gcry_sexp_t key)1039 gcry_pk_testkey (gcry_sexp_t key)
1040 {
1041 if (!fips_is_operational ())
1042 return gpg_error (fips_not_operational ());
1043 return gpg_error (_gcry_pk_testkey (key));
1044 }
1045
1046 gcry_error_t
gcry_pk_genkey(gcry_sexp_t * r_key,gcry_sexp_t s_parms)1047 gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
1048 {
1049 if (!fips_is_operational ())
1050 {
1051 *r_key = NULL;
1052 return gpg_error (fips_not_operational ());
1053 }
1054 return gpg_error (_gcry_pk_genkey (r_key, s_parms));
1055 }
1056
1057 gcry_error_t
gcry_pk_ctl(int cmd,void * buffer,size_t buflen)1058 gcry_pk_ctl (int cmd, void *buffer, size_t buflen)
1059 {
1060 return gpg_error (_gcry_pk_ctl (cmd, buffer, buflen));
1061 }
1062
1063 gcry_error_t
gcry_pk_algo_info(int algo,int what,void * buffer,size_t * nbytes)1064 gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes)
1065 {
1066 if (!fips_is_operational ())
1067 return gpg_error (fips_not_operational ());
1068
1069 return gpg_error (_gcry_pk_algo_info (algo, what, buffer, nbytes));
1070 }
1071
1072 const char *
gcry_pk_algo_name(int algorithm)1073 gcry_pk_algo_name (int algorithm)
1074 {
1075 return _gcry_pk_algo_name (algorithm);
1076 }
1077
1078 int
gcry_pk_map_name(const char * name)1079 gcry_pk_map_name (const char *name)
1080 {
1081 return _gcry_pk_map_name (name);
1082 }
1083
1084 unsigned int
gcry_pk_get_nbits(gcry_sexp_t key)1085 gcry_pk_get_nbits (gcry_sexp_t key)
1086 {
1087 if (!fips_is_operational ())
1088 {
1089 (void)fips_not_operational ();
1090 return 0;
1091 }
1092
1093 return _gcry_pk_get_nbits (key);
1094 }
1095
1096 unsigned char *
gcry_pk_get_keygrip(gcry_sexp_t key,unsigned char * array)1097 gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
1098 {
1099 if (!fips_is_operational ())
1100 {
1101 (void)fips_not_operational ();
1102 return NULL;
1103 }
1104 return _gcry_pk_get_keygrip (key, array);
1105 }
1106
1107 const char *
gcry_pk_get_curve(gcry_sexp_t key,int iterator,unsigned int * r_nbits)1108 gcry_pk_get_curve (gcry_sexp_t key, int iterator, unsigned int *r_nbits)
1109 {
1110 if (!fips_is_operational ())
1111 {
1112 (void)fips_not_operational ();
1113 return NULL;
1114 }
1115 return _gcry_pk_get_curve (key, iterator, r_nbits);
1116 }
1117
1118 gcry_sexp_t
gcry_pk_get_param(int algo,const char * name)1119 gcry_pk_get_param (int algo, const char *name)
1120 {
1121 if (!fips_is_operational ())
1122 {
1123 (void)fips_not_operational ();
1124 return NULL;
1125 }
1126 return _gcry_pk_get_param (algo, name);
1127 }
1128
1129 gcry_error_t
gcry_pubkey_get_sexp(gcry_sexp_t * r_sexp,int mode,gcry_ctx_t ctx)1130 gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp, int mode, gcry_ctx_t ctx)
1131 {
1132 if (!fips_is_operational ())
1133 {
1134 *r_sexp = NULL;
1135 return gpg_error (fips_not_operational ());
1136 }
1137 return gpg_error (_gcry_pubkey_get_sexp (r_sexp, mode, ctx));
1138 }
1139
1140 unsigned int
gcry_ecc_get_algo_keylen(int curveid)1141 gcry_ecc_get_algo_keylen (int curveid)
1142 {
1143 return _gcry_ecc_get_algo_keylen (curveid);
1144 }
1145
1146 gpg_error_t
gcry_ecc_mul_point(int curveid,unsigned char * result,const unsigned char * scalar,const unsigned char * point)1147 gcry_ecc_mul_point (int curveid, unsigned char *result,
1148 const unsigned char *scalar, const unsigned char *point)
1149 {
1150 return _gcry_ecc_mul_point (curveid, result, scalar, point);
1151 }
1152
1153 gcry_error_t
gcry_md_open(gcry_md_hd_t * h,int algo,unsigned int flags)1154 gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
1155 {
1156 if (!fips_is_operational ())
1157 {
1158 *h = NULL;
1159 return gpg_error (fips_not_operational ());
1160 }
1161
1162 return gpg_error (_gcry_md_open (h, algo, flags));
1163 }
1164
1165 void
gcry_md_close(gcry_md_hd_t hd)1166 gcry_md_close (gcry_md_hd_t hd)
1167 {
1168 _gcry_md_close (hd);
1169 }
1170
1171 gcry_error_t
gcry_md_enable(gcry_md_hd_t hd,int algo)1172 gcry_md_enable (gcry_md_hd_t hd, int algo)
1173 {
1174 if (!fips_is_operational ())
1175 return gpg_error (fips_not_operational ());
1176 return gpg_error (_gcry_md_enable (hd, algo));
1177 }
1178
1179 gcry_error_t
gcry_md_copy(gcry_md_hd_t * bhd,gcry_md_hd_t ahd)1180 gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd)
1181 {
1182 if (!fips_is_operational ())
1183 {
1184 *bhd = NULL;
1185 return gpg_error (fips_not_operational ());
1186 }
1187 return gpg_error (_gcry_md_copy (bhd, ahd));
1188 }
1189
1190 void
gcry_md_reset(gcry_md_hd_t hd)1191 gcry_md_reset (gcry_md_hd_t hd)
1192 {
1193 _gcry_md_reset (hd);
1194 }
1195
1196 gcry_error_t
gcry_md_ctl(gcry_md_hd_t hd,int cmd,void * buffer,size_t buflen)1197 gcry_md_ctl (gcry_md_hd_t hd, int cmd, void *buffer, size_t buflen)
1198 {
1199 if (!fips_is_operational ())
1200 return gpg_error (fips_not_operational ());
1201 return gpg_error (_gcry_md_ctl (hd, cmd, buffer, buflen));
1202 }
1203
1204 void
gcry_md_write(gcry_md_hd_t hd,const void * buffer,size_t length)1205 gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length)
1206 {
1207 if (!fips_is_operational ())
1208 {
1209 (void)fips_not_operational ();
1210 return;
1211 }
1212 _gcry_md_write (hd, buffer, length);
1213 }
1214
1215 unsigned char *
gcry_md_read(gcry_md_hd_t hd,int algo)1216 gcry_md_read (gcry_md_hd_t hd, int algo)
1217 {
1218 return _gcry_md_read (hd, algo);
1219 }
1220
1221 gcry_error_t
gcry_md_extract(gcry_md_hd_t hd,int algo,void * buffer,size_t length)1222 gcry_md_extract (gcry_md_hd_t hd, int algo, void *buffer, size_t length)
1223 {
1224 return gpg_error (_gcry_md_extract(hd, algo, buffer, length));
1225 }
1226
1227 void
gcry_md_hash_buffer(int algo,void * digest,const void * buffer,size_t length)1228 gcry_md_hash_buffer (int algo, void *digest,
1229 const void *buffer, size_t length)
1230 {
1231 if (!fips_is_operational ())
1232 {
1233 (void)fips_not_operational ();
1234 fips_signal_error ("called in non-operational state");
1235 }
1236 _gcry_md_hash_buffer (algo, digest, buffer, length);
1237 }
1238
1239 gpg_error_t
gcry_md_hash_buffers(int algo,unsigned int flags,void * digest,const gcry_buffer_t * iov,int iovcnt)1240 gcry_md_hash_buffers (int algo, unsigned int flags, void *digest,
1241 const gcry_buffer_t *iov, int iovcnt)
1242 {
1243 if (!fips_is_operational ())
1244 {
1245 (void)fips_not_operational ();
1246 fips_signal_error ("called in non-operational state");
1247 }
1248 return gpg_error (_gcry_md_hash_buffers (algo, flags, digest, iov, iovcnt));
1249 }
1250
1251 int
gcry_md_get_algo(gcry_md_hd_t hd)1252 gcry_md_get_algo (gcry_md_hd_t hd)
1253 {
1254 if (!fips_is_operational ())
1255 {
1256 (void)fips_not_operational ();
1257 fips_signal_error ("used in non-operational state");
1258 return 0;
1259 }
1260 return _gcry_md_get_algo (hd);
1261 }
1262
1263 unsigned int
gcry_md_get_algo_dlen(int algo)1264 gcry_md_get_algo_dlen (int algo)
1265 {
1266 return _gcry_md_get_algo_dlen (algo);
1267 }
1268
1269 int
gcry_md_is_enabled(gcry_md_hd_t a,int algo)1270 gcry_md_is_enabled (gcry_md_hd_t a, int algo)
1271 {
1272 if (!fips_is_operational ())
1273 {
1274 (void)fips_not_operational ();
1275 return 0;
1276 }
1277
1278 return _gcry_md_is_enabled (a, algo);
1279 }
1280
1281 int
gcry_md_is_secure(gcry_md_hd_t a)1282 gcry_md_is_secure (gcry_md_hd_t a)
1283 {
1284 return _gcry_md_is_secure (a);
1285 }
1286
1287 gcry_error_t
gcry_md_info(gcry_md_hd_t h,int what,void * buffer,size_t * nbytes)1288 gcry_md_info (gcry_md_hd_t h, int what, void *buffer, size_t *nbytes)
1289 {
1290 if (!fips_is_operational ())
1291 return gpg_error (fips_not_operational ());
1292
1293 return gpg_error (_gcry_md_info (h, what, buffer, nbytes));
1294 }
1295
1296 gcry_error_t
gcry_md_algo_info(int algo,int what,void * buffer,size_t * nbytes)1297 gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes)
1298 {
1299 return gpg_error (_gcry_md_algo_info (algo, what, buffer, nbytes));
1300 }
1301
1302 const char *
gcry_md_algo_name(int algo)1303 gcry_md_algo_name (int algo)
1304 {
1305 return _gcry_md_algo_name (algo);
1306 }
1307
1308 int
gcry_md_map_name(const char * name)1309 gcry_md_map_name (const char* name)
1310 {
1311 return _gcry_md_map_name (name);
1312 }
1313
1314 gcry_error_t
gcry_md_setkey(gcry_md_hd_t hd,const void * key,size_t keylen)1315 gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen)
1316 {
1317 if (!fips_is_operational ())
1318 return gpg_error (fips_not_operational ());
1319 return gpg_error (_gcry_md_setkey (hd, key, keylen));
1320 }
1321
1322 void
gcry_md_debug(gcry_md_hd_t hd,const char * suffix)1323 gcry_md_debug (gcry_md_hd_t hd, const char *suffix)
1324 {
1325 _gcry_md_debug (hd, suffix);
1326 }
1327
1328 gpg_error_t
gcry_kdf_derive(const void * passphrase,size_t passphraselen,int algo,int hashalgo,const void * salt,size_t saltlen,unsigned long iterations,size_t keysize,void * keybuffer)1329 gcry_kdf_derive (const void *passphrase, size_t passphraselen,
1330 int algo, int hashalgo,
1331 const void *salt, size_t saltlen,
1332 unsigned long iterations,
1333 size_t keysize, void *keybuffer)
1334 {
1335 if (!fips_is_operational ())
1336 return gpg_error (fips_not_operational ());
1337 return gpg_error (_gcry_kdf_derive (passphrase, passphraselen, algo, hashalgo,
1338 salt, saltlen, iterations,
1339 keysize, keybuffer));
1340 }
1341
1342 void
gcry_randomize(void * buffer,size_t length,enum gcry_random_level level)1343 gcry_randomize (void *buffer, size_t length, enum gcry_random_level level)
1344 {
1345 if (!fips_is_operational ())
1346 {
1347 (void)fips_not_operational ();
1348 fips_signal_fatal_error ("called in non-operational state");
1349 fips_noreturn ();
1350 }
1351 _gcry_randomize (buffer, length, level);
1352 }
1353
1354 gcry_error_t
gcry_random_add_bytes(const void * buffer,size_t length,int quality)1355 gcry_random_add_bytes (const void *buffer, size_t length, int quality)
1356 {
1357 if (!fips_is_operational ())
1358 return gpg_error (fips_not_operational ());
1359 return gpg_error (_gcry_random_add_bytes (buffer, length, quality));
1360 }
1361
1362 void *
gcry_random_bytes(size_t nbytes,enum gcry_random_level level)1363 gcry_random_bytes (size_t nbytes, enum gcry_random_level level)
1364 {
1365 if (!fips_is_operational ())
1366 {
1367 (void)fips_not_operational ();
1368 fips_signal_fatal_error ("called in non-operational state");
1369 fips_noreturn ();
1370 }
1371
1372 return _gcry_random_bytes (nbytes,level);
1373 }
1374
1375 void *
gcry_random_bytes_secure(size_t nbytes,enum gcry_random_level level)1376 gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
1377 {
1378 if (!fips_is_operational ())
1379 {
1380 (void)fips_not_operational ();
1381 fips_signal_fatal_error ("called in non-operational state");
1382 fips_noreturn ();
1383 }
1384
1385 return _gcry_random_bytes_secure (nbytes, level);
1386 }
1387
1388 void
gcry_mpi_randomize(gcry_mpi_t w,unsigned int nbits,enum gcry_random_level level)1389 gcry_mpi_randomize (gcry_mpi_t w,
1390 unsigned int nbits, enum gcry_random_level level)
1391 {
1392 if (!fips_is_operational ())
1393 {
1394 (void)fips_not_operational ();
1395 fips_signal_fatal_error ("called in non-operational state");
1396 fips_noreturn ();
1397 }
1398
1399 _gcry_mpi_randomize (w, nbits, level);
1400 }
1401
1402 void
gcry_create_nonce(void * buffer,size_t length)1403 gcry_create_nonce (void *buffer, size_t length)
1404 {
1405 if (!fips_is_operational ())
1406 {
1407 (void)fips_not_operational ();
1408 fips_signal_fatal_error ("called in non-operational state");
1409 fips_noreturn ();
1410 }
1411 _gcry_create_nonce (buffer, length);
1412 }
1413
1414 gcry_error_t
gcry_prime_generate(gcry_mpi_t * prime,unsigned int prime_bits,unsigned int factor_bits,gcry_mpi_t ** factors,gcry_prime_check_func_t cb_func,void * cb_arg,gcry_random_level_t random_level,unsigned int flags)1415 gcry_prime_generate (gcry_mpi_t *prime,
1416 unsigned int prime_bits,
1417 unsigned int factor_bits,
1418 gcry_mpi_t **factors,
1419 gcry_prime_check_func_t cb_func,
1420 void *cb_arg,
1421 gcry_random_level_t random_level,
1422 unsigned int flags)
1423 {
1424 if (!fips_is_operational ())
1425 return gpg_error (fips_not_operational ());
1426 return gpg_error (_gcry_prime_generate (prime, prime_bits, factor_bits,
1427 factors, cb_func, cb_arg,
1428 random_level, flags));
1429 }
1430
1431 gcry_error_t
gcry_prime_group_generator(gcry_mpi_t * r_g,gcry_mpi_t prime,gcry_mpi_t * factors,gcry_mpi_t start_g)1432 gcry_prime_group_generator (gcry_mpi_t *r_g,
1433 gcry_mpi_t prime, gcry_mpi_t *factors,
1434 gcry_mpi_t start_g)
1435 {
1436 if (!fips_is_operational ())
1437 return gpg_error (fips_not_operational ());
1438 return gpg_error (_gcry_prime_group_generator (r_g, prime, factors, start_g));
1439 }
1440
1441 void
gcry_prime_release_factors(gcry_mpi_t * factors)1442 gcry_prime_release_factors (gcry_mpi_t *factors)
1443 {
1444 _gcry_prime_release_factors (factors);
1445 }
1446
1447 gcry_error_t
gcry_prime_check(gcry_mpi_t x,unsigned int flags)1448 gcry_prime_check (gcry_mpi_t x, unsigned int flags)
1449 {
1450 return gpg_error (_gcry_prime_check (x, flags));
1451 }
1452
1453 void
gcry_ctx_release(gcry_ctx_t ctx)1454 gcry_ctx_release (gcry_ctx_t ctx)
1455 {
1456 _gcry_ctx_release (ctx);
1457 }
1458
1459 void
gcry_log_debug(const char * fmt,...)1460 gcry_log_debug (const char *fmt, ...)
1461 {
1462 va_list arg_ptr ;
1463
1464 va_start( arg_ptr, fmt ) ;
1465 _gcry_logv (GCRY_LOG_DEBUG, fmt, arg_ptr);
1466 va_end (arg_ptr);
1467 }
1468
1469 void
gcry_log_debughex(const char * text,const void * buffer,size_t length)1470 gcry_log_debughex (const char *text, const void *buffer, size_t length)
1471 {
1472 _gcry_log_printhex (text, buffer, length);
1473 }
1474
1475 void
gcry_log_debugmpi(const char * text,gcry_mpi_t mpi)1476 gcry_log_debugmpi (const char *text, gcry_mpi_t mpi)
1477 {
1478 _gcry_log_printmpi (text, mpi);
1479 }
1480
1481 void
gcry_log_debugpnt(const char * text,mpi_point_t point,gcry_ctx_t ctx)1482 gcry_log_debugpnt (const char *text, mpi_point_t point, gcry_ctx_t ctx)
1483 {
1484 mpi_ec_t ec = ctx? _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC) : NULL;
1485
1486 _gcry_mpi_point_log (text, point, ec);
1487 }
1488
1489 void
gcry_log_debugsxp(const char * text,gcry_sexp_t sexp)1490 gcry_log_debugsxp (const char *text, gcry_sexp_t sexp)
1491 {
1492 _gcry_log_printsxp (text, sexp);
1493 }
1494
1495 char *
gcry_get_config(int mode,const char * what)1496 gcry_get_config (int mode, const char *what)
1497 {
1498 return _gcry_get_config (mode, what);
1499 }
1500
1501 void
gcry_set_progress_handler(gcry_handler_progress_t cb,void * cb_data)1502 gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data)
1503 {
1504 _gcry_set_progress_handler (cb, cb_data);
1505 }
1506
1507 void
gcry_set_allocation_handler(gcry_handler_alloc_t func_alloc,gcry_handler_alloc_t func_alloc_secure,gcry_handler_secure_check_t func_secure_check,gcry_handler_realloc_t func_realloc,gcry_handler_free_t func_free)1508 gcry_set_allocation_handler (gcry_handler_alloc_t func_alloc,
1509 gcry_handler_alloc_t func_alloc_secure,
1510 gcry_handler_secure_check_t func_secure_check,
1511 gcry_handler_realloc_t func_realloc,
1512 gcry_handler_free_t func_free)
1513 {
1514 _gcry_set_allocation_handler (func_alloc, func_alloc_secure,
1515 func_secure_check, func_realloc, func_free);
1516 }
1517
1518 void
gcry_set_outofcore_handler(gcry_handler_no_mem_t h,void * opaque)1519 gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque)
1520 {
1521 _gcry_set_outofcore_handler (h, opaque);
1522 }
1523
1524 void
gcry_set_fatalerror_handler(gcry_handler_error_t fnc,void * opaque)1525 gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque)
1526 {
1527 _gcry_set_fatalerror_handler (fnc, opaque);
1528 }
1529
1530 void
gcry_set_log_handler(gcry_handler_log_t f,void * opaque)1531 gcry_set_log_handler (gcry_handler_log_t f, void *opaque)
1532 {
1533 _gcry_set_log_handler (f, opaque);
1534 }
1535
1536 void
gcry_set_gettext_handler(const char * (* f)(const char *))1537 gcry_set_gettext_handler (const char *(*f)(const char*))
1538 {
1539 _gcry_set_gettext_handler (f);
1540 }
1541
1542 void *
gcry_malloc(size_t n)1543 gcry_malloc (size_t n)
1544 {
1545 return _gcry_malloc (n);
1546 }
1547
1548 void *
gcry_calloc(size_t n,size_t m)1549 gcry_calloc (size_t n, size_t m)
1550 {
1551 return _gcry_calloc (n, m);
1552 }
1553
1554 void *
gcry_malloc_secure(size_t n)1555 gcry_malloc_secure (size_t n)
1556 {
1557 return _gcry_malloc_secure (n);
1558 }
1559
1560 void *
gcry_calloc_secure(size_t n,size_t m)1561 gcry_calloc_secure (size_t n, size_t m)
1562 {
1563 return _gcry_calloc_secure (n,m);
1564 }
1565
1566 void *
gcry_realloc(void * a,size_t n)1567 gcry_realloc (void *a, size_t n)
1568 {
1569 return _gcry_realloc (a, n);
1570 }
1571
1572 char *
gcry_strdup(const char * string)1573 gcry_strdup (const char *string)
1574 {
1575 return _gcry_strdup (string);
1576 }
1577
1578 void *
gcry_xmalloc(size_t n)1579 gcry_xmalloc (size_t n)
1580 {
1581 return _gcry_xmalloc (n);
1582 }
1583
1584 void *
gcry_xcalloc(size_t n,size_t m)1585 gcry_xcalloc (size_t n, size_t m)
1586 {
1587 return _gcry_xcalloc (n, m);
1588 }
1589
1590 void *
gcry_xmalloc_secure(size_t n)1591 gcry_xmalloc_secure (size_t n)
1592 {
1593 return _gcry_xmalloc_secure (n);
1594 }
1595
1596 void *
gcry_xcalloc_secure(size_t n,size_t m)1597 gcry_xcalloc_secure (size_t n, size_t m)
1598 {
1599 return _gcry_xcalloc_secure (n, m);
1600 }
1601
1602 void *
gcry_xrealloc(void * a,size_t n)1603 gcry_xrealloc (void *a, size_t n)
1604 {
1605 return _gcry_xrealloc (a, n);
1606 }
1607
1608 char *
gcry_xstrdup(const char * a)1609 gcry_xstrdup (const char *a)
1610 {
1611 return _gcry_xstrdup (a);
1612 }
1613
1614 void
gcry_free(void * a)1615 gcry_free (void *a)
1616 {
1617 _gcry_free (a);
1618 }
1619
1620 int
gcry_is_secure(const void * a)1621 gcry_is_secure (const void *a)
1622 {
1623 return _gcry_is_secure (a);
1624 }
1625