Imported Upstream version 1.6.2
[platform/upstream/libgcrypt.git] / src / cipher.h
1 /* cipher.h
2  *      Copyright (C) 1998, 2002, 2003, 2009 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, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19  */
20 #ifndef G10_CIPHER_H
21 #define G10_CIPHER_H
22
23 #include "gcrypt-int.h"
24
25 #define DBG_CIPHER _gcry_get_debug_flag( 1 )
26
27 #include "../random/random.h"
28
29 #define PUBKEY_FLAG_NO_BLINDING    (1 << 0)
30 #define PUBKEY_FLAG_RFC6979        (1 << 1)
31 #define PUBKEY_FLAG_FIXEDLEN       (1 << 2)
32 #define PUBKEY_FLAG_LEGACYRESULT   (1 << 3)
33 #define PUBKEY_FLAG_RAW_FLAG       (1 << 4)
34 #define PUBKEY_FLAG_TRANSIENT_KEY  (1 << 5)
35 #define PUBKEY_FLAG_USE_X931       (1 << 6)
36 #define PUBKEY_FLAG_USE_FIPS186    (1 << 7)
37 #define PUBKEY_FLAG_USE_FIPS186_2  (1 << 8)
38 #define PUBKEY_FLAG_PARAM          (1 << 9)
39 #define PUBKEY_FLAG_COMP           (1 << 10)
40 #define PUBKEY_FLAG_NOCOMP         (1 << 11)
41 #define PUBKEY_FLAG_EDDSA          (1 << 12)
42 #define PUBKEY_FLAG_GOST           (1 << 13)
43
44
45 enum pk_operation
46   {
47     PUBKEY_OP_ENCRYPT,
48     PUBKEY_OP_DECRYPT,
49     PUBKEY_OP_SIGN,
50     PUBKEY_OP_VERIFY
51   };
52
53 enum pk_encoding
54   {
55     PUBKEY_ENC_RAW,
56     PUBKEY_ENC_PKCS1,
57     PUBKEY_ENC_OAEP,
58     PUBKEY_ENC_PSS,
59     PUBKEY_ENC_UNKNOWN
60   };
61
62 struct pk_encoding_ctx
63 {
64   enum pk_operation op;
65   unsigned int nbits;
66
67   enum pk_encoding encoding;
68   int flags;
69
70   int hash_algo;
71
72   /* for OAEP */
73   unsigned char *label;
74   size_t labellen;
75
76   /* for PSS */
77   size_t saltlen;
78
79   int (* verify_cmp) (void *opaque, gcry_mpi_t tmp);
80   void *verify_arg;
81 };
82
83 #define CIPHER_INFO_NO_WEAK_KEY    1
84
85 #include "cipher-proto.h"
86
87 /* The internal encryption modes. */
88 enum gcry_cipher_internal_modes
89   {
90     GCRY_CIPHER_MODE_INTERNAL = 0x10000,
91     GCRY_CIPHER_MODE_CMAC     = 0x10000 + 1   /* Cipher-based MAC. */
92   };
93
94
95 /*-- cipher.c --*/
96 gcry_err_code_t _gcry_cipher_open_internal (gcry_cipher_hd_t *handle,
97                                             int algo, int mode,
98                                             unsigned int flags);
99
100 /*-- cipher-cmac.c --*/
101 gcry_err_code_t _gcry_cipher_cmac_authenticate
102 /*           */ (gcry_cipher_hd_t c, const unsigned char *abuf, size_t abuflen);
103 gcry_err_code_t _gcry_cipher_cmac_get_tag
104 /*           */ (gcry_cipher_hd_t c,
105                  unsigned char *outtag, size_t taglen);
106 gcry_err_code_t _gcry_cipher_cmac_check_tag
107 /*           */ (gcry_cipher_hd_t c,
108                  const unsigned char *intag, size_t taglen);
109 gcry_err_code_t _gcry_cipher_cmac_set_subkeys
110 /*           */ (gcry_cipher_hd_t c);
111
112 /*-- rmd160.c --*/
113 void _gcry_rmd160_hash_buffer (void *outbuf,
114                                const void *buffer, size_t length);
115 /*-- sha1.c --*/
116 void _gcry_sha1_hash_buffer (void *outbuf,
117                              const void *buffer, size_t length);
118 void _gcry_sha1_hash_buffers (void *outbuf,
119                               const gcry_buffer_t *iov, int iovcnt);
120
121 /*-- rijndael.c --*/
122 void _gcry_aes_cfb_enc (void *context, unsigned char *iv,
123                         void *outbuf, const void *inbuf,
124                         size_t nblocks);
125 void _gcry_aes_cfb_dec (void *context, unsigned char *iv,
126                         void *outbuf_arg, const void *inbuf_arg,
127                         size_t nblocks);
128 void _gcry_aes_cbc_enc (void *context, unsigned char *iv,
129                         void *outbuf_arg, const void *inbuf_arg,
130                         size_t nblocks, int cbc_mac);
131 void _gcry_aes_cbc_dec (void *context, unsigned char *iv,
132                         void *outbuf_arg, const void *inbuf_arg,
133                         size_t nblocks);
134 void _gcry_aes_ctr_enc (void *context, unsigned char *ctr,
135                         void *outbuf_arg, const void *inbuf_arg,
136                         size_t nblocks);
137
138 /*-- blowfish.c --*/
139 void _gcry_blowfish_cfb_dec (void *context, unsigned char *iv,
140                              void *outbuf_arg, const void *inbuf_arg,
141                              size_t nblocks);
142
143 void _gcry_blowfish_cbc_dec (void *context, unsigned char *iv,
144                              void *outbuf_arg, const void *inbuf_arg,
145                              size_t nblocks);
146
147 void _gcry_blowfish_ctr_enc (void *context, unsigned char *ctr,
148                              void *outbuf_arg, const void *inbuf_arg,
149                              size_t nblocks);
150
151 /*-- cast5.c --*/
152 void _gcry_cast5_cfb_dec (void *context, unsigned char *iv,
153                           void *outbuf_arg, const void *inbuf_arg,
154                           size_t nblocks);
155
156 void _gcry_cast5_cbc_dec (void *context, unsigned char *iv,
157                           void *outbuf_arg, const void *inbuf_arg,
158                           size_t nblocks);
159
160 void _gcry_cast5_ctr_enc (void *context, unsigned char *ctr,
161                           void *outbuf_arg, const void *inbuf_arg,
162                           size_t nblocks);
163
164 /*-- camellia-glue.c --*/
165 void _gcry_camellia_ctr_enc (void *context, unsigned char *ctr,
166                              void *outbuf_arg, const void *inbuf_arg,
167                              size_t nblocks);
168 void _gcry_camellia_cbc_dec (void *context, unsigned char *iv,
169                              void *outbuf_arg, const void *inbuf_arg,
170                              size_t nblocks);
171 void _gcry_camellia_cfb_dec (void *context, unsigned char *iv,
172                              void *outbuf_arg, const void *inbuf_arg,
173                              size_t nblocks);
174
175 /*-- serpent.c --*/
176 void _gcry_serpent_ctr_enc (void *context, unsigned char *ctr,
177                             void *outbuf_arg, const void *inbuf_arg,
178                             size_t nblocks);
179 void _gcry_serpent_cbc_dec (void *context, unsigned char *iv,
180                             void *outbuf_arg, const void *inbuf_arg,
181                             size_t nblocks);
182 void _gcry_serpent_cfb_dec (void *context, unsigned char *iv,
183                             void *outbuf_arg, const void *inbuf_arg,
184                             size_t nblocks);
185
186 /*-- twofish.c --*/
187 void _gcry_twofish_ctr_enc (void *context, unsigned char *ctr,
188                             void *outbuf_arg, const void *inbuf_arg,
189                             size_t nblocks);
190 void _gcry_twofish_cbc_dec (void *context, unsigned char *iv,
191                             void *outbuf_arg, const void *inbuf_arg,
192                             size_t nblocks);
193 void _gcry_twofish_cfb_dec (void *context, unsigned char *iv,
194                             void *outbuf_arg, const void *inbuf_arg,
195                             size_t nblocks);
196
197 /*-- dsa.c --*/
198 void _gcry_register_pk_dsa_progress (gcry_handler_progress_t cbc, void *cb_data);
199
200 /*-- elgamal.c --*/
201 void _gcry_register_pk_elg_progress (gcry_handler_progress_t cb,
202                                      void *cb_data);
203
204
205 /*-- ecc.c --*/
206 void _gcry_register_pk_ecc_progress (gcry_handler_progress_t cbc,
207                                      void *cb_data);
208
209
210 /*-- primegen.c --*/
211 void _gcry_register_primegen_progress (gcry_handler_progress_t cb,
212                                        void *cb_data);
213
214 /*-- pubkey.c --*/
215
216 /* Declarations for the cipher specifications.  */
217 extern gcry_cipher_spec_t _gcry_cipher_spec_blowfish;
218 extern gcry_cipher_spec_t _gcry_cipher_spec_des;
219 extern gcry_cipher_spec_t _gcry_cipher_spec_tripledes;
220 extern gcry_cipher_spec_t _gcry_cipher_spec_arcfour;
221 extern gcry_cipher_spec_t _gcry_cipher_spec_cast5;
222 extern gcry_cipher_spec_t _gcry_cipher_spec_aes;
223 extern gcry_cipher_spec_t _gcry_cipher_spec_aes192;
224 extern gcry_cipher_spec_t _gcry_cipher_spec_aes256;
225 extern gcry_cipher_spec_t _gcry_cipher_spec_twofish;
226 extern gcry_cipher_spec_t _gcry_cipher_spec_twofish128;
227 extern gcry_cipher_spec_t _gcry_cipher_spec_serpent128;
228 extern gcry_cipher_spec_t _gcry_cipher_spec_serpent192;
229 extern gcry_cipher_spec_t _gcry_cipher_spec_serpent256;
230 extern gcry_cipher_spec_t _gcry_cipher_spec_rfc2268_40;
231 extern gcry_cipher_spec_t _gcry_cipher_spec_rfc2268_128;
232 extern gcry_cipher_spec_t _gcry_cipher_spec_seed;
233 extern gcry_cipher_spec_t _gcry_cipher_spec_camellia128;
234 extern gcry_cipher_spec_t _gcry_cipher_spec_camellia192;
235 extern gcry_cipher_spec_t _gcry_cipher_spec_camellia256;
236 extern gcry_cipher_spec_t _gcry_cipher_spec_idea;
237 extern gcry_cipher_spec_t _gcry_cipher_spec_salsa20;
238 extern gcry_cipher_spec_t _gcry_cipher_spec_salsa20r12;
239 extern gcry_cipher_spec_t _gcry_cipher_spec_gost28147;
240
241 /* Declarations for the digest specifications.  */
242 extern gcry_md_spec_t _gcry_digest_spec_crc32;
243 extern gcry_md_spec_t _gcry_digest_spec_crc32_rfc1510;
244 extern gcry_md_spec_t _gcry_digest_spec_crc24_rfc2440;
245 extern gcry_md_spec_t _gcry_digest_spec_gost3411_94;
246 extern gcry_md_spec_t _gcry_digest_spec_stribog_256;
247 extern gcry_md_spec_t _gcry_digest_spec_stribog_512;
248 extern gcry_md_spec_t _gcry_digest_spec_md4;
249 extern gcry_md_spec_t _gcry_digest_spec_md5;
250 extern gcry_md_spec_t _gcry_digest_spec_rmd160;
251 extern gcry_md_spec_t _gcry_digest_spec_sha1;
252 extern gcry_md_spec_t _gcry_digest_spec_sha224;
253 extern gcry_md_spec_t _gcry_digest_spec_sha256;
254 extern gcry_md_spec_t _gcry_digest_spec_sha512;
255 extern gcry_md_spec_t _gcry_digest_spec_sha384;
256 extern gcry_md_spec_t _gcry_digest_spec_tiger;
257 extern gcry_md_spec_t _gcry_digest_spec_tiger1;
258 extern gcry_md_spec_t _gcry_digest_spec_tiger2;
259 extern gcry_md_spec_t _gcry_digest_spec_whirlpool;
260
261 /* Declarations for the pubkey cipher specifications.  */
262 extern gcry_pk_spec_t _gcry_pubkey_spec_rsa;
263 extern gcry_pk_spec_t _gcry_pubkey_spec_elg;
264 extern gcry_pk_spec_t _gcry_pubkey_spec_elg_e;
265 extern gcry_pk_spec_t _gcry_pubkey_spec_dsa;
266 extern gcry_pk_spec_t _gcry_pubkey_spec_ecc;
267
268
269 #endif /*G10_CIPHER_H*/