if ((md = md_list_find(iface, iface->auth_keyid)) == NULL) { log_debug("auth_validate: keyid %d not configured, " "interface %s", iface->auth_keyid, iface->name); return (-1); }
auth_validate(void *buf, u_int16_t len, struct iface *iface, struct nbr *nbr){	MD5_CTX		 hash;	u_int8_t	 digest[MD5_DIGEST_LENGTH];	u_int8_t	 recv_digest[MD5_DIGEST_LENGTH];	struct ospf_hdr	*ospf_hdr = buf;	struct auth_md	*md;	char		*auth_data;	if (ntohs(ospf_hdr->auth_type) != (u_int16_t)iface->auth_type) {		log_debug("auth_validate: wrong auth type, interface %s",		    iface->name);		return (-1);	}	switch (iface->auth_type) {	case AUTH_SIMPLE:		if (bcmp(ospf_hdr->auth_key.simple, iface->auth_key,		    sizeof(ospf_hdr->auth_key.simple))) {			log_debug("auth_validate: wrong password, interface %s",			    iface->name);			return (-1);		}		/* FALLTHROUGH */	case AUTH_NONE:		/* clear the key before chksum */		bzero(ospf_hdr->auth_key.simple,		     sizeof(ospf_hdr->auth_key.simple));		if (in_cksum(ospf_hdr, ntohs(ospf_hdr->len))) {			log_debug("recv_packet: invalid checksum, interface %s",			    iface->name);			return (-1);		}		break;	case AUTH_CRYPT:		if (ospf_hdr->auth_key.crypt.keyid != iface->auth_keyid) {			log_debug("auth_validate: invalid key id, "			    "interface %s", iface->name);			return (-1);		}		if (nbr != NULL && ntohl(ospf_hdr->auth_key.crypt.seq_num) <		    nbr->crypt_seq_num) {			log_debug("auth_validate: decreasing seq num, "			    "interface %s", iface->name);			return (-1);		}		if (ospf_hdr->auth_key.crypt.len != MD5_DIGEST_LENGTH) {			log_debug("auth_validate: invalid key length, "			    "interface %s", iface->name);			return (-1);		}		if (len - ntohs(ospf_hdr->len) < MD5_DIGEST_LENGTH) {			log_debug("auth_validate: invalid key length, "			    "interface %s", iface->name);			return (-1);		}		auth_data = buf;		auth_data += ntohs(ospf_hdr->len);		/* save the received digest and clear it in the packet */		bcopy(auth_data, recv_digest, sizeof(recv_digest));		bzero(auth_data, MD5_DIGEST_LENGTH);		/* insert plaintext key */		if ((md = md_list_find(iface, iface->auth_keyid))		    == NULL) {			log_debug("auth_validate: keyid %d not configured, "			    "interface %s", iface->auth_keyid,			    iface->name);			return (-1);		}		bzero(digest, MD5_DIGEST_LENGTH);		strncpy(digest, md->key, MD5_DIGEST_LENGTH);		/* calculate MD5 digest */		MD5Init(&hash);		MD5Update(&hash, buf, ntohs(ospf_hdr->len));		MD5Update(&hash, digest, MD5_DIGEST_LENGTH);		MD5Final(digest, &hash);		if (bcmp(recv_digest, digest, sizeof(digest))) {			log_debug("auth_validate: invalid MD5 digest, "			    "interface %s", iface->name);			return (-1);		}		if (nbr != NULL)			nbr->crypt_seq_num =			    ntohl(ospf_hdr->auth_key.crypt.seq_num);		break;	default:		log_debug("auth_validate: unknown auth type, interface %s",		    iface->name);		return (-1);	}	return (0);}