1 /*	$NetBSD: crypto_openssl.h,v 1.9 2018/02/07 03:59:03 christos Exp $	*/
2 
3 /* Id: crypto_openssl.h,v 1.11 2004/11/13 11:28:01 manubsd Exp */
4 
5 /*
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #ifndef _CRYPTO_OPENSSL_H
35 #define _CRYPTO_OPENSSL_H
36 
37 #include <openssl/x509v3.h>
38 #include <openssl/rsa.h>
39 
40 #define GENT_OTHERNAME	GEN_OTHERNAME
41 #define GENT_EMAIL	GEN_EMAIL
42 #define GENT_DNS	GEN_DNS
43 #define GENT_X400	GEN_X400
44 #define GENT_DIRNAME	GEN_DIRNAME
45 #define GENT_EDIPARTY	GEN_EDIPARTY
46 #define GENT_URI	GEN_URI
47 #define GENT_IPADD	GEN_IPADD
48 #define GENT_RID	GEN_RID
49 
50 extern vchar_t *eay_str2asn1dn(const char *, int);
51 extern vchar_t *eay_hex2asn1dn(const char *, int);
52 extern int eay_cmp_asn1dn(vchar_t *, vchar_t *);
53 extern int eay_check_x509cert(vchar_t *, char *, char *, int);
54 extern vchar_t *eay_get_x509asn1subjectname(vchar_t *);
55 extern int eay_get_x509subjectaltname(vchar_t *, char **, int *, int);
56 extern vchar_t * eay_get_x509asn1issuername(vchar_t *);
57 extern char *eay_get_x509text(vchar_t *);
58 extern vchar_t *eay_get_x509cert(char *);
59 extern vchar_t *eay_get_x509sign(vchar_t *, vchar_t *);
60 extern int eay_check_x509sign(vchar_t *, vchar_t *, vchar_t *);
61 
62 extern int eay_check_rsasign(vchar_t *, vchar_t *, RSA *);
63 extern vchar_t *eay_get_rsasign(vchar_t *, RSA *);
64 
65 /* RSA */
66 extern vchar_t *eay_rsa_sign(vchar_t *, RSA *);
67 extern int eay_rsa_verify(vchar_t *, vchar_t *, RSA *);
68 
69 /* ASN.1 */
70 extern vchar_t *eay_get_pkcs1privkey(char *);
71 extern vchar_t *eay_get_pkcs1pubkey(char *);
72 
73 /* string error */
74 extern char *eay_strerror(void);
75 
76 /* OpenSSL initialization */
77 extern void eay_init(void);
78 
79 /* Generic EVP */
80 extern vchar_t *evp_crypt(vchar_t *data, vchar_t *key, vchar_t *iv,
81     const EVP_CIPHER *e, int enc);
82 extern int evp_weakkey(vchar_t *key, const EVP_CIPHER *e);
83 extern int evp_keylen(int len, const EVP_CIPHER *e);
84 
85 /* DES */
86 extern vchar_t *eay_des_encrypt(vchar_t *, vchar_t *, vchar_t *);
87 extern vchar_t *eay_des_decrypt(vchar_t *, vchar_t *, vchar_t *);
88 extern int eay_des_weakkey(vchar_t *);
89 extern int eay_des_keylen(int);
90 
91 /* IDEA */
92 extern vchar_t *eay_idea_encrypt(vchar_t *, vchar_t *, vchar_t *);
93 extern vchar_t *eay_idea_decrypt(vchar_t *, vchar_t *, vchar_t *);
94 extern int eay_idea_weakkey(vchar_t *);
95 extern int eay_idea_keylen(int);
96 
97 /* blowfish */
98 extern vchar_t *eay_bf_encrypt(vchar_t *, vchar_t *, vchar_t *);
99 extern vchar_t *eay_bf_decrypt(vchar_t *, vchar_t *, vchar_t *);
100 extern int eay_bf_weakkey(vchar_t *);
101 extern int eay_bf_keylen(int);
102 
103 /* RC5 */
104 extern vchar_t *eay_rc5_encrypt(vchar_t *, vchar_t *, vchar_t *);
105 extern vchar_t *eay_rc5_decrypt(vchar_t *, vchar_t *, vchar_t *);
106 extern int eay_rc5_weakkey(vchar_t *);
107 extern int eay_rc5_keylen(int);
108 
109 /* 3DES */
110 extern vchar_t *eay_3des_encrypt(vchar_t *, vchar_t *, vchar_t *);
111 extern vchar_t *eay_3des_decrypt(vchar_t *, vchar_t *, vchar_t *);
112 extern int eay_3des_weakkey(vchar_t *);
113 extern int eay_3des_keylen(int);
114 
115 /* CAST */
116 extern vchar_t *eay_cast_encrypt(vchar_t *, vchar_t *, vchar_t *);
117 extern vchar_t *eay_cast_decrypt(vchar_t *, vchar_t *, vchar_t *);
118 extern int eay_cast_weakkey(vchar_t *);
119 extern int eay_cast_keylen(int);
120 
121 /* AES(RIJNDAEL) */
122 extern vchar_t *eay_aes_encrypt(vchar_t *, vchar_t *, vchar_t *);
123 extern vchar_t *eay_aes_decrypt(vchar_t *, vchar_t *, vchar_t *);
124 extern int eay_aes_weakkey(vchar_t *);
125 extern int eay_aes_keylen(int);
126 
127 /* AES GCM 16*/
128 extern int eay_aesgcm_keylen(int);
129 
130 #if defined(HAVE_OPENSSL_CAMELLIA_H)
131 /* Camellia */
132 extern vchar_t *eay_camellia_encrypt(vchar_t *, vchar_t *, vchar_t *);
133 extern vchar_t *eay_camellia_decrypt(vchar_t *, vchar_t *, vchar_t *);
134 extern int eay_camellia_weakkey(vchar_t *);
135 extern int eay_camellia_keylen(int);
136 #endif
137 
138 /* misc */
139 extern int eay_null_keylen(int);
140 extern int eay_null_hashlen(void);
141 extern int eay_kpdk_hashlen(void);
142 extern int eay_twofish_keylen(int);
143 
144 /* hash */
145 #if defined(WITH_SHA2)
146 /* HMAC SHA2 */
147 extern vchar_t *eay_hmacsha2_512_one(vchar_t *, vchar_t *);
148 extern caddr_t eay_hmacsha2_512_init(vchar_t *);
149 extern void eay_hmacsha2_512_update(caddr_t, vchar_t *);
150 extern vchar_t *eay_hmacsha2_512_final(caddr_t);
151 extern vchar_t *eay_hmacsha2_384_one(vchar_t *, vchar_t *);
152 extern caddr_t eay_hmacsha2_384_init(vchar_t *);
153 extern void eay_hmacsha2_384_update(caddr_t, vchar_t *);
154 extern vchar_t *eay_hmacsha2_384_final(caddr_t);
155 extern vchar_t *eay_hmacsha2_256_one(vchar_t *, vchar_t *);
156 extern caddr_t eay_hmacsha2_256_init(vchar_t *);
157 extern void eay_hmacsha2_256_update(caddr_t, vchar_t *);
158 extern vchar_t *eay_hmacsha2_256_final(caddr_t);
159 #endif
160 /* HMAC SHA1 */
161 extern vchar_t *eay_hmacsha1_one(vchar_t *, vchar_t *);
162 extern caddr_t eay_hmacsha1_init(vchar_t *);
163 extern void eay_hmacsha1_update(caddr_t, vchar_t *);
164 extern vchar_t *eay_hmacsha1_final(caddr_t);
165 /* HMAC MD5 */
166 extern vchar_t *eay_hmacmd5_one(vchar_t *, vchar_t *);
167 extern caddr_t eay_hmacmd5_init(vchar_t *);
168 extern void eay_hmacmd5_update(caddr_t, vchar_t *);
169 extern vchar_t *eay_hmacmd5_final(caddr_t);
170 
171 #if defined(WITH_SHA2)
172 /* SHA2 functions */
173 extern caddr_t eay_sha2_512_init(void);
174 extern void eay_sha2_512_update(caddr_t, vchar_t *);
175 extern vchar_t *eay_sha2_512_final(caddr_t);
176 extern vchar_t *eay_sha2_512_one(vchar_t *);
177 #endif
178 extern int eay_sha2_512_hashlen(void);
179 
180 #if defined(WITH_SHA2)
181 extern caddr_t eay_sha2_384_init(void);
182 extern void eay_sha2_384_update(caddr_t, vchar_t *);
183 extern vchar_t *eay_sha2_384_final(caddr_t);
184 extern vchar_t *eay_sha2_384_one(vchar_t *);
185 #endif
186 extern int eay_sha2_384_hashlen(void);
187 
188 #if defined(WITH_SHA2)
189 extern caddr_t eay_sha2_256_init(void);
190 extern void eay_sha2_256_update(caddr_t, vchar_t *);
191 extern vchar_t *eay_sha2_256_final(caddr_t);
192 extern vchar_t *eay_sha2_256_one(vchar_t *);
193 #endif
194 extern int eay_sha2_256_hashlen(void);
195 
196 /* SHA functions */
197 extern caddr_t eay_sha1_init(void);
198 extern void eay_sha1_update(caddr_t, vchar_t *);
199 extern vchar_t *eay_sha1_final(caddr_t);
200 extern vchar_t *eay_sha1_one(vchar_t *);
201 extern int eay_sha1_hashlen(void);
202 
203 /* MD5 functions */
204 extern caddr_t eay_md5_init(void);
205 extern void eay_md5_update(caddr_t, vchar_t *);
206 extern vchar_t *eay_md5_final(caddr_t);
207 extern vchar_t *eay_md5_one(vchar_t *);
208 extern int eay_md5_hashlen(void);
209 
210 /* RNG */
211 extern vchar_t *eay_set_random(u_int32_t);
212 extern u_int32_t eay_random(void);
213 
214 /* DH */
215 extern int eay_dh_generate(vchar_t *, u_int32_t, u_int, vchar_t **, vchar_t **);
216 extern int eay_dh_compute(vchar_t *, u_int32_t, vchar_t *, vchar_t *,
217     vchar_t *, vchar_t **);
218 
219 /* Base 64 */
220 vchar_t *base64_encode(char *, long);
221 vchar_t *base64_decode(char *, long);
222 
223 RSA *base64_pubkey2rsa(char *);
224 RSA *bignum_pubkey2rsa(BIGNUM *);
225 
226 /* misc */
227 extern int eay_revbnl(vchar_t *);
228 #include <openssl/bn.h>
229 extern int eay_v2bn(BIGNUM **, vchar_t *);
230 extern int eay_bn2v(vchar_t **, BIGNUM *);
231 
232 extern const char *eay_version(void);
233 
234 #define CBC_BLOCKLEN 8
235 #define IPSEC_ENCRYPTKEYLEN 8
236 
237 #endif /* _CRYPTO_OPENSSL_H */
238