Line data Source code
1 : /* gcrypt-int.h - Internal version of gcrypt.h
2 : * Copyright (C) 2013 g10 Code GmbH
3 : *
4 : * This file is part of Libgcrypt.
5 : *
6 : * Libgcrypt is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU Lesser General Public License as
8 : * published by the Free Software Foundation; either version 2.1 of
9 : * the License, or (at your option) any later version.
10 : *
11 : * Libgcrypt is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU Lesser General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public
17 : * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #ifndef GCRY_GCRYPT_INT_H
21 : #define GCRY_GCRYPT_INT_H
22 :
23 : #ifdef _GCRYPT_H
24 : #error gcrypt.h already included
25 : #endif
26 :
27 : #include "gcrypt.h"
28 : #include "types.h"
29 :
30 : /* These error codes are used but not defined in the required
31 : libgpg-error 1.11. Define them here. */
32 : #if GPG_ERROR_VERSION_NUMBER < 0x010c00 /* 1.12 */
33 : # define GPG_ERR_NO_CRYPT_CTX 191
34 : # define GPG_ERR_WRONG_CRYPT_CTX 192
35 : # define GPG_ERR_BAD_CRYPT_CTX 193
36 : # define GPG_ERR_CRYPT_CTX_CONFLICT 194
37 : # define GPG_ERR_BROKEN_PUBKEY 195
38 : # define GPG_ERR_BROKEN_SECKEY 196
39 : #endif
40 :
41 : #if GPG_ERROR_VERSION_NUMBER < 0x010d00 /* 1.13 */
42 : # define GPG_ERR_MAC_ALGO 197
43 : #endif
44 :
45 :
46 : /* Context used with elliptic curve functions. */
47 : struct mpi_ec_ctx_s;
48 : typedef struct mpi_ec_ctx_s *mpi_ec_t;
49 :
50 :
51 :
52 : /* Underscore prefixed internal versions of the public functions.
53 : They return gpg_err_code and not gpg_error_t. Some macros also
54 : need an underscore prefixed internal version.
55 :
56 : Note that the memory allocation functions and macros (xmalloc etc.)
57 : are not defined here but in g10lib.h because this file here is
58 : included by some test programs which define theie own xmalloc
59 : macros. */
60 :
61 : gpg_err_code_t _gcry_cipher_open (gcry_cipher_hd_t *handle,
62 : int algo, int mode, unsigned int flags);
63 : void _gcry_cipher_close (gcry_cipher_hd_t h);
64 : gpg_err_code_t _gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer,
65 : size_t buflen);
66 : gpg_err_code_t _gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer,
67 : size_t *nbytes);
68 : gpg_err_code_t _gcry_cipher_algo_info (int algo, int what, void *buffer,
69 : size_t *nbytes);
70 : const char *_gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
71 : int _gcry_cipher_map_name (const char *name) _GCRY_GCC_ATTR_PURE;
72 : int _gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE;
73 : gpg_err_code_t _gcry_cipher_encrypt (gcry_cipher_hd_t h,
74 : void *out, size_t outsize,
75 : const void *in, size_t inlen);
76 : gpg_err_code_t _gcry_cipher_decrypt (gcry_cipher_hd_t h,
77 : void *out, size_t outsize,
78 : const void *in, size_t inlen);
79 : gcry_err_code_t _gcry_cipher_setkey (gcry_cipher_hd_t hd,
80 : const void *key, size_t keylen);
81 : gcry_err_code_t _gcry_cipher_setiv (gcry_cipher_hd_t hd,
82 : const void *iv, size_t ivlen);
83 : gpg_err_code_t _gcry_cipher_authenticate (gcry_cipher_hd_t hd, const void *abuf,
84 : size_t abuflen);
85 : gpg_err_code_t _gcry_cipher_gettag (gcry_cipher_hd_t hd, void *outtag,
86 : size_t taglen);
87 : gpg_err_code_t _gcry_cipher_checktag (gcry_cipher_hd_t hd, const void *intag,
88 : size_t taglen);
89 : gpg_err_code_t _gcry_cipher_setctr (gcry_cipher_hd_t hd,
90 : const void *ctr, size_t ctrlen);
91 : size_t _gcry_cipher_get_algo_keylen (int algo);
92 : size_t _gcry_cipher_get_algo_blklen (int algo);
93 :
94 : #define _gcry_cipher_reset(h) _gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0)
95 :
96 :
97 :
98 :
99 : gpg_err_code_t _gcry_pk_encrypt (gcry_sexp_t *result,
100 : gcry_sexp_t data, gcry_sexp_t pkey);
101 : gpg_err_code_t _gcry_pk_decrypt (gcry_sexp_t *result,
102 : gcry_sexp_t data, gcry_sexp_t skey);
103 : gpg_err_code_t _gcry_pk_sign (gcry_sexp_t *result,
104 : gcry_sexp_t data, gcry_sexp_t skey);
105 : gpg_err_code_t _gcry_pk_verify (gcry_sexp_t sigval,
106 : gcry_sexp_t data, gcry_sexp_t pkey);
107 : gpg_err_code_t _gcry_pk_testkey (gcry_sexp_t key);
108 : gpg_err_code_t _gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms);
109 : gpg_err_code_t _gcry_pk_ctl (int cmd, void *buffer, size_t buflen);
110 : gpg_err_code_t _gcry_pk_algo_info (int algo, int what,
111 : void *buffer, size_t *nbytes);
112 : const char *_gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
113 : int _gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
114 : unsigned int _gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE;
115 : unsigned char *_gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array);
116 : const char *_gcry_pk_get_curve (gcry_sexp_t key, int iterator,
117 : unsigned int *r_nbits);
118 : gcry_sexp_t _gcry_pk_get_param (int algo, const char *name);
119 : gpg_err_code_t _gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp,
120 : int mode, gcry_ctx_t ctx);
121 :
122 :
123 : gpg_err_code_t _gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags);
124 : void _gcry_md_close (gcry_md_hd_t hd);
125 : gpg_err_code_t _gcry_md_enable (gcry_md_hd_t hd, int algo);
126 : gpg_err_code_t _gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd);
127 : void _gcry_md_reset (gcry_md_hd_t hd);
128 : gpg_err_code_t _gcry_md_ctl (gcry_md_hd_t hd, int cmd,
129 : void *buffer, size_t buflen);
130 : void _gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length);
131 : unsigned char *_gcry_md_read (gcry_md_hd_t hd, int algo);
132 : gpg_error_t _gcry_md_extract (gcry_md_hd_t hd, int algo, void *buffer,
133 : size_t length);
134 : void _gcry_md_hash_buffer (int algo, void *digest,
135 : const void *buffer, size_t length);
136 : gpg_err_code_t _gcry_md_hash_buffers (int algo, unsigned int flags,
137 : void *digest,
138 : const gcry_buffer_t *iov, int iovcnt);
139 : int _gcry_md_get_algo (gcry_md_hd_t hd);
140 : unsigned int _gcry_md_get_algo_dlen (int algo);
141 : int _gcry_md_is_enabled (gcry_md_hd_t a, int algo);
142 : int _gcry_md_is_secure (gcry_md_hd_t a);
143 : gpg_err_code_t _gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
144 : size_t *nbytes);
145 : gpg_err_code_t _gcry_md_algo_info (int algo, int what, void *buffer,
146 : size_t *nbytes);
147 : const char *_gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
148 : int _gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
149 : gpg_err_code_t _gcry_md_setkey (gcry_md_hd_t hd,
150 : const void *key, size_t keylen);
151 : void _gcry_md_debug (gcry_md_hd_t hd, const char *suffix);
152 :
153 : #define _gcry_md_test_algo(a) \
154 : _gcry_md_algo_info ((a), GCRYCTL_TEST_ALGO, NULL, NULL)
155 :
156 : #define _gcry_md_final(a) \
157 : _gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
158 :
159 : #define _gcry_md_putc(h,c) \
160 : do { \
161 : gcry_md_hd_t h__ = (h); \
162 : if( (h__)->bufpos == (h__)->bufsize ) \
163 : _gcry_md_write( (h__), NULL, 0 ); \
164 : (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
165 : } while(0)
166 :
167 :
168 :
169 : gpg_err_code_t _gcry_mac_open (gcry_mac_hd_t *handle, int algo,
170 : unsigned int flags, gcry_ctx_t ctx);
171 : void _gcry_mac_close (gcry_mac_hd_t h);
172 : gpg_err_code_t _gcry_mac_ctl (gcry_mac_hd_t h, int cmd, void *buffer,
173 : size_t buflen);
174 : gpg_err_code_t _gcry_mac_algo_info (int algo, int what, void *buffer,
175 : size_t *nbytes);
176 : gpg_err_code_t _gcry_mac_setkey (gcry_mac_hd_t hd, const void *key,
177 : size_t keylen);
178 : gpg_err_code_t _gcry_mac_setiv (gcry_mac_hd_t hd, const void *iv,
179 : size_t ivlen);
180 : gpg_err_code_t _gcry_mac_write (gcry_mac_hd_t hd, const void *buffer,
181 : size_t length);
182 : gpg_err_code_t _gcry_mac_read (gcry_mac_hd_t hd, void *buffer, size_t *buflen);
183 : gpg_err_code_t _gcry_mac_verify (gcry_mac_hd_t hd, const void *buffer,
184 : size_t buflen);
185 : int _gcry_mac_get_algo (gcry_mac_hd_t hd);
186 : unsigned int _gcry_mac_get_algo_maclen (int algo);
187 : unsigned int _gcry_mac_get_algo_keylen (int algo);
188 : const char *_gcry_mac_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
189 : int _gcry_mac_map_name (const char *name) _GCRY_GCC_ATTR_PURE;
190 :
191 : #define _gcry_mac_reset(h) _gcry_mac_ctl ((h), GCRYCTL_RESET, NULL, 0)
192 :
193 :
194 : gpg_err_code_t _gcry_kdf_derive (const void *passphrase, size_t passphraselen,
195 : int algo, int subalgo,
196 : const void *salt, size_t saltlen,
197 : unsigned long iterations,
198 : size_t keysize, void *keybuffer);
199 :
200 :
201 : gpg_err_code_t _gcry_prime_generate (gcry_mpi_t *prime,
202 : unsigned int prime_bits,
203 : unsigned int factor_bits,
204 : gcry_mpi_t **factors,
205 : gcry_prime_check_func_t cb_func,
206 : void *cb_arg,
207 : gcry_random_level_t random_level,
208 : unsigned int flags);
209 : gpg_err_code_t _gcry_prime_group_generator (gcry_mpi_t *r_g,
210 : gcry_mpi_t prime,
211 : gcry_mpi_t *factors,
212 : gcry_mpi_t start_g);
213 : void _gcry_prime_release_factors (gcry_mpi_t *factors);
214 : gpg_err_code_t _gcry_prime_check (gcry_mpi_t x, unsigned int flags);
215 :
216 :
217 : void _gcry_randomize (void *buffer, size_t length,
218 : enum gcry_random_level level);
219 : gpg_err_code_t _gcry_random_add_bytes (const void *buffer, size_t length,
220 : int quality);
221 : void *_gcry_random_bytes (size_t nbytes, enum gcry_random_level level)
222 : _GCRY_GCC_ATTR_MALLOC;
223 : void *_gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
224 : _GCRY_GCC_ATTR_MALLOC;
225 : void _gcry_mpi_randomize (gcry_mpi_t w,
226 : unsigned int nbits, enum gcry_random_level level);
227 : void _gcry_create_nonce (void *buffer, size_t length);
228 :
229 :
230 : void _gcry_ctx_release (gcry_ctx_t ctx);
231 :
232 :
233 : const char *_gcry_check_version (const char *req_version);
234 :
235 : void _gcry_set_allocation_handler (gcry_handler_alloc_t func_alloc,
236 : gcry_handler_alloc_t func_alloc_secure,
237 : gcry_handler_secure_check_t func_secure_check,
238 : gcry_handler_realloc_t func_realloc,
239 : gcry_handler_free_t func_free);
240 : void _gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque);
241 : void _gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque);
242 : void _gcry_set_log_handler (gcry_handler_log_t f, void *opaque);
243 : void _gcry_set_gettext_handler (const char *(*f)(const char*));
244 : void _gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data);
245 :
246 :
247 : /* Return a pointer to a string containing a description of the error
248 : code in the error value ERR. */
249 : static inline const char *
250 0 : _gcry_strerror (gcry_error_t err)
251 : {
252 0 : return gpg_strerror (err);
253 : }
254 :
255 : /* Return a pointer to a string containing a description of the error
256 : source in the error value ERR. */
257 : static inline const char *
258 0 : _gcry_strsource (gcry_error_t err)
259 : {
260 0 : return gpg_strsource (err);
261 : }
262 :
263 : /* Retrieve the error code for the system error ERR. This returns
264 : GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
265 : this). */
266 : static inline gcry_err_code_t
267 0 : _gcry_err_code_from_errno (int err)
268 : {
269 0 : return gpg_err_code_from_errno (err);
270 : }
271 :
272 : /* Retrieve the system error for the error code CODE. This returns 0
273 : if CODE is not a system error code. */
274 : static inline int
275 0 : _gcry_err_code_to_errno (gcry_err_code_t code)
276 : {
277 0 : return gpg_err_code_from_errno (code);
278 : }
279 :
280 : /* Return an error value with the error source SOURCE and the system
281 : error ERR. */
282 : static inline gcry_error_t
283 0 : _gcry_err_make_from_errno (gpg_err_source_t source, int err)
284 : {
285 0 : return gpg_err_make_from_errno (source, err);
286 : }
287 :
288 :
289 : /* Return an error value with the system error ERR. */
290 : static inline gcry_error_t
291 0 : _gcry_error_from_errno (int err)
292 : {
293 0 : return gpg_error (gpg_err_code_from_errno (err));
294 : }
295 :
296 :
297 :
298 : gpg_err_code_t _gcry_sexp_new (gcry_sexp_t *retsexp,
299 : const void *buffer, size_t length,
300 : int autodetect);
301 : gpg_err_code_t _gcry_sexp_create (gcry_sexp_t *retsexp,
302 : void *buffer, size_t length,
303 : int autodetect, void (*freefnc) (void *));
304 : gpg_err_code_t _gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
305 : const char *buffer, size_t length);
306 : gpg_err_code_t _gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff,
307 : const char *format, ...);
308 : gpg_err_code_t _gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
309 : const char *format, void **arg_list);
310 : void _gcry_sexp_release (gcry_sexp_t sexp);
311 : size_t _gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
312 : size_t *erroff, gcry_err_code_t *errcode);
313 : size_t _gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer,
314 : size_t maxlength);
315 : void _gcry_sexp_dump (const gcry_sexp_t a);
316 : gcry_sexp_t _gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b);
317 : gcry_sexp_t _gcry_sexp_alist (const gcry_sexp_t *array);
318 : gcry_sexp_t _gcry_sexp_vlist (const gcry_sexp_t a, ...);
319 : gcry_sexp_t _gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n);
320 : gcry_sexp_t _gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n);
321 : gcry_sexp_t _gcry_sexp_find_token (gcry_sexp_t list,
322 : const char *tok, size_t toklen);
323 : int _gcry_sexp_length (const gcry_sexp_t list);
324 : gcry_sexp_t _gcry_sexp_nth (const gcry_sexp_t list, int number);
325 : gcry_sexp_t _gcry_sexp_car (const gcry_sexp_t list);
326 : gcry_sexp_t _gcry_sexp_cdr (const gcry_sexp_t list);
327 : gcry_sexp_t _gcry_sexp_cadr (const gcry_sexp_t list);
328 : const char *_gcry_sexp_nth_data (const gcry_sexp_t list, int number,
329 : size_t *datalen);
330 : void *_gcry_sexp_nth_buffer (const gcry_sexp_t list, int number,
331 : size_t *rlength);
332 : char *_gcry_sexp_nth_string (gcry_sexp_t list, int number);
333 : gcry_mpi_t _gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt);
334 : gpg_err_code_t _gcry_sexp_extract_param (gcry_sexp_t sexp,
335 : const char *path,
336 : const char *list,
337 : ...) _GCRY_GCC_ATTR_SENTINEL(0);
338 :
339 : #define sexp_new(a, b, c, d) _gcry_sexp_new ((a), (b), (c), (d))
340 : #define sexp_create(a, b, c, d, e) _gcry_sexp_create ((a), (b), (c), (d), (e))
341 : #define sexp_sscan(a, b, c, d) _gcry_sexp_sscan ((a), (b), (c), (d))
342 : #define sexp_build _gcry_sexp_build
343 : #define sexp_build_array(a, b, c, d) _gcry_sexp_build_array ((a), (b), (c), (d))
344 : #define sexp_release(a) _gcry_sexp_release ((a))
345 : #define sexp_canon_len(a, b, c, d) _gcry_sexp_canon_len ((a), (b), (c), (d))
346 : #define sexp_sprint(a, b, c, d) _gcry_sexp_sprint ((a), (b), (c), (d))
347 : #define sexp_dump(a) _gcry_sexp_dump ((a))
348 : #define sexp_cons(a, b) _gcry_sexp_cons ((a), (b))
349 : #define sexp_alist(a) _gcry_sexp_alist ((a))
350 : #define sexp_vlist _gcry_sexp_vlist
351 : #define sexp_append(a, b) _gcry_sexp_append ((a), (b))
352 : #define sexp_prepend(a, b) _gcry_sexp_prepend ((a), (b))
353 : #define sexp_find_token(a, b, c) _gcry_sexp_find_token ((a), (b), (c))
354 : #define sexp_length(a) _gcry_sexp_length ((a))
355 : #define sexp_nth(a, b) _gcry_sexp_nth ((a), (b))
356 : #define sexp_car(a) _gcry_sexp_car ((a))
357 : #define sexp_cdr(a) _gcry_sexp_cdr ((a))
358 : #define sexp_cadr(a) _gcry_sexp_cadr ((a))
359 : #define sexp_nth_data(a, b, c) _gcry_sexp_nth_data ((a), (b), (c))
360 : #define sexp_nth_buffer(a, b, c) _gcry_sexp_nth_buffer ((a), (b), (c))
361 : #define sexp_nth_string(a, b) _gcry_sexp_nth_string ((a), (b))
362 : #define sexp_nth_mpi(a, b, c) _gcry_sexp_nth_mpi ((a), (b), (c))
363 : #define sexp_extract_param _gcry_sexp_extract_param
364 :
365 :
366 :
367 : gcry_mpi_t _gcry_mpi_new (unsigned int nbits);
368 : gcry_mpi_t _gcry_mpi_snew (unsigned int nbits);
369 : void _gcry_mpi_release (gcry_mpi_t a);
370 : gcry_mpi_t _gcry_mpi_copy (const gcry_mpi_t a);
371 : void _gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u);
372 : gcry_mpi_t _gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u);
373 : gcry_mpi_t _gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u);
374 : gcry_err_code_t _gcry_mpi_get_ui (gcry_mpi_t w, ulong *u);
375 : void _gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b);
376 : int _gcry_mpi_is_neg (gcry_mpi_t a);
377 : void _gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u);
378 : void _gcry_mpi_abs (gcry_mpi_t w);
379 : int _gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v);
380 : int _gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v);
381 : gpg_err_code_t _gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format,
382 : const void *buffer, size_t buflen,
383 : size_t *nscanned);
384 : gpg_err_code_t _gcry_mpi_print (enum gcry_mpi_format format,
385 : unsigned char *buffer, size_t buflen,
386 : size_t *nwritten,
387 : const gcry_mpi_t a);
388 : gpg_err_code_t _gcry_mpi_aprint (enum gcry_mpi_format format,
389 : unsigned char **buffer, size_t *nwritten,
390 : const gcry_mpi_t a);
391 : void _gcry_mpi_dump (const gcry_mpi_t a);
392 : void _gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
393 : void _gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v);
394 : void _gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
395 : void _gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
396 : void _gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
397 : void _gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
398 : void _gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
399 : void _gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
400 : void _gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
401 : void _gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt);
402 : void _gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r,
403 : gcry_mpi_t dividend, gcry_mpi_t divisor, int round);
404 : void _gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor);
405 : void _gcry_mpi_powm (gcry_mpi_t w,
406 : const gcry_mpi_t b, const gcry_mpi_t e,
407 : const gcry_mpi_t m);
408 : int _gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b);
409 : int _gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m);
410 : gcry_mpi_point_t _gcry_mpi_point_new (unsigned int nbits);
411 : void _gcry_mpi_point_release (gcry_mpi_point_t point);
412 : void _gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
413 : gcry_mpi_point_t point);
414 : void _gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z,
415 : gcry_mpi_point_t point);
416 : gcry_mpi_point_t _gcry_mpi_point_set (gcry_mpi_point_t point,
417 : gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z);
418 : gcry_mpi_point_t _gcry_mpi_point_snatch_set (gcry_mpi_point_t point,
419 : gcry_mpi_t x, gcry_mpi_t y,
420 : gcry_mpi_t z);
421 :
422 : gcry_mpi_t _gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy);
423 : gcry_mpi_point_t _gcry_mpi_ec_get_point (const char *name,
424 : gcry_ctx_t ctx, int copy);
425 : int _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point,
426 : mpi_ec_t ctx);
427 : void _gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx);
428 : void _gcry_mpi_ec_add (gcry_mpi_point_t w,
429 : gcry_mpi_point_t u, gcry_mpi_point_t v, mpi_ec_t ctx);
430 : void _gcry_mpi_ec_sub (gcry_mpi_point_t w,
431 : gcry_mpi_point_t u, gcry_mpi_point_t v, mpi_ec_t ctx);
432 : void _gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u,
433 : mpi_ec_t ctx);
434 : int _gcry_mpi_ec_curve_point (gcry_mpi_point_t w, mpi_ec_t ctx);
435 : unsigned int _gcry_mpi_get_nbits (gcry_mpi_t a);
436 : int _gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n);
437 : void _gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n);
438 : void _gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n);
439 : void _gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n);
440 : void _gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n);
441 : void _gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n);
442 : void _gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n);
443 : gcry_mpi_t _gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits);
444 : gcry_mpi_t _gcry_mpi_set_opaque_copy (gcry_mpi_t a,
445 : const void *p, unsigned int nbits);
446 : void *_gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits);
447 : void _gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
448 : void _gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
449 : int _gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
450 :
451 :
452 : /* Private function - do not use. */
453 : /* gcry_mpi_t _gcry_mpi_get_const (int no); */
454 :
455 : /* We need our internal versions of the macros. */
456 : #ifndef GCRYPT_NO_MPI_MACROS
457 : # error GCRYPT_NO_MPI_MACROS is not defined
458 : #endif
459 :
460 : #define mpi_new(n) _gcry_mpi_new ((n))
461 : #define mpi_secure_new( n ) _gcry_mpi_snew ((n))
462 : #define mpi_snew(n) _gcry_mpi_snew ((n))
463 :
464 : #define mpi_release(a) \
465 : do \
466 : { \
467 : _gcry_mpi_release ((a));\
468 : (a) = NULL; \
469 : } \
470 : while (0)
471 :
472 : #define mpi_snatch( w, u) _gcry_mpi_snatch( (w), (u) )
473 : #define mpi_set( w, u) _gcry_mpi_set( (w), (u) )
474 : #define mpi_set_ui( w, u) _gcry_mpi_set_ui( (w), (u) )
475 : #define mpi_get_ui(a,b) _gcry_mpi_get_ui( (a), (b) )
476 : #define mpi_swap(a,b) _gcry_mpi_swap ((a),(b))
477 : #define mpi_abs( w ) _gcry_mpi_abs( (w) )
478 : #define mpi_neg( w, u) _gcry_mpi_neg( (w), (u) )
479 : #define mpi_cmp( u, v ) _gcry_mpi_cmp( (u), (v) )
480 : #define mpi_cmp_ui( u, v ) _gcry_mpi_cmp_ui( (u), (v) )
481 : #define mpi_is_neg( a ) _gcry_mpi_is_neg ((a))
482 :
483 : #define mpi_add_ui(w,u,v) _gcry_mpi_add_ui((w),(u),(v))
484 : #define mpi_add(w,u,v) _gcry_mpi_add ((w),(u),(v))
485 : #define mpi_addm(w,u,v,m) _gcry_mpi_addm ((w),(u),(v),(m))
486 : #define mpi_sub_ui(w,u,v) _gcry_mpi_sub_ui ((w),(u),(v))
487 : #define mpi_sub(w,u,v) _gcry_mpi_sub ((w),(u),(v))
488 : #define mpi_subm(w,u,v,m) _gcry_mpi_subm ((w),(u),(v),(m))
489 : #define mpi_mul_ui(w,u,v) _gcry_mpi_mul_ui ((w),(u),(v))
490 : #define mpi_mul_2exp(w,u,v) _gcry_mpi_mul_2exp ((w),(u),(v))
491 : #define mpi_mul(w,u,v) _gcry_mpi_mul ((w),(u),(v))
492 : #define mpi_mulm(w,u,v,m) _gcry_mpi_mulm ((w),(u),(v),(m))
493 : #define mpi_powm(w,b,e,m) _gcry_mpi_powm ( (w), (b), (e), (m) )
494 : #define mpi_tdiv(q,r,a,m) _gcry_mpi_div ( (q), (r), (a), (m), 0)
495 : #define mpi_fdiv(q,r,a,m) _gcry_mpi_div ( (q), (r), (a), (m), -1)
496 : #define mpi_mod(r,a,m) _gcry_mpi_mod ((r), (a), (m))
497 : #define mpi_gcd(g,a,b) _gcry_mpi_gcd ( (g), (a), (b) )
498 : #define mpi_invm(g,a,b) _gcry_mpi_invm ( (g), (a), (b) )
499 :
500 : #define mpi_point_new(n) _gcry_mpi_point_new((n))
501 :
502 : #define mpi_point_release(p) \
503 : do \
504 : { \
505 : _gcry_mpi_point_release ((p)); \
506 : (p) = NULL; \
507 : } \
508 : while (0)
509 :
510 : #define mpi_point_get(x,y,z,p) _gcry_mpi_point_get((x),(y),(z),(p))
511 : #define mpi_point_snatch_get(x,y,z,p) _gcry_mpi_point_snatch_get((x),(y), \
512 : (z),(p))
513 : #define mpi_point_set(p,x,y,z) _gcry_mpi_point_set((p),(x),(y),(z))
514 : #define mpi_point_snatch_set(p,x,y,z) _gcry_mpi_point_snatch_set((p),(x), \
515 : (y),(z))
516 :
517 : #define mpi_get_nbits(a) _gcry_mpi_get_nbits ((a))
518 : #define mpi_test_bit(a,b) _gcry_mpi_test_bit ((a),(b))
519 : #define mpi_set_bit(a,b) _gcry_mpi_set_bit ((a),(b))
520 : #define mpi_set_highbit(a,b) _gcry_mpi_set_highbit ((a),(b))
521 : #define mpi_clear_bit(a,b) _gcry_mpi_clear_bit ((a),(b))
522 : #define mpi_clear_highbit(a,b) _gcry_mpi_clear_highbit ((a),(b))
523 : #define mpi_rshift(a,b,c) _gcry_mpi_rshift ((a),(b),(c))
524 : #define mpi_lshift(a,b,c) _gcry_mpi_lshift ((a),(b),(c))
525 :
526 : #define mpi_set_opaque(a,b,c) _gcry_mpi_set_opaque ((a), (b), (c))
527 : #define mpi_get_opaque(a,b) _gcry_mpi_get_opaque ((a), (b))
528 : #define mpi_set_flag(a,f) _gcry_mpi_set_flag ((a), (f))
529 : #define mpi_set_flag(a,f) _gcry_mpi_set_flag ((a), (f))
530 : #define mpi_clear_flag(a,f) _gcry_mpi_clear_flag ((a), (f))
531 : #define mpi_get_flag(a,f) _gcry_mpi_get_flag ((a), (f))
532 :
533 :
534 : #endif /*GCRY_GCRYPT_INT_H*/
|