1 /* cipher-proto.h - Internal declarations
2 * Copyright (C) 2008, 2011 Free Software Foundation, Inc.
4 * This file is part of Libgcrypt.
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.
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.
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/>.
20 /* This file has been factored out from cipher.h so that it can be
21 used standalone in visibility.c . */
23 #ifndef G10_CIPHER_PROTO_H
24 #define G10_CIPHER_PROTO_H
30 /* Definition of a function used to report selftest failures.
31 DOMAIN is a string describing the function block:
32 "cipher", "digest", "pubkey or "random",
33 ALGO is the algorithm under test,
34 WHAT is a string describing what has been tested,
35 DESC is a string describing the error. */
36 typedef void (*selftest_report_func_t)(const char *domain,
41 /* Definition of the selftest functions. */
42 typedef gpg_err_code_t (*selftest_func_t)
43 (int algo, int extended, selftest_report_func_t report);
48 * Public key related definitions.
52 /* Type for the pk_generate function. */
53 typedef gcry_err_code_t (*gcry_pk_generate_t) (gcry_sexp_t genparms,
56 /* Type for the pk_check_secret_key function. */
57 typedef gcry_err_code_t (*gcry_pk_check_secret_key_t) (gcry_sexp_t keyparms);
59 /* Type for the pk_encrypt function. */
60 typedef gcry_err_code_t (*gcry_pk_encrypt_t) (gcry_sexp_t *r_ciph,
62 gcry_sexp_t keyparms);
64 /* Type for the pk_decrypt function. */
65 typedef gcry_err_code_t (*gcry_pk_decrypt_t) (gcry_sexp_t *r_plain,
67 gcry_sexp_t keyparms);
69 /* Type for the pk_sign function. */
70 typedef gcry_err_code_t (*gcry_pk_sign_t) (gcry_sexp_t *r_sig,
72 gcry_sexp_t keyparms);
74 /* Type for the pk_verify function. */
75 typedef gcry_err_code_t (*gcry_pk_verify_t) (gcry_sexp_t s_sig,
77 gcry_sexp_t keyparms);
79 /* Type for the pk_get_nbits function. */
80 typedef unsigned (*gcry_pk_get_nbits_t) (gcry_sexp_t keyparms);
83 /* The type used to compute the keygrip. */
84 typedef gpg_err_code_t (*pk_comp_keygrip_t) (gcry_md_hd_t md,
87 /* The type used to query an ECC curve name. */
88 typedef const char *(*pk_get_curve_t)(gcry_sexp_t keyparms, int iterator,
89 unsigned int *r_nbits);
91 /* The type used to query ECC curve parameters by name. */
92 typedef gcry_sexp_t (*pk_get_curve_param_t)(const char *name);
95 /* Module specification structure for public key algorithms. */
96 typedef struct gcry_pk_spec
100 unsigned int disabled:1;
105 const char **aliases;
106 const char *elements_pkey;
107 const char *elements_skey;
108 const char *elements_enc;
109 const char *elements_sig;
110 const char *elements_grip;
111 gcry_pk_generate_t generate;
112 gcry_pk_check_secret_key_t check_secret_key;
113 gcry_pk_encrypt_t encrypt;
114 gcry_pk_decrypt_t decrypt;
116 gcry_pk_verify_t verify;
117 gcry_pk_get_nbits_t get_nbits;
118 selftest_func_t selftest;
119 pk_comp_keygrip_t comp_keygrip;
120 pk_get_curve_t get_curve;
121 pk_get_curve_param_t get_curve_param;
128 * Symmetric cipher related definitions.
132 /* Type for the cipher_setkey function. */
133 typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c,
134 const unsigned char *key,
137 /* Type for the cipher_encrypt function. */
138 typedef unsigned int (*gcry_cipher_encrypt_t) (void *c,
139 unsigned char *outbuf,
140 const unsigned char *inbuf);
142 /* Type for the cipher_decrypt function. */
143 typedef unsigned int (*gcry_cipher_decrypt_t) (void *c,
144 unsigned char *outbuf,
145 const unsigned char *inbuf);
147 /* Type for the cipher_stencrypt function. */
148 typedef void (*gcry_cipher_stencrypt_t) (void *c,
149 unsigned char *outbuf,
150 const unsigned char *inbuf,
153 /* Type for the cipher_stdecrypt function. */
154 typedef void (*gcry_cipher_stdecrypt_t) (void *c,
155 unsigned char *outbuf,
156 const unsigned char *inbuf,
159 /* The type used to convey additional information to a cipher. */
160 typedef gpg_err_code_t (*cipher_set_extra_info_t)
161 (void *c, int what, const void *buffer, size_t buflen);
163 /* The type used to set an IV directly in the algorithm module. */
164 typedef void (*cipher_setiv_func_t)(void *c, const byte *iv, size_t ivlen);
166 /* A structure to map OIDs to encryption modes. */
167 typedef struct gcry_cipher_oid_spec
171 } gcry_cipher_oid_spec_t;
174 /* Module specification structure for ciphers. */
175 typedef struct gcry_cipher_spec
179 unsigned int disabled:1;
183 const char **aliases;
184 gcry_cipher_oid_spec_t *oids;
188 gcry_cipher_setkey_t setkey;
189 gcry_cipher_encrypt_t encrypt;
190 gcry_cipher_decrypt_t decrypt;
191 gcry_cipher_stencrypt_t stencrypt;
192 gcry_cipher_stdecrypt_t stdecrypt;
193 selftest_func_t selftest;
194 cipher_set_extra_info_t set_extra_info;
195 cipher_setiv_func_t setiv;
196 } gcry_cipher_spec_t;
202 * Message digest related definitions.
206 /* Type for the md_init function. */
207 typedef void (*gcry_md_init_t) (void *c, unsigned int flags);
209 /* Type for the md_write function. */
210 typedef void (*gcry_md_write_t) (void *c, const void *buf, size_t nbytes);
212 /* Type for the md_final function. */
213 typedef void (*gcry_md_final_t) (void *c);
215 /* Type for the md_read function. */
216 typedef unsigned char *(*gcry_md_read_t) (void *c);
218 /* Type for the md_extract function. */
219 typedef void (*gcry_md_extract_t) (void *c, void *outbuf, size_t nbytes);
221 typedef struct gcry_md_oid_spec
223 const char *oidstring;
224 } gcry_md_oid_spec_t;
226 /* Module specification structure for message digests. */
227 typedef struct gcry_md_spec
231 unsigned int disabled:1;
235 unsigned char *asnoid;
237 gcry_md_oid_spec_t *oids;
240 gcry_md_write_t write;
241 gcry_md_final_t final;
243 gcry_md_extract_t extract;
244 size_t contextsize; /* allocate this amount of context */
245 selftest_func_t selftest;
250 /* The selftest functions. */
251 gcry_error_t _gcry_cipher_selftest (int algo, int extended,
252 selftest_report_func_t report);
253 gcry_error_t _gcry_md_selftest (int algo, int extended,
254 selftest_report_func_t report);
255 gcry_error_t _gcry_pk_selftest (int algo, int extended,
256 selftest_report_func_t report);
257 gcry_error_t _gcry_hmac_selftest (int algo, int extended,
258 selftest_report_func_t report);
260 gcry_error_t _gcry_random_selftest (selftest_report_func_t report);
265 #endif /*G10_CIPHER_PROTO_H*/