1 /* $Id: algorithm.c,v 1.11.4.1 2005/06/28 22:38:02 manubsd Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
35 #include <sys/types.h>
44 #include "crypto_openssl.h"
46 #include "algorithm.h"
48 #include "isakmp_var.h"
50 #include "ipsec_doi.h"
53 static struct hash_algorithm oakley_hashdef
[] = {
54 { "md5", algtype_md5
, OAKLEY_ATTR_HASH_ALG_MD5
,
55 eay_md5_init
, eay_md5_update
,
56 eay_md5_final
, eay_md5_hashlen
,
58 { "sha1", algtype_sha1
, OAKLEY_ATTR_HASH_ALG_SHA
,
59 eay_sha1_init
, eay_sha1_update
,
60 eay_sha1_final
, eay_sha1_hashlen
,
63 { "sha2_256", algtype_sha2_256
, OAKLEY_ATTR_HASH_ALG_SHA2_256
,
64 eay_sha2_256_init
, eay_sha2_256_update
,
65 eay_sha2_256_final
, eay_sha2_256_hashlen
,
67 { "sha2_384", algtype_sha2_384
, OAKLEY_ATTR_HASH_ALG_SHA2_384
,
68 eay_sha2_384_init
, eay_sha2_384_update
,
69 eay_sha2_384_final
, eay_sha2_384_hashlen
,
71 { "sha2_512", algtype_sha2_512
, OAKLEY_ATTR_HASH_ALG_SHA2_512
,
72 eay_sha2_512_init
, eay_sha2_512_update
,
73 eay_sha2_512_final
, eay_sha2_512_hashlen
,
78 static struct hmac_algorithm oakley_hmacdef
[] = {
79 { "hmac_md5", algtype_md5
, OAKLEY_ATTR_HASH_ALG_MD5
,
80 eay_hmacmd5_init
, eay_hmacmd5_update
,
81 eay_hmacmd5_final
, NULL
,
83 { "hmac_sha1", algtype_sha1
, OAKLEY_ATTR_HASH_ALG_SHA
,
84 eay_hmacsha1_init
, eay_hmacsha1_update
,
85 eay_hmacsha1_final
, NULL
,
88 { "hmac_sha2_256", algtype_sha2_256
, OAKLEY_ATTR_HASH_ALG_SHA2_256
,
89 eay_hmacsha2_256_init
, eay_hmacsha2_256_update
,
90 eay_hmacsha2_256_final
, NULL
,
91 eay_hmacsha2_256_one
, },
92 { "hmac_sha2_384", algtype_sha2_384
, OAKLEY_ATTR_HASH_ALG_SHA2_384
,
93 eay_hmacsha2_384_init
, eay_hmacsha2_384_update
,
94 eay_hmacsha2_384_final
, NULL
,
95 eay_hmacsha2_384_one
, },
96 { "hmac_sha2_512", algtype_sha2_512
, OAKLEY_ATTR_HASH_ALG_SHA2_512
,
97 eay_hmacsha2_512_init
, eay_hmacsha2_512_update
,
98 eay_hmacsha2_512_final
, NULL
,
99 eay_hmacsha2_512_one
, },
103 static struct enc_algorithm oakley_encdef
[] = {
104 { "des", algtype_des
, OAKLEY_ATTR_ENC_ALG_DES
, 8,
105 eay_des_encrypt
, eay_des_decrypt
,
106 eay_des_weakkey
, eay_des_keylen
, },
108 #ifdef HAVE_OPENSSL_IDEA_H
109 { "idea", algtype_idea
, OAKLEY_ATTR_ENC_ALG_IDEA
, 8,
110 eay_idea_encrypt
, eay_idea_decrypt
,
111 eay_idea_weakkey
, eay_idea_keylen
, },
113 { "blowfish", algtype_blowfish
, OAKLEY_ATTR_ENC_ALG_BLOWFISH
, 8,
114 eay_bf_encrypt
, eay_bf_decrypt
,
115 eay_bf_weakkey
, eay_bf_keylen
, },
116 #ifdef HAVE_OPENSSL_RC5_H
117 { "rc5", algtype_rc5
, OAKLEY_ATTR_ENC_ALG_RC5
, 8,
118 eay_rc5_encrypt
, eay_rc5_decrypt
,
119 eay_rc5_weakkey
, eay_rc5_keylen
, },
122 { "3des", algtype_3des
, OAKLEY_ATTR_ENC_ALG_3DES
, 8,
123 eay_3des_encrypt
, eay_3des_decrypt
,
124 eay_3des_weakkey
, eay_3des_keylen
, },
126 { "cast", algtype_cast128
, OAKLEY_ATTR_ENC_ALG_CAST
, 8,
127 eay_cast_encrypt
, eay_cast_decrypt
,
128 eay_cast_weakkey
, eay_cast_keylen
, },
130 { "aes", algtype_aes
, OAKLEY_ATTR_ENC_ALG_AES
, 16,
131 eay_aes_encrypt
, eay_aes_decrypt
,
132 eay_aes_weakkey
, eay_aes_keylen
, },
135 static struct enc_algorithm ipsec_encdef
[] = {
136 { "des-iv64", algtype_des_iv64
, IPSECDOI_ESP_DES_IV64
, 8,
138 NULL
, eay_des_keylen
, },
139 { "des", algtype_des
, IPSECDOI_ESP_DES
, 8,
141 NULL
, eay_des_keylen
, },
142 { "3des", algtype_3des
, IPSECDOI_ESP_3DES
, 8,
144 NULL
, eay_3des_keylen
, },
146 #ifdef HAVE_OPENSSL_RC5_H
147 { "rc5", algtype_rc5
, IPSECDOI_ESP_RC5
, 8,
149 NULL
, eay_rc5_keylen
, },
151 { "cast", algtype_cast128
, IPSECDOI_ESP_CAST
, 8,
153 NULL
, eay_cast_keylen
, },
154 { "blowfish", algtype_blowfish
, IPSECDOI_ESP_BLOWFISH
, 8,
156 NULL
, eay_bf_keylen
, },
158 { "des-iv32", algtype_des_iv32
, IPSECDOI_ESP_DES_IV32
, 8,
160 NULL
, eay_des_keylen
, },
161 { "null", algtype_null_enc
, IPSECDOI_ESP_NULL
, 8,
163 NULL
, eay_null_keylen
, },
164 { "aes", algtype_aes
, IPSECDOI_ESP_AES
, 16,
166 NULL
, eay_aes_keylen
, },
168 { "twofish", algtype_twofish
, IPSECDOI_ESP_TWOFISH
, 16,
170 NULL
, eay_twofish_keylen
, },
171 #ifdef HAVE_OPENSSL_IDEA_H
172 { "3idea", algtype_3idea
, IPSECDOI_ESP_3IDEA
, 8,
175 { "idea", algtype_idea
, IPSECDOI_ESP_IDEA
, 8,
179 { "rc4", algtype_rc4
, IPSECDOI_ESP_RC4
, 8,
185 static struct hmac_algorithm ipsec_hmacdef
[] = {
186 { "md5", algtype_hmac_md5
, IPSECDOI_ATTR_AUTH_HMAC_MD5
,
188 NULL
, eay_md5_hashlen
,
190 { "sha1", algtype_hmac_sha1
, IPSECDOI_ATTR_AUTH_HMAC_SHA1
,
192 NULL
, eay_sha1_hashlen
,
195 { "kpdk", algtype_kpdk
, IPSECDOI_ATTR_AUTH_KPDK
,
197 NULL
, eay_kpdk_hashlen
,
200 { "null", algtype_non_auth
, IPSECDOI_ATTR_AUTH_NONE
,
202 NULL
, eay_null_hashlen
,
205 { "hmac_sha2_256", algtype_hmac_sha2_256
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_256
,
207 NULL
, eay_sha2_256_hashlen
,
209 { "hmac_sha2_384", algtype_hmac_sha2_384
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_384
,
211 NULL
, eay_sha2_384_hashlen
,
213 { "hmac_sha2_512", algtype_hmac_sha2_512
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_512
,
215 NULL
, eay_sha2_512_hashlen
,
220 static struct misc_algorithm ipsec_compdef
[] = {
221 { "oui", algtype_oui
, IPSECDOI_IPCOMP_OUI
, },
222 { "deflate", algtype_deflate
, IPSECDOI_IPCOMP_DEFLATE
, },
223 { "lzs", algtype_lzs
, IPSECDOI_IPCOMP_LZS
, },
227 * In case of asymetric modes (hybrid xauth), what's racoon mode of
228 * operations ; it seems that the proposal should always use the
229 * initiator half (unless a server initiates a connection, which is
230 * not handled, and probably not useful).
232 static struct misc_algorithm oakley_authdef
[] = {
233 { "pre_shared_key", algtype_psk
, OAKLEY_ATTR_AUTH_METHOD_PSKEY
, },
234 { "dsssig", algtype_dsssig
, OAKLEY_ATTR_AUTH_METHOD_DSSSIG
, },
235 { "rsasig", algtype_rsasig
, OAKLEY_ATTR_AUTH_METHOD_RSASIG
, },
236 { "rsaenc", algtype_rsaenc
, OAKLEY_ATTR_AUTH_METHOD_RSAENC
, },
237 { "rsarev", algtype_rsarev
, OAKLEY_ATTR_AUTH_METHOD_RSAREV
, },
239 { "gssapi_krb", algtype_gssapikrb
,
240 OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
, },
243 { "hybrid_rsa_server", algtype_hybrid_rsa_s
,
244 OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
, },
246 { "hybrid_dss_server", algtype_hybrid_dss_s
,
247 OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
, },
249 { "xauth_psk_server", algtype_xauth_psk_s
,
250 OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
, },
252 { "xauth_rsa_server", algtype_xauth_rsa_s
,
253 OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
, },
255 { "hybrid_rsa_client", algtype_hybrid_rsa_c
,
256 OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
, },
258 { "hybrid_dss_client", algtype_hybrid_dss_c
,
259 OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
, },
261 { "xauth_psk_client", algtype_xauth_psk_c
,
262 OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
, },
264 { "xauth_rsa_client", algtype_xauth_rsa_c
,
265 OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
, },
269 static struct dh_algorithm oakley_dhdef
[] = {
270 { "modp768", algtype_modp768
, OAKLEY_ATTR_GRP_DESC_MODP768
,
272 { "modp1024", algtype_modp1024
, OAKLEY_ATTR_GRP_DESC_MODP1024
,
274 { "modp1536", algtype_modp1536
, OAKLEY_ATTR_GRP_DESC_MODP1536
,
276 { "modp2048", algtype_modp2048
, OAKLEY_ATTR_GRP_DESC_MODP2048
,
278 { "modp3072", algtype_modp3072
, OAKLEY_ATTR_GRP_DESC_MODP3072
,
280 { "modp4096", algtype_modp4096
, OAKLEY_ATTR_GRP_DESC_MODP4096
,
282 { "modp6144", algtype_modp6144
, OAKLEY_ATTR_GRP_DESC_MODP6144
,
284 { "modp8192", algtype_modp8192
, OAKLEY_ATTR_GRP_DESC_MODP8192
,
288 static struct hash_algorithm
*alg_oakley_hashdef
__P((int));
289 static struct hmac_algorithm
*alg_oakley_hmacdef
__P((int));
290 static struct enc_algorithm
*alg_oakley_encdef
__P((int));
291 static struct enc_algorithm
*alg_ipsec_encdef
__P((int));
292 static struct hmac_algorithm
*alg_ipsec_hmacdef
__P((int));
293 static struct dh_algorithm
*alg_oakley_dhdef
__P((int));
295 /* oakley hash algorithm */
296 static struct hash_algorithm
*
297 alg_oakley_hashdef(doi
)
302 for (i
= 0; i
< ARRAYLEN(oakley_hashdef
); i
++)
303 if (doi
== oakley_hashdef
[i
].doi
) {
304 plog(LLV_DEBUG
, LOCATION
, NULL
, "hash(%s)\n",
305 oakley_hashdef
[i
].name
);
306 return &oakley_hashdef
[i
];
312 alg_oakley_hashdef_ok(doi
)
315 struct hash_algorithm
*f
;
317 f
= alg_oakley_hashdef(doi
);
325 alg_oakley_hashdef_doi(type
)
330 for (i
= 0; i
< ARRAYLEN(oakley_hashdef
); i
++)
331 if (type
== oakley_hashdef
[i
].type
) {
332 res
= oakley_hashdef
[i
].doi
;
339 alg_oakley_hashdef_hashlen(doi
)
342 struct hash_algorithm
*f
;
344 f
= alg_oakley_hashdef(doi
);
345 if (f
== NULL
|| f
->hashlen
== NULL
)
348 return (f
->hashlen
)();
352 alg_oakley_hashdef_name (doi
)
355 struct hash_algorithm
*f
;
357 f
= alg_oakley_hashdef(doi
);
365 alg_oakley_hashdef_one(doi
, buf
)
369 struct hash_algorithm
*f
;
371 f
= alg_oakley_hashdef(doi
);
372 if (f
== NULL
|| f
->hashlen
== NULL
)
375 return (f
->one
)(buf
);
378 /* oakley hmac algorithm */
379 static struct hmac_algorithm
*
380 alg_oakley_hmacdef(doi
)
385 for (i
= 0; i
< ARRAYLEN(oakley_hmacdef
); i
++)
386 if (doi
== oakley_hmacdef
[i
].doi
) {
387 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
388 oakley_hmacdef
[i
].name
);
389 return &oakley_hmacdef
[i
];
395 alg_oakley_hmacdef_doi(type
)
400 for (i
= 0; i
< ARRAYLEN(oakley_hmacdef
); i
++)
401 if (type
== oakley_hmacdef
[i
].type
) {
402 res
= oakley_hmacdef
[i
].doi
;
409 alg_oakley_hmacdef_one(doi
, key
, buf
)
413 struct hmac_algorithm
*f
;
416 struct timeval start
, end
;
419 f
= alg_oakley_hmacdef(doi
);
420 if (f
== NULL
|| f
->one
== NULL
)
424 gettimeofday(&start
, NULL
);
427 res
= (f
->one
)(key
, buf
);
430 gettimeofday(&end
, NULL
);
431 syslog(LOG_NOTICE
, "%s(%s size=%zu): %8.6f", __func__
,
432 f
->name
, buf
->l
, timedelta(&start
, &end
));
438 /* oakley encryption algorithm */
439 static struct enc_algorithm
*
440 alg_oakley_encdef(doi
)
445 for (i
= 0; i
< ARRAYLEN(oakley_encdef
); i
++)
446 if (doi
== oakley_encdef
[i
].doi
) {
447 plog(LLV_DEBUG
, LOCATION
, NULL
, "encryption(%s)\n",
448 oakley_encdef
[i
].name
);
449 return &oakley_encdef
[i
];
455 alg_oakley_encdef_ok(doi
)
458 struct enc_algorithm
*f
;
460 f
= alg_oakley_encdef(doi
);
468 alg_oakley_encdef_doi(type
)
473 for (i
= 0; i
< ARRAYLEN(oakley_encdef
); i
++)
474 if (type
== oakley_encdef
[i
].type
) {
475 res
= oakley_encdef
[i
].doi
;
482 alg_oakley_encdef_keylen(doi
, len
)
485 struct enc_algorithm
*f
;
487 f
= alg_oakley_encdef(doi
);
488 if (f
== NULL
|| f
->keylen
== NULL
)
491 return (f
->keylen
)(len
);
495 alg_oakley_encdef_blocklen(doi
)
498 struct enc_algorithm
*f
;
500 f
= alg_oakley_encdef(doi
);
508 alg_oakley_encdef_name (doi
)
511 struct enc_algorithm
*f
;
513 f
= alg_oakley_encdef(doi
);
521 alg_oakley_encdef_decrypt(doi
, buf
, key
, iv
)
523 vchar_t
*buf
, *key
, *iv
;
526 struct enc_algorithm
*f
;
528 struct timeval start
, end
;
531 f
= alg_oakley_encdef(doi
);
532 if (f
== NULL
|| f
->decrypt
== NULL
)
536 gettimeofday(&start
, NULL
);
539 res
= (f
->decrypt
)(buf
, key
, iv
);
542 gettimeofday(&end
, NULL
);
543 syslog(LOG_NOTICE
, "%s(%s klen=%zu size=%zu): %8.6f", __func__
,
544 f
->name
, key
->l
<< 3, buf
->l
, timedelta(&start
, &end
));
550 alg_oakley_encdef_encrypt(doi
, buf
, key
, iv
)
552 vchar_t
*buf
, *key
, *iv
;
555 struct enc_algorithm
*f
;
557 struct timeval start
, end
;
560 f
= alg_oakley_encdef(doi
);
561 if (f
== NULL
|| f
->encrypt
== NULL
)
565 gettimeofday(&start
, NULL
);
568 res
= (f
->encrypt
)(buf
, key
, iv
);
571 gettimeofday(&end
, NULL
);
572 syslog(LOG_NOTICE
, "%s(%s klen=%zu size=%zu): %8.6f", __func__
,
573 f
->name
, key
->l
<< 3, buf
->l
, timedelta(&start
, &end
));
578 /* ipsec encryption algorithm */
579 static struct enc_algorithm
*
580 alg_ipsec_encdef(doi
)
585 for (i
= 0; i
< ARRAYLEN(ipsec_encdef
); i
++)
586 if (doi
== ipsec_encdef
[i
].doi
) {
587 plog(LLV_DEBUG
, LOCATION
, NULL
, "encryption(%s)\n",
588 ipsec_encdef
[i
].name
);
589 return &ipsec_encdef
[i
];
595 alg_ipsec_encdef_doi(type
)
600 for (i
= 0; i
< ARRAYLEN(ipsec_encdef
); i
++)
601 if (type
== ipsec_encdef
[i
].type
) {
602 res
= ipsec_encdef
[i
].doi
;
609 alg_ipsec_encdef_keylen(doi
, len
)
612 struct enc_algorithm
*f
;
614 f
= alg_ipsec_encdef(doi
);
615 if (f
== NULL
|| f
->keylen
== NULL
)
618 return (f
->keylen
)(len
);
621 /* ipsec hmac algorithm */
622 static struct hmac_algorithm
*
623 alg_ipsec_hmacdef(doi
)
628 for (i
= 0; i
< ARRAYLEN(ipsec_hmacdef
); i
++)
629 if (doi
== ipsec_hmacdef
[i
].doi
) {
630 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
631 ipsec_hmacdef
[i
].name
);
632 return &ipsec_hmacdef
[i
];
638 alg_ipsec_hmacdef_doi(type
)
643 for (i
= 0; i
< ARRAYLEN(ipsec_hmacdef
); i
++)
644 if (type
== ipsec_hmacdef
[i
].type
) {
645 res
= ipsec_hmacdef
[i
].doi
;
652 alg_ipsec_hmacdef_hashlen(doi
)
655 struct hmac_algorithm
*f
;
657 f
= alg_ipsec_hmacdef(doi
);
658 if (f
== NULL
|| f
->hashlen
== NULL
)
661 return (f
->hashlen
)();
666 alg_ipsec_compdef_doi(type
)
671 for (i
= 0; i
< ARRAYLEN(ipsec_compdef
); i
++)
672 if (type
== ipsec_compdef
[i
].type
) {
673 res
= ipsec_compdef
[i
].doi
;
680 static struct dh_algorithm
*
681 alg_oakley_dhdef(doi
)
686 for (i
= 0; i
< ARRAYLEN(oakley_dhdef
); i
++)
687 if (doi
== oakley_dhdef
[i
].doi
) {
688 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
689 oakley_dhdef
[i
].name
);
690 return &oakley_dhdef
[i
];
696 alg_oakley_dhdef_ok(doi
)
699 struct dh_algorithm
*f
;
701 f
= alg_oakley_dhdef(doi
);
709 alg_oakley_dhdef_doi(type
)
714 for (i
= 0; i
< ARRAYLEN(oakley_dhdef
); i
++)
715 if (type
== oakley_dhdef
[i
].type
) {
716 res
= oakley_dhdef
[i
].doi
;
723 alg_oakley_dhdef_group(doi
)
726 struct dh_algorithm
*f
;
728 f
= alg_oakley_dhdef(doi
);
729 if (f
== NULL
|| f
->dhgroup
== NULL
)
736 alg_oakley_dhdef_name (doi
)
739 struct dh_algorithm
*f
;
741 f
= alg_oakley_dhdef(doi
);
747 /* authentication method */
749 alg_oakley_authdef_doi(type
)
754 for (i
= 0; i
< ARRAYLEN(oakley_authdef
); i
++)
755 if (type
== oakley_authdef
[i
].type
) {
756 res
= oakley_authdef
[i
].doi
;
763 alg_oakley_authdef_name (doi
)
768 for (i
= 0; i
< ARRAYLEN(oakley_authdef
); i
++)
769 if (doi
== oakley_authdef
[i
].doi
) {
770 return oakley_authdef
[i
].name
;
776 * give the default key length
778 * 0: fixed key cipher, key length not allowed
779 * positive: default key length
782 default_keylen(class, type
)
787 case algclass_isakmp_enc
:
788 case algclass_ipsec_enc
:
795 case algtype_blowfish
:
797 case algtype_cast128
:
799 case algtype_twofish
:
812 check_keylen(class, type
, len
)
813 int class, type
, len
;
818 case algclass_isakmp_enc
:
819 case algclass_ipsec_enc
:
822 /* unknown class, punt */
823 plog(LLV_ERROR
, LOCATION
, NULL
,
824 "unknown algclass %d\n", class);
828 /* key length must be multiple of 8 bytes - RFC2451 2.2 */
830 case algtype_blowfish
:
832 case algtype_cast128
:
834 case algtype_twofish
:
836 plog(LLV_ERROR
, LOCATION
, NULL
,
837 "key length %d is not multiple of 8\n", len
);
843 /* key length range */
846 case algtype_blowfish
:
847 if (len
< 40 || 448 < len
)
851 if (len
< 40 || 2040 < len
)
854 case algtype_cast128
:
855 if (len
< 40 || 128 < len
)
859 if (!(len
== 128 || len
== 192 || len
== 256))
862 case algtype_twofish
:
863 if (len
< 40 || 256 < len
)
868 plog(LLV_ERROR
, LOCATION
, NULL
,
869 "key length is not allowed");
875 plog(LLV_ERROR
, LOCATION
, NULL
,
876 "key length out of range\n");
884 * convert algorithm type to DOI value.
889 algtype2doi(class, type
)
895 case algclass_ipsec_enc
:
896 res
= alg_ipsec_encdef_doi(type
);
898 case algclass_ipsec_auth
:
899 res
= alg_ipsec_hmacdef_doi(type
);
901 case algclass_ipsec_comp
:
902 res
= alg_ipsec_compdef_doi(type
);
904 case algclass_isakmp_enc
:
905 res
= alg_oakley_encdef_doi(type
);
907 case algclass_isakmp_hash
:
908 res
= alg_oakley_hashdef_doi(type
);
910 case algclass_isakmp_dh
:
911 res
= alg_oakley_dhdef_doi(type
);
913 case algclass_isakmp_ameth
:
914 res
= alg_oakley_authdef_doi(type
);
921 * convert algorithm class to DOI value.
930 case algclass_ipsec_enc
:
931 return IPSECDOI_PROTO_IPSEC_ESP
;
932 case algclass_ipsec_auth
:
933 return IPSECDOI_ATTR_AUTH
;
934 case algclass_ipsec_comp
:
935 return IPSECDOI_PROTO_IPCOMP
;
936 case algclass_isakmp_enc
:
937 return OAKLEY_ATTR_ENC_ALG
;
938 case algclass_isakmp_hash
:
939 return OAKLEY_ATTR_HASH_ALG
;
940 case algclass_isakmp_dh
:
941 return OAKLEY_ATTR_GRP_DESC
;
942 case algclass_isakmp_ameth
:
943 return OAKLEY_ATTR_AUTH_METHOD
;