1 /* crypto.h --- Crypto prototypes.
2  * Copyright (C) 2002-2013 Simon Josefsson
3  *
4  * This file is part of Shishi.
5  *
6  * Shishi is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Shishi is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Shishi; if not, see http://www.gnu.org/licenses or write
18  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19  * Floor, Boston, MA 02110-1301, USA
20  *
21  */
22 
23 #ifndef _CRYPTO_H
24 #define _CRYPTO_H
25 
26 #define SHISHI_DK_CONSTANT "\x6b\x65\x72\x62\x65\x72\x6f\x73"
27 
28 int
29 _shishi_simplified_derivekey (Shishi * handle,
30 			      Shishi_key * key,
31 			      int keyusage,
32 			      int derivekeymode, Shishi_key ** outkey);
33 int
34 _shishi_simplified_checksum (Shishi * handle,
35 			     Shishi_key * key,
36 			     int keyusage,
37 			     int cksumtype,
38 			     const char *in, size_t inlen,
39 			     char **out, size_t * outlen);
40 int
41 _shishi_simplified_dencrypt (Shishi * handle,
42 			     Shishi_key * key,
43 			     const char *iv, size_t ivlen,
44 			     char **ivout, size_t * ivoutlen,
45 			     const char *in, size_t inlen,
46 			     char **out, size_t * outlen, int decryptp);
47 int
48 _shishi_simplified_encrypt (Shishi * handle,
49 			    Shishi_key * key,
50 			    int keyusage,
51 			    const char *iv, size_t ivlen,
52 			    char **ivout, size_t * ivoutlen,
53 			    const char *in, size_t inlen,
54 			    char **out, size_t * outlen);
55 int
56 _shishi_simplified_decrypt (Shishi * handle,
57 			    Shishi_key * key,
58 			    int keyusage,
59 			    const char *iv, size_t ivlen,
60 			    char **ivout, size_t * ivoutlen,
61 			    const char *in, size_t inlen,
62 			    char **out, size_t * outlen);
63 
64 typedef enum
65 {
66   SHISHI_DERIVEKEYMODE_CHECKSUM,
67   SHISHI_DERIVEKEYMODE_PRIVACY,
68   SHISHI_DERIVEKEYMODE_INTEGRITY
69 }
70 Shishi_derivekeymode;
71 
72 typedef int (*Shishi_random_to_key_function) (Shishi * handle,
73 					      const char *rnd,
74 					      size_t rndlen,
75 					      Shishi_key * outkey);
76 
77 typedef int (*Shishi_string_to_key_function) (Shishi * handle,
78 					      const char *password,
79 					      size_t passwordlen,
80 					      const char *salt,
81 					      size_t saltlen,
82 					      const char *parameter,
83 					      Shishi_key * outkey);
84 
85 typedef int (*Shishi_encrypt_function) (Shishi * handle,
86 					Shishi_key * key,
87 					int keyusage,
88 					const char *iv, size_t ivlen,
89 					char **ivout, size_t * ivoutlen,
90 					const char *in, size_t inlen,
91 					char **out, size_t * outlen);
92 
93 typedef int (*Shishi_decrypt_function) (Shishi * handle,
94 					Shishi_key * key,
95 					int keyusage,
96 					const char *iv, size_t ivlen,
97 					char **ivout, size_t * ivoutlen,
98 					const char *in, size_t inlen,
99 					char **out, size_t * outlen);
100 
101 typedef int (*Shishi_checksum_function) (Shishi * handle,
102 					 Shishi_key * key,
103 					 int keyusage,
104 					 int cksumtype,
105 					 const char *in, size_t inlen,
106 					 char **out, size_t * outlen);
107 
108 typedef int (*Shishi_verify_function) (Shishi * handle,
109 				       Shishi_key * key,
110 				       int keyusage,
111 				       int cksumtype,
112 				       const char *in, size_t inlen,
113 				       const char *cksum, size_t cksumlen);
114 
115 struct cipherinfo
116 {
117   int32_t type;
118   const char *name;
119   size_t blocksize;
120   size_t confoundersize;
121   size_t keylen;
122   size_t randomlen;
123   uint32_t defaultcksumtype;
124   Shishi_random_to_key_function random2key;
125   Shishi_string_to_key_function string2key;
126   Shishi_encrypt_function encrypt;
127   Shishi_decrypt_function decrypt;
128 };
129 typedef struct cipherinfo cipherinfo;
130 
131 struct checksuminfo
132 {
133   int32_t type;
134   const char *name;
135   int cksumlen;
136   Shishi_checksum_function checksum;
137   Shishi_verify_function verify;
138 };
139 typedef struct checksuminfo checksuminfo;
140 
141 extern cipherinfo null_info;
142 
143 extern checksuminfo crc32_info;
144 extern checksuminfo md4_info;
145 extern checksuminfo md5_info;
146 
147 extern cipherinfo des_cbc_crc_info;
148 extern cipherinfo des_cbc_md4_info;
149 extern cipherinfo des_cbc_md5_info;
150 extern cipherinfo des_cbc_none_info;
151 extern checksuminfo md4_des_info;
152 extern checksuminfo md5_des_info;
153 extern checksuminfo md5_gss_info;
154 
155 extern cipherinfo des3_cbc_none_info;
156 extern cipherinfo des3_cbc_sha1_kd_info;
157 extern checksuminfo hmac_sha1_des3_kd_info;
158 
159 extern cipherinfo aes128_cts_hmac_sha1_96_info;
160 extern cipherinfo aes256_cts_hmac_sha1_96_info;
161 extern checksuminfo hmac_sha1_96_aes128_info;
162 extern checksuminfo hmac_sha1_96_aes256_info;
163 
164 extern cipherinfo arcfour_hmac_info;
165 extern cipherinfo arcfour_hmac_exp_info;
166 extern checksuminfo arcfour_hmac_md5_info;
167 
168 #endif
169