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