2 * DES interface for rsaref2.0
4 * These routines implement an interface for the RSA Laboratories
5 * implementation of the Data Encryption Standard (DES) algorithm
6 * operating in Cipher-Block Chaining (CBC) mode. This algorithm is
7 * included in the rsaref2.0 package available from RSA in the US and
8 * foreign countries. Further information is available at www.rsa.com.
11 #include "ntp_machine.h"
18 #include "ntp_types.h"
20 #include "ntp_string.h"
23 #include "ntp_stdlib.h"
25 #define BLOCK_OCTETS 8 /* message digest size */
26 #define MAXTPKT 128 /* max packet size */
30 * DESauthencrypt - generate DES-CBC message authenticator
32 * Returns length of authenticator field.
36 u_char *key, /* key pointer */
37 u_int32 *pkt, /* packet pointer */
38 int length /* packet length */
42 u_int32 tpkt[MAXTPKT];
47 * DES-CBC with zero IV. Note the encrypted text is discarded.
49 work[0] = work[1] = 0;
50 DES_CBCInit(&ctx, key, (u_char *)work, 1);
51 DES_CBCUpdate(&ctx, (u_char *)tpkt, (u_char *)pkt,
55 pkt[i++] = (u_int32)htonl(tpkt[j++]);
56 pkt[i] = (u_int32)htonl(tpkt[j]);
57 return (BLOCK_OCTETS + 4);
62 * DESauthdecrypt - verify DES message authenticator
64 * Returns one if authenticator valid, zero if invalid.
68 u_char *key, /* key pointer */
69 u_int32 *pkt, /* packet pointer */
70 int length, /* packet length */
71 int size /* size of MAC field */
75 u_int32 tpkt[MAXTPKT];
80 * DES-CBC with zero IV. Note the encrypted text is discarded.
82 if (size != BLOCK_OCTETS + 4)
84 work[0] = work[1] = 0;
85 DES_CBCInit (&ctx, key, (u_char *)work, 1);
86 DES_CBCUpdate (&ctx, (u_char *)tpkt, (u_char *)pkt,
90 if ((u_int32)ntohl(pkt[i++]) == tpkt[j++] &&
91 (u_int32)ntohl(pkt[i]) == tpkt[j])