]> The Tcpdump Group git mirrors - tcpdump/blob - print-esp.c
struct newesp is required regardless of whether we have libcrypto or not.
[tcpdump] / print-esp.c
1 /* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */
2
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <string.h>
29
30 #include <tcpdump-stdinc.h>
31
32 #include <stdlib.h>
33
34 /* Any code in this file that depends on HAVE_LIBCRYPTO depends on
35 * HAVE_OPENSSL_EVP_H too. Undefining the former when the latter isn't defined
36 * is the simplest way of handling the dependency.
37 */
38 #ifdef HAVE_LIBCRYPTO
39 #ifdef HAVE_OPENSSL_EVP_H
40 #include <openssl/evp.h>
41 #else
42 #undef HAVE_LIBCRYPTO
43 #endif
44 #endif
45
46 #include <stdio.h>
47
48 #include "ip.h"
49 #ifdef INET6
50 #include "ip6.h"
51 #endif
52
53 #include "netdissect.h"
54 #include "addrtoname.h"
55 #include "extract.h"
56
57 #ifndef HAVE_SOCKADDR_STORAGE
58 #ifdef INET6
59 struct sockaddr_storage {
60 union {
61 struct sockaddr_in sin;
62 struct sockaddr_in6 sin6;
63 } un;
64 };
65 #else
66 #define sockaddr_storage sockaddr
67 #endif
68 #endif /* HAVE_SOCKADDR_STORAGE */
69
70 /*
71 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
72 * All rights reserved.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. Neither the name of the project nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
85 *
86 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
87 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
92 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * SUCH DAMAGE.
97 */
98
99 /*
100 * RFC1827/2406 Encapsulated Security Payload.
101 */
102
103 struct newesp {
104 u_int32_t esp_spi; /* ESP */
105 u_int32_t esp_seq; /* Sequence number */
106 /*variable size*/ /* (IV and) Payload data */
107 /*variable size*/ /* padding */
108 /*8bit*/ /* pad size */
109 /*8bit*/ /* next header */
110 /*8bit*/ /* next header */
111 /*variable size, 32bit bound*/ /* Authentication data */
112 };
113
114 #ifdef HAVE_LIBCRYPTO
115 struct sa_list {
116 struct sa_list *next;
117 struct sockaddr_storage daddr;
118 u_int32_t spi; /* if == 0, then IKEv2 */
119 int initiator;
120 u_char spii[8]; /* for IKEv2 */
121 u_char spir[8];
122 const EVP_CIPHER *evp;
123 int ivlen;
124 int authlen;
125 u_char authsecret[256];
126 int authsecret_len;
127 u_char secret[256]; /* is that big enough for all secrets? */
128 int secretlen;
129 };
130
131 /*
132 * this will adjust ndo_packetp and ndo_snapend to new buffer!
133 */
134 USES_APPLE_DEPRECATED_API
135 int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
136 int initiator,
137 u_char spii[8], u_char spir[8],
138 u_char *buf, u_char *end)
139 {
140 struct sa_list *sa;
141 u_char *iv;
142 int len;
143 EVP_CIPHER_CTX ctx;
144
145 /* initiator arg is any non-zero value */
146 if(initiator) initiator=1;
147
148 /* see if we can find the SA, and if so, decode it */
149 for (sa = ndo->ndo_sa_list_head; sa != NULL; sa = sa->next) {
150 if (sa->spi == 0
151 && initiator == sa->initiator
152 && memcmp(spii, sa->spii, 8) == 0
153 && memcmp(spir, sa->spir, 8) == 0)
154 break;
155 }
156
157 if(sa == NULL) return 0;
158 if(sa->evp == NULL) return 0;
159
160 /*
161 * remove authenticator, and see if we still have something to
162 * work with
163 */
164 end = end - sa->authlen;
165 iv = buf;
166 buf = buf + sa->ivlen;
167 len = end-buf;
168
169 if(end <= buf) return 0;
170
171 memset(&ctx, 0, sizeof(ctx));
172 if (EVP_CipherInit(&ctx, sa->evp, sa->secret, NULL, 0) < 0)
173 (*ndo->ndo_warning)(ndo, "espkey init failed");
174 EVP_CipherInit(&ctx, NULL, NULL, iv, 0);
175 EVP_Cipher(&ctx, buf, buf, len);
176 EVP_CIPHER_CTX_cleanup(&ctx);
177
178 ndo->ndo_packetp = buf;
179 ndo->ndo_snapend = end;
180
181 return 1;
182
183 }
184 USES_APPLE_RST
185
186 static void esp_print_addsa(netdissect_options *ndo,
187 struct sa_list *sa, int sa_def)
188 {
189 /* copy the "sa" */
190
191 struct sa_list *nsa;
192
193 nsa = (struct sa_list *)malloc(sizeof(struct sa_list));
194 if (nsa == NULL)
195 (*ndo->ndo_error)(ndo, "ran out of memory to allocate sa structure");
196
197 *nsa = *sa;
198
199 if (sa_def)
200 ndo->ndo_sa_default = nsa;
201
202 nsa->next = ndo->ndo_sa_list_head;
203 ndo->ndo_sa_list_head = nsa;
204 }
205
206
207 static u_int hexdigit(netdissect_options *ndo, char hex)
208 {
209 if (hex >= '0' && hex <= '9')
210 return (hex - '0');
211 else if (hex >= 'A' && hex <= 'F')
212 return (hex - 'A' + 10);
213 else if (hex >= 'a' && hex <= 'f')
214 return (hex - 'a' + 10);
215 else {
216 (*ndo->ndo_error)(ndo, "invalid hex digit %c in espsecret\n", hex);
217 return 0;
218 }
219 }
220
221 static u_int hex2byte(netdissect_options *ndo, char *hexstring)
222 {
223 u_int byte;
224
225 byte = (hexdigit(ndo, hexstring[0]) << 4) + hexdigit(ndo, hexstring[1]);
226 return byte;
227 }
228
229 /*
230 * returns size of binary, 0 on failure.
231 */
232 static
233 int espprint_decode_hex(netdissect_options *ndo,
234 u_char *binbuf, unsigned int binbuf_len,
235 char *hex)
236 {
237 unsigned int len;
238 int i;
239
240 len = strlen(hex) / 2;
241
242 if (len > binbuf_len) {
243 (*ndo->ndo_warning)(ndo, "secret is too big: %d\n", len);
244 return 0;
245 }
246
247 i = 0;
248 while (hex[0] != '\0' && hex[1]!='\0') {
249 binbuf[i] = hex2byte(ndo, hex);
250 hex += 2;
251 i++;
252 }
253
254 return i;
255 }
256
257 /*
258 * decode the form: SPINUM@IP <tab> ALGONAME:0xsecret
259 */
260
261 USES_APPLE_DEPRECATED_API
262 static int
263 espprint_decode_encalgo(netdissect_options *ndo,
264 char *decode, struct sa_list *sa)
265 {
266 size_t i;
267 const EVP_CIPHER *evp;
268 int authlen = 0;
269 char *colon, *p;
270
271 colon = strchr(decode, ':');
272 if (colon == NULL) {
273 (*ndo->ndo_warning)(ndo, "failed to decode espsecret: %s\n", decode);
274 return 0;
275 }
276 *colon = '\0';
277
278 if (strlen(decode) > strlen("-hmac96") &&
279 !strcmp(decode + strlen(decode) - strlen("-hmac96"),
280 "-hmac96")) {
281 p = strstr(decode, "-hmac96");
282 *p = '\0';
283 authlen = 12;
284 }
285 if (strlen(decode) > strlen("-cbc") &&
286 !strcmp(decode + strlen(decode) - strlen("-cbc"), "-cbc")) {
287 p = strstr(decode, "-cbc");
288 *p = '\0';
289 }
290 evp = EVP_get_cipherbyname(decode);
291
292 if (!evp) {
293 (*ndo->ndo_warning)(ndo, "failed to find cipher algo %s\n", decode);
294 sa->evp = NULL;
295 sa->authlen = 0;
296 sa->ivlen = 0;
297 return 0;
298 }
299
300 sa->evp = evp;
301 sa->authlen = authlen;
302 sa->ivlen = EVP_CIPHER_iv_length(evp);
303
304 colon++;
305 if (colon[0] == '0' && colon[1] == 'x') {
306 /* decode some hex! */
307
308 colon += 2;
309 sa->secretlen = espprint_decode_hex(ndo, sa->secret, sizeof(sa->secret), colon);
310 if(sa->secretlen == 0) return 0;
311 } else {
312 i = strlen(colon);
313
314 if (i < sizeof(sa->secret)) {
315 memcpy(sa->secret, colon, i);
316 sa->secretlen = i;
317 } else {
318 memcpy(sa->secret, colon, sizeof(sa->secret));
319 sa->secretlen = sizeof(sa->secret);
320 }
321 }
322
323 return 1;
324 }
325 USES_APPLE_RST
326
327 /*
328 * for the moment, ignore the auth algorith, just hard code the authenticator
329 * length. Need to research how openssl looks up HMAC stuff.
330 */
331 static int
332 espprint_decode_authalgo(netdissect_options *ndo,
333 char *decode, struct sa_list *sa)
334 {
335 char *colon;
336
337 colon = strchr(decode, ':');
338 if (colon == NULL) {
339 (*ndo->ndo_warning)(ndo, "failed to decode espsecret: %s\n", decode);
340 return 0;
341 }
342 *colon = '\0';
343
344 if(strcasecmp(colon,"sha1") == 0 ||
345 strcasecmp(colon,"md5") == 0) {
346 sa->authlen = 12;
347 }
348 return 1;
349 }
350
351 static void esp_print_decode_ikeline(netdissect_options *ndo, char *line,
352 const char *file, int lineno)
353 {
354 /* it's an IKEv2 secret, store it instead */
355 struct sa_list sa1;
356
357 char *init;
358 char *icookie, *rcookie;
359 int ilen, rlen;
360 char *authkey;
361 char *enckey;
362
363 init = strsep(&line, " \t");
364 icookie = strsep(&line, " \t");
365 rcookie = strsep(&line, " \t");
366 authkey = strsep(&line, " \t");
367 enckey = strsep(&line, " \t");
368
369 /* if any fields are missing */
370 if(!init || !icookie || !rcookie || !authkey || !enckey) {
371 (*ndo->ndo_warning)(ndo, "print_esp: failed to find all fields for ikev2 at %s:%u",
372 file, lineno);
373
374 return;
375 }
376
377 ilen = strlen(icookie);
378 rlen = strlen(rcookie);
379
380 if((init[0]!='I' && init[0]!='R')
381 || icookie[0]!='0' || icookie[1]!='x'
382 || rcookie[0]!='0' || rcookie[1]!='x'
383 || ilen!=18
384 || rlen!=18) {
385 (*ndo->ndo_warning)(ndo, "print_esp: line %s:%u improperly formatted.",
386 file, lineno);
387
388 (*ndo->ndo_warning)(ndo, "init=%s icookie=%s(%u) rcookie=%s(%u)",
389 init, icookie, ilen, rcookie, rlen);
390
391 return;
392 }
393
394 sa1.spi = 0;
395 sa1.initiator = (init[0] == 'I');
396 if(espprint_decode_hex(ndo, sa1.spii, sizeof(sa1.spii), icookie+2)!=8)
397 return;
398
399 if(espprint_decode_hex(ndo, sa1.spir, sizeof(sa1.spir), rcookie+2)!=8)
400 return;
401
402 if(!espprint_decode_encalgo(ndo, enckey, &sa1)) return;
403
404 if(!espprint_decode_authalgo(ndo, authkey, &sa1)) return;
405
406 esp_print_addsa(ndo, &sa1, FALSE);
407 }
408
409 /*
410 *
411 * special form: file /name
412 * causes us to go read from this file instead.
413 *
414 */
415 static void esp_print_decode_onesecret(netdissect_options *ndo, char *line,
416 const char *file, int lineno)
417 {
418 struct sa_list sa1;
419 int sa_def;
420
421 char *spikey;
422 char *decode;
423
424 spikey = strsep(&line, " \t");
425 sa_def = 0;
426 memset(&sa1, 0, sizeof(struct sa_list));
427
428 /* if there is only one token, then it is an algo:key token */
429 if (line == NULL) {
430 decode = spikey;
431 spikey = NULL;
432 /* memset(&sa1.daddr, 0, sizeof(sa1.daddr)); */
433 /* sa1.spi = 0; */
434 sa_def = 1;
435 } else
436 decode = line;
437
438 if (spikey && strcasecmp(spikey, "file") == 0) {
439 /* open file and read it */
440 FILE *secretfile;
441 char fileline[1024];
442 int lineno=0;
443 char *nl;
444 char *filename = line;
445
446 secretfile = fopen(filename, FOPEN_READ_TXT);
447 if (secretfile == NULL) {
448 perror(filename);
449 exit(3);
450 }
451
452 while (fgets(fileline, sizeof(fileline)-1, secretfile) != NULL) {
453 lineno++;
454 /* remove newline from the line */
455 nl = strchr(fileline, '\n');
456 if (nl)
457 *nl = '\0';
458 if (fileline[0] == '#') continue;
459 if (fileline[0] == '\0') continue;
460
461 esp_print_decode_onesecret(ndo, fileline, filename, lineno);
462 }
463 fclose(secretfile);
464
465 return;
466 }
467
468 if (spikey && strcasecmp(spikey, "ikev2") == 0) {
469 esp_print_decode_ikeline(ndo, line, file, lineno);
470 return;
471 }
472
473 if (spikey) {
474
475 char *spistr, *foo;
476 u_int32_t spino;
477 struct sockaddr_in *sin;
478 #ifdef INET6
479 struct sockaddr_in6 *sin6;
480 #endif
481
482 spistr = strsep(&spikey, "@");
483
484 spino = strtoul(spistr, &foo, 0);
485 if (spistr == foo || !spikey) {
486 (*ndo->ndo_warning)(ndo, "print_esp: failed to decode spi# %s\n", foo);
487 return;
488 }
489
490 sa1.spi = spino;
491
492 sin = (struct sockaddr_in *)&sa1.daddr;
493 #ifdef INET6
494 sin6 = (struct sockaddr_in6 *)&sa1.daddr;
495 if (inet_pton(AF_INET6, spikey, &sin6->sin6_addr) == 1) {
496 #ifdef HAVE_SOCKADDR_SA_LEN
497 sin6->sin6_len = sizeof(struct sockaddr_in6);
498 #endif
499 sin6->sin6_family = AF_INET6;
500 } else
501 #endif
502 if (inet_pton(AF_INET, spikey, &sin->sin_addr) == 1) {
503 #ifdef HAVE_SOCKADDR_SA_LEN
504 sin->sin_len = sizeof(struct sockaddr_in);
505 #endif
506 sin->sin_family = AF_INET;
507 } else {
508 (*ndo->ndo_warning)(ndo, "print_esp: can not decode IP# %s\n", spikey);
509 return;
510 }
511 }
512
513 if (decode) {
514 /* skip any blank spaces */
515 while (isspace((unsigned char)*decode))
516 decode++;
517
518 if(!espprint_decode_encalgo(ndo, decode, &sa1)) {
519 return;
520 }
521 }
522
523 esp_print_addsa(ndo, &sa1, sa_def);
524 }
525
526 USES_APPLE_DEPRECATED_API
527 static void esp_init(netdissect_options *ndo _U_)
528 {
529
530 OpenSSL_add_all_algorithms();
531 EVP_add_cipher_alias(SN_des_ede3_cbc, "3des");
532 }
533 USES_APPLE_RST
534
535 void esp_print_decodesecret(netdissect_options *ndo)
536 {
537 char *line;
538 char *p;
539 static int initialized = 0;
540
541 if (!initialized) {
542 esp_init(ndo);
543 initialized = 1;
544 }
545
546 p = ndo->ndo_espsecret;
547
548 while (p && p[0] != '\0') {
549 /* pick out the first line or first thing until a comma */
550 if ((line = strsep(&p, "\n,")) == NULL) {
551 line = p;
552 p = NULL;
553 }
554
555 esp_print_decode_onesecret(ndo, line, "cmdline", 0);
556 }
557
558 ndo->ndo_espsecret = NULL;
559 }
560
561 #endif
562
563 #ifdef HAVE_LIBCRYPTO
564 USES_APPLE_DEPRECATED_API
565 #endif
566 int
567 esp_print(netdissect_options *ndo,
568 const u_char *bp, const int length, const u_char *bp2
569 #ifndef HAVE_LIBCRYPTO
570 _U_
571 #endif
572 ,
573 int *nhdr
574 #ifndef HAVE_LIBCRYPTO
575 _U_
576 #endif
577 ,
578 int *padlen
579 #ifndef HAVE_LIBCRYPTO
580 _U_
581 #endif
582 )
583 {
584 register const struct newesp *esp;
585 register const u_char *ep;
586 #ifdef HAVE_LIBCRYPTO
587 struct ip *ip;
588 struct sa_list *sa = NULL;
589 #ifdef INET6
590 struct ip6_hdr *ip6 = NULL;
591 #endif
592 int advance;
593 int len;
594 u_char *secret;
595 int ivlen = 0;
596 u_char *ivoff;
597 u_char *p;
598 EVP_CIPHER_CTX ctx;
599 #endif
600
601 esp = (struct newesp *)bp;
602
603 #ifdef HAVE_LIBCRYPTO
604 secret = NULL;
605 advance = 0;
606 #endif
607
608 #if 0
609 /* keep secret out of a register */
610 p = (u_char *)&secret;
611 #endif
612
613 /* 'ep' points to the end of available data. */
614 ep = ndo->ndo_snapend;
615
616 if ((u_char *)(esp + 1) >= ep) {
617 fputs("[|ESP]", stdout);
618 goto fail;
619 }
620 (*ndo->ndo_printf)(ndo, "ESP(spi=0x%08x", EXTRACT_32BITS(&esp->esp_spi));
621 (*ndo->ndo_printf)(ndo, ",seq=0x%x)", EXTRACT_32BITS(&esp->esp_seq));
622 (*ndo->ndo_printf)(ndo, ", length %u", length);
623
624 #ifndef HAVE_LIBCRYPTO
625 goto fail;
626 #else
627 /* initiailize SAs */
628 if (ndo->ndo_sa_list_head == NULL) {
629 if (!ndo->ndo_espsecret)
630 goto fail;
631
632 esp_print_decodesecret(ndo);
633 }
634
635 if (ndo->ndo_sa_list_head == NULL)
636 goto fail;
637
638 ip = (struct ip *)bp2;
639 switch (IP_V(ip)) {
640 #ifdef INET6
641 case 6:
642 ip6 = (struct ip6_hdr *)bp2;
643 /* we do not attempt to decrypt jumbograms */
644 if (!EXTRACT_16BITS(&ip6->ip6_plen))
645 goto fail;
646 /* if we can't get nexthdr, we do not need to decrypt it */
647 len = sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen);
648
649 /* see if we can find the SA, and if so, decode it */
650 for (sa = ndo->ndo_sa_list_head; sa != NULL; sa = sa->next) {
651 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa->daddr;
652 if (sa->spi == EXTRACT_32BITS(&esp->esp_spi) &&
653 sin6->sin6_family == AF_INET6 &&
654 memcmp(&sin6->sin6_addr, &ip6->ip6_dst,
655 sizeof(struct in6_addr)) == 0) {
656 break;
657 }
658 }
659 break;
660 #endif /*INET6*/
661 case 4:
662 /* nexthdr & padding are in the last fragment */
663 if (EXTRACT_16BITS(&ip->ip_off) & IP_MF)
664 goto fail;
665 len = EXTRACT_16BITS(&ip->ip_len);
666
667 /* see if we can find the SA, and if so, decode it */
668 for (sa = ndo->ndo_sa_list_head; sa != NULL; sa = sa->next) {
669 struct sockaddr_in *sin = (struct sockaddr_in *)&sa->daddr;
670 if (sa->spi == EXTRACT_32BITS(&esp->esp_spi) &&
671 sin->sin_family == AF_INET &&
672 sin->sin_addr.s_addr == ip->ip_dst.s_addr) {
673 break;
674 }
675 }
676 break;
677 default:
678 goto fail;
679 }
680
681 /* if we didn't find the specific one, then look for
682 * an unspecified one.
683 */
684 if (sa == NULL)
685 sa = ndo->ndo_sa_default;
686
687 /* if not found fail */
688 if (sa == NULL)
689 goto fail;
690
691 /* if we can't get nexthdr, we do not need to decrypt it */
692 if (ep - bp2 < len)
693 goto fail;
694 if (ep - bp2 > len) {
695 /* FCS included at end of frame (NetBSD 1.6 or later) */
696 ep = bp2 + len;
697 }
698
699 ivoff = (u_char *)(esp + 1) + 0;
700 ivlen = sa->ivlen;
701 secret = sa->secret;
702 ep = ep - sa->authlen;
703
704 if (sa->evp) {
705 memset(&ctx, 0, sizeof(ctx));
706 if (EVP_CipherInit(&ctx, sa->evp, secret, NULL, 0) < 0)
707 (*ndo->ndo_warning)(ndo, "espkey init failed");
708
709 p = ivoff;
710 EVP_CipherInit(&ctx, NULL, NULL, p, 0);
711 EVP_Cipher(&ctx, p + ivlen, p + ivlen, ep - (p + ivlen));
712 EVP_CIPHER_CTX_cleanup(&ctx);
713 advance = ivoff - (u_char *)esp + ivlen;
714 } else
715 advance = sizeof(struct newesp);
716
717 /* sanity check for pad length */
718 if (ep - bp < *(ep - 2))
719 goto fail;
720
721 if (padlen)
722 *padlen = *(ep - 2) + 2;
723
724 if (nhdr)
725 *nhdr = *(ep - 1);
726
727 (ndo->ndo_printf)(ndo, ": ");
728 return advance;
729 #endif
730
731 fail:
732 return -1;
733 }
734 #ifdef HAVE_LIBCRYPTO
735 USES_APPLE_RST
736 #endif
737
738 /*
739 * Local Variables:
740 * c-style: whitesmith
741 * c-basic-offset: 8
742 * End:
743 */