fixed CHILD_SA proposal selection when not using DH exchange
[strongswan.git] / src / charon / config / proposal.c
1 /**
2 * @file proposal.c
3 *
4 * @brief Implementation of proposal_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <string.h>
24
25 #include "proposal.h"
26
27 #include <daemon.h>
28 #include <utils/linked_list.h>
29 #include <utils/identification.h>
30 #include <utils/lexparser.h>
31 #include <crypto/prfs/prf.h>
32 #include <crypto/crypters/crypter.h>
33 #include <crypto/signers/signer.h>
34
35
36 ENUM(protocol_id_names, PROTO_NONE, PROTO_ESP,
37 "PROTO_NONE",
38 "IKE",
39 "AH",
40 "ESP",
41 );
42
43 ENUM_BEGIN(transform_type_names, UNDEFINED_TRANSFORM_TYPE, UNDEFINED_TRANSFORM_TYPE,
44 "UNDEFINED_TRANSFORM_TYPE");
45 ENUM_NEXT(transform_type_names, ENCRYPTION_ALGORITHM, EXTENDED_SEQUENCE_NUMBERS, UNDEFINED_TRANSFORM_TYPE,
46 "ENCRYPTION_ALGORITHM",
47 "PSEUDO_RANDOM_FUNCTION",
48 "INTEGRITY_ALGORITHM",
49 "DIFFIE_HELLMAN_GROUP",
50 "EXTENDED_SEQUENCE_NUMBERS");
51 ENUM_END(transform_type_names, EXTENDED_SEQUENCE_NUMBERS);
52
53 ENUM(extended_sequence_numbers_names, NO_EXT_SEQ_NUMBERS, EXT_SEQ_NUMBERS,
54 "NO_EXT_SEQ_NUMBERS",
55 "EXT_SEQ_NUMBERS",
56 );
57
58 typedef struct private_proposal_t private_proposal_t;
59
60 /**
61 * Private data of an proposal_t object
62 */
63 struct private_proposal_t {
64
65 /**
66 * Public part
67 */
68 proposal_t public;
69
70 /**
71 * protocol (ESP or AH)
72 */
73 protocol_id_t protocol;
74
75 /**
76 * priority ordered list of encryption algorithms
77 */
78 linked_list_t *encryption_algos;
79
80 /**
81 * priority ordered list of integrity algorithms
82 */
83 linked_list_t *integrity_algos;
84
85 /**
86 * priority ordered list of pseudo random functions
87 */
88 linked_list_t *prf_algos;
89
90 /**
91 * priority ordered list of dh groups
92 */
93 linked_list_t *dh_groups;
94
95 /**
96 * priority ordered list of extended sequence number flags
97 */
98 linked_list_t *esns;
99
100 /**
101 * senders SPI
102 */
103 u_int64_t spi;
104 };
105
106 /**
107 * Add algorithm/keysize to a algorithm list
108 */
109 static void add_algo(linked_list_t *list, u_int16_t algo, size_t key_size)
110 {
111 algorithm_t *algo_key;
112
113 algo_key = malloc_thing(algorithm_t);
114 algo_key->algorithm = algo;
115 algo_key->key_size = key_size;
116 list->insert_last(list, (void*)algo_key);
117 }
118
119 /**
120 * Implements proposal_t.add_algorithm
121 */
122 static void add_algorithm(private_proposal_t *this, transform_type_t type, u_int16_t algo, size_t key_size)
123 {
124 switch (type)
125 {
126 case ENCRYPTION_ALGORITHM:
127 add_algo(this->encryption_algos, algo, key_size);
128 break;
129 case INTEGRITY_ALGORITHM:
130 add_algo(this->integrity_algos, algo, key_size);
131 break;
132 case PSEUDO_RANDOM_FUNCTION:
133 add_algo(this->prf_algos, algo, key_size);
134 break;
135 case DIFFIE_HELLMAN_GROUP:
136 add_algo(this->dh_groups, algo, 0);
137 break;
138 case EXTENDED_SEQUENCE_NUMBERS:
139 add_algo(this->esns, algo, 0);
140 break;
141 default:
142 break;
143 }
144 }
145
146 /**
147 * Implements proposal_t.create_algorithm_iterator.
148 */
149 static iterator_t *create_algorithm_iterator(private_proposal_t *this, transform_type_t type)
150 {
151 switch (type)
152 {
153 case ENCRYPTION_ALGORITHM:
154 return this->encryption_algos->create_iterator(this->encryption_algos, TRUE);
155 case INTEGRITY_ALGORITHM:
156 return this->integrity_algos->create_iterator(this->integrity_algos, TRUE);
157 case PSEUDO_RANDOM_FUNCTION:
158 return this->prf_algos->create_iterator(this->prf_algos, TRUE);
159 case DIFFIE_HELLMAN_GROUP:
160 return this->dh_groups->create_iterator(this->dh_groups, TRUE);
161 case EXTENDED_SEQUENCE_NUMBERS:
162 return this->esns->create_iterator(this->esns, TRUE);
163 default:
164 break;
165 }
166 return NULL;
167 }
168
169 /**
170 * Implements proposal_t.get_algorithm.
171 */
172 static bool get_algorithm(private_proposal_t *this, transform_type_t type, algorithm_t** algo)
173 {
174 iterator_t *iterator = create_algorithm_iterator(this, type);
175 if (iterator->iterate(iterator, (void**)algo))
176 {
177 iterator->destroy(iterator);
178 return TRUE;
179 }
180 iterator->destroy(iterator);
181 return FALSE;
182 }
183
184 /**
185 * Implements proposal_t.has_dh_group
186 */
187 static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
188 {
189 algorithm_t *current;
190 iterator_t *iterator;
191 bool result = FALSE;
192
193 iterator = this->dh_groups->create_iterator(this->dh_groups, TRUE);
194 if (iterator->get_count(iterator))
195 {
196 while (iterator->iterate(iterator, (void**)&current))
197 {
198 if (current->algorithm == group)
199 {
200 result = TRUE;
201 break;
202 }
203 }
204 }
205 else if (group == MODP_NONE)
206 {
207 result = TRUE;
208 }
209 iterator->destroy(iterator);
210 return result;
211 }
212
213 /**
214 * Find a matching alg/keysize in two linked lists
215 */
216 static bool select_algo(linked_list_t *first, linked_list_t *second, bool *add, u_int16_t *alg, size_t *key_size)
217 {
218 iterator_t *first_iter, *second_iter;
219 algorithm_t *first_alg, *second_alg;
220
221 /* if in both are zero algorithms specified, we HAVE a match */
222 if (first->get_count(first) == 0 && second->get_count(second) == 0)
223 {
224 *add = FALSE;
225 return TRUE;
226 }
227
228 first_iter = first->create_iterator(first, TRUE);
229 second_iter = second->create_iterator(second, TRUE);
230 /* compare algs, order of algs in "first" is preferred */
231 while (first_iter->iterate(first_iter, (void**)&first_alg))
232 {
233 second_iter->reset(second_iter);
234 while (second_iter->iterate(second_iter, (void**)&second_alg))
235 {
236 if (first_alg->algorithm == second_alg->algorithm &&
237 first_alg->key_size == second_alg->key_size)
238 {
239 /* ok, we have an algorithm */
240 *alg = first_alg->algorithm;
241 *key_size = first_alg->key_size;
242 *add = TRUE;
243 first_iter->destroy(first_iter);
244 second_iter->destroy(second_iter);
245 return TRUE;
246 }
247 }
248 }
249 /* no match in all comparisons */
250 first_iter->destroy(first_iter);
251 second_iter->destroy(second_iter);
252 return FALSE;
253 }
254
255 /**
256 * Implements proposal_t.select.
257 */
258 static proposal_t *select_proposal(private_proposal_t *this, private_proposal_t *other)
259 {
260 proposal_t *selected;
261 u_int16_t algo;
262 size_t key_size;
263 bool add;
264
265 DBG2(DBG_CFG, "selecting proposal:");
266
267 /* check protocol */
268 if (this->protocol != other->protocol)
269 {
270 DBG2(DBG_CFG, " protocol mismatch, skipping");
271 return NULL;
272 }
273
274 selected = proposal_create(this->protocol);
275
276 /* select encryption algorithm */
277 if (select_algo(this->encryption_algos, other->encryption_algos, &add, &algo, &key_size))
278 {
279 if (add)
280 {
281 selected->add_algorithm(selected, ENCRYPTION_ALGORITHM, algo, key_size);
282 }
283 }
284 else
285 {
286 selected->destroy(selected);
287 DBG2(DBG_CFG, " no acceptable ENCRYPTION_ALGORITHM found, skipping");
288 return NULL;
289 }
290 /* select integrity algorithm */
291 if (select_algo(this->integrity_algos, other->integrity_algos, &add, &algo, &key_size))
292 {
293 if (add)
294 {
295 selected->add_algorithm(selected, INTEGRITY_ALGORITHM, algo, key_size);
296 }
297 }
298 else
299 {
300 selected->destroy(selected);
301 DBG2(DBG_CFG, " no acceptable INTEGRITY_ALGORITHM found, skipping");
302 return NULL;
303 }
304 /* select prf algorithm */
305 if (select_algo(this->prf_algos, other->prf_algos, &add, &algo, &key_size))
306 {
307 if (add)
308 {
309 selected->add_algorithm(selected, PSEUDO_RANDOM_FUNCTION, algo, key_size);
310 }
311 }
312 else
313 {
314 selected->destroy(selected);
315 DBG2(DBG_CFG, " no acceptable PSEUDO_RANDOM_FUNCTION found, skipping");
316 return NULL;
317 }
318 /* select a DH-group */
319 if (select_algo(this->dh_groups, other->dh_groups, &add, &algo, &key_size))
320 {
321 if (add)
322 {
323 selected->add_algorithm(selected, DIFFIE_HELLMAN_GROUP, algo, 0);
324 }
325 }
326 else
327 {
328 selected->destroy(selected);
329 DBG2(DBG_CFG, " no acceptable DIFFIE_HELLMAN_GROUP found, skipping");
330 return NULL;
331 }
332 /* select if we use ESNs */
333 if (select_algo(this->esns, other->esns, &add, &algo, &key_size))
334 {
335 if (add)
336 {
337 selected->add_algorithm(selected, EXTENDED_SEQUENCE_NUMBERS, algo, 0);
338 }
339 }
340 else
341 {
342 selected->destroy(selected);
343 DBG2(DBG_CFG, " no acceptable EXTENDED_SEQUENCE_NUMBERS found, skipping");
344 return NULL;
345 }
346 DBG2(DBG_CFG, " proposal matches");
347
348 /* apply SPI from "other" */
349 selected->set_spi(selected, other->spi);
350
351 /* everything matched, return new proposal */
352 return selected;
353 }
354
355 /**
356 * Implements proposal_t.get_protocols.
357 */
358 static protocol_id_t get_protocol(private_proposal_t *this)
359 {
360 return this->protocol;
361 }
362
363 /**
364 * Implements proposal_t.set_spi.
365 */
366 static void set_spi(private_proposal_t *this, u_int64_t spi)
367 {
368 this->spi = spi;
369 }
370
371 /**
372 * Implements proposal_t.get_spi.
373 */
374 static u_int64_t get_spi(private_proposal_t *this)
375 {
376 return this->spi;
377 }
378
379 /**
380 * Clone a algorithm list
381 */
382 static void clone_algo_list(linked_list_t *list, linked_list_t *clone_list)
383 {
384 algorithm_t *algo, *clone_algo;
385 iterator_t *iterator = list->create_iterator(list, TRUE);
386 while (iterator->iterate(iterator, (void**)&algo))
387 {
388 clone_algo = malloc_thing(algorithm_t);
389 memcpy(clone_algo, algo, sizeof(algorithm_t));
390 clone_list->insert_last(clone_list, (void*)clone_algo);
391 }
392 iterator->destroy(iterator);
393 }
394
395 /**
396 * Implements proposal_t.clone
397 */
398 static proposal_t *clone_(private_proposal_t *this)
399 {
400 private_proposal_t *clone = (private_proposal_t*)proposal_create(this->protocol);
401
402 clone_algo_list(this->encryption_algos, clone->encryption_algos);
403 clone_algo_list(this->integrity_algos, clone->integrity_algos);
404 clone_algo_list(this->prf_algos, clone->prf_algos);
405 clone_algo_list(this->dh_groups, clone->dh_groups);
406 clone_algo_list(this->esns, clone->esns);
407
408 clone->spi = this->spi;
409
410 return &clone->public;
411 }
412
413 static status_t add_string_algo(private_proposal_t *this, chunk_t alg)
414 {
415 if (strncmp(alg.ptr, "null", alg.len) == 0)
416 {
417 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_NULL, 0);
418 }
419 else if (strncmp(alg.ptr, "aes128", alg.len) == 0)
420 {
421 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
422 }
423 else if (strncmp(alg.ptr, "aes192", alg.len) == 0)
424 {
425 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
426 }
427 else if (strncmp(alg.ptr, "aes256", alg.len) == 0)
428 {
429 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
430 }
431 else if (strncmp(alg.ptr, "3des", alg.len) == 0)
432 {
433 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
434 }
435 /* blowfish only uses some predefined key sizes yet */
436 else if (strncmp(alg.ptr, "blowfish128", alg.len) == 0)
437 {
438 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 128);
439 }
440 else if (strncmp(alg.ptr, "blowfish192", alg.len) == 0)
441 {
442 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 192);
443 }
444 else if (strncmp(alg.ptr, "blowfish256", alg.len) == 0)
445 {
446 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 256);
447 }
448 else if (strncmp(alg.ptr, "sha", alg.len) == 0 ||
449 strncmp(alg.ptr, "sha1", alg.len) == 0)
450 {
451 /* sha means we use SHA for both, PRF and AUTH */
452 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
453 if (this->protocol == PROTO_IKE)
454 {
455 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0);
456 }
457 }
458 else if (strncmp(alg.ptr, "sha256", alg.len) == 0)
459 {
460 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_256_128, 0);
461 if (this->protocol == PROTO_IKE)
462 {
463 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_256, 0);
464 }
465 }
466 else if (strncmp(alg.ptr, "sha384", alg.len) == 0)
467 {
468 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_384_192, 0);
469 if (this->protocol == PROTO_IKE)
470 {
471 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_384, 0);
472 }
473 }
474 else if (strncmp(alg.ptr, "sha512", alg.len) == 0)
475 {
476 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_512_256, 0);
477 if (this->protocol == PROTO_IKE)
478 {
479 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_512, 0);
480 }
481 }
482 else if (strncmp(alg.ptr, "md5", alg.len) == 0)
483 {
484 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
485 if (this->protocol == PROTO_IKE)
486 {
487 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 0);
488 }
489 }
490 else if (strncmp(alg.ptr, "modp768", alg.len) == 0)
491 {
492 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_768_BIT, 0);
493 }
494 else if (strncmp(alg.ptr, "modp1024", alg.len) == 0)
495 {
496 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
497 }
498 else if (strncmp(alg.ptr, "modp1536", alg.len) == 0)
499 {
500 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1536_BIT, 0);
501 }
502 else if (strncmp(alg.ptr, "modp2048", alg.len) == 0)
503 {
504 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
505 }
506 else if (strncmp(alg.ptr, "modp4096", alg.len) == 0)
507 {
508 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_4096_BIT, 0);
509 }
510 else if (strncmp(alg.ptr, "modp8192", alg.len) == 0)
511 {
512 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_8192_BIT, 0);
513 }
514 else
515 {
516 return FAILED;
517 }
518 return SUCCESS;
519 }
520
521 /**
522 * Implements proposal_t.destroy.
523 */
524 static void destroy(private_proposal_t *this)
525 {
526 this->encryption_algos->destroy_function(this->encryption_algos, free);
527 this->integrity_algos->destroy_function(this->integrity_algos, free);
528 this->prf_algos->destroy_function(this->prf_algos, free);
529 this->dh_groups->destroy_function(this->dh_groups, free);
530 this->esns->destroy_function(this->esns, free);
531 free(this);
532 }
533
534 /*
535 * Describtion in header-file
536 */
537 proposal_t *proposal_create(protocol_id_t protocol)
538 {
539 private_proposal_t *this = malloc_thing(private_proposal_t);
540
541 this->public.add_algorithm = (void (*)(proposal_t*,transform_type_t,u_int16_t,size_t))add_algorithm;
542 this->public.create_algorithm_iterator = (iterator_t* (*)(proposal_t*,transform_type_t))create_algorithm_iterator;
543 this->public.get_algorithm = (bool (*)(proposal_t*,transform_type_t,algorithm_t**))get_algorithm;
544 this->public.has_dh_group = (bool (*)(proposal_t*,diffie_hellman_group_t))has_dh_group;
545 this->public.select = (proposal_t* (*)(proposal_t*,proposal_t*))select_proposal;
546 this->public.get_protocol = (protocol_id_t(*)(proposal_t*))get_protocol;
547 this->public.set_spi = (void(*)(proposal_t*,u_int64_t))set_spi;
548 this->public.get_spi = (u_int64_t(*)(proposal_t*))get_spi;
549 this->public.clone = (proposal_t*(*)(proposal_t*))clone_;
550 this->public.destroy = (void(*)(proposal_t*))destroy;
551
552 this->spi = 0;
553 this->protocol = protocol;
554
555 this->encryption_algos = linked_list_create();
556 this->integrity_algos = linked_list_create();
557 this->prf_algos = linked_list_create();
558 this->dh_groups = linked_list_create();
559 this->esns = linked_list_create();
560
561 return &this->public;
562 }
563
564 /*
565 * Describtion in header-file
566 */
567 proposal_t *proposal_create_default(protocol_id_t protocol)
568 {
569 private_proposal_t *this = (private_proposal_t*)proposal_create(protocol);
570
571 switch (protocol)
572 {
573 case PROTO_IKE:
574 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
575 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
576 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
577 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
578 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_256_128, 0);
579 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
580 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
581 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_384_192, 0);
582 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_512_256, 0);
583 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_256, 0);
584 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0);
585 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 0);
586 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_384, 0);
587 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_512, 0);
588 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
589 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1536_BIT, 0);
590 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
591 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_4096_BIT, 0);
592 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_8192_BIT, 0);
593 break;
594 case PROTO_ESP:
595 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
596 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
597 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
598 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
599 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 256);
600 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
601 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
602 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
603 break;
604 case PROTO_AH:
605 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
606 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
607 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
608 break;
609 default:
610 break;
611 }
612
613 return &this->public;
614 }
615
616 /*
617 * Describtion in header-file
618 */
619 proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs)
620 {
621 private_proposal_t *this = (private_proposal_t*)proposal_create(protocol);
622 chunk_t string = {(void*)algs, strlen(algs)};
623 chunk_t alg;
624 status_t status = SUCCESS;
625
626 eat_whitespace(&string);
627 if (string.len < 1)
628 {
629 destroy(this);
630 return NULL;
631 }
632
633 /* get all tokens, separated by '-' */
634 while (extract_token(&alg, '-', &string))
635 {
636 status |= add_string_algo(this, alg);
637 }
638 if (string.len)
639 {
640 status |= add_string_algo(this, string);
641 }
642 if (status != SUCCESS)
643 {
644 destroy(this);
645 return NULL;
646 }
647
648 if (protocol == PROTO_AH || protocol == PROTO_ESP)
649 {
650 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
651 }
652 return &this->public;
653 }