xform_ah.c revision 1.77 1 /* $NetBSD: xform_ah.c,v 1.77 2018/01/24 13:49:23 maxv Exp $ */
2 /* $FreeBSD: src/sys/netipsec/xform_ah.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */
3 /* $OpenBSD: ip_ah.c,v 1.63 2001/06/26 06:18:58 angelos Exp $ */
4 /*
5 * The authors of this code are John Ioannidis (ji (at) tla.org),
6 * Angelos D. Keromytis (kermit (at) csd.uch.gr) and
7 * Niels Provos (provos (at) physnet.uni-hamburg.de).
8 *
9 * The original version of this code was written by John Ioannidis
10 * for BSD/OS in Athens, Greece, in November 1995.
11 *
12 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
13 * by Angelos D. Keromytis.
14 *
15 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
16 * and Niels Provos.
17 *
18 * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist.
19 *
20 * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
21 * Angelos D. Keromytis and Niels Provos.
22 * Copyright (c) 1999 Niklas Hallqvist.
23 * Copyright (c) 2001 Angelos D. Keromytis.
24 *
25 * Permission to use, copy, and modify this software with or without fee
26 * is hereby granted, provided that this entire notice is included in
27 * all copies of any software which is or includes a copy or
28 * modification of this software.
29 * You may use this code under the GNU public license if you so wish. Please
30 * contribute changes back to the authors under this freer than GPL license
31 * so that we may further the use of strong encryption without limitations to
32 * all.
33 *
34 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
35 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
36 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
37 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
38 * PURPOSE.
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.77 2018/01/24 13:49:23 maxv Exp $");
43
44 #if defined(_KERNEL_OPT)
45 #include "opt_inet.h"
46 #include "opt_ipsec.h"
47 #endif
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <sys/syslog.h>
54 #include <sys/kernel.h>
55 #include <sys/sysctl.h>
56 #include <sys/pool.h>
57 #include <sys/pserialize.h>
58
59 #include <net/if.h>
60
61 #include <netinet/in.h>
62 #include <netinet/in_systm.h>
63 #include <netinet/ip.h>
64 #include <netinet/ip_ecn.h>
65 #include <netinet/ip_var.h>
66 #include <netinet/ip6.h>
67
68 #include <net/route.h>
69 #include <netipsec/ipsec.h>
70 #include <netipsec/ipsec_private.h>
71 #include <netipsec/ah.h>
72 #include <netipsec/ah_var.h>
73 #include <netipsec/xform.h>
74
75 #ifdef INET6
76 #include <netinet6/ip6_var.h>
77 #include <netinet6/scope6_var.h>
78 #include <netipsec/ipsec6.h>
79 #endif
80
81 #include <netipsec/key.h>
82 #include <netipsec/key_debug.h>
83
84 #include <opencrypto/cryptodev.h>
85
86 /*
87 * Return header size in bytes. The old protocol did not support
88 * the replay counter; the new protocol always includes the counter.
89 */
90 #define HDRSIZE(sav) \
91 (((sav)->flags & SADB_X_EXT_OLD) ? \
92 sizeof(struct ah) : sizeof(struct ah) + sizeof(uint32_t))
93 /*
94 * Return authenticator size in bytes. The old protocol is known
95 * to use a fixed 16-byte authenticator. The new algorithm gets
96 * this size from the xform but is (currently) always 12.
97 */
98 #define AUTHSIZE(sav) \
99 ((sav->flags & SADB_X_EXT_OLD) ? 16 : (sav)->tdb_authalgxform->authsize)
100
101 percpu_t *ahstat_percpu;
102
103 int ah_enable = 1; /* control flow of packets with AH */
104 int ip4_ah_cleartos = 1; /* clear ip_tos when doing AH calc */
105
106 #ifdef __FreeBSD__
107 SYSCTL_DECL(_net_inet_ah);
108 SYSCTL_INT(_net_inet_ah, OID_AUTO,
109 ah_enable, CTLFLAG_RW, &ah_enable, 0, "");
110 SYSCTL_INT(_net_inet_ah, OID_AUTO,
111 ah_cleartos, CTLFLAG_RW, &ip4_ah_cleartos, 0, "");
112 SYSCTL_STRUCT(_net_inet_ah, IPSECCTL_STATS,
113 stats, CTLFLAG_RD, &ahstat, ahstat, "");
114
115 #endif /* __FreeBSD__ */
116
117 static unsigned char ipseczeroes[256]; /* larger than an ip6 extension hdr */
118
119 int ah_max_authsize; /* max authsize over all algorithms */
120
121 static int ah_input_cb(struct cryptop *);
122 static int ah_output_cb(struct cryptop *);
123
124 const uint8_t ah_stats[256] = { SADB_AALG_STATS_INIT };
125
126 static pool_cache_t ah_tdb_crypto_pool_cache;
127 static size_t ah_pool_item_size;
128
129 /*
130 * NB: this is public for use by the PF_KEY support.
131 */
132 const struct auth_hash *
133 ah_algorithm_lookup(int alg)
134 {
135
136 switch (alg) {
137 case SADB_X_AALG_NULL:
138 return &auth_hash_null;
139 case SADB_AALG_MD5HMAC:
140 return &auth_hash_hmac_md5_96;
141 case SADB_AALG_SHA1HMAC:
142 return &auth_hash_hmac_sha1_96;
143 case SADB_X_AALG_RIPEMD160HMAC:
144 return &auth_hash_hmac_ripemd_160_96;
145 case SADB_X_AALG_MD5:
146 return &auth_hash_key_md5;
147 case SADB_X_AALG_SHA:
148 return &auth_hash_key_sha1;
149 case SADB_X_AALG_SHA2_256:
150 return &auth_hash_hmac_sha2_256;
151 case SADB_X_AALG_SHA2_384:
152 return &auth_hash_hmac_sha2_384;
153 case SADB_X_AALG_SHA2_512:
154 return &auth_hash_hmac_sha2_512;
155 case SADB_X_AALG_AES_XCBC_MAC:
156 return &auth_hash_aes_xcbc_mac_96;
157 }
158 return NULL;
159 }
160
161 size_t
162 ah_hdrsiz(const struct secasvar *sav)
163 {
164 size_t size;
165
166 if (sav != NULL) {
167 int authsize;
168 KASSERT(sav->tdb_authalgxform != NULL);
169 /*XXX not right for null algorithm--does it matter??*/
170 authsize = AUTHSIZE(sav);
171 size = roundup(authsize, sizeof(uint32_t)) + HDRSIZE(sav);
172 } else {
173 /* default guess */
174 size = sizeof(struct ah) + sizeof(uint32_t) + ah_max_authsize;
175 }
176 return size;
177 }
178
179 /*
180 * NB: public for use by esp_init.
181 */
182 int
183 ah_init0(struct secasvar *sav, const struct xformsw *xsp,
184 struct cryptoini *cria)
185 {
186 const struct auth_hash *thash;
187 int keylen;
188
189 thash = ah_algorithm_lookup(sav->alg_auth);
190 if (thash == NULL) {
191 DPRINTF(("%s: unsupported authentication algorithm %u\n",
192 __func__, sav->alg_auth));
193 return EINVAL;
194 }
195 /*
196 * Verify the replay state block allocation is consistent with
197 * the protocol type. We check here so we can make assumptions
198 * later during protocol processing.
199 */
200 /* NB: replay state is setup elsewhere (sigh) */
201 if (((sav->flags&SADB_X_EXT_OLD) == 0) ^ (sav->replay != NULL)) {
202 DPRINTF(("%s: replay state block inconsistency, "
203 "%s algorithm %s replay state\n", __func__,
204 (sav->flags & SADB_X_EXT_OLD) ? "old" : "new",
205 sav->replay == NULL ? "without" : "with"));
206 return EINVAL;
207 }
208 if (sav->key_auth == NULL) {
209 DPRINTF(("%s: no authentication key for %s algorithm\n",
210 __func__, thash->name));
211 return EINVAL;
212 }
213 keylen = _KEYLEN(sav->key_auth);
214 if (keylen != thash->keysize && thash->keysize != 0) {
215 DPRINTF(("%s: invalid keylength %d, algorithm %s requires "
216 "keysize %d\n", __func__,
217 keylen, thash->name, thash->keysize));
218 return EINVAL;
219 }
220
221 sav->tdb_xform = xsp;
222 sav->tdb_authalgxform = thash;
223
224 /* Initialize crypto session. */
225 memset(cria, 0, sizeof(*cria));
226 cria->cri_alg = sav->tdb_authalgxform->type;
227 cria->cri_klen = _KEYBITS(sav->key_auth);
228 cria->cri_key = _KEYBUF(sav->key_auth);
229
230 return 0;
231 }
232
233 /*
234 * ah_init() is called when an SPI is being set up.
235 */
236 static int
237 ah_init(struct secasvar *sav, const struct xformsw *xsp)
238 {
239 struct cryptoini cria;
240 int error;
241
242 error = ah_init0(sav, xsp, &cria);
243 if (!error)
244 error = crypto_newsession(&sav->tdb_cryptoid,
245 &cria, crypto_support);
246 return error;
247 }
248
249 /*
250 * Paranoia.
251 *
252 * NB: public for use by esp_zeroize (XXX).
253 */
254 int
255 ah_zeroize(struct secasvar *sav)
256 {
257 int err;
258
259 if (sav->key_auth) {
260 explicit_memset(_KEYBUF(sav->key_auth), 0,
261 _KEYLEN(sav->key_auth));
262 }
263
264 err = crypto_freesession(sav->tdb_cryptoid);
265 sav->tdb_cryptoid = 0;
266 sav->tdb_authalgxform = NULL;
267 sav->tdb_xform = NULL;
268 return err;
269 }
270
271 /*
272 * Massage IPv4/IPv6 headers for AH processing.
273 */
274 static int
275 ah_massage_headers(struct mbuf **m0, int proto, int skip, int alg, int out)
276 {
277 struct mbuf *m = *m0;
278 unsigned char *ptr;
279 int off, count;
280
281 #ifdef INET
282 struct ip *ip;
283 #endif /* INET */
284
285 #ifdef INET6
286 struct ip6_ext *ip6e;
287 struct ip6_hdr ip6;
288 struct ip6_rthdr *rh;
289 int alloc, ad, nxt;
290 #endif /* INET6 */
291
292 switch (proto) {
293 #ifdef INET
294 case AF_INET:
295 /*
296 * This is the least painful way of dealing with IPv4 header
297 * and option processing -- just make sure they're in
298 * contiguous memory.
299 */
300 *m0 = m = m_pullup(m, skip);
301 if (m == NULL) {
302 DPRINTF(("%s: m_pullup failed\n", __func__));
303 return ENOBUFS;
304 }
305
306 /* Fix the IP header */
307 ip = mtod(m, struct ip *);
308 if (ip4_ah_cleartos)
309 ip->ip_tos = 0;
310 ip->ip_ttl = 0;
311 ip->ip_sum = 0;
312 ip->ip_off = htons(ntohs(ip->ip_off) & ip4_ah_offsetmask);
313
314 /*
315 * On FreeBSD, ip_off and ip_len assumed in host endian;
316 * they are converted (if necessary) by ip_input().
317 * On NetBSD, ip_off and ip_len are in network byte order.
318 * They must be massaged back to network byte order
319 * before verifying the HMAC. Moreover, on FreeBSD,
320 * we should add `skip' back into the massaged ip_len
321 * (presumably ip_input() deducted it before we got here?)
322 * whereas on NetBSD, we should not.
323 */
324 if (!out) {
325 uint16_t inlen = ntohs(ip->ip_len);
326
327 ip->ip_len = htons(inlen);
328
329 if (alg == CRYPTO_MD5_KPDK || alg == CRYPTO_SHA1_KPDK)
330 ip->ip_off &= htons(IP_DF);
331 else
332 ip->ip_off = 0;
333 } else {
334 if (alg == CRYPTO_MD5_KPDK || alg == CRYPTO_SHA1_KPDK)
335 ip->ip_off &= htons(IP_DF);
336 else
337 ip->ip_off = 0;
338 }
339
340 ptr = mtod(m, unsigned char *);
341
342 /* IPv4 option processing */
343 for (off = sizeof(struct ip); off < skip;) {
344 if (ptr[off] == IPOPT_EOL || ptr[off] == IPOPT_NOP ||
345 off + 1 < skip)
346 ;
347 else {
348 DPRINTF(("%s: illegal IPv4 option length for "
349 "option %d\n", __func__, ptr[off]));
350
351 m_freem(m);
352 return EINVAL;
353 }
354
355 switch (ptr[off]) {
356 case IPOPT_EOL:
357 off = skip; /* End the loop. */
358 break;
359
360 case IPOPT_NOP:
361 off++;
362 break;
363
364 case IPOPT_SECURITY: /* 0x82 */
365 case 0x85: /* Extended security. */
366 case 0x86: /* Commercial security. */
367 case 0x94: /* Router alert */
368 case 0x95: /* RFC1770 */
369 /* Sanity check for option length. */
370 if (ptr[off + 1] < 2) {
371 DPRINTF(("%s: illegal IPv4 option "
372 "length for option %d\n", __func__,
373 ptr[off]));
374
375 m_freem(m);
376 return EINVAL;
377 }
378
379 off += ptr[off + 1];
380 break;
381
382 case IPOPT_LSRR:
383 case IPOPT_SSRR:
384 /* Sanity check for option length. */
385 if (ptr[off + 1] < 2) {
386 DPRINTF(("%s: illegal IPv4 option "
387 "length for option %d\n", __func__,
388 ptr[off]));
389
390 m_freem(m);
391 return EINVAL;
392 }
393
394 /*
395 * On output, if we have either of the
396 * source routing options, we should
397 * swap the destination address of the
398 * IP header with the last address
399 * specified in the option, as that is
400 * what the destination's IP header
401 * will look like.
402 */
403 if (out)
404 memcpy(&ip->ip_dst,
405 ptr + off + ptr[off + 1] -
406 sizeof(struct in_addr),
407 sizeof(struct in_addr));
408
409 /* Fall through */
410 default:
411 /* Sanity check for option length. */
412 if (ptr[off + 1] < 2) {
413 DPRINTF(("%s: illegal IPv4 option "
414 "length for option %d\n", __func__,
415 ptr[off]));
416 m_freem(m);
417 return EINVAL;
418 }
419
420 /* Zeroize all other options. */
421 count = ptr[off + 1];
422 memcpy(ptr + off, ipseczeroes, count);
423 off += count;
424 break;
425 }
426
427 /* Sanity check. */
428 if (off > skip) {
429 DPRINTF(("%s: malformed IPv4 options header\n",
430 __func__));
431
432 m_freem(m);
433 return EINVAL;
434 }
435 }
436
437 break;
438 #endif /* INET */
439
440 #ifdef INET6
441 case AF_INET6: /* Ugly... */
442 /* Copy and "cook" the IPv6 header. */
443 m_copydata(m, 0, sizeof(ip6), &ip6);
444
445 /* We don't do IPv6 Jumbograms. */
446 if (ip6.ip6_plen == 0) {
447 DPRINTF(("%s: unsupported IPv6 jumbogram\n", __func__));
448 m_freem(m);
449 return EMSGSIZE;
450 }
451
452 ip6.ip6_flow = 0;
453 ip6.ip6_hlim = 0;
454 ip6.ip6_vfc &= ~IPV6_VERSION_MASK;
455 ip6.ip6_vfc |= IPV6_VERSION;
456
457 /* Scoped address handling. */
458 if (IN6_IS_SCOPE_LINKLOCAL(&ip6.ip6_src))
459 ip6.ip6_src.s6_addr16[1] = 0;
460 if (IN6_IS_SCOPE_LINKLOCAL(&ip6.ip6_dst))
461 ip6.ip6_dst.s6_addr16[1] = 0;
462
463 /* Done with IPv6 header. */
464 m_copyback(m, 0, sizeof(struct ip6_hdr), &ip6);
465
466 /* Let's deal with the remaining headers (if any). */
467 if (skip - sizeof(struct ip6_hdr) > 0) {
468 if (m->m_len <= skip) {
469 ptr = malloc(skip - sizeof(struct ip6_hdr),
470 M_XDATA, M_NOWAIT);
471 if (ptr == NULL) {
472 DPRINTF(("%s: failed to allocate "
473 "memory for IPv6 headers\n",
474 __func__));
475 m_freem(m);
476 return ENOBUFS;
477 }
478
479 /*
480 * Copy all the protocol headers after
481 * the IPv6 header.
482 */
483 m_copydata(m, sizeof(struct ip6_hdr),
484 skip - sizeof(struct ip6_hdr), ptr);
485 alloc = 1;
486 } else {
487 /* No need to allocate memory. */
488 ptr = mtod(m, unsigned char *) +
489 sizeof(struct ip6_hdr);
490 alloc = 0;
491 }
492 } else
493 break;
494
495 nxt = ip6.ip6_nxt & 0xff; /* Next header type. */
496
497 for (off = 0; off < skip - sizeof(struct ip6_hdr);) {
498 int noff;
499
500 switch (nxt) {
501 case IPPROTO_HOPOPTS:
502 case IPPROTO_DSTOPTS:
503 ip6e = (struct ip6_ext *)(ptr + off);
504 noff = off + ((ip6e->ip6e_len + 1) << 3);
505
506 /* Sanity check. */
507 if (noff > skip - sizeof(struct ip6_hdr)) {
508 goto error6;
509 }
510
511 /*
512 * Zero out mutable options.
513 */
514 for (count = off + sizeof(struct ip6_ext);
515 count < noff;) {
516 if (ptr[count] == IP6OPT_PAD1) {
517 count++;
518 continue;
519 }
520
521 ad = ptr[count + 1] + 2;
522
523 if (count + ad > noff) {
524 goto error6;
525 }
526
527 if (ptr[count] & IP6OPT_MUTABLE) {
528 memset(ptr + count, 0, ad);
529 }
530
531 count += ad;
532 }
533
534 if (count != noff) {
535 goto error6;
536 }
537
538 /* Advance. */
539 off += ((ip6e->ip6e_len + 1) << 3);
540 nxt = ip6e->ip6e_nxt;
541 break;
542
543 case IPPROTO_ROUTING:
544 /*
545 * Always include routing headers in
546 * computation.
547 */
548 ip6e = (struct ip6_ext *) (ptr + off);
549 rh = (struct ip6_rthdr *)(ptr + off);
550 /*
551 * must adjust content to make it look like
552 * its final form (as seen at the final
553 * destination).
554 * we only know how to massage type 0 routing
555 * header.
556 */
557 if (out && rh->ip6r_type == IPV6_RTHDR_TYPE_0) {
558 struct ip6_rthdr0 *rh0;
559 struct in6_addr *addr, finaldst;
560 int i;
561
562 rh0 = (struct ip6_rthdr0 *)rh;
563 addr = (struct in6_addr *)(rh0 + 1);
564
565 for (i = 0; i < rh0->ip6r0_segleft; i++)
566 in6_clearscope(&addr[i]);
567
568 finaldst = addr[rh0->ip6r0_segleft - 1];
569 memmove(&addr[1], &addr[0],
570 sizeof(struct in6_addr) *
571 (rh0->ip6r0_segleft - 1));
572
573 m_copydata(m, 0, sizeof(ip6), &ip6);
574 addr[0] = ip6.ip6_dst;
575 ip6.ip6_dst = finaldst;
576 m_copyback(m, 0, sizeof(ip6), &ip6);
577
578 rh0->ip6r0_segleft = 0;
579 }
580
581 /* advance */
582 off += ((ip6e->ip6e_len + 1) << 3);
583 nxt = ip6e->ip6e_nxt;
584 break;
585
586 default:
587 DPRINTF(("%s: unexpected IPv6 header type %d\n",
588 __func__, off));
589 error6:
590 if (alloc)
591 free(ptr, M_XDATA);
592 m_freem(m);
593 return EINVAL;
594 }
595 }
596
597 /* Copyback and free, if we allocated. */
598 if (alloc) {
599 m_copyback(m, sizeof(struct ip6_hdr),
600 skip - sizeof(struct ip6_hdr), ptr);
601 free(ptr, M_XDATA);
602 }
603
604 break;
605 #endif /* INET6 */
606 }
607
608 return 0;
609 }
610
611 /*
612 * ah_input() gets called to verify that an input packet
613 * passes authentication.
614 */
615 static int
616 ah_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
617 {
618 const struct auth_hash *ahx;
619 struct tdb_crypto *tc = NULL;
620 struct newah *ah;
621 int hl, rplen, authsize, error, stat = AH_STAT_HDROPS;
622 struct cryptodesc *crda;
623 struct cryptop *crp = NULL;
624
625 IPSEC_SPLASSERT_SOFTNET(__func__);
626
627 KASSERT(sav != NULL);
628 KASSERT(sav->key_auth != NULL);
629 KASSERT(sav->tdb_authalgxform != NULL);
630
631 /* Figure out header size. */
632 rplen = HDRSIZE(sav);
633
634 /* XXX don't pullup, just copy header */
635 IP6_EXTHDR_GET(ah, struct newah *, m, skip, rplen);
636 if (ah == NULL) {
637 DPRINTF(("%s: cannot pullup header\n", __func__));
638 error = ENOBUFS;
639 stat = AH_STAT_HDROPS; /*XXX*/
640 goto bad;
641 }
642
643 /* Check replay window, if applicable. */
644 if (sav->replay && !ipsec_chkreplay(ntohl(ah->ah_seq), sav)) {
645 char buf[IPSEC_LOGSASTRLEN];
646 DPRINTF(("%s: packet replay failure: %s\n", __func__,
647 ipsec_logsastr(sav, buf, sizeof(buf))));
648 stat = AH_STAT_REPLAY;
649 error = ENOBUFS;
650 goto bad;
651 }
652
653 /* Verify AH header length. */
654 hl = ah->ah_len * sizeof(uint32_t);
655 ahx = sav->tdb_authalgxform;
656 authsize = AUTHSIZE(sav);
657 if (hl != authsize + rplen - sizeof(struct ah)) {
658 char buf[IPSEC_ADDRSTRLEN];
659 DPRINTF(("%s: bad authenticator length %u (expecting %lu)"
660 " for packet in SA %s/%08lx\n", __func__,
661 hl, (u_long) (authsize + rplen - sizeof(struct ah)),
662 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
663 (u_long) ntohl(sav->spi)));
664 stat = AH_STAT_BADAUTHL;
665 error = EACCES;
666 goto bad;
667 }
668 AH_STATADD(AH_STAT_IBYTES, m->m_pkthdr.len - skip - hl);
669
670 /* Get crypto descriptors. */
671 crp = crypto_getreq(1);
672 if (crp == NULL) {
673 DPRINTF(("%s: failed to acquire crypto descriptor\n", __func__));
674 stat = AH_STAT_CRYPTO;
675 error = ENOBUFS;
676 goto bad;
677 }
678
679 crda = crp->crp_desc;
680 KASSERT(crda != NULL);
681
682 crda->crd_skip = 0;
683 crda->crd_len = m->m_pkthdr.len;
684 crda->crd_inject = skip + rplen;
685
686 /* Authentication operation. */
687 crda->crd_alg = ahx->type;
688 crda->crd_key = _KEYBUF(sav->key_auth);
689 crda->crd_klen = _KEYBITS(sav->key_auth);
690
691 /* Allocate IPsec-specific opaque crypto info. */
692 size_t size = sizeof(*tc);
693 size_t extra = skip + rplen + authsize;
694 size += extra;
695
696 KASSERTMSG(size <= ah_pool_item_size,
697 "size=%zu > ah_pool_item_size=%zu\n", size, ah_pool_item_size);
698 tc = pool_cache_get(ah_tdb_crypto_pool_cache, PR_NOWAIT);
699 if (tc == NULL) {
700 DPRINTF(("%s: failed to allocate tdb_crypto\n", __func__));
701 stat = AH_STAT_CRYPTO;
702 error = ENOBUFS;
703 goto bad;
704 }
705
706 error = m_makewritable(&m, 0, extra, M_NOWAIT);
707 if (error) {
708 DPRINTF(("%s: failed to m_makewritable\n", __func__));
709 goto bad;
710 }
711
712 /*
713 * Save the authenticator, the skipped portion of the packet,
714 * and the AH header.
715 */
716 m_copydata(m, 0, extra, (tc + 1));
717 /* Zeroize the authenticator on the packet. */
718 m_copyback(m, skip + rplen, authsize, ipseczeroes);
719
720 /* "Massage" the packet headers for crypto processing. */
721 error = ah_massage_headers(&m, sav->sah->saidx.dst.sa.sa_family,
722 skip, ahx->type, 0);
723 if (error != 0) {
724 /* NB: mbuf is free'd by ah_massage_headers */
725 m = NULL;
726 goto bad;
727 }
728
729 {
730 int s = pserialize_read_enter();
731
732 /*
733 * Take another reference to the SA for opencrypto callback.
734 */
735 if (__predict_false(sav->state == SADB_SASTATE_DEAD)) {
736 pserialize_read_exit(s);
737 stat = AH_STAT_NOTDB;
738 error = ENOENT;
739 goto bad;
740 }
741 KEY_SA_REF(sav);
742 pserialize_read_exit(s);
743 }
744
745 /* Crypto operation descriptor. */
746 crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */
747 crp->crp_flags = CRYPTO_F_IMBUF;
748 crp->crp_buf = m;
749 crp->crp_callback = ah_input_cb;
750 crp->crp_sid = sav->tdb_cryptoid;
751 crp->crp_opaque = tc;
752
753 /* These are passed as-is to the callback. */
754 tc->tc_spi = sav->spi;
755 tc->tc_dst = sav->sah->saidx.dst;
756 tc->tc_proto = sav->sah->saidx.proto;
757 tc->tc_nxt = ah->ah_nxt;
758 tc->tc_protoff = protoff;
759 tc->tc_skip = skip;
760 tc->tc_sav = sav;
761
762 DPRINTF(("%s: hash over %d bytes, skip %d: "
763 "crda len %d skip %d inject %d\n", __func__,
764 crp->crp_ilen, tc->tc_skip,
765 crda->crd_len, crda->crd_skip, crda->crd_inject));
766
767 return crypto_dispatch(crp);
768
769 bad:
770 if (tc != NULL)
771 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
772 if (crp != NULL)
773 crypto_freereq(crp);
774 if (m != NULL)
775 m_freem(m);
776 AH_STATINC(stat);
777 return error;
778 }
779
780 #ifdef INET6
781 #define IPSEC_COMMON_INPUT_CB(m, sav, skip, protoff) do { \
782 if (saidx->dst.sa.sa_family == AF_INET6) { \
783 error = ipsec6_common_input_cb(m, sav, skip, protoff); \
784 } else { \
785 error = ipsec4_common_input_cb(m, sav, skip, protoff); \
786 } \
787 } while (0)
788 #else
789 #define IPSEC_COMMON_INPUT_CB(m, sav, skip, protoff) \
790 (error = ipsec4_common_input_cb(m, sav, skip, protoff))
791 #endif
792
793 /*
794 * AH input callback from the crypto driver.
795 */
796 static int
797 ah_input_cb(struct cryptop *crp)
798 {
799 char buf[IPSEC_ADDRSTRLEN];
800 int rplen, error, skip, protoff;
801 unsigned char calc[AH_ALEN_MAX];
802 struct mbuf *m;
803 struct tdb_crypto *tc;
804 struct secasvar *sav;
805 struct secasindex *saidx;
806 uint8_t nxt;
807 char *ptr;
808 int authsize;
809 uint16_t dport;
810 uint16_t sport;
811 IPSEC_DECLARE_LOCK_VARIABLE;
812
813 KASSERT(crp->crp_opaque != NULL);
814 tc = crp->crp_opaque;
815 skip = tc->tc_skip;
816 nxt = tc->tc_nxt;
817 protoff = tc->tc_protoff;
818 m = crp->crp_buf;
819
820
821 /* find the source port for NAT-T */
822 nat_t_ports_get(m, &dport, &sport);
823
824 IPSEC_ACQUIRE_GLOBAL_LOCKS();
825
826 sav = tc->tc_sav;
827 if (__predict_false(!SADB_SASTATE_USABLE_P(sav))) {
828 KEY_SA_UNREF(&sav);
829 sav = KEY_LOOKUP_SA(&tc->tc_dst, tc->tc_proto, tc->tc_spi,
830 sport, dport);
831 if (sav == NULL) {
832 AH_STATINC(AH_STAT_NOTDB);
833 DPRINTF(("%s: SA expired while in crypto\n", __func__));
834 error = ENOBUFS; /*XXX*/
835 goto bad;
836 }
837 }
838
839 saidx = &sav->sah->saidx;
840 KASSERTMSG(saidx->dst.sa.sa_family == AF_INET ||
841 saidx->dst.sa.sa_family == AF_INET6,
842 "unexpected protocol family %u", saidx->dst.sa.sa_family);
843
844 /* Check for crypto errors. */
845 if (crp->crp_etype) {
846 if (sav->tdb_cryptoid != 0)
847 sav->tdb_cryptoid = crp->crp_sid;
848
849 if (crp->crp_etype == EAGAIN) {
850 IPSEC_RELEASE_GLOBAL_LOCKS();
851 return crypto_dispatch(crp);
852 }
853
854 AH_STATINC(AH_STAT_NOXFORM);
855 DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
856 error = crp->crp_etype;
857 goto bad;
858 } else {
859 AH_STATINC(AH_STAT_HIST + ah_stats[sav->alg_auth]);
860 crypto_freereq(crp); /* No longer needed. */
861 crp = NULL;
862 }
863
864 /* Figure out header size. */
865 rplen = HDRSIZE(sav);
866 authsize = AUTHSIZE(sav);
867
868 if (ipsec_debug)
869 memset(calc, 0, sizeof(calc));
870
871 /* Copy authenticator off the packet. */
872 m_copydata(m, skip + rplen, authsize, calc);
873
874 ptr = (char *)(tc + 1);
875 const uint8_t *pppp = ptr + skip + rplen;
876
877 /* Verify authenticator. */
878 if (!consttime_memequal(pppp, calc, authsize)) {
879 DPRINTF(("%s: authentication hash mismatch " \
880 "over %d bytes " \
881 "for packet in SA %s/%08lx:\n" \
882 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x, " \
883 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
884 __func__, authsize,
885 ipsec_address(&saidx->dst, buf, sizeof(buf)),
886 (u_long) ntohl(sav->spi),
887 calc[0], calc[1], calc[2], calc[3],
888 calc[4], calc[5], calc[6], calc[7],
889 calc[8], calc[9], calc[10], calc[11],
890 pppp[0], pppp[1], pppp[2], pppp[3],
891 pppp[4], pppp[5], pppp[6], pppp[7],
892 pppp[8], pppp[9], pppp[10], pppp[11]
893 ));
894 AH_STATINC(AH_STAT_BADAUTH);
895 error = EACCES;
896 goto bad;
897 }
898
899 /* Fix the Next Protocol field. */
900 ptr[protoff] = nxt;
901
902 /* Copyback the saved (uncooked) network headers. */
903 m_copyback(m, 0, skip, ptr);
904
905 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
906 tc = NULL;
907
908 /*
909 * Header is now authenticated.
910 */
911 m->m_flags |= M_AUTHIPHDR|M_AUTHIPDGM;
912
913 /*
914 * Update replay sequence number, if appropriate.
915 */
916 if (sav->replay) {
917 uint32_t seq;
918
919 m_copydata(m, skip + offsetof(struct newah, ah_seq),
920 sizeof(seq), &seq);
921 if (ipsec_updatereplay(ntohl(seq), sav)) {
922 AH_STATINC(AH_STAT_REPLAY);
923 error = ENOBUFS; /*XXX as above*/
924 goto bad;
925 }
926 }
927
928 /*
929 * Remove the AH header and authenticator from the mbuf.
930 */
931 error = m_striphdr(m, skip, rplen + authsize);
932 if (error) {
933 DPRINTF(("%s: mangled mbuf chain for SA %s/%08lx\n", __func__,
934 ipsec_address(&saidx->dst, buf, sizeof(buf)),
935 (u_long) ntohl(sav->spi)));
936
937 AH_STATINC(AH_STAT_HDROPS);
938 goto bad;
939 }
940
941 IPSEC_COMMON_INPUT_CB(m, sav, skip, protoff);
942
943 KEY_SA_UNREF(&sav);
944 IPSEC_RELEASE_GLOBAL_LOCKS();
945 return error;
946 bad:
947 if (sav)
948 KEY_SA_UNREF(&sav);
949 IPSEC_RELEASE_GLOBAL_LOCKS();
950 if (m != NULL)
951 m_freem(m);
952 if (tc != NULL)
953 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
954 if (crp != NULL)
955 crypto_freereq(crp);
956 return error;
957 }
958
959 /*
960 * AH output routine, called by ipsec[46]_process_packet().
961 */
962 static int
963 ah_output(
964 struct mbuf *m,
965 const struct ipsecrequest *isr,
966 struct secasvar *sav,
967 struct mbuf **mp,
968 int skip,
969 int protoff
970 )
971 {
972 char buf[IPSEC_ADDRSTRLEN];
973 const struct auth_hash *ahx;
974 struct cryptodesc *crda;
975 struct tdb_crypto *tc;
976 struct mbuf *mi;
977 struct cryptop *crp;
978 uint16_t iplen;
979 int error, rplen, authsize, maxpacketsize, roff;
980 uint8_t prot;
981 struct newah *ah;
982
983 IPSEC_SPLASSERT_SOFTNET(__func__);
984
985 KASSERT(sav != NULL);
986 KASSERT(sav->tdb_authalgxform != NULL);
987 ahx = sav->tdb_authalgxform;
988
989 AH_STATINC(AH_STAT_OUTPUT);
990
991 /* Figure out header size. */
992 rplen = HDRSIZE(sav);
993
994 size_t ipoffs;
995 /* Check for maximum packet size violations. */
996 switch (sav->sah->saidx.dst.sa.sa_family) {
997 #ifdef INET
998 case AF_INET:
999 maxpacketsize = IP_MAXPACKET;
1000 ipoffs = offsetof(struct ip, ip_len);
1001 break;
1002 #endif /* INET */
1003 #ifdef INET6
1004 case AF_INET6:
1005 maxpacketsize = IPV6_MAXPACKET;
1006 ipoffs = offsetof(struct ip6_hdr, ip6_plen);
1007 break;
1008 #endif /* INET6 */
1009 default:
1010 DPRINTF(("%s: unknown/unsupported protocol "
1011 "family %u, SA %s/%08lx\n", __func__,
1012 sav->sah->saidx.dst.sa.sa_family,
1013 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
1014 (u_long) ntohl(sav->spi)));
1015 AH_STATINC(AH_STAT_NOPF);
1016 error = EPFNOSUPPORT;
1017 goto bad;
1018 }
1019 authsize = AUTHSIZE(sav);
1020 if (rplen + authsize + m->m_pkthdr.len > maxpacketsize) {
1021 DPRINTF(("%s: packet in SA %s/%08lx got too big "
1022 "(len %u, max len %u)\n", __func__,
1023 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
1024 (u_long) ntohl(sav->spi),
1025 rplen + authsize + m->m_pkthdr.len, maxpacketsize));
1026 AH_STATINC(AH_STAT_TOOBIG);
1027 error = EMSGSIZE;
1028 goto bad;
1029 }
1030
1031 /* Update the counters. */
1032 AH_STATADD(AH_STAT_OBYTES, m->m_pkthdr.len - skip);
1033
1034 m = m_clone(m);
1035 if (m == NULL) {
1036 DPRINTF(("%s: cannot clone mbuf chain, SA %s/%08lx\n", __func__,
1037 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
1038 (u_long) ntohl(sav->spi)));
1039 AH_STATINC(AH_STAT_HDROPS);
1040 error = ENOBUFS;
1041 goto bad;
1042 }
1043
1044 /* Inject AH header. */
1045 mi = m_makespace(m, skip, rplen + authsize, &roff);
1046 if (mi == NULL) {
1047 DPRINTF(("%s: failed to inject %u byte AH header for SA "
1048 "%s/%08lx\n", __func__,
1049 rplen + authsize,
1050 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
1051 (u_long) ntohl(sav->spi)));
1052 AH_STATINC(AH_STAT_HDROPS); /*XXX differs from openbsd */
1053 error = ENOBUFS;
1054 goto bad;
1055 }
1056
1057 /*
1058 * The AH header is guaranteed by m_makespace() to be in
1059 * contiguous memory, at roff bytes offset into the returned mbuf.
1060 */
1061 ah = (struct newah *)(mtod(mi, char *) + roff);
1062
1063 /* Initialize the AH header. */
1064 m_copydata(m, protoff, sizeof(uint8_t), &ah->ah_nxt);
1065 ah->ah_len = (rplen + authsize - sizeof(struct ah)) / sizeof(uint32_t);
1066 ah->ah_reserve = 0;
1067 ah->ah_spi = sav->spi;
1068
1069 /* Zeroize authenticator. */
1070 m_copyback(m, skip + rplen, authsize, ipseczeroes);
1071
1072 /* Insert packet replay counter, as requested. */
1073 if (sav->replay) {
1074 if (sav->replay->count == ~0 &&
1075 (sav->flags & SADB_X_EXT_CYCSEQ) == 0) {
1076 DPRINTF(("%s: replay counter wrapped for SA %s/%08lx\n",
1077 __func__, ipsec_address(&sav->sah->saidx.dst, buf,
1078 sizeof(buf)), (u_long) ntohl(sav->spi)));
1079 AH_STATINC(AH_STAT_WRAP);
1080 error = EINVAL;
1081 goto bad;
1082 }
1083 #ifdef IPSEC_DEBUG
1084 /* Emulate replay attack when ipsec_replay is TRUE. */
1085 if (!ipsec_replay)
1086 #endif
1087 sav->replay->count++;
1088 ah->ah_seq = htonl(sav->replay->count);
1089 }
1090
1091 /* Get crypto descriptors. */
1092 crp = crypto_getreq(1);
1093 if (crp == NULL) {
1094 DPRINTF(("%s: failed to acquire crypto descriptors\n",
1095 __func__));
1096 AH_STATINC(AH_STAT_CRYPTO);
1097 error = ENOBUFS;
1098 goto bad;
1099 }
1100
1101 crda = crp->crp_desc;
1102
1103 crda->crd_skip = 0;
1104 crda->crd_inject = skip + rplen;
1105 crda->crd_len = m->m_pkthdr.len;
1106
1107 /* Authentication operation. */
1108 crda->crd_alg = ahx->type;
1109 crda->crd_key = _KEYBUF(sav->key_auth);
1110 crda->crd_klen = _KEYBITS(sav->key_auth);
1111
1112 /* Allocate IPsec-specific opaque crypto info. */
1113 tc = pool_cache_get(ah_tdb_crypto_pool_cache, PR_NOWAIT);
1114 if (tc == NULL) {
1115 crypto_freereq(crp);
1116 DPRINTF(("%s: failed to allocate tdb_crypto\n", __func__));
1117 AH_STATINC(AH_STAT_CRYPTO);
1118 error = ENOBUFS;
1119 goto bad;
1120 }
1121
1122 uint8_t *pext = (char *)(tc + 1);
1123 /* Save the skipped portion of the packet. */
1124 m_copydata(m, 0, skip, pext);
1125
1126 /*
1127 * Fix IP header length on the header used for
1128 * authentication. We don't need to fix the original
1129 * header length as it will be fixed by our caller.
1130 */
1131 memcpy(&iplen, pext + ipoffs, sizeof(iplen));
1132 iplen = htons(ntohs(iplen) + rplen + authsize);
1133 m_copyback(m, ipoffs, sizeof(iplen), &iplen);
1134
1135 /* Fix the Next Header field in saved header. */
1136 pext[protoff] = IPPROTO_AH;
1137
1138 /* Update the Next Protocol field in the IP header. */
1139 prot = IPPROTO_AH;
1140 m_copyback(m, protoff, sizeof(prot), &prot);
1141
1142 /* "Massage" the packet headers for crypto processing. */
1143 error = ah_massage_headers(&m, sav->sah->saidx.dst.sa.sa_family,
1144 skip, ahx->type, 1);
1145 if (error != 0) {
1146 m = NULL; /* mbuf was free'd by ah_massage_headers. */
1147 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
1148 crypto_freereq(crp);
1149 goto bad;
1150 }
1151
1152 {
1153 int s = pserialize_read_enter();
1154
1155 /*
1156 * Take another reference to the SP and the SA for opencrypto callback.
1157 */
1158 if (__predict_false(isr->sp->state == IPSEC_SPSTATE_DEAD ||
1159 sav->state == SADB_SASTATE_DEAD)) {
1160 pserialize_read_exit(s);
1161 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
1162 crypto_freereq(crp);
1163 AH_STATINC(AH_STAT_NOTDB);
1164 error = ENOENT;
1165 goto bad;
1166 }
1167 KEY_SP_REF(isr->sp);
1168 KEY_SA_REF(sav);
1169 pserialize_read_exit(s);
1170 }
1171
1172 /* Crypto operation descriptor. */
1173 crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */
1174 crp->crp_flags = CRYPTO_F_IMBUF;
1175 crp->crp_buf = m;
1176 crp->crp_callback = ah_output_cb;
1177 crp->crp_sid = sav->tdb_cryptoid;
1178 crp->crp_opaque = tc;
1179
1180 /* These are passed as-is to the callback. */
1181 tc->tc_isr = isr;
1182 tc->tc_spi = sav->spi;
1183 tc->tc_dst = sav->sah->saidx.dst;
1184 tc->tc_proto = sav->sah->saidx.proto;
1185 tc->tc_skip = skip;
1186 tc->tc_protoff = protoff;
1187 tc->tc_sav = sav;
1188
1189 return crypto_dispatch(crp);
1190 bad:
1191 if (m)
1192 m_freem(m);
1193 return (error);
1194 }
1195
1196 /*
1197 * AH output callback from the crypto driver.
1198 */
1199 static int
1200 ah_output_cb(struct cryptop *crp)
1201 {
1202 int skip, error;
1203 struct tdb_crypto *tc;
1204 const struct ipsecrequest *isr;
1205 struct secasvar *sav;
1206 struct mbuf *m;
1207 void *ptr;
1208 int err;
1209 IPSEC_DECLARE_LOCK_VARIABLE;
1210
1211 KASSERT(crp->crp_opaque != NULL);
1212 tc = crp->crp_opaque;
1213 skip = tc->tc_skip;
1214 ptr = (tc + 1);
1215 m = crp->crp_buf;
1216
1217 IPSEC_ACQUIRE_GLOBAL_LOCKS();
1218
1219 isr = tc->tc_isr;
1220 sav = tc->tc_sav;
1221 if (__predict_false(isr->sp->state == IPSEC_SPSTATE_DEAD)) {
1222 AH_STATINC(AH_STAT_NOTDB);
1223 IPSECLOG(LOG_DEBUG,
1224 "SP is being destroyed while in crypto (id=%u)\n",
1225 isr->sp->id);
1226 error = ENOENT;
1227 goto bad;
1228 }
1229 if (__predict_false(!SADB_SASTATE_USABLE_P(sav))) {
1230 KEY_SA_UNREF(&sav);
1231 sav = KEY_LOOKUP_SA(&tc->tc_dst, tc->tc_proto, tc->tc_spi, 0, 0);
1232 if (sav == NULL) {
1233 AH_STATINC(AH_STAT_NOTDB);
1234 DPRINTF(("%s: SA expired while in crypto\n", __func__));
1235 error = ENOBUFS; /*XXX*/
1236 goto bad;
1237 }
1238 }
1239
1240 /* Check for crypto errors. */
1241 if (crp->crp_etype) {
1242 if (sav->tdb_cryptoid != 0)
1243 sav->tdb_cryptoid = crp->crp_sid;
1244
1245 if (crp->crp_etype == EAGAIN) {
1246 IPSEC_RELEASE_GLOBAL_LOCKS();
1247 return crypto_dispatch(crp);
1248 }
1249
1250 AH_STATINC(AH_STAT_NOXFORM);
1251 DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
1252 error = crp->crp_etype;
1253 goto bad;
1254 }
1255
1256 AH_STATINC(AH_STAT_HIST + ah_stats[sav->alg_auth]);
1257
1258 /*
1259 * Copy original headers (with the new protocol number) back
1260 * in place.
1261 */
1262 m_copyback(m, 0, skip, ptr);
1263
1264 /* No longer needed. */
1265 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
1266 crypto_freereq(crp);
1267
1268 #ifdef IPSEC_DEBUG
1269 /* Emulate man-in-the-middle attack when ipsec_integrity is TRUE. */
1270 if (ipsec_integrity) {
1271 int alen;
1272
1273 /*
1274 * Corrupt HMAC if we want to test integrity verification of
1275 * the other side.
1276 */
1277 alen = AUTHSIZE(sav);
1278 m_copyback(m, m->m_pkthdr.len - alen, alen, ipseczeroes);
1279 }
1280 #endif
1281
1282 /* NB: m is reclaimed by ipsec_process_done. */
1283 err = ipsec_process_done(m, isr, sav);
1284 KEY_SA_UNREF(&sav);
1285 KEY_SP_UNREF(&isr->sp);
1286 IPSEC_RELEASE_GLOBAL_LOCKS();
1287 return err;
1288 bad:
1289 if (sav)
1290 KEY_SA_UNREF(&sav);
1291 KEY_SP_UNREF(&isr->sp);
1292 IPSEC_RELEASE_GLOBAL_LOCKS();
1293 if (m)
1294 m_freem(m);
1295 pool_cache_put(ah_tdb_crypto_pool_cache, tc);
1296 crypto_freereq(crp);
1297 return error;
1298 }
1299
1300 static struct xformsw ah_xformsw = {
1301 .xf_type = XF_AH,
1302 .xf_flags = XFT_AUTH,
1303 .xf_name = "IPsec AH",
1304 .xf_init = ah_init,
1305 .xf_zeroize = ah_zeroize,
1306 .xf_input = ah_input,
1307 .xf_output = ah_output,
1308 .xf_next = NULL,
1309 };
1310
1311 void
1312 ah_attach(void)
1313 {
1314 ahstat_percpu = percpu_alloc(sizeof(uint64_t) * AH_NSTATS);
1315
1316 #define MAXAUTHSIZE(name) \
1317 if ((auth_hash_ ## name).authsize > ah_max_authsize) \
1318 ah_max_authsize = (auth_hash_ ## name).authsize
1319
1320 ah_max_authsize = 0;
1321 MAXAUTHSIZE(null);
1322 MAXAUTHSIZE(md5);
1323 MAXAUTHSIZE(sha1);
1324 MAXAUTHSIZE(key_md5);
1325 MAXAUTHSIZE(key_sha1);
1326 MAXAUTHSIZE(hmac_md5);
1327 MAXAUTHSIZE(hmac_sha1);
1328 MAXAUTHSIZE(hmac_ripemd_160);
1329 MAXAUTHSIZE(hmac_md5_96);
1330 MAXAUTHSIZE(hmac_sha1_96);
1331 MAXAUTHSIZE(hmac_ripemd_160_96);
1332 MAXAUTHSIZE(hmac_sha2_256);
1333 MAXAUTHSIZE(hmac_sha2_384);
1334 MAXAUTHSIZE(hmac_sha2_512);
1335 MAXAUTHSIZE(aes_xcbc_mac_96);
1336 MAXAUTHSIZE(gmac_aes_128);
1337 MAXAUTHSIZE(gmac_aes_192);
1338 MAXAUTHSIZE(gmac_aes_256);
1339 IPSECLOG(LOG_DEBUG, "ah_max_authsize=%d\n", ah_max_authsize);
1340
1341 #undef MAXAUTHSIZE
1342
1343 ah_pool_item_size = sizeof(struct tdb_crypto) +
1344 sizeof(struct ip) + MAX_IPOPTLEN +
1345 sizeof(struct ah) + sizeof(uint32_t) + ah_max_authsize;
1346 ah_tdb_crypto_pool_cache = pool_cache_init(ah_pool_item_size,
1347 coherency_unit, 0, 0, "ah_tdb_crypto", NULL, IPL_SOFTNET,
1348 NULL, NULL, NULL);
1349
1350 xform_register(&ah_xformsw);
1351 }
1352