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
, },
107 #ifdef HAVE_OPENSSL_IDEA_H
108 { "idea", algtype_idea
, OAKLEY_ATTR_ENC_ALG_IDEA
, 8,
109 eay_idea_encrypt
, eay_idea_decrypt
,
110 eay_idea_weakkey
, eay_idea_keylen
, },
112 { "blowfish", algtype_blowfish
, OAKLEY_ATTR_ENC_ALG_BLOWFISH
, 8,
113 eay_bf_encrypt
, eay_bf_decrypt
,
114 eay_bf_weakkey
, eay_bf_keylen
, },
115 #ifdef HAVE_OPENSSL_RC5_H
116 { "rc5", algtype_rc5
, OAKLEY_ATTR_ENC_ALG_RC5
, 8,
117 eay_rc5_encrypt
, eay_rc5_decrypt
,
118 eay_rc5_weakkey
, eay_rc5_keylen
, },
120 { "3des", algtype_3des
, OAKLEY_ATTR_ENC_ALG_3DES
, 8,
121 eay_3des_encrypt
, eay_3des_decrypt
,
122 eay_3des_weakkey
, eay_3des_keylen
, },
123 { "cast", algtype_cast128
, OAKLEY_ATTR_ENC_ALG_CAST
, 8,
124 eay_cast_encrypt
, eay_cast_decrypt
,
125 eay_cast_weakkey
, eay_cast_keylen
, },
126 { "aes", algtype_aes
, OAKLEY_ATTR_ENC_ALG_AES
, 16,
127 eay_aes_encrypt
, eay_aes_decrypt
,
128 eay_aes_weakkey
, eay_aes_keylen
, },
131 static struct enc_algorithm ipsec_encdef
[] = {
132 { "des-iv64", algtype_des_iv64
, IPSECDOI_ESP_DES_IV64
, 8,
134 NULL
, eay_des_keylen
, },
135 { "des", algtype_des
, IPSECDOI_ESP_DES
, 8,
137 NULL
, eay_des_keylen
, },
138 { "3des", algtype_3des
, IPSECDOI_ESP_3DES
, 8,
140 NULL
, eay_3des_keylen
, },
141 #ifdef HAVE_OPENSSL_RC5_H
142 { "rc5", algtype_rc5
, IPSECDOI_ESP_RC5
, 8,
144 NULL
, eay_rc5_keylen
, },
146 { "cast", algtype_cast128
, IPSECDOI_ESP_CAST
, 8,
148 NULL
, eay_cast_keylen
, },
149 { "blowfish", algtype_blowfish
, IPSECDOI_ESP_BLOWFISH
, 8,
151 NULL
, eay_bf_keylen
, },
152 { "des-iv32", algtype_des_iv32
, IPSECDOI_ESP_DES_IV32
, 8,
154 NULL
, eay_des_keylen
, },
155 { "null", algtype_null_enc
, IPSECDOI_ESP_NULL
, 8,
157 NULL
, eay_null_keylen
, },
158 { "aes", algtype_aes
, IPSECDOI_ESP_AES
, 16,
160 NULL
, eay_aes_keylen
, },
161 { "twofish", algtype_twofish
, IPSECDOI_ESP_TWOFISH
, 16,
163 NULL
, eay_twofish_keylen
, },
164 #ifdef HAVE_OPENSSL_IDEA_H
165 { "3idea", algtype_3idea
, IPSECDOI_ESP_3IDEA
, 8,
168 { "idea", algtype_idea
, IPSECDOI_ESP_IDEA
, 8,
172 { "rc4", algtype_rc4
, IPSECDOI_ESP_RC4
, 8,
177 static struct hmac_algorithm ipsec_hmacdef
[] = {
178 { "md5", algtype_hmac_md5
, IPSECDOI_ATTR_AUTH_HMAC_MD5
,
180 NULL
, eay_md5_hashlen
,
182 { "sha1", algtype_hmac_sha1
, IPSECDOI_ATTR_AUTH_HMAC_SHA1
,
184 NULL
, eay_sha1_hashlen
,
186 { "kpdk", algtype_kpdk
, IPSECDOI_ATTR_AUTH_KPDK
,
188 NULL
, eay_kpdk_hashlen
,
190 { "null", algtype_non_auth
, IPSECDOI_ATTR_AUTH_NONE
,
192 NULL
, eay_null_hashlen
,
195 { "hmac_sha2_256", algtype_hmac_sha2_256
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_256
,
197 NULL
, eay_sha2_256_hashlen
,
199 { "hmac_sha2_384", algtype_hmac_sha2_384
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_384
,
201 NULL
, eay_sha2_384_hashlen
,
203 { "hmac_sha2_512", algtype_hmac_sha2_512
,IPSECDOI_ATTR_AUTH_HMAC_SHA2_512
,
205 NULL
, eay_sha2_512_hashlen
,
210 static struct misc_algorithm ipsec_compdef
[] = {
211 { "oui", algtype_oui
, IPSECDOI_IPCOMP_OUI
, },
212 { "deflate", algtype_deflate
, IPSECDOI_IPCOMP_DEFLATE
, },
213 { "lzs", algtype_lzs
, IPSECDOI_IPCOMP_LZS
, },
217 * In case of asymetric modes (hybrid xauth), what's racoon mode of
218 * operations ; it seems that the proposal should always use the
219 * initiator half (unless a server initiates a connection, which is
220 * not handled, and probably not useful).
222 static struct misc_algorithm oakley_authdef
[] = {
223 { "pre_shared_key", algtype_psk
, OAKLEY_ATTR_AUTH_METHOD_PSKEY
, },
224 { "dsssig", algtype_dsssig
, OAKLEY_ATTR_AUTH_METHOD_DSSSIG
, },
225 { "rsasig", algtype_rsasig
, OAKLEY_ATTR_AUTH_METHOD_RSASIG
, },
226 { "rsaenc", algtype_rsaenc
, OAKLEY_ATTR_AUTH_METHOD_RSAENC
, },
227 { "rsarev", algtype_rsarev
, OAKLEY_ATTR_AUTH_METHOD_RSAREV
, },
229 { "gssapi_krb", algtype_gssapikrb
,
230 OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
, },
233 { "hybrid_rsa_server", algtype_hybrid_rsa_s
,
234 OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
, },
236 { "hybrid_dss_server", algtype_hybrid_dss_s
,
237 OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
, },
239 { "xauth_psk_server", algtype_xauth_psk_s
,
240 OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
, },
242 { "xauth_rsa_server", algtype_xauth_rsa_s
,
243 OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
, },
245 { "hybrid_rsa_client", algtype_hybrid_rsa_c
,
246 OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
, },
248 { "hybrid_dss_client", algtype_hybrid_dss_c
,
249 OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
, },
251 { "xauth_psk_client", algtype_xauth_psk_c
,
252 OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
, },
254 { "xauth_rsa_client", algtype_xauth_rsa_c
,
255 OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
, },
259 static struct dh_algorithm oakley_dhdef
[] = {
260 { "modp768", algtype_modp768
, OAKLEY_ATTR_GRP_DESC_MODP768
,
262 { "modp1024", algtype_modp1024
, OAKLEY_ATTR_GRP_DESC_MODP1024
,
264 { "modp1536", algtype_modp1536
, OAKLEY_ATTR_GRP_DESC_MODP1536
,
266 { "modp2048", algtype_modp2048
, OAKLEY_ATTR_GRP_DESC_MODP2048
,
268 { "modp3072", algtype_modp3072
, OAKLEY_ATTR_GRP_DESC_MODP3072
,
270 { "modp4096", algtype_modp4096
, OAKLEY_ATTR_GRP_DESC_MODP4096
,
272 { "modp6144", algtype_modp6144
, OAKLEY_ATTR_GRP_DESC_MODP6144
,
274 { "modp8192", algtype_modp8192
, OAKLEY_ATTR_GRP_DESC_MODP8192
,
278 static struct hash_algorithm
*alg_oakley_hashdef
__P((int));
279 static struct hmac_algorithm
*alg_oakley_hmacdef
__P((int));
280 static struct enc_algorithm
*alg_oakley_encdef
__P((int));
281 static struct enc_algorithm
*alg_ipsec_encdef
__P((int));
282 static struct hmac_algorithm
*alg_ipsec_hmacdef
__P((int));
283 static struct dh_algorithm
*alg_oakley_dhdef
__P((int));
285 /* oakley hash algorithm */
286 static struct hash_algorithm
*
287 alg_oakley_hashdef(doi
)
292 for (i
= 0; i
< ARRAYLEN(oakley_hashdef
); i
++)
293 if (doi
== oakley_hashdef
[i
].doi
) {
294 plog(LLV_DEBUG
, LOCATION
, NULL
, "hash(%s)\n",
295 oakley_hashdef
[i
].name
);
296 return &oakley_hashdef
[i
];
302 alg_oakley_hashdef_ok(doi
)
305 struct hash_algorithm
*f
;
307 f
= alg_oakley_hashdef(doi
);
315 alg_oakley_hashdef_doi(type
)
320 for (i
= 0; i
< ARRAYLEN(oakley_hashdef
); i
++)
321 if (type
== oakley_hashdef
[i
].type
) {
322 res
= oakley_hashdef
[i
].doi
;
329 alg_oakley_hashdef_hashlen(doi
)
332 struct hash_algorithm
*f
;
334 f
= alg_oakley_hashdef(doi
);
335 if (f
== NULL
|| f
->hashlen
== NULL
)
338 return (f
->hashlen
)();
342 alg_oakley_hashdef_name (doi
)
345 struct hash_algorithm
*f
;
347 f
= alg_oakley_hashdef(doi
);
355 alg_oakley_hashdef_one(doi
, buf
)
359 struct hash_algorithm
*f
;
361 f
= alg_oakley_hashdef(doi
);
362 if (f
== NULL
|| f
->hashlen
== NULL
)
365 return (f
->one
)(buf
);
368 /* oakley hmac algorithm */
369 static struct hmac_algorithm
*
370 alg_oakley_hmacdef(doi
)
375 for (i
= 0; i
< ARRAYLEN(oakley_hmacdef
); i
++)
376 if (doi
== oakley_hmacdef
[i
].doi
) {
377 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
378 oakley_hmacdef
[i
].name
);
379 return &oakley_hmacdef
[i
];
385 alg_oakley_hmacdef_doi(type
)
390 for (i
= 0; i
< ARRAYLEN(oakley_hmacdef
); i
++)
391 if (type
== oakley_hmacdef
[i
].type
) {
392 res
= oakley_hmacdef
[i
].doi
;
399 alg_oakley_hmacdef_one(doi
, key
, buf
)
403 struct hmac_algorithm
*f
;
406 struct timeval start
, end
;
409 f
= alg_oakley_hmacdef(doi
);
410 if (f
== NULL
|| f
->one
== NULL
)
414 gettimeofday(&start
, NULL
);
417 res
= (f
->one
)(key
, buf
);
420 gettimeofday(&end
, NULL
);
421 syslog(LOG_NOTICE
, "%s(%s size=%zu): %8.6f", __func__
,
422 f
->name
, buf
->l
, timedelta(&start
, &end
));
428 /* oakley encryption algorithm */
429 static struct enc_algorithm
*
430 alg_oakley_encdef(doi
)
435 for (i
= 0; i
< ARRAYLEN(oakley_encdef
); i
++)
436 if (doi
== oakley_encdef
[i
].doi
) {
437 plog(LLV_DEBUG
, LOCATION
, NULL
, "encryption(%s)\n",
438 oakley_encdef
[i
].name
);
439 return &oakley_encdef
[i
];
445 alg_oakley_encdef_ok(doi
)
448 struct enc_algorithm
*f
;
450 f
= alg_oakley_encdef(doi
);
458 alg_oakley_encdef_doi(type
)
463 for (i
= 0; i
< ARRAYLEN(oakley_encdef
); i
++)
464 if (type
== oakley_encdef
[i
].type
) {
465 res
= oakley_encdef
[i
].doi
;
472 alg_oakley_encdef_keylen(doi
, len
)
475 struct enc_algorithm
*f
;
477 f
= alg_oakley_encdef(doi
);
478 if (f
== NULL
|| f
->keylen
== NULL
)
481 return (f
->keylen
)(len
);
485 alg_oakley_encdef_blocklen(doi
)
488 struct enc_algorithm
*f
;
490 f
= alg_oakley_encdef(doi
);
498 alg_oakley_encdef_name (doi
)
501 struct enc_algorithm
*f
;
503 f
= alg_oakley_encdef(doi
);
511 alg_oakley_encdef_decrypt(doi
, buf
, key
, iv
)
513 vchar_t
*buf
, *key
, *iv
;
516 struct enc_algorithm
*f
;
518 struct timeval start
, end
;
521 f
= alg_oakley_encdef(doi
);
522 if (f
== NULL
|| f
->decrypt
== NULL
)
526 gettimeofday(&start
, NULL
);
529 res
= (f
->decrypt
)(buf
, key
, iv
);
532 gettimeofday(&end
, NULL
);
533 syslog(LOG_NOTICE
, "%s(%s klen=%zu size=%zu): %8.6f", __func__
,
534 f
->name
, key
->l
<< 3, buf
->l
, timedelta(&start
, &end
));
540 alg_oakley_encdef_encrypt(doi
, buf
, key
, iv
)
542 vchar_t
*buf
, *key
, *iv
;
545 struct enc_algorithm
*f
;
547 struct timeval start
, end
;
550 f
= alg_oakley_encdef(doi
);
551 if (f
== NULL
|| f
->encrypt
== NULL
)
555 gettimeofday(&start
, NULL
);
558 res
= (f
->encrypt
)(buf
, key
, iv
);
561 gettimeofday(&end
, NULL
);
562 syslog(LOG_NOTICE
, "%s(%s klen=%zu size=%zu): %8.6f", __func__
,
563 f
->name
, key
->l
<< 3, buf
->l
, timedelta(&start
, &end
));
568 /* ipsec encryption algorithm */
569 static struct enc_algorithm
*
570 alg_ipsec_encdef(doi
)
575 for (i
= 0; i
< ARRAYLEN(ipsec_encdef
); i
++)
576 if (doi
== ipsec_encdef
[i
].doi
) {
577 plog(LLV_DEBUG
, LOCATION
, NULL
, "encryption(%s)\n",
578 ipsec_encdef
[i
].name
);
579 return &ipsec_encdef
[i
];
585 alg_ipsec_encdef_doi(type
)
590 for (i
= 0; i
< ARRAYLEN(ipsec_encdef
); i
++)
591 if (type
== ipsec_encdef
[i
].type
) {
592 res
= ipsec_encdef
[i
].doi
;
599 alg_ipsec_encdef_keylen(doi
, len
)
602 struct enc_algorithm
*f
;
604 f
= alg_ipsec_encdef(doi
);
605 if (f
== NULL
|| f
->keylen
== NULL
)
608 return (f
->keylen
)(len
);
611 /* ipsec hmac algorithm */
612 static struct hmac_algorithm
*
613 alg_ipsec_hmacdef(doi
)
618 for (i
= 0; i
< ARRAYLEN(ipsec_hmacdef
); i
++)
619 if (doi
== ipsec_hmacdef
[i
].doi
) {
620 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
621 ipsec_hmacdef
[i
].name
);
622 return &ipsec_hmacdef
[i
];
628 alg_ipsec_hmacdef_doi(type
)
633 for (i
= 0; i
< ARRAYLEN(ipsec_hmacdef
); i
++)
634 if (type
== ipsec_hmacdef
[i
].type
) {
635 res
= ipsec_hmacdef
[i
].doi
;
642 alg_ipsec_hmacdef_hashlen(doi
)
645 struct hmac_algorithm
*f
;
647 f
= alg_ipsec_hmacdef(doi
);
648 if (f
== NULL
|| f
->hashlen
== NULL
)
651 return (f
->hashlen
)();
656 alg_ipsec_compdef_doi(type
)
661 for (i
= 0; i
< ARRAYLEN(ipsec_compdef
); i
++)
662 if (type
== ipsec_compdef
[i
].type
) {
663 res
= ipsec_compdef
[i
].doi
;
670 static struct dh_algorithm
*
671 alg_oakley_dhdef(doi
)
676 for (i
= 0; i
< ARRAYLEN(oakley_dhdef
); i
++)
677 if (doi
== oakley_dhdef
[i
].doi
) {
678 plog(LLV_DEBUG
, LOCATION
, NULL
, "hmac(%s)\n",
679 oakley_dhdef
[i
].name
);
680 return &oakley_dhdef
[i
];
686 alg_oakley_dhdef_ok(doi
)
689 struct dh_algorithm
*f
;
691 f
= alg_oakley_dhdef(doi
);
699 alg_oakley_dhdef_doi(type
)
704 for (i
= 0; i
< ARRAYLEN(oakley_dhdef
); i
++)
705 if (type
== oakley_dhdef
[i
].type
) {
706 res
= oakley_dhdef
[i
].doi
;
713 alg_oakley_dhdef_group(doi
)
716 struct dh_algorithm
*f
;
718 f
= alg_oakley_dhdef(doi
);
719 if (f
== NULL
|| f
->dhgroup
== NULL
)
726 alg_oakley_dhdef_name (doi
)
729 struct dh_algorithm
*f
;
731 f
= alg_oakley_dhdef(doi
);
737 /* authentication method */
739 alg_oakley_authdef_doi(type
)
744 for (i
= 0; i
< ARRAYLEN(oakley_authdef
); i
++)
745 if (type
== oakley_authdef
[i
].type
) {
746 res
= oakley_authdef
[i
].doi
;
753 alg_oakley_authdef_name (doi
)
758 for (i
= 0; i
< ARRAYLEN(oakley_authdef
); i
++)
759 if (doi
== oakley_authdef
[i
].doi
) {
760 return oakley_authdef
[i
].name
;
766 * give the default key length
768 * 0: fixed key cipher, key length not allowed
769 * positive: default key length
772 default_keylen(class, type
)
777 case algclass_isakmp_enc
:
778 case algclass_ipsec_enc
:
785 case algtype_blowfish
:
787 case algtype_cast128
:
789 case algtype_twofish
:
802 check_keylen(class, type
, len
)
803 int class, type
, len
;
808 case algclass_isakmp_enc
:
809 case algclass_ipsec_enc
:
812 /* unknown class, punt */
813 plog(LLV_ERROR
, LOCATION
, NULL
,
814 "unknown algclass %d\n", class);
818 /* key length must be multiple of 8 bytes - RFC2451 2.2 */
820 case algtype_blowfish
:
822 case algtype_cast128
:
824 case algtype_twofish
:
826 plog(LLV_ERROR
, LOCATION
, NULL
,
827 "key length %d is not multiple of 8\n", len
);
833 /* key length range */
836 case algtype_blowfish
:
837 if (len
< 40 || 448 < len
)
841 if (len
< 40 || 2040 < len
)
844 case algtype_cast128
:
845 if (len
< 40 || 128 < len
)
849 if (!(len
== 128 || len
== 192 || len
== 256))
852 case algtype_twofish
:
853 if (len
< 40 || 256 < len
)
858 plog(LLV_ERROR
, LOCATION
, NULL
,
859 "key length is not allowed");
865 plog(LLV_ERROR
, LOCATION
, NULL
,
866 "key length out of range\n");
874 * convert algorithm type to DOI value.
879 algtype2doi(class, type
)
885 case algclass_ipsec_enc
:
886 res
= alg_ipsec_encdef_doi(type
);
888 case algclass_ipsec_auth
:
889 res
= alg_ipsec_hmacdef_doi(type
);
891 case algclass_ipsec_comp
:
892 res
= alg_ipsec_compdef_doi(type
);
894 case algclass_isakmp_enc
:
895 res
= alg_oakley_encdef_doi(type
);
897 case algclass_isakmp_hash
:
898 res
= alg_oakley_hashdef_doi(type
);
900 case algclass_isakmp_dh
:
901 res
= alg_oakley_dhdef_doi(type
);
903 case algclass_isakmp_ameth
:
904 res
= alg_oakley_authdef_doi(type
);
911 * convert algorithm class to DOI value.
920 case algclass_ipsec_enc
:
921 return IPSECDOI_PROTO_IPSEC_ESP
;
922 case algclass_ipsec_auth
:
923 return IPSECDOI_ATTR_AUTH
;
924 case algclass_ipsec_comp
:
925 return IPSECDOI_PROTO_IPCOMP
;
926 case algclass_isakmp_enc
:
927 return OAKLEY_ATTR_ENC_ALG
;
928 case algclass_isakmp_hash
:
929 return OAKLEY_ATTR_HASH_ALG
;
930 case algclass_isakmp_dh
:
931 return OAKLEY_ATTR_GRP_DESC
;
932 case algclass_isakmp_ameth
:
933 return OAKLEY_ATTR_AUTH_METHOD
;