X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=encrypt.c;h=2840916ed5ada7a3c4a4c281796474c57c2b0157;hb=72205dd2ca8ed37d59c03a69039f827cb377fc98;hp=60ba5e97b46f39d31b45b7774ec07458e272e3de;hpb=a4d53c2fe3dc1952c7c7d8a4283545389ba5aa64;p=tac_plus.git diff --git a/encrypt.c b/encrypt.c index 60ba5e9..2840916 100644 --- a/encrypt.c +++ b/encrypt.c @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 1995-1998 by Cisco systems, Inc. Permission to use, copy, modify, and distribute this software for @@ -17,8 +17,19 @@ FITNESS FOR A PARTICULAR PURPOSE. */ + #include "tac_plus.h" + +#include +#include /* 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 @@ -36,21 +47,25 @@ * */ -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; @@ -62,11 +77,11 @@ u_char *hash; 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); @@ -90,10 +105,13 @@ u_char *hash; * 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 */ @@ -120,7 +138,7 @@ char *key; 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) { @@ -141,7 +159,7 @@ char *key; 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); } @@ -157,7 +175,7 @@ char *key; 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); }