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
11 #include "ntp_machine.h"
19 #include "ntp_types.h"
20 #include "ntp_string.h"
23 #include "ntp_stdlib.h"
25 #define BLOCK_OCTETS 16 /* message digest size */
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 */
41 u_char digest[BLOCK_OCTETS];
45 * MD5 with key identifier concatenated with packet.
48 MD5Update(&ctx, key, (u_int)cache_keylen);
49 MD5Update(&ctx, (u_char *)pkt, (u_int)length);
50 MD5Final(digest, &ctx);
52 memmove((char *)&pkt[i + 1], (char *)digest, BLOCK_OCTETS);
53 return (BLOCK_OCTETS + 4);
58 * MD5authdecrypt - verify MD5 message authenticator
60 * Returns one if authenticator valid, zero if invalid.
64 u_char *key, /* key pointer */
65 u_int32 *pkt, /* packet pointer */
66 int length, /* packet length */
67 int size /* MAC size */
71 u_char digest[BLOCK_OCTETS];
74 * MD5 with key identifier concatenated with packet.
76 if (size != BLOCK_OCTETS + 4)
79 MD5Update(&ctx, key, (u_int)cache_keylen);
80 MD5Update(&ctx, (u_char *)pkt, (u_int)length);
81 MD5Final(digest, &ctx);
82 return (!memcmp((char *)digest, (char *)pkt + length + 4,