1/* cipher-proto.h - Internal declarations
2 *	Copyright (C) 2008, 2011 Free Software Foundation, Inc.
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/* This file has been factored out from cipher.h so that it can be
21   used standalone in visibility.c . */
22
23#ifndef G10_CIPHER_PROTO_H
24#define G10_CIPHER_PROTO_H
25
26/* Definition of a function used to report selftest failures.
27   DOMAIN is a string describing the function block:
28          "cipher", "digest", "pubkey or "random",
29   ALGO   is the algorithm under test,
30   WHAT   is a string describing what has been tested,
31   DESC   is a string describing the error. */
32typedef void (*selftest_report_func_t)(const char *domain,
33                                       int algo,
34                                       const char *what,
35                                       const char *errdesc);
36
37/* Definition of the selftest functions.  */
38typedef gpg_err_code_t (*selftest_func_t)
39     (int algo, int extended, selftest_report_func_t report);
40
41
42/* An extended type of the generate function.  */
43typedef gcry_err_code_t (*pk_ext_generate_t)
44     (int algo,
45      unsigned int nbits,
46      unsigned long evalue,
47      gcry_sexp_t genparms,
48      gcry_mpi_t *skey,
49      gcry_mpi_t **retfactors,
50      gcry_sexp_t *extrainfo);
51
52/* The type used to compute the keygrip.  */
53typedef gpg_err_code_t (*pk_comp_keygrip_t)
54     (gcry_md_hd_t md, gcry_sexp_t keyparm);
55
56/* The type used to query ECC curve parameters.  */
57typedef gcry_err_code_t (*pk_get_param_t)
58     (const char *name, gcry_mpi_t *pkey);
59
60/* The type used to query an ECC curve name.  */
61typedef const char *(*pk_get_curve_t)(gcry_mpi_t *pkey, int iterator,
62                                      unsigned int *r_nbits);
63
64/* The type used to query ECC curve parameters by name.  */
65typedef gcry_sexp_t (*pk_get_curve_param_t)(const char *name);
66
67/* The type used to convey additional information to a cipher.  */
68typedef gpg_err_code_t (*cipher_set_extra_info_t)
69     (void *c, int what, const void *buffer, size_t buflen);
70
71
72/* Extra module specification structures.  These are used for internal
73   modules which provide more functions than available through the
74   public algorithm register APIs.  */
75typedef struct cipher_extra_spec
76{
77  selftest_func_t selftest;
78  cipher_set_extra_info_t set_extra_info;
79} cipher_extra_spec_t;
80
81typedef struct md_extra_spec
82{
83  selftest_func_t selftest;
84} md_extra_spec_t;
85
86typedef struct pk_extra_spec
87{
88  selftest_func_t selftest;
89  pk_ext_generate_t ext_generate;
90  pk_comp_keygrip_t comp_keygrip;
91  pk_get_param_t get_param;
92  pk_get_curve_t get_curve;
93  pk_get_curve_param_t get_curve_param;
94} pk_extra_spec_t;
95
96
97
98/* The private register functions. */
99gcry_error_t _gcry_cipher_register (gcry_cipher_spec_t *cipher,
100                                    cipher_extra_spec_t *extraspec,
101                                    int *algorithm_id,
102                                    gcry_module_t *module);
103gcry_error_t _gcry_md_register (gcry_md_spec_t *cipher,
104                                md_extra_spec_t *extraspec,
105                                unsigned int *algorithm_id,
106                                gcry_module_t *module);
107gcry_error_t _gcry_pk_register (gcry_pk_spec_t *cipher,
108                                pk_extra_spec_t *extraspec,
109                                unsigned int *algorithm_id,
110                                gcry_module_t *module);
111
112/* The selftest functions.  */
113gcry_error_t _gcry_cipher_selftest (int algo, int extended,
114                                    selftest_report_func_t report);
115gcry_error_t _gcry_md_selftest (int algo, int extended,
116                                selftest_report_func_t report);
117gcry_error_t _gcry_pk_selftest (int algo, int extended,
118                                selftest_report_func_t report);
119gcry_error_t _gcry_hmac_selftest (int algo, int extended,
120                                  selftest_report_func_t report);
121
122gcry_error_t _gcry_random_selftest (selftest_report_func_t report);
123
124#endif /*G10_CIPHER_PROTO_H*/
125