/* auth12crypt.c,v 3.1 1993/07/06 01:07:43 jbj Exp
* auth12crypt.c - routines to support two stage NTP encryption
* For our purposes an NTP packet looks like:
* a variable amount of encrypted data, multiple of 8 bytes, which
* is encrypted in pass 1, followed by:
* an 8 byte chunk of data which is encrypted in pass 2
* NOCRYPT_OCTETS worth of unencrypted data, followed by:
* BLOCK_OCTETS worth of ciphered checksum.
#define NOCRYPT_LONGS ((NOCRYPT_OCTETS)/sizeof(U_LONG))
#define BLOCK_LONGS ((BLOCK_OCTETS)/sizeof(U_LONG))
* Imported from the key data base module
extern U_LONG cache_keyid
; /* cached key ID */
extern u_char DEScache_ekeys
[]; /* cached decryption keys */
extern u_char DESzeroekeys
[]; /* zero key decryption keys */
* Stat counters, from the database module
extern U_LONG authencryptions
;
extern U_LONG authkeyuncached
;
* auth1crypt - do the first stage of a two stage encryption
DESauth1crypt(keyno
, pkt
, length
)
int length
; /* length of all encrypted data */
if (keyno
!= cache_keyid
) {
if (!authhavekey(keyno
)) {
* Do the first five encryptions. Stick the intermediate result
* in the mac field. The sixth encryption must wait until the
* caller freezes a transmit time stamp, and will be done in stage 2.
for (i
= (length
/BLOCK_OCTETS
- 1); i
> 0; i
--) {
* Space to the end of the packet and stick the intermediate
* result in the mac field.
pd
+= BLOCK_LONGS
+ NOCRYPT_LONGS
;
* auth2crypt - do the second stage of a two stage encryption
DESauth2crypt(keyno
, pkt
, length
)
int length
; /* total length of encrypted area */
* Skip the key check. The call to the first stage should
* The mac currently should hold the results of the first `n'
* encryptions. We xor in the last block in data section and
* do the final encryption in place.
* Get a pointer to the MAC block. XOR in the last two words of
* the data area. Call the encryption routine.
pd
= pkt
+ (length
/sizeof(U_LONG
)) + NOCRYPT_LONGS
;
*pd
^= *(pd
- NOCRYPT_LONGS
- 2);
*(pd
+ 1) ^= *(pd
- NOCRYPT_LONGS
- 1);
return 4 + 8; /* return size of key number and MAC */