-/*
+/*
Copyright (c) 1995-1998 by Cisco systems, Inc.
Permission to use, copy, modify, and distribute this software for
FITNESS FOR A PARTICULAR PURPOSE.
*/
+
#include "tac_plus.h"
+
+#include <stdlib.h>
+#include <netinet/in.h> /* for ntohl() */
+
+#include "encrypt.h"
#include "md5.h"
+#include "utils.h"
+#include "report.h"
+#include "packet.h"
+#include "main.h"
+
/*
* create_md5_hash(): create an md5 hash of the "session_id", "the user's
*
*/
-void
+static void create_md5_hash TAC_ARGS((int session_id, const char *key, unsigned version, unsigned seq_no, u_char *prev_hash, u_char *hash));
+
+static void
create_md5_hash(session_id, key, version, seq_no, prev_hash, hash)
int session_id;
-char *key;
-u_char version;
-u_char seq_no;
+const char *key;
+unsigned version; /* promoted "u_char" type */
+unsigned seq_no; /* promoted "u_char" type */
u_char *prev_hash;
u_char *hash;
{
u_char *md_stream, *mdp;
int md_len;
MD5_CTX mdcontext;
+ u_char version_uchar = version;
+ u_char seq_no_uchar = seq_no;
- md_len = sizeof(session_id) + strlen(key) + sizeof(version) +
- sizeof(seq_no);
+ md_len = sizeof(session_id) + strlen(key) + sizeof(version_uchar) +
+ sizeof(seq_no_uchar);
if (prev_hash) {
md_len += MD5_LEN;
bcopy(key, mdp, strlen(key));
mdp += strlen(key);
- bcopy(&version, mdp, sizeof(version));
- mdp += sizeof(version);
+ bcopy(&version_uchar, mdp, sizeof(version_uchar));
+ mdp += sizeof(version_uchar);
- bcopy(&seq_no, mdp, sizeof(seq_no));
- mdp += sizeof(seq_no);
+ bcopy(&seq_no_uchar, mdp, sizeof(seq_no_uchar));
+ mdp += sizeof(seq_no_uchar);
if (prev_hash) {
bcopy(prev_hash, mdp, MD5_LEN);
* Return 0 on success, -1 on failure.
*/
+int md5_xor TAC_ARGS((HDR *hdr, u_char *data, const char *key));
+
+int
md5_xor(hdr, data, key)
HDR *hdr;
u_char *data;
-char *key;
+const char *key;
{
int i, j;
u_char hash[MD5_LEN]; /* the md5 hash */
if (debug & DEBUG_MD5_HASH_FLAG) {
int k;
- report(LOG_DEBUG,
+ report(LOG_DEBUG,
"hash: session_id=%u, key=%s, version=%d, seq_no=%d",
session_id, key, version, seq_no);
if (prev_hashp) {
for (j = 0; j < 16; j++) {
if ((i + j) >= data_len) {
- hdr->encryption = (hdr->encryption == TAC_PLUS_CLEAR)
+ hdr->encryption = (hdr->encryption == TAC_PLUS_CLEAR)
? TAC_PLUS_ENCRYPTED : TAC_PLUS_CLEAR;
return (0);
}
data[i + j] ^= hash[j];
}
}
- hdr->encryption = (hdr->encryption == TAC_PLUS_CLEAR)
+ hdr->encryption = (hdr->encryption == TAC_PLUS_CLEAR)
? TAC_PLUS_ENCRYPTED : TAC_PLUS_CLEAR;
return (0);
}