2 * MD5 interface for rsaref2.0
4 * These routines implement an interface for the RSA Laboratories
5 * implementation of the Message Digest 5 (MD5) algorithm. This
6 * algorithm is included in the rsaref2.0 package available from RSA in
7 * the US and foreign countries. Further information is available at
16 #include "ntp_string.h"
17 #include "ntp_stdlib.h"
19 /* Disable the openssl md5 includes, because they'd clash with ours. */
21 /* #define OPENSSL_NO_MD5 */
29 * MD5authencrypt - generate MD5 message authenticator
31 * Returns length of authenticator field.
35 u_char *key, /* key pointer */
36 u_int32 *pkt, /* packet pointer */
37 int length /* packet length */
44 * MD5 with key identifier concatenated with packet.
47 MD5Update(&md5, key, (u_int)cache_keylen);
48 MD5Update(&md5, (u_char *)pkt, (u_int)length);
49 MD5Final(digest, &md5);
50 memmove((u_char *)pkt + length + 4, digest, 16);
56 * MD5authdecrypt - verify MD5 message authenticator
58 * Returns one if authenticator valid, zero if invalid.
62 u_char *key, /* key pointer */
63 u_int32 *pkt, /* packet pointer */
64 int length, /* packet length */
65 int size /* MAC size */
72 * MD5 with key identifier concatenated with packet.
75 MD5Update(&md5, key, (u_int)cache_keylen);
76 MD5Update(&md5, (u_char *)pkt, (u_int)length);
77 MD5Final(digest, &md5);
80 return (!memcmp(digest, (char *)pkt + length + 4, 16));
84 * Calculate the reference id from the address. If it is an IPv4
85 * address, use it as is. If it is an IPv6 address, do a md5 on
86 * it and use the bottom 4 bytes.
89 addr2refid(struct sockaddr_storage *addr)
95 if (addr->ss_family == AF_INET)
96 return (GET_INADDR(*addr));
99 MD5Update(&md5, (u_char *)&GET_INADDR6(*addr),
100 sizeof(struct in6_addr));
101 MD5Final(digest, &md5);
102 memcpy(&addr_refid, digest, 4);