+static bool authenticate_udppacket(node_t *n, vpn_packet_t *inpkt) {
+ char hmac[EVP_MAX_MD_SIZE];
+
+ if(inpkt->len < sizeof(inpkt->seqno) + (myself->digest ? myself->maclength : 0))
+ return false;
+
+ /* Check the message authentication code */
+
+ if(myself->digest && myself->maclength) {
+ HMAC(myself->digest, myself->key, myself->keylength,
+ (char *) &inpkt->seqno, inpkt->len - myself->maclength, hmac, NULL);
+
+ if(memcmp(hmac, (char *) &inpkt->seqno + inpkt->len - myself->maclength, myself->maclength))
+ return false;
+ }
+
+ return true;
+}
+