diff --git a/cipher/pubkey.c b/cipher/pubkey.c index fcc9fb29..cb19fbbd 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -1,1075 +1,1087 @@ /* pubkey.c - pubkey dispatcher * Copyright (C) 1998, 1999, 2000, 2002, 2003, 2005, * 2007, 2008, 2011 Free Software Foundation, Inc. * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser general Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . */ #include #include #include #include #include #include "g10lib.h" #include "mpi.h" #include "cipher.h" #include "context.h" #include "pubkey-internal.h" /* This is the list of the public-key algorithms included in Libgcrypt. */ static gcry_pk_spec_t * const pubkey_list[] = { #if USE_ECC &_gcry_pubkey_spec_ecc, #endif #if USE_RSA &_gcry_pubkey_spec_rsa, #endif #if USE_DSA &_gcry_pubkey_spec_dsa, #endif #if USE_ELGAMAL &_gcry_pubkey_spec_elg, #endif NULL }; static int map_algo (int algo) { switch (algo) { case GCRY_PK_RSA_E: return GCRY_PK_RSA; case GCRY_PK_RSA_S: return GCRY_PK_RSA; case GCRY_PK_ELG_E: return GCRY_PK_ELG; case GCRY_PK_ECDSA: return GCRY_PK_ECC; case GCRY_PK_EDDSA: return GCRY_PK_ECC; case GCRY_PK_ECDH: return GCRY_PK_ECC; default: return algo; } } /* Return the spec structure for the public key algorithm ALGO. For an unknown algorithm NULL is returned. */ static gcry_pk_spec_t * spec_from_algo (int algo) { int idx; gcry_pk_spec_t *spec; algo = map_algo (algo); for (idx = 0; (spec = pubkey_list[idx]); idx++) if (algo == spec->algo) return spec; return NULL; } /* Return the spec structure for the public key algorithm with NAME. For an unknown name NULL is returned. */ static gcry_pk_spec_t * spec_from_name (const char *name) { gcry_pk_spec_t *spec; int idx; const char **aliases; for (idx=0; (spec = pubkey_list[idx]); idx++) { if (!stricmp (name, spec->name)) return spec; for (aliases = spec->aliases; *aliases; aliases++) if (!stricmp (name, *aliases)) return spec; } return NULL; } /* Given the s-expression SEXP with the first element be either * "private-key" or "public-key" return the spec structure for it. We * look through the list to find a list beginning with "private-key" * or "public-key" - the first one found is used. If WANT_PRIVATE is * set the function will only succeed if a private key has been given. * On success the spec is stored at R_SPEC. On error NULL is stored * at R_SPEC and an error code returned. If R_PARMS is not NULL and * the function returns success, the parameter list below * "private-key" or "public-key" is stored there and the caller must * call gcry_sexp_release on it. */ static gcry_err_code_t spec_from_sexp (gcry_sexp_t sexp, int want_private, gcry_pk_spec_t **r_spec, gcry_sexp_t *r_parms) { gcry_sexp_t list, l2; char *name; gcry_pk_spec_t *spec; *r_spec = NULL; if (r_parms) *r_parms = NULL; /* Check that the first element is valid. If we are looking for a public key but a private key was supplied, we allow the use of the private key anyway. The rationale for this is that the private key is a superset of the public key. */ list = sexp_find_token (sexp, want_private? "private-key":"public-key", 0); if (!list && !want_private) list = sexp_find_token (sexp, "private-key", 0); if (!list) return GPG_ERR_INV_OBJ; /* Does not contain a key object. */ l2 = sexp_cadr (list); sexp_release (list); list = l2; name = sexp_nth_string (list, 0); if (!name) { sexp_release ( list ); return GPG_ERR_INV_OBJ; /* Invalid structure of object. */ } spec = spec_from_name (name); xfree (name); if (!spec) { sexp_release (list); return GPG_ERR_PUBKEY_ALGO; /* Unknown algorithm. */ } *r_spec = spec; if (r_parms) *r_parms = list; else sexp_release (list); return 0; } /* Disable the use of the algorithm ALGO. This is not thread safe and should thus be called early. */ static void disable_pubkey_algo (int algo) { gcry_pk_spec_t *spec = spec_from_algo (algo); if (spec) spec->flags.disabled = 1; } /* * Map a string to the pubkey algo */ int _gcry_pk_map_name (const char *string) { gcry_pk_spec_t *spec; if (!string) return 0; spec = spec_from_name (string); if (!spec) return 0; if (spec->flags.disabled) return 0; return spec->algo; } /* Map the public key algorithm whose ID is contained in ALGORITHM to a string representation of the algorithm name. For unknown algorithm IDs this functions returns "?". */ const char * _gcry_pk_algo_name (int algo) { gcry_pk_spec_t *spec; spec = spec_from_algo (algo); if (spec) return spec->name; return "?"; } /**************** * A USE of 0 means: don't care. */ static gcry_err_code_t check_pubkey_algo (int algo, unsigned use) { gcry_err_code_t err = 0; gcry_pk_spec_t *spec; spec = spec_from_algo (algo); if (spec) { if (((use & GCRY_PK_USAGE_SIGN) && (! (spec->use & GCRY_PK_USAGE_SIGN))) || ((use & GCRY_PK_USAGE_ENCR) && (! (spec->use & GCRY_PK_USAGE_ENCR)))) err = GPG_ERR_WRONG_PUBKEY_ALGO; } else err = GPG_ERR_PUBKEY_ALGO; return err; } /**************** * Return the number of public key material numbers */ static int pubkey_get_npkey (int algo) { gcry_pk_spec_t *spec = spec_from_algo (algo); return spec? strlen (spec->elements_pkey) : 0; } /**************** * Return the number of secret key material numbers */ static int pubkey_get_nskey (int algo) { gcry_pk_spec_t *spec = spec_from_algo (algo); return spec? strlen (spec->elements_skey) : 0; } /**************** * Return the number of signature material numbers */ static int pubkey_get_nsig (int algo) { gcry_pk_spec_t *spec = spec_from_algo (algo); return spec? strlen (spec->elements_sig) : 0; } /**************** * Return the number of encryption material numbers */ static int pubkey_get_nenc (int algo) { gcry_pk_spec_t *spec = spec_from_algo (algo); return spec? strlen (spec->elements_enc) : 0; } /* Do a PK encrypt operation Caller has to provide a public key as the SEXP pkey and data as a SEXP with just one MPI in it. Alternatively S_DATA might be a complex S-Expression, similar to the one used for signature verification. This provides a flag which allows to handle PKCS#1 block type 2 padding. The function returns a sexp which may be passed to to pk_decrypt. Returns: 0 or an errorcode. s_data = See comment for _gcry_pk_util_data_to_mpi s_pkey = r_ciph = (enc-val ( ( ) ... ( ) )) */ gcry_err_code_t _gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms; *r_ciph = NULL; rc = spec_from_sexp (s_pkey, 0, &spec, &keyparms); if (rc) goto leave; if (spec->encrypt) rc = spec->encrypt (r_ciph, s_data, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (keyparms); return rc; } /* Do a PK decrypt operation Caller has to provide a secret key as the SEXP skey and data in a format as created by gcry_pk_encrypt. For historic reasons the function returns simply an MPI as an S-expression part; this is deprecated and the new method should be used which returns a real S-expressionl this is selected by adding at least an empty flags list to S_DATA. Returns: 0 or an errorcode. s_data = (enc-val [(flags [raw, pkcs1, oaep])] ( ( ) ... ( ) )) s_skey = r_plain= Either an incomplete S-expression without the parentheses or if the flags list is used (even if empty) a real S-expression: (value PLAIN). In raw mode (or no flags given) the returned value is to be interpreted as a signed MPI, thus it may have an extra leading zero octet even if not included in the original data. With pkcs1 or oaep decoding enabled the returned value is a verbatim octet string. */ gcry_err_code_t _gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms; *r_plain = NULL; rc = spec_from_sexp (s_skey, 1, &spec, &keyparms); if (rc) goto leave; if (spec->decrypt) rc = spec->decrypt (r_plain, s_data, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (keyparms); return rc; } /* Create a signature. Caller has to provide a secret key as the SEXP skey and data expressed as a SEXP list hash with only one element which should instantly be available as a MPI. Alternatively the structure given below may be used for S_HASH, it provides the abiliy to pass flags to the operation; the flags defined by now are "pkcs1" which does PKCS#1 block type 1 style padding and "pss" for PSS encoding. Returns: 0 or an errorcode. In case of 0 the function returns a new SEXP with the signature value; the structure of this signature depends on the other arguments but is always suitable to be passed to gcry_pk_verify s_hash = See comment for _gcry-pk_util_data_to_mpi s_skey = r_sig = (sig-val ( ( ) ... ( )) [(hash algo)]) Note that (hash algo) in R_SIG is not used. */ gcry_err_code_t _gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms; *r_sig = NULL; rc = spec_from_sexp (s_skey, 1, &spec, &keyparms); if (rc) goto leave; if (spec->sign) rc = spec->sign (r_sig, s_hash, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (keyparms); return rc; } gcry_err_code_t _gcry_pk_sign_md (gcry_sexp_t *r_sig, const char *tmpl, gcry_md_hd_t hd_orig, - gcry_sexp_t s_skey) + gcry_sexp_t s_skey, gcry_ctx_t ctx) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms = NULL; gcry_sexp_t s_hash = NULL; int algo; const unsigned char *digest; gcry_error_t err; gcry_md_hd_t hd; *r_sig = NULL; err = _gcry_md_copy (&hd, hd_orig); if (err) return gpg_err_code (err); algo = _gcry_md_get_algo (hd); digest = _gcry_md_read (hd, 0); if (!digest) { _gcry_md_close (hd); - return GPG_ERR_DIGEST_ALGO; + return GPG_ERR_NOT_IMPLEMENTED; } - rc = _gcry_sexp_build (&s_hash, NULL, tmpl, - _gcry_md_algo_name (algo), - (int) _gcry_md_get_algo_dlen (algo), - digest); + if (!ctx) + rc = _gcry_sexp_build (&s_hash, NULL, tmpl, + _gcry_md_algo_name (algo), + (int) _gcry_md_get_algo_dlen (algo), + digest); + else + { + _gcry_md_close (hd); + return GPG_ERR_DIGEST_ALGO; + } _gcry_md_close (hd); if (rc) goto leave; rc = spec_from_sexp (s_skey, 1, &spec, &keyparms); if (rc) goto leave; if (spec->sign) rc = spec->sign (r_sig, s_hash, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (s_hash); sexp_release (keyparms); return rc; } /* Verify a signature. Caller has to supply the public key pkey, the signature sig and his hashvalue data. Public key has to be a standard public key given as an S-Exp, sig is a S-Exp as returned from gcry_pk_sign and data must be an S-Exp like the one in sign too. */ gcry_err_code_t _gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms; rc = spec_from_sexp (s_pkey, 0, &spec, &keyparms); if (rc) goto leave; if (spec->verify) rc = spec->verify (s_sig, s_hash, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (keyparms); return rc; } gcry_err_code_t _gcry_pk_verify_md (gcry_sexp_t s_sig, const char *tmpl, gcry_md_hd_t hd_orig, - gcry_sexp_t s_pkey) + gcry_sexp_t s_pkey, gcry_ctx_t ctx) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms = NULL; gcry_sexp_t s_hash = NULL; int algo; const unsigned char *digest; gcry_error_t err; gcry_md_hd_t hd; err = _gcry_md_copy (&hd, hd_orig); if (err) return gpg_err_code (err); algo = _gcry_md_get_algo (hd); digest = _gcry_md_read (hd, 0); if (!digest) { _gcry_md_close (hd); return GPG_ERR_DIGEST_ALGO; } - rc = _gcry_sexp_build (&s_hash, NULL, tmpl, - _gcry_md_algo_name (algo), - (int) _gcry_md_get_algo_dlen (algo), - digest); + if (!ctx) + rc = _gcry_sexp_build (&s_hash, NULL, tmpl, + _gcry_md_algo_name (algo), + (int) _gcry_md_get_algo_dlen (algo), + digest); + else + { + _gcry_md_close (hd); + return GPG_ERR_NOT_IMPLEMENTED; + } _gcry_md_close (hd); if (rc) goto leave; rc = spec_from_sexp (s_pkey, 1, &spec, &keyparms); if (rc) goto leave; if (spec->verify) rc = spec->verify (s_sig, s_hash, keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (s_hash); sexp_release (keyparms); return rc; } /* Test a key. This may be used either for a public or a secret key to see whether the internal structure is okay. Returns: 0 or an errorcode. NOTE: We currently support only secret key checking. */ gcry_err_code_t _gcry_pk_testkey (gcry_sexp_t s_key) { gcry_err_code_t rc; gcry_pk_spec_t *spec; gcry_sexp_t keyparms; rc = spec_from_sexp (s_key, 1, &spec, &keyparms); if (rc) goto leave; if (spec->check_secret_key) rc = spec->check_secret_key (keyparms); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (keyparms); return rc; } /* Create a public key pair and return it in r_key. How the key is created depends on s_parms: (genkey (algo (parameter_name_1 ....) .... (parameter_name_n ....) )) The key is returned in a format depending on the algorithm. Both, private and secret keys are returned and optionally some additional informatin. For elgamal we return this structure: (key-data (public-key (elg (p ) (g ) (y ) ) ) (private-key (elg (p ) (g ) (y ) (x ) ) ) (misc-key-info (pm1-factors n1 n2 ... nn) )) */ gcry_err_code_t _gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) { gcry_pk_spec_t *spec = NULL; gcry_sexp_t list = NULL; gcry_sexp_t l2 = NULL; char *name = NULL; gcry_err_code_t rc; *r_key = NULL; list = sexp_find_token (s_parms, "genkey", 0); if (!list) { rc = GPG_ERR_INV_OBJ; /* Does not contain genkey data. */ goto leave; } l2 = sexp_cadr (list); sexp_release (list); list = l2; l2 = NULL; if (! list) { rc = GPG_ERR_NO_OBJ; /* No cdr for the genkey. */ goto leave; } name = _gcry_sexp_nth_string (list, 0); if (!name) { rc = GPG_ERR_INV_OBJ; /* Algo string missing. */ goto leave; } spec = spec_from_name (name); xfree (name); name = NULL; if (!spec) { rc = GPG_ERR_PUBKEY_ALGO; /* Unknown algorithm. */ goto leave; } if (spec->generate) rc = spec->generate (list, r_key); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: sexp_release (list); xfree (name); sexp_release (l2); return rc; } /* Get the number of nbits from the public key. Hmmm: Should we have really this function or is it better to have a more general function to retrieve different properties of the key? */ unsigned int _gcry_pk_get_nbits (gcry_sexp_t key) { gcry_pk_spec_t *spec; gcry_sexp_t parms; unsigned int nbits; /* Parsing KEY might be considered too much overhead. For example for RSA we would only need to look at P and stop parsing right away. However, with ECC things are more complicate in that only a curve name might be specified. Thus we need to tear the sexp apart. */ if (spec_from_sexp (key, 0, &spec, &parms)) return 0; /* Error - 0 is a suitable indication for that. */ nbits = spec->get_nbits (parms); sexp_release (parms); return nbits; } /* Return the so called KEYGRIP which is the SHA-1 hash of the public key parameters expressed in a way depending on the algorithm. ARRAY must either be 20 bytes long or NULL; in the latter case a newly allocated array of that size is returned, otherwise ARRAY or NULL is returned to indicate an error which is most likely an unknown algorithm. The function accepts public or secret keys. */ unsigned char * _gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array) { gcry_sexp_t list = NULL; gcry_sexp_t l2 = NULL; gcry_pk_spec_t *spec = NULL; const char *s; char *name = NULL; int idx; const char *elems; gcry_md_hd_t md = NULL; int okay = 0; /* Check that the first element is valid. */ list = sexp_find_token (key, "public-key", 0); if (! list) list = sexp_find_token (key, "private-key", 0); if (! list) list = sexp_find_token (key, "protected-private-key", 0); if (! list) list = sexp_find_token (key, "shadowed-private-key", 0); if (! list) return NULL; /* No public- or private-key object. */ l2 = sexp_cadr (list); sexp_release (list); list = l2; l2 = NULL; name = _gcry_sexp_nth_string (list, 0); if (!name) goto fail; /* Invalid structure of object. */ spec = spec_from_name (name); if (!spec) goto fail; /* Unknown algorithm. */ elems = spec->elements_grip; if (!elems) goto fail; /* No grip parameter. */ if (_gcry_md_open (&md, GCRY_MD_SHA1, 0)) goto fail; if (spec->comp_keygrip) { /* Module specific method to compute a keygrip. */ if (spec->comp_keygrip (md, list)) goto fail; } else { /* Generic method to compute a keygrip. */ for (idx = 0, s = elems; *s; s++, idx++) { const char *data; size_t datalen; char buf[30]; l2 = sexp_find_token (list, s, 1); if (! l2) goto fail; data = sexp_nth_data (l2, 1, &datalen); if (! data) goto fail; snprintf (buf, sizeof buf, "(1:%c%u:", *s, (unsigned int)datalen); _gcry_md_write (md, buf, strlen (buf)); _gcry_md_write (md, data, datalen); sexp_release (l2); l2 = NULL; _gcry_md_write (md, ")", 1); } } if (!array) { array = xtrymalloc (20); if (! array) goto fail; } memcpy (array, _gcry_md_read (md, GCRY_MD_SHA1), 20); okay = 1; fail: xfree (name); sexp_release (l2); _gcry_md_close (md); sexp_release (list); return okay? array : NULL; } const char * _gcry_pk_get_curve (gcry_sexp_t key, int iterator, unsigned int *r_nbits) { const char *result = NULL; gcry_pk_spec_t *spec; gcry_sexp_t keyparms = NULL; if (r_nbits) *r_nbits = 0; if (key) { iterator = 0; if (spec_from_sexp (key, 0, &spec, &keyparms)) return NULL; } else { spec = spec_from_name ("ecc"); if (!spec) return NULL; } if (spec->get_curve) result = spec->get_curve (keyparms, iterator, r_nbits); sexp_release (keyparms); return result; } gcry_sexp_t _gcry_pk_get_param (int algo, const char *name) { gcry_sexp_t result = NULL; gcry_pk_spec_t *spec = NULL; algo = map_algo (algo); if (algo != GCRY_PK_ECC) return NULL; spec = spec_from_name ("ecc"); if (spec) { if (spec && spec->get_curve_param) result = spec->get_curve_param (name); } return result; } gcry_err_code_t _gcry_pk_ctl (int cmd, void *buffer, size_t buflen) { gcry_err_code_t rc = 0; switch (cmd) { case GCRYCTL_DISABLE_ALGO: /* This one expects a buffer pointing to an integer with the algo number. */ if ((! buffer) || (buflen != sizeof (int))) rc = GPG_ERR_INV_ARG; else disable_pubkey_algo (*((int *) buffer)); break; default: rc = GPG_ERR_INV_OP; } return rc; } /* Return information about the given algorithm WHAT selects the kind of information returned: GCRYCTL_TEST_ALGO: Returns 0 when the specified algorithm is available for use. Buffer must be NULL, nbytes may have the address of a variable with the required usage of the algorithm. It may be 0 for don't care or a combination of the GCRY_PK_USAGE_xxx flags; GCRYCTL_GET_ALGO_USAGE: Return the usage flags for the given algo. An invalid algo returns 0. Disabled algos are ignored here because we only want to know whether the algo is at all capable of the usage. Note: Because this function is in most cases used to return an integer value, we can make it easier for the caller to just look at the return value. The caller will in all cases consult the value and thereby detecting whether a error occurred or not (i.e. while checking the block size) */ gcry_err_code_t _gcry_pk_algo_info (int algorithm, int what, void *buffer, size_t *nbytes) { gcry_err_code_t rc = 0; switch (what) { case GCRYCTL_TEST_ALGO: { int use = nbytes ? *nbytes : 0; if (buffer) rc = GPG_ERR_INV_ARG; else if (check_pubkey_algo (algorithm, use)) rc = GPG_ERR_PUBKEY_ALGO; break; } case GCRYCTL_GET_ALGO_USAGE: { gcry_pk_spec_t *spec; spec = spec_from_algo (algorithm); *nbytes = spec? spec->use : 0; break; } case GCRYCTL_GET_ALGO_NPKEY: { /* FIXME? */ int npkey = pubkey_get_npkey (algorithm); *nbytes = npkey; break; } case GCRYCTL_GET_ALGO_NSKEY: { /* FIXME? */ int nskey = pubkey_get_nskey (algorithm); *nbytes = nskey; break; } case GCRYCTL_GET_ALGO_NSIGN: { /* FIXME? */ int nsign = pubkey_get_nsig (algorithm); *nbytes = nsign; break; } case GCRYCTL_GET_ALGO_NENCR: { /* FIXME? */ int nencr = pubkey_get_nenc (algorithm); *nbytes = nencr; break; } default: rc = GPG_ERR_INV_OP; } return rc; } /* Return an S-expression representing the context CTX. Depending on the state of that context, the S-expression may either be a public key, a private key or any other object used with public key operations. On success a new S-expression is stored at R_SEXP and 0 is returned, on error NULL is store there and an error code is returned. MODE is either 0 or one of the GCRY_PK_GET_xxx values. As of now it only support certain ECC operations because a context object is right now only defined for ECC. Over time this function will be extended to cover more algorithms. Note also that the name of the function is gcry_pubkey_xxx and not gcry_pk_xxx. The idea is that we will eventually provide variants of the existing gcry_pk_xxx functions which will take a context parameter. */ gcry_err_code_t _gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp, int mode, gcry_ctx_t ctx) { mpi_ec_t ec; if (!r_sexp) return GPG_ERR_INV_VALUE; *r_sexp = NULL; switch (mode) { case 0: case GCRY_PK_GET_PUBKEY: case GCRY_PK_GET_SECKEY: break; default: return GPG_ERR_INV_VALUE; } if (!ctx) return GPG_ERR_NO_CRYPT_CTX; ec = _gcry_ctx_find_pointer (ctx, CONTEXT_TYPE_EC); if (ec) return _gcry_pk_ecc_get_sexp (r_sexp, mode, ec); return GPG_ERR_WRONG_CRYPT_CTX; } /* Explicitly initialize this module. */ gcry_err_code_t _gcry_pk_init (void) { if (fips_mode()) { /* disable algorithms that are disallowed in fips */ int idx; gcry_pk_spec_t *spec; for (idx = 0; (spec = pubkey_list[idx]); idx++) if (!spec->flags.fips) spec->flags.disabled = 1; } return 0; } /* Run the selftests for pubkey algorithm ALGO with optional reporting function REPORT. */ gpg_error_t _gcry_pk_selftest (int algo, int extended, selftest_report_func_t report) { gcry_err_code_t ec; gcry_pk_spec_t *spec; algo = map_algo (algo); spec = spec_from_algo (algo); if (spec && !spec->flags.disabled && spec->selftest) ec = spec->selftest (algo, extended, report); else { ec = GPG_ERR_PUBKEY_ALGO; /* Fixme: We need to change the report function to allow passing of an encryption mode (e.g. pkcs1, ecdsa, or ecdh). */ if (report) report ("pubkey", algo, "module", spec && !spec->flags.disabled? "no selftest available" : spec? "algorithm disabled" : "algorithm not found"); } return gpg_error (ec); } diff --git a/src/gcrypt-int.h b/src/gcrypt-int.h index 6829a427..1307bd76 100644 --- a/src/gcrypt-int.h +++ b/src/gcrypt-int.h @@ -1,553 +1,554 @@ /* gcrypt-int.h - Internal version of gcrypt.h * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . */ #ifndef GCRY_GCRYPT_INT_H #define GCRY_GCRYPT_INT_H #ifdef _GCRYPT_H #error gcrypt.h already included #endif #include "gcrypt.h" #include "types.h" /* These error codes are used but not defined in the required * libgpg-error N.MM. Define them here. [None right now.] */ /* Context used with elliptic curve functions. */ struct mpi_ec_ctx_s; typedef struct mpi_ec_ctx_s *mpi_ec_t; /* Underscore prefixed internal versions of the public functions. They return gpg_err_code_t and not gpg_error_t. Some macros also need an underscore prefixed internal version. Note that the memory allocation functions and macros (xmalloc etc.) are not defined here but in g10lib.h because this file here is included by some test programs which define theie own xmalloc macros. */ gpg_err_code_t _gcry_cipher_open (gcry_cipher_hd_t *handle, int algo, int mode, unsigned int flags); void _gcry_cipher_close (gcry_cipher_hd_t h); gpg_err_code_t _gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen); gpg_err_code_t _gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer, size_t *nbytes); gpg_err_code_t _gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes); const char *_gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; int _gcry_cipher_map_name (const char *name) _GCRY_GCC_ATTR_PURE; int _gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE; gpg_err_code_t _gcry_cipher_encrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen); gpg_err_code_t _gcry_cipher_decrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen); gcry_err_code_t _gcry_cipher_setkey (gcry_cipher_hd_t hd, const void *key, size_t keylen); gcry_err_code_t _gcry_cipher_setiv (gcry_cipher_hd_t hd, const void *iv, size_t ivlen); gpg_err_code_t _gcry_cipher_authenticate (gcry_cipher_hd_t hd, const void *abuf, size_t abuflen); gpg_err_code_t _gcry_cipher_gettag (gcry_cipher_hd_t hd, void *outtag, size_t taglen); gpg_err_code_t _gcry_cipher_checktag (gcry_cipher_hd_t hd, const void *intag, size_t taglen); gpg_err_code_t _gcry_cipher_setctr (gcry_cipher_hd_t hd, const void *ctr, size_t ctrlen); gpg_err_code_t _gcry_cipher_getctr (gcry_cipher_hd_t hd, void *ctr, size_t ctrlen); size_t _gcry_cipher_get_algo_keylen (int algo); size_t _gcry_cipher_get_algo_blklen (int algo); #define _gcry_cipher_reset(h) _gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0) gpg_err_code_t _gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey); gpg_err_code_t _gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey); gpg_err_code_t _gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey); gpg_err_code_t _gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey); gpg_err_code_t _gcry_pk_testkey (gcry_sexp_t key); gpg_err_code_t _gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms); gpg_err_code_t _gcry_pk_ctl (int cmd, void *buffer, size_t buflen); gpg_err_code_t _gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes); const char *_gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; int _gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE; unsigned int _gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE; unsigned char *_gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array); const char *_gcry_pk_get_curve (gcry_sexp_t key, int iterator, unsigned int *r_nbits); gcry_sexp_t _gcry_pk_get_param (int algo, const char *name); gpg_err_code_t _gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp, int mode, gcry_ctx_t ctx); unsigned int _gcry_ecc_get_algo_keylen (int algo); gpg_error_t _gcry_ecc_mul_point (int algo, unsigned char *result, const unsigned char *scalar, const unsigned char *point); gcry_err_code_t _gcry_pk_sign_md (gcry_sexp_t *r_sig, const char *tmpl, - gcry_md_hd_t hd, gcry_sexp_t s_skey); + gcry_md_hd_t hd, gcry_sexp_t s_skey, gcry_ctx_t ctx); gcry_err_code_t _gcry_pk_verify_md (gcry_sexp_t s_sig, const char *tmpl, - gcry_md_hd_t hd, gcry_sexp_t s_pkey); + gcry_md_hd_t hd, gcry_sexp_t s_pkey, + gcry_ctx_t ctx); gcry_error_t _gcry_pkey_vopen (gcry_pkey_hd_t *h, int algo, unsigned int flags, va_list arg_ptr); gcry_error_t _gcry_pkey_ctl (gcry_pkey_hd_t h, int cmd, void *buffer, size_t buflen); gcry_error_t _gcry_pkey_op (gcry_pkey_hd_t h, int cmd, int num_in, const unsigned char *const in[], const size_t in_len[], int num_out, unsigned char *out[], size_t out_len[]); void _gcry_pkey_close (gcry_pkey_hd_t h); gpg_err_code_t _gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags); void _gcry_md_close (gcry_md_hd_t hd); gpg_err_code_t _gcry_md_enable (gcry_md_hd_t hd, int algo); gpg_err_code_t _gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd); void _gcry_md_reset (gcry_md_hd_t hd); gpg_err_code_t _gcry_md_ctl (gcry_md_hd_t hd, int cmd, void *buffer, size_t buflen); void _gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length); unsigned char *_gcry_md_read (gcry_md_hd_t hd, int algo); gpg_err_code_t _gcry_md_extract (gcry_md_hd_t hd, int algo, void *buffer, size_t length); void _gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length); gpg_err_code_t _gcry_md_hash_buffers_extract (int algo, unsigned int flags, void *digest, int digestlen, const gcry_buffer_t *iov, int iovcnt); gpg_err_code_t _gcry_md_hash_buffers (int algo, unsigned int flags, void *digest, const gcry_buffer_t *iov, int iovcnt); int _gcry_md_get_algo (gcry_md_hd_t hd); unsigned int _gcry_md_get_algo_dlen (int algo); int _gcry_md_is_enabled (gcry_md_hd_t a, int algo); int _gcry_md_is_secure (gcry_md_hd_t a); gpg_err_code_t _gcry_md_info (gcry_md_hd_t h, int what, void *buffer, size_t *nbytes); gpg_err_code_t _gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes); const char *_gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE; int _gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE; gpg_err_code_t _gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen); void _gcry_md_debug (gcry_md_hd_t hd, const char *suffix); #define _gcry_md_test_algo(a) \ _gcry_md_algo_info ((a), GCRYCTL_TEST_ALGO, NULL, NULL) #define _gcry_md_final(a) \ _gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0) #define _gcry_md_putc(h,c) \ do { \ gcry_md_hd_t h__ = (h); \ if( (h__)->bufpos == (h__)->bufsize ) \ _gcry_md_write( (h__), NULL, 0 ); \ (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \ } while(0) gpg_err_code_t _gcry_mac_open (gcry_mac_hd_t *handle, int algo, unsigned int flags, gcry_ctx_t ctx); void _gcry_mac_close (gcry_mac_hd_t h); gpg_err_code_t _gcry_mac_ctl (gcry_mac_hd_t h, int cmd, void *buffer, size_t buflen); gpg_err_code_t _gcry_mac_algo_info (int algo, int what, void *buffer, size_t *nbytes); gpg_err_code_t _gcry_mac_setkey (gcry_mac_hd_t hd, const void *key, size_t keylen); gpg_err_code_t _gcry_mac_setiv (gcry_mac_hd_t hd, const void *iv, size_t ivlen); gpg_err_code_t _gcry_mac_write (gcry_mac_hd_t hd, const void *buffer, size_t length); gpg_err_code_t _gcry_mac_read (gcry_mac_hd_t hd, void *buffer, size_t *buflen); gpg_err_code_t _gcry_mac_verify (gcry_mac_hd_t hd, const void *buffer, size_t buflen); int _gcry_mac_get_algo (gcry_mac_hd_t hd); unsigned int _gcry_mac_get_algo_maclen (int algo); unsigned int _gcry_mac_get_algo_keylen (int algo); const char *_gcry_mac_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; int _gcry_mac_map_name (const char *name) _GCRY_GCC_ATTR_PURE; #define _gcry_mac_reset(h) _gcry_mac_ctl ((h), GCRYCTL_RESET, NULL, 0) gpg_err_code_t _gcry_kdf_derive (const void *passphrase, size_t passphraselen, int algo, int subalgo, const void *salt, size_t saltlen, unsigned long iterations, size_t keysize, void *keybuffer); gpg_err_code_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); gpg_err_code_t _gcry_prime_group_generator (gcry_mpi_t *r_g, gcry_mpi_t prime, gcry_mpi_t *factors, gcry_mpi_t start_g); void _gcry_prime_release_factors (gcry_mpi_t *factors); gpg_err_code_t _gcry_prime_check (gcry_mpi_t x, unsigned int flags); void _gcry_randomize (void *buffer, size_t length, enum gcry_random_level level); gpg_err_code_t _gcry_random_add_bytes (const void *buffer, size_t length, int quality); void *_gcry_random_bytes (size_t nbytes, enum gcry_random_level level) _GCRY_GCC_ATTR_MALLOC; void *_gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level) _GCRY_GCC_ATTR_MALLOC; void _gcry_mpi_randomize (gcry_mpi_t w, unsigned int nbits, enum gcry_random_level level); void _gcry_create_nonce (void *buffer, size_t length); void _gcry_ctx_release (gcry_ctx_t ctx); const char *_gcry_check_version (const char *req_version); 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); void _gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque); void _gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque); void _gcry_set_log_handler (gcry_handler_log_t f, void *opaque); void _gcry_set_gettext_handler (const char *(*f)(const char*)); void _gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data); /* Return a pointer to a string containing a description of the error code in the error value ERR. */ static inline const char * _gcry_strerror (gcry_error_t err) { return gpg_strerror (err); } /* Return a pointer to a string containing a description of the error source in the error value ERR. */ static inline const char * _gcry_strsource (gcry_error_t err) { return gpg_strsource (err); } /* Retrieve the error code for the system error ERR. This returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report this). */ static inline gcry_err_code_t _gcry_err_code_from_errno (int err) { return gpg_err_code_from_errno (err); } /* Retrieve the system error for the error code CODE. This returns 0 if CODE is not a system error code. */ static inline int _gcry_err_code_to_errno (gcry_err_code_t code) { return gpg_err_code_from_errno (code); } /* Return an error value with the error source SOURCE and the system error ERR. */ static inline gcry_error_t _gcry_err_make_from_errno (gpg_err_source_t source, int err) { return gpg_err_make_from_errno (source, err); } /* Return an error value with the system error ERR. */ static inline gcry_error_t _gcry_error_from_errno (int err) { return gpg_error (gpg_err_code_from_errno (err)); } gpg_err_code_t _gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length, int autodetect); gpg_err_code_t _gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length, int autodetect, void (*freefnc) (void *)); gpg_err_code_t _gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff, const char *buffer, size_t length); gpg_err_code_t _gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...); gpg_err_code_t _gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff, const char *format, void **arg_list); void _gcry_sexp_release (gcry_sexp_t sexp); size_t _gcry_sexp_canon_len (const unsigned char *buffer, size_t length, size_t *erroff, gcry_err_code_t *errcode); size_t _gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer, size_t maxlength); void _gcry_sexp_dump (const gcry_sexp_t a); gcry_sexp_t _gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b); gcry_sexp_t _gcry_sexp_alist (const gcry_sexp_t *array); gcry_sexp_t _gcry_sexp_vlist (const gcry_sexp_t a, ...); gcry_sexp_t _gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n); gcry_sexp_t _gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n); gcry_sexp_t _gcry_sexp_find_token (gcry_sexp_t list, const char *tok, size_t toklen); int _gcry_sexp_length (const gcry_sexp_t list); gcry_sexp_t _gcry_sexp_nth (const gcry_sexp_t list, int number); gcry_sexp_t _gcry_sexp_car (const gcry_sexp_t list); gcry_sexp_t _gcry_sexp_cdr (const gcry_sexp_t list); gcry_sexp_t _gcry_sexp_cadr (const gcry_sexp_t list); const char *_gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen); void *_gcry_sexp_nth_buffer (const gcry_sexp_t list, int number, size_t *rlength); char *_gcry_sexp_nth_string (gcry_sexp_t list, int number); gcry_mpi_t _gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt); gpg_err_code_t _gcry_sexp_extract_param (gcry_sexp_t sexp, const char *path, const char *list, ...) _GCRY_GCC_ATTR_SENTINEL(0); #define sexp_new(a, b, c, d) _gcry_sexp_new ((a), (b), (c), (d)) #define sexp_create(a, b, c, d, e) _gcry_sexp_create ((a), (b), (c), (d), (e)) #define sexp_sscan(a, b, c, d) _gcry_sexp_sscan ((a), (b), (c), (d)) #define sexp_build _gcry_sexp_build #define sexp_build_array(a, b, c, d) _gcry_sexp_build_array ((a), (b), (c), (d)) #define sexp_release(a) _gcry_sexp_release ((a)) #define sexp_canon_len(a, b, c, d) _gcry_sexp_canon_len ((a), (b), (c), (d)) #define sexp_sprint(a, b, c, d) _gcry_sexp_sprint ((a), (b), (c), (d)) #define sexp_dump(a) _gcry_sexp_dump ((a)) #define sexp_cons(a, b) _gcry_sexp_cons ((a), (b)) #define sexp_alist(a) _gcry_sexp_alist ((a)) #define sexp_vlist _gcry_sexp_vlist #define sexp_append(a, b) _gcry_sexp_append ((a), (b)) #define sexp_prepend(a, b) _gcry_sexp_prepend ((a), (b)) #define sexp_find_token(a, b, c) _gcry_sexp_find_token ((a), (b), (c)) #define sexp_length(a) _gcry_sexp_length ((a)) #define sexp_nth(a, b) _gcry_sexp_nth ((a), (b)) #define sexp_car(a) _gcry_sexp_car ((a)) #define sexp_cdr(a) _gcry_sexp_cdr ((a)) #define sexp_cadr(a) _gcry_sexp_cadr ((a)) #define sexp_nth_data(a, b, c) _gcry_sexp_nth_data ((a), (b), (c)) #define sexp_nth_buffer(a, b, c) _gcry_sexp_nth_buffer ((a), (b), (c)) #define sexp_nth_string(a, b) _gcry_sexp_nth_string ((a), (b)) #define sexp_nth_mpi(a, b, c) _gcry_sexp_nth_mpi ((a), (b), (c)) #define sexp_extract_param _gcry_sexp_extract_param gcry_mpi_t _gcry_mpi_new (unsigned int nbits); gcry_mpi_t _gcry_mpi_snew (unsigned int nbits); void _gcry_mpi_release (gcry_mpi_t a); gcry_mpi_t _gcry_mpi_copy (const gcry_mpi_t a); void _gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u); gcry_mpi_t _gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u); gcry_mpi_t _gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u); gcry_err_code_t _gcry_mpi_get_ui (unsigned int *w, gcry_mpi_t u); void _gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b); int _gcry_mpi_is_neg (gcry_mpi_t a); void _gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u); void _gcry_mpi_abs (gcry_mpi_t w); int _gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v); int _gcry_mpi_cmpabs (const gcry_mpi_t u, const gcry_mpi_t v); int _gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v); gpg_err_code_t _gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format, const void *buffer, size_t buflen, size_t *nscanned); gpg_err_code_t _gcry_mpi_print (enum gcry_mpi_format format, unsigned char *buffer, size_t buflen, size_t *nwritten, const gcry_mpi_t a); gpg_err_code_t _gcry_mpi_aprint (enum gcry_mpi_format format, unsigned char **buffer, size_t *nwritten, const gcry_mpi_t a); void _gcry_mpi_dump (const gcry_mpi_t a); void _gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); void _gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v); void _gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); void _gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); void _gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); void _gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); void _gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); void _gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); void _gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); void _gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt); void _gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor, int round); void _gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor); void _gcry_mpi_powm (gcry_mpi_t w, const gcry_mpi_t b, const gcry_mpi_t e, const gcry_mpi_t m); int _gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b); int _gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m); gcry_mpi_point_t _gcry_mpi_point_new (unsigned int nbits); void _gcry_mpi_point_release (gcry_mpi_point_t point); gcry_mpi_point_t _gcry_mpi_point_copy (gcry_mpi_point_t point); void _gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point); void _gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point); 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); 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); gcry_mpi_t _gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy); gcry_mpi_point_t _gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy); int _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, mpi_ec_t ctx); void _gcry_mpi_ec_point_resize (gcry_mpi_point_t p, mpi_ec_t ctx); void _gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx); void _gcry_mpi_ec_add (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_mpi_point_t v, mpi_ec_t ctx); void _gcry_mpi_ec_sub (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_mpi_point_t v, mpi_ec_t ctx); void _gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u, mpi_ec_t ctx); int _gcry_mpi_ec_curve_point (gcry_mpi_point_t w, mpi_ec_t ctx); unsigned int _gcry_mpi_get_nbits (gcry_mpi_t a); int _gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n); void _gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n); void _gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n); void _gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n); void _gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n); void _gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); void _gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); gcry_mpi_t _gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits); gcry_mpi_t _gcry_mpi_set_opaque_copy (gcry_mpi_t a, const void *p, unsigned int nbits); void *_gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits); void _gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); void _gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); int _gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); /* Private function - do not use. */ /* gcry_mpi_t _gcry_mpi_get_const (int no); */ /* We need our internal versions of the macros. */ #ifndef GCRYPT_NO_MPI_MACROS # error GCRYPT_NO_MPI_MACROS is not defined #endif #define mpi_new(n) _gcry_mpi_new ((n)) #define mpi_secure_new( n ) _gcry_mpi_snew ((n)) #define mpi_snew(n) _gcry_mpi_snew ((n)) #define mpi_release(a) \ do \ { \ _gcry_mpi_release ((a));\ (a) = NULL; \ } \ while (0) #define mpi_snatch( w, u) _gcry_mpi_snatch( (w), (u) ) #define mpi_set( w, u) _gcry_mpi_set( (w), (u) ) #define mpi_set_ui( w, u) _gcry_mpi_set_ui( (w), (u) ) #define mpi_get_ui(w,u) _gcry_mpi_get_ui( (w), (u) ) #define mpi_swap(a,b) _gcry_mpi_swap ((a),(b)) #define mpi_abs( w ) _gcry_mpi_abs( (w) ) #define mpi_neg( w, u) _gcry_mpi_neg( (w), (u) ) #define mpi_cmp( u, v ) _gcry_mpi_cmp( (u), (v) ) #define mpi_cmpabs( u, v ) _gcry_mpi_cmpabs( (u), (v) ) #define mpi_cmp_ui( u, v ) _gcry_mpi_cmp_ui( (u), (v) ) #define mpi_is_neg( a ) _gcry_mpi_is_neg ((a)) #define mpi_add_ui(w,u,v) _gcry_mpi_add_ui((w),(u),(v)) #define mpi_add(w,u,v) _gcry_mpi_add ((w),(u),(v)) #define mpi_addm(w,u,v,m) _gcry_mpi_addm ((w),(u),(v),(m)) #define mpi_sub_ui(w,u,v) _gcry_mpi_sub_ui ((w),(u),(v)) #define mpi_sub(w,u,v) _gcry_mpi_sub ((w),(u),(v)) #define mpi_subm(w,u,v,m) _gcry_mpi_subm ((w),(u),(v),(m)) #define mpi_mul_ui(w,u,v) _gcry_mpi_mul_ui ((w),(u),(v)) #define mpi_mul_2exp(w,u,v) _gcry_mpi_mul_2exp ((w),(u),(v)) #define mpi_mul(w,u,v) _gcry_mpi_mul ((w),(u),(v)) #define mpi_mulm(w,u,v,m) _gcry_mpi_mulm ((w),(u),(v),(m)) #define mpi_powm(w,b,e,m) _gcry_mpi_powm ( (w), (b), (e), (m) ) #define mpi_tdiv(q,r,a,m) _gcry_mpi_div ( (q), (r), (a), (m), 0) #define mpi_fdiv(q,r,a,m) _gcry_mpi_div ( (q), (r), (a), (m), -1) #define mpi_mod(r,a,m) _gcry_mpi_mod ((r), (a), (m)) #define mpi_gcd(g,a,b) _gcry_mpi_gcd ( (g), (a), (b) ) #define mpi_invm(g,a,b) _gcry_mpi_invm ( (g), (a), (b) ) #define mpi_point_new(n) _gcry_mpi_point_new((n)) #define mpi_point_release(p) \ do \ { \ _gcry_mpi_point_release ((p)); \ (p) = NULL; \ } \ while (0) #define mpi_point_copy(p) _gcry_mpi_point_copy((p)) #define mpi_point_get(x,y,z,p) _gcry_mpi_point_get((x),(y),(z),(p)) #define mpi_point_snatch_get(x,y,z,p) _gcry_mpi_point_snatch_get((x),(y), \ (z),(p)) #define mpi_point_set(p,x,y,z) _gcry_mpi_point_set((p),(x),(y),(z)) #define mpi_point_snatch_set(p,x,y,z) _gcry_mpi_point_snatch_set((p),(x), \ (y),(z)) #define mpi_point_resize(p,ctx) _gcry_mpi_ec_point_resize (p, ctx) #define mpi_get_nbits(a) _gcry_mpi_get_nbits ((a)) #define mpi_test_bit(a,b) _gcry_mpi_test_bit ((a),(b)) #define mpi_set_bit(a,b) _gcry_mpi_set_bit ((a),(b)) #define mpi_set_highbit(a,b) _gcry_mpi_set_highbit ((a),(b)) #define mpi_clear_bit(a,b) _gcry_mpi_clear_bit ((a),(b)) #define mpi_clear_highbit(a,b) _gcry_mpi_clear_highbit ((a),(b)) #define mpi_rshift(a,b,c) _gcry_mpi_rshift ((a),(b),(c)) #define mpi_lshift(a,b,c) _gcry_mpi_lshift ((a),(b),(c)) #define mpi_set_opaque(a,b,c) _gcry_mpi_set_opaque ((a), (b), (c)) #define mpi_get_opaque(a,b) _gcry_mpi_get_opaque ((a), (b)) #define mpi_set_flag(a,f) _gcry_mpi_set_flag ((a), (f)) #define mpi_set_flag(a,f) _gcry_mpi_set_flag ((a), (f)) #define mpi_clear_flag(a,f) _gcry_mpi_clear_flag ((a), (f)) #define mpi_get_flag(a,f) _gcry_mpi_get_flag ((a), (f)) #endif /*GCRY_GCRYPT_INT_H*/ diff --git a/src/visibility.c b/src/visibility.c index 3f0514f7..7223cab5 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -1,1674 +1,1672 @@ /* visibility.c - Wrapper for all public functions. * Copyright (C) 2007, 2008, 2011 Free Software Foundation, Inc. * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see . */ #include #include #define _GCRY_INCLUDED_BY_VISIBILITY_C #include "g10lib.h" #include "cipher-proto.h" #include "context.h" #include "mpi.h" #include "ec-context.h" const char * gcry_strerror (gcry_error_t err) { return _gcry_strerror (err); } const char * gcry_strsource (gcry_error_t err) { return _gcry_strsource (err); } gcry_err_code_t gcry_err_code_from_errno (int err) { return _gcry_err_code_from_errno (err); } int gcry_err_code_to_errno (gcry_err_code_t code) { return _gcry_err_code_to_errno (code); } gcry_error_t gcry_err_make_from_errno (gcry_err_source_t source, int err) { return _gcry_err_make_from_errno (source, err); } gcry_error_t gcry_error_from_errno (int err) { return _gcry_error_from_errno (err); } const char * gcry_check_version (const char *req_version) { return _gcry_check_version (req_version); } gcry_error_t gcry_control (enum gcry_ctl_cmds cmd, ...) { gcry_error_t err; va_list arg_ptr; va_start (arg_ptr, cmd); err = gpg_error (_gcry_vcontrol (cmd, arg_ptr)); va_end(arg_ptr); return err; } gcry_error_t gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length, int autodetect) { return gpg_error (_gcry_sexp_new (retsexp, buffer, length, autodetect)); } gcry_error_t gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length, int autodetect, void (*freefnc) (void *)) { return gpg_error (_gcry_sexp_create (retsexp, buffer, length, autodetect, freefnc)); } gcry_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff, const char *buffer, size_t length) { return gpg_error (_gcry_sexp_sscan (retsexp, erroff, buffer, length)); } gcry_error_t gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...) { gcry_err_code_t rc; va_list arg_ptr; va_start (arg_ptr, format); rc = _gcry_sexp_vbuild (retsexp, erroff, format, arg_ptr); va_end (arg_ptr); return gpg_error (rc); } gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff, const char *format, void **arg_list) { return gpg_error (_gcry_sexp_build_array (retsexp, erroff, format, arg_list)); } void gcry_sexp_release (gcry_sexp_t sexp) { _gcry_sexp_release (sexp); } size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length, size_t *erroff, gcry_error_t *errcode) { size_t n; gpg_err_code_t rc; n = _gcry_sexp_canon_len (buffer, length, erroff, &rc); if (errcode) *errcode = gpg_error (rc); return n; } size_t gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer, size_t maxlength) { return _gcry_sexp_sprint (sexp, mode, buffer, maxlength); } void gcry_sexp_dump (const gcry_sexp_t a) { _gcry_sexp_dump (a); } gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b) { return _gcry_sexp_cons (a, b); } gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array) { return _gcry_sexp_alist (array); } gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...) { /* This is not yet implemented in sexp.c. */ (void)a; BUG (); return NULL; } gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n) { return _gcry_sexp_append (a, n); } gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n) { return _gcry_sexp_prepend (a, n); } gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list, const char *tok, size_t toklen) { return _gcry_sexp_find_token (list, tok, toklen); } int gcry_sexp_length (const gcry_sexp_t list) { return _gcry_sexp_length (list); } gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number) { return _gcry_sexp_nth (list, number); } gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list) { return _gcry_sexp_car (list); } gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list) { return _gcry_sexp_cdr (list); } gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list) { return _gcry_sexp_cadr (list); } const char * gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen) { return _gcry_sexp_nth_data (list, number, datalen); } void * gcry_sexp_nth_buffer (const gcry_sexp_t list, int number, size_t *rlength) { return _gcry_sexp_nth_buffer (list, number, rlength); } char * gcry_sexp_nth_string (gcry_sexp_t list, int number) { return _gcry_sexp_nth_string (list, number); } gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt) { return _gcry_sexp_nth_mpi (list, number, mpifmt); } gpg_error_t gcry_sexp_extract_param (gcry_sexp_t sexp, const char *path, const char *list, ...) { gcry_err_code_t rc; va_list arg_ptr; va_start (arg_ptr, list); rc = _gcry_sexp_vextract_param (sexp, path, list, arg_ptr); va_end (arg_ptr); return gpg_error (rc); } gcry_mpi_t gcry_mpi_new (unsigned int nbits) { return _gcry_mpi_new (nbits); } gcry_mpi_t gcry_mpi_snew (unsigned int nbits) { return _gcry_mpi_snew (nbits); } void gcry_mpi_release (gcry_mpi_t a) { _gcry_mpi_release (a); } gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a) { return _gcry_mpi_copy (a); } void gcry_mpi_snatch (gcry_mpi_t w, const gcry_mpi_t u) { _gcry_mpi_snatch (w, u); } gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u) { return _gcry_mpi_set (w, u); } gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u) { return _gcry_mpi_set_ui (w, u); } gcry_error_t gcry_mpi_get_ui (unsigned int *w, gcry_mpi_t u) { return gpg_error (_gcry_mpi_get_ui (w, u)); } void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b) { _gcry_mpi_swap (a, b); } int gcry_mpi_is_neg (gcry_mpi_t a) { return _gcry_mpi_is_neg (a); } void gcry_mpi_neg (gcry_mpi_t w, gcry_mpi_t u) { _gcry_mpi_neg (w, u); } void gcry_mpi_abs (gcry_mpi_t w) { _gcry_mpi_abs (w); } int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v) { return _gcry_mpi_cmp (u, v); } int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v) { return _gcry_mpi_cmp_ui (u, v); } 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) { return gpg_error (_gcry_mpi_scan (ret_mpi, format, buffer, buflen, nscanned)); } 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) { return gpg_error (_gcry_mpi_print (format, buffer, buflen, nwritten, a)); } gcry_error_t gcry_mpi_aprint (enum gcry_mpi_format format, unsigned char **buffer, size_t *nwritten, const gcry_mpi_t a) { return gpg_error (_gcry_mpi_aprint (format, buffer, nwritten, a)); } void gcry_mpi_dump (const gcry_mpi_t a) { _gcry_log_printmpi (NULL, a); } void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v) { _gcry_mpi_add (w, u, v); } void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v) { _gcry_mpi_add_ui (w, u, v); } void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m) { _gcry_mpi_addm (w, u, v, m); } void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v) { _gcry_mpi_sub (w, u, v); } void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ) { _gcry_mpi_sub_ui (w, u, v); } void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m) { _gcry_mpi_subm (w, u, v, m); } void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v) { _gcry_mpi_mul (w, u, v); } void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ) { _gcry_mpi_mul_ui (w, u, v); } void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m) { _gcry_mpi_mulm (w, u, v, m); } void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt) { _gcry_mpi_mul_2exp (w, u, cnt); } void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor, int round) { _gcry_mpi_div (q, r, dividend, divisor, round); } void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor) { _gcry_mpi_mod (r, dividend, divisor); } void gcry_mpi_powm (gcry_mpi_t w, const gcry_mpi_t b, const gcry_mpi_t e, const gcry_mpi_t m) { _gcry_mpi_powm (w, b, e, m); } int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b) { return _gcry_mpi_gcd (g, a, b); } int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m) { return _gcry_mpi_invm (x, a, m); } gcry_mpi_point_t gcry_mpi_point_new (unsigned int nbits) { return _gcry_mpi_point_new (nbits); } void gcry_mpi_point_release (gcry_mpi_point_t point) { _gcry_mpi_point_release (point); } gcry_mpi_point_t gcry_mpi_point_copy (gcry_mpi_point_t point) { return _gcry_mpi_point_copy (point); } void gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point) { _gcry_mpi_point_get (x, y, z, point); } void gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point) { _gcry_mpi_point_snatch_get (x, y, z, point); } 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) { return _gcry_mpi_point_set (point, x, y, z); } 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) { return _gcry_mpi_point_snatch_set (point, x, y, z); } gpg_error_t gcry_mpi_ec_new (gcry_ctx_t *r_ctx, gcry_sexp_t keyparam, const char *curvename) { return gpg_error (_gcry_mpi_ec_new (r_ctx, keyparam, curvename)); } gcry_mpi_t gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy) { return _gcry_mpi_ec_get_mpi (name, ctx, copy); } gcry_mpi_point_t gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy) { return _gcry_mpi_ec_get_point (name, ctx, copy); } gpg_error_t gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, gcry_ctx_t ctx) { return gpg_error (_gcry_mpi_ec_set_mpi (name, newvalue, ctx)); } gpg_error_t gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue, gcry_ctx_t ctx) { return gpg_error (_gcry_mpi_ec_set_point (name, newvalue, ctx)); } gpg_error_t gcry_mpi_ec_decode_point (gcry_mpi_point_t result, gcry_mpi_t value, gcry_ctx_t ctx) { return gpg_error (_gcry_mpi_ec_decode_point (result, value, ctx? _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC) : NULL)); } int gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, gcry_ctx_t ctx) { return _gcry_mpi_ec_get_affine (x, y, point, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); } void gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx) { mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY) { mpi_point_resize (w, ec); mpi_point_resize (u, ec); } _gcry_mpi_ec_dup_point (w, u, ec); } void gcry_mpi_ec_add (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx) { mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY) { mpi_point_resize (w, ec); mpi_point_resize (u, ec); mpi_point_resize (v, ec); } _gcry_mpi_ec_add_points (w, u, v, ec); } void gcry_mpi_ec_sub (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx) { mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); if (ec->model == MPI_EC_EDWARDS || ec->model == MPI_EC_MONTGOMERY) { mpi_point_resize (w, ec); mpi_point_resize (u, ec); mpi_point_resize (v, ec); } _gcry_mpi_ec_sub_points (w, u, v, ec); } void gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u, gcry_ctx_t ctx) { _gcry_mpi_ec_mul_point (w, n, u, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); } int gcry_mpi_ec_curve_point (gcry_mpi_point_t point, gcry_ctx_t ctx) { return _gcry_mpi_ec_curve_point (point, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); } unsigned int gcry_mpi_get_nbits (gcry_mpi_t a) { return _gcry_mpi_get_nbits (a); } int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n) { return _gcry_mpi_test_bit (a, n); } void gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n) { _gcry_mpi_set_bit (a, n); } void gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n) { _gcry_mpi_clear_bit (a, n); } void gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n) { _gcry_mpi_set_highbit (a, n); } void gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n) { _gcry_mpi_clear_highbit (a, n); } void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n) { _gcry_mpi_rshift (x, a, n); } void gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n) { _gcry_mpi_lshift (x, a, n); } gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits) { return _gcry_mpi_set_opaque (a, p, nbits); } gcry_mpi_t gcry_mpi_set_opaque_copy (gcry_mpi_t a, const void *p, unsigned int nbits) { return _gcry_mpi_set_opaque_copy (a, p, nbits); } void * gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits) { return _gcry_mpi_get_opaque (a, nbits); } void gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { _gcry_mpi_set_flag (a, flag); } void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { _gcry_mpi_clear_flag (a, flag); } int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { return _gcry_mpi_get_flag (a, flag); } gcry_mpi_t _gcry_mpi_get_const (int no) { switch (no) { case 1: return _gcry_mpi_const (MPI_C_ONE); case 2: return _gcry_mpi_const (MPI_C_TWO); case 3: return _gcry_mpi_const (MPI_C_THREE); case 4: return _gcry_mpi_const (MPI_C_FOUR); case 8: return _gcry_mpi_const (MPI_C_EIGHT); default: log_bug("unsupported GCRYMPI_CONST_ macro used\n"); } } gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle, int algo, int mode, unsigned int flags) { if (!fips_is_operational ()) { *handle = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_cipher_open (handle, algo, mode, flags)); } void gcry_cipher_close (gcry_cipher_hd_t h) { _gcry_cipher_close (h); } gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t hd, const void *key, size_t keylen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gcry_error (_gcry_cipher_setkey (hd, key, keylen)); } gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t hd, const void *iv, size_t ivlen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gcry_error (_gcry_cipher_setiv (hd, iv, ivlen)); } gpg_error_t gcry_cipher_setctr (gcry_cipher_hd_t hd, const void *ctr, size_t ctrlen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gcry_error (_gcry_cipher_setctr (hd, ctr, ctrlen)); } gcry_error_t gcry_cipher_authenticate (gcry_cipher_hd_t hd, const void *abuf, size_t abuflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_authenticate (hd, abuf, abuflen)); } gcry_error_t gcry_cipher_gettag (gcry_cipher_hd_t hd, void *outtag, size_t taglen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_gettag (hd, outtag, taglen)); } gcry_error_t gcry_cipher_checktag (gcry_cipher_hd_t hd, const void *intag, size_t taglen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_checktag (hd, intag, taglen)); } gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_ctl (h, cmd, buffer, buflen)); } gcry_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer, size_t *nbytes) { return gpg_error (_gcry_cipher_info (h, what, buffer, nbytes)); } gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_algo_info (algo, what, buffer, nbytes)); } const char * gcry_cipher_algo_name (int algorithm) { return _gcry_cipher_algo_name (algorithm); } int gcry_cipher_map_name (const char *name) { return _gcry_cipher_map_name (name); } int gcry_cipher_mode_from_oid (const char *string) { return _gcry_cipher_mode_from_oid (string); } gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen) { if (!fips_is_operational ()) { /* Make sure that the plaintext will never make it to OUT. */ if (out) memset (out, 0x42, outsize); return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_cipher_encrypt (h, out, outsize, in, inlen)); } gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h, void *out, size_t outsize, const void *in, size_t inlen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_cipher_decrypt (h, out, outsize, in, inlen)); } size_t gcry_cipher_get_algo_keylen (int algo) { return _gcry_cipher_get_algo_keylen (algo); } size_t gcry_cipher_get_algo_blklen (int algo) { return _gcry_cipher_get_algo_blklen (algo); } gcry_error_t gcry_mac_algo_info (int algo, int what, void *buffer, size_t *nbytes) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_algo_info (algo, what, buffer, nbytes)); } const char * gcry_mac_algo_name (int algorithm) { return _gcry_mac_algo_name (algorithm); } int gcry_mac_map_name (const char *string) { return _gcry_mac_map_name (string); } int gcry_mac_get_algo (gcry_mac_hd_t hd) { return _gcry_mac_get_algo (hd); } unsigned int gcry_mac_get_algo_maclen (int algo) { return _gcry_mac_get_algo_maclen (algo); } unsigned int gcry_mac_get_algo_keylen (int algo) { return _gcry_mac_get_algo_keylen (algo); } gcry_error_t gcry_mac_open (gcry_mac_hd_t *handle, int algo, unsigned int flags, gcry_ctx_t ctx) { if (!fips_is_operational ()) { *handle = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_mac_open (handle, algo, flags, ctx)); } void gcry_mac_close (gcry_mac_hd_t hd) { _gcry_mac_close (hd); } gcry_error_t gcry_mac_setkey (gcry_mac_hd_t hd, const void *key, size_t keylen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_setkey (hd, key, keylen)); } gcry_error_t gcry_mac_setiv (gcry_mac_hd_t hd, const void *iv, size_t ivlen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_setiv (hd, iv, ivlen)); } gcry_error_t gcry_mac_write (gcry_mac_hd_t hd, const void *buf, size_t buflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_write (hd, buf, buflen)); } gcry_error_t gcry_mac_read (gcry_mac_hd_t hd, void *outbuf, size_t *outlen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_read (hd, outbuf, outlen)); } gcry_error_t gcry_mac_verify (gcry_mac_hd_t hd, const void *buf, size_t buflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_verify (hd, buf, buflen)); } gcry_error_t gcry_mac_ctl (gcry_mac_hd_t h, int cmd, void *buffer, size_t buflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_mac_ctl (h, cmd, buffer, buflen)); } gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey) { if (!fips_is_operational ()) { *result = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_pk_encrypt (result, data, pkey)); } gcry_error_t gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey) { if (!fips_is_operational ()) { *result = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_pk_decrypt (result, data, skey)); } gcry_error_t gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey) { if (!fips_is_operational ()) { *result = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_pk_sign (result, data, skey)); } gcry_error_t gcry_pk_hash_sign (gcry_sexp_t *result, const char *data_tmpl, gcry_sexp_t skey, gcry_md_hd_t hd, gcry_ctx_t ctx) { - (void)ctx; - return gpg_error (_gcry_pk_sign_md (result, data_tmpl, hd, skey)); + return gpg_error (_gcry_pk_sign_md (result, data_tmpl, hd, skey, ctx)); } gcry_error_t gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_pk_verify (sigval, data, pkey)); } gcry_error_t gcry_pk_hash_verify (gcry_sexp_t sigval, const char *data_tmpl, gcry_sexp_t pkey, gcry_md_hd_t hd, gcry_ctx_t ctx) { - (void)ctx; - return gpg_error (_gcry_pk_verify_md (sigval, data_tmpl, hd, pkey)); + return gpg_error (_gcry_pk_verify_md (sigval, data_tmpl, hd, pkey, ctx)); } gcry_error_t gcry_pk_testkey (gcry_sexp_t key) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_pk_testkey (key)); } gcry_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) { if (!fips_is_operational ()) { *r_key = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_pk_genkey (r_key, s_parms)); } gcry_error_t gcry_pk_ctl (int cmd, void *buffer, size_t buflen) { return gpg_error (_gcry_pk_ctl (cmd, buffer, buflen)); } gcry_error_t gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_pk_algo_info (algo, what, buffer, nbytes)); } const char * gcry_pk_algo_name (int algorithm) { return _gcry_pk_algo_name (algorithm); } int gcry_pk_map_name (const char *name) { return _gcry_pk_map_name (name); } unsigned int gcry_pk_get_nbits (gcry_sexp_t key) { if (!fips_is_operational ()) { (void)fips_not_operational (); return 0; } return _gcry_pk_get_nbits (key); } unsigned char * gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array) { if (!fips_is_operational ()) { (void)fips_not_operational (); return NULL; } return _gcry_pk_get_keygrip (key, array); } const char * gcry_pk_get_curve (gcry_sexp_t key, int iterator, unsigned int *r_nbits) { if (!fips_is_operational ()) { (void)fips_not_operational (); return NULL; } return _gcry_pk_get_curve (key, iterator, r_nbits); } gcry_sexp_t gcry_pk_get_param (int algo, const char *name) { if (!fips_is_operational ()) { (void)fips_not_operational (); return NULL; } return _gcry_pk_get_param (algo, name); } gcry_error_t gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp, int mode, gcry_ctx_t ctx) { if (!fips_is_operational ()) { *r_sexp = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_pubkey_get_sexp (r_sexp, mode, ctx)); } unsigned int gcry_ecc_get_algo_keylen (int curveid) { return _gcry_ecc_get_algo_keylen (curveid); } gpg_error_t gcry_ecc_mul_point (int curveid, unsigned char *result, const unsigned char *scalar, const unsigned char *point) { return _gcry_ecc_mul_point (curveid, result, scalar, point); } gcry_error_t gcry_pkey_open (gcry_pkey_hd_t *h_p, int algo, unsigned int flags, ...) { gcry_error_t err; va_list arg_ptr; va_start (arg_ptr, flags); err = _gcry_pkey_vopen (h_p, algo, flags, arg_ptr); va_end (arg_ptr); return err; } gcry_error_t gcry_pkey_ctl (gcry_pkey_hd_t h, int cmd, void *buffer, size_t buflen) { return _gcry_pkey_ctl (h, cmd, buffer, buflen); } gcry_error_t gcry_pkey_op (gcry_pkey_hd_t h, int cmd, int num_in, const unsigned char *const in[], const size_t in_len[], int num_out, unsigned char *out[], size_t out_len[]) { return _gcry_pkey_op (h, cmd, num_in, in, in_len, num_out, out, out_len); } void gcry_pkey_close (gcry_pkey_hd_t h) { _gcry_pkey_close (h); } gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags) { if (!fips_is_operational ()) { *h = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_md_open (h, algo, flags)); } void gcry_md_close (gcry_md_hd_t hd) { _gcry_md_close (hd); } gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_md_enable (hd, algo)); } gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd) { if (!fips_is_operational ()) { *bhd = NULL; return gpg_error (fips_not_operational ()); } return gpg_error (_gcry_md_copy (bhd, ahd)); } void gcry_md_reset (gcry_md_hd_t hd) { _gcry_md_reset (hd); } gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, void *buffer, size_t buflen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_md_ctl (hd, cmd, buffer, buflen)); } void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length) { if (!fips_is_operational ()) { (void)fips_not_operational (); return; } _gcry_md_write (hd, buffer, length); } unsigned char * gcry_md_read (gcry_md_hd_t hd, int algo) { return _gcry_md_read (hd, algo); } gcry_error_t gcry_md_extract (gcry_md_hd_t hd, int algo, void *buffer, size_t length) { return gpg_error (_gcry_md_extract(hd, algo, buffer, length)); } void gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_error ("called in non-operational state"); } _gcry_md_hash_buffer (algo, digest, buffer, length); } gpg_error_t gcry_md_hash_buffers (int algo, unsigned int flags, void *digest, const gcry_buffer_t *iov, int iovcnt) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_error ("called in non-operational state"); } return gpg_error (_gcry_md_hash_buffers (algo, flags, digest, iov, iovcnt)); } int gcry_md_get_algo (gcry_md_hd_t hd) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_error ("used in non-operational state"); return 0; } return _gcry_md_get_algo (hd); } unsigned int gcry_md_get_algo_dlen (int algo) { return _gcry_md_get_algo_dlen (algo); } int gcry_md_is_enabled (gcry_md_hd_t a, int algo) { if (!fips_is_operational ()) { (void)fips_not_operational (); return 0; } return _gcry_md_is_enabled (a, algo); } int gcry_md_is_secure (gcry_md_hd_t a) { return _gcry_md_is_secure (a); } gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer, size_t *nbytes) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_md_info (h, what, buffer, nbytes)); } gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes) { return gpg_error (_gcry_md_algo_info (algo, what, buffer, nbytes)); } const char * gcry_md_algo_name (int algo) { return _gcry_md_algo_name (algo); } int gcry_md_map_name (const char* name) { return _gcry_md_map_name (name); } gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_md_setkey (hd, key, keylen)); } void gcry_md_debug (gcry_md_hd_t hd, const char *suffix) { _gcry_md_debug (hd, suffix); } 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) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_kdf_derive (passphrase, passphraselen, algo, hashalgo, salt, saltlen, iterations, keysize, keybuffer)); } void gcry_randomize (void *buffer, size_t length, enum gcry_random_level level) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_fatal_error ("called in non-operational state"); fips_noreturn (); } _gcry_randomize (buffer, length, level); } gcry_error_t gcry_random_add_bytes (const void *buffer, size_t length, int quality) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_random_add_bytes (buffer, length, quality)); } void * gcry_random_bytes (size_t nbytes, enum gcry_random_level level) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_fatal_error ("called in non-operational state"); fips_noreturn (); } return _gcry_random_bytes (nbytes,level); } void * gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_fatal_error ("called in non-operational state"); fips_noreturn (); } return _gcry_random_bytes_secure (nbytes, level); } void gcry_mpi_randomize (gcry_mpi_t w, unsigned int nbits, enum gcry_random_level level) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_fatal_error ("called in non-operational state"); fips_noreturn (); } _gcry_mpi_randomize (w, nbits, level); } void gcry_create_nonce (void *buffer, size_t length) { if (!fips_is_operational ()) { (void)fips_not_operational (); fips_signal_fatal_error ("called in non-operational state"); fips_noreturn (); } _gcry_create_nonce (buffer, length); } 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) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_prime_generate (prime, prime_bits, factor_bits, factors, cb_func, cb_arg, random_level, flags)); } 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) { if (!fips_is_operational ()) return gpg_error (fips_not_operational ()); return gpg_error (_gcry_prime_group_generator (r_g, prime, factors, start_g)); } void gcry_prime_release_factors (gcry_mpi_t *factors) { _gcry_prime_release_factors (factors); } gcry_error_t gcry_prime_check (gcry_mpi_t x, unsigned int flags) { return gpg_error (_gcry_prime_check (x, flags)); } void gcry_ctx_release (gcry_ctx_t ctx) { _gcry_ctx_release (ctx); } void gcry_log_debug (const char *fmt, ...) { va_list arg_ptr ; va_start( arg_ptr, fmt ) ; _gcry_logv (GCRY_LOG_DEBUG, fmt, arg_ptr); va_end (arg_ptr); } void gcry_log_debughex (const char *text, const void *buffer, size_t length) { _gcry_log_printhex (text, buffer, length); } void gcry_log_debugmpi (const char *text, gcry_mpi_t mpi) { _gcry_log_printmpi (text, mpi); } void gcry_log_debugpnt (const char *text, mpi_point_t point, gcry_ctx_t ctx) { mpi_ec_t ec = ctx? _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC) : NULL; _gcry_mpi_point_log (text, point, ec); } void gcry_log_debugsxp (const char *text, gcry_sexp_t sexp) { _gcry_log_printsxp (text, sexp); } char * gcry_get_config (int mode, const char *what) { return _gcry_get_config (mode, what); } void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data) { _gcry_set_progress_handler (cb, cb_data); } 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) { _gcry_set_allocation_handler (func_alloc, func_alloc_secure, func_secure_check, func_realloc, func_free); } void gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque) { _gcry_set_outofcore_handler (h, opaque); } void gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque) { _gcry_set_fatalerror_handler (fnc, opaque); } void gcry_set_log_handler (gcry_handler_log_t f, void *opaque) { _gcry_set_log_handler (f, opaque); } void gcry_set_gettext_handler (const char *(*f)(const char*)) { _gcry_set_gettext_handler (f); } void * gcry_malloc (size_t n) { return _gcry_malloc (n); } void * gcry_calloc (size_t n, size_t m) { return _gcry_calloc (n, m); } void * gcry_malloc_secure (size_t n) { return _gcry_malloc_secure (n); } void * gcry_calloc_secure (size_t n, size_t m) { return _gcry_calloc_secure (n,m); } void * gcry_realloc (void *a, size_t n) { return _gcry_realloc (a, n); } char * gcry_strdup (const char *string) { return _gcry_strdup (string); } void * gcry_xmalloc (size_t n) { return _gcry_xmalloc (n); } void * gcry_xcalloc (size_t n, size_t m) { return _gcry_xcalloc (n, m); } void * gcry_xmalloc_secure (size_t n) { return _gcry_xmalloc_secure (n); } void * gcry_xcalloc_secure (size_t n, size_t m) { return _gcry_xcalloc_secure (n, m); } void * gcry_xrealloc (void *a, size_t n) { return _gcry_xrealloc (a, n); } char * gcry_xstrdup (const char *a) { return _gcry_xstrdup (a); } void gcry_free (void *a) { _gcry_free (a); } int gcry_is_secure (const void *a) { return _gcry_is_secure (a); }