From 2e19e184c3a369df9f113a4ccc5a444c784b987e Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Wed, 8 Nov 2000 23:13:13 +0000 Subject: [PATCH] * des.h: Change to make KRB4_32 an int if it's at least 32 bits wide, else a long. This is a change from previously where it was a long except on the alpha. We may want to rethink this if there are binary compat issues that result. Also, define DES_INT32 as KRB4_INT32. * krb.h: Add new macros KRB4_PUT32, KRB4_PUT16 which unconditionally encode integers by bytes as big-endian. Add new macros KRB4_GET32BE, KRB4_GET32LE, KRB4_GET32, KRB4_GET16BE, KRB4_GET16LE, KRB4_GET16 to retrieve integers by bytes. Add prototype for krb_strnlen. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12858 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/kerberosIV/ChangeLog | 14 ++++++ src/include/kerberosIV/des.h | 45 ++++++++++--------- src/include/kerberosIV/krb.h | 76 ++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 22 deletions(-) diff --git a/src/include/kerberosIV/ChangeLog b/src/include/kerberosIV/ChangeLog index 7bbb3341f..8d52c871b 100644 --- a/src/include/kerberosIV/ChangeLog +++ b/src/include/kerberosIV/ChangeLog @@ -1,3 +1,17 @@ +2000-11-08 Tom Yu + + * des.h: Change to make KRB4_32 an int if it's at least 32 bits + wide, else a long. This is a change from previously where it was + a long except on the alpha. We may want to rethink this if there + are binary compat issues that result. Also, define DES_INT32 as + KRB4_INT32. + + * krb.h: Add new macros KRB4_PUT32, KRB4_PUT16 which + unconditionally encode integers by bytes as big-endian. Add new + macros KRB4_GET32BE, KRB4_GET32LE, KRB4_GET32, KRB4_GET16BE, + KRB4_GET16LE, KRB4_GET16 to retrieve integers by bytes. Add + prototype for krb_strnlen. + 2000-10-23 Tom Yu * krb.h: Modify krb_{mk,rd}_{priv,safe} prototypes to align with diff --git a/src/include/kerberosIV/des.h b/src/include/kerberosIV/des.h index 86556083c..e861d72c5 100644 --- a/src/include/kerberosIV/des.h +++ b/src/include/kerberosIV/des.h @@ -40,6 +40,9 @@ #endif #include #endif +#ifdef __STDC__ +#include +#endif /* Windows declarations */ #ifndef KRB5_CALLCONV @@ -54,12 +57,25 @@ #define NEAR #endif -#ifndef __alpha -#define KRB4_32 long -#else -#define KRB4_32 int -#endif - +#ifndef KRB4_32 +#ifdef SIZEOF_INT +#if SIZEOF_INT >= 4 +#define KRB4_32 int +#else /* !(SIZEOF_INT >= 4) */ +#define KRB4_32 long +#endif /* !(SIZEOF_INT >= 4) */ +#else /* !defined(SIZEOF_INT) */ +#ifdef __STDC__ +#if INT_MAX >= 0x7fffffff +#define KRB4_32 int +#else /* !(INT_MAX >= 0x7ffffff) */ +#define KRB4_32 long +#endif /* !(INT_MAX >= 0x7ffffff) */ +#else /* !defined(__STDC__) */ +#define KRB4_32 long /* worst case */ +#endif /* !defined(__STDC__) */ +#endif /* !defined(SIZEOF_INT) */ +#endif /* !defined(KRB4_32) */ #ifndef PROTOTYPE #if (defined(__STDC__) || defined(_WINDOWS)) && !defined(KRB5_NO_PROTOTYPES) @@ -69,28 +85,13 @@ #endif #endif - - typedef unsigned char des_cblock[8]; /* crypto-block size */ /* Key schedule */ /* Ick. We need this in here unfortunately... */ #ifndef DES_INT32 -#ifdef SIZEOF_INT -#if SIZEOF_INT >= 4 -#define DES_INT32 int -#else -#define DES_INT32 long +#define DES_INT32 KRB4_32 #endif -#else /* !defined(SIZEOF_INT) */ -#include -#if (UINT_MAX >= 0xffffffff) -#define DES_INT32 int -#else -#define DES_INT32 long -#endif -#endif /* !defined(SIZEOF_INT) */ -#endif /* !defined(DES_INT32) */ typedef struct des_ks_struct { DES_INT32 _[2]; } des_key_schedule[16]; diff --git a/src/include/kerberosIV/krb.h b/src/include/kerberosIV/krb.h index bb5006f4d..73b40a2a4 100644 --- a/src/include/kerberosIV/krb.h +++ b/src/include/kerberosIV/krb.h @@ -346,6 +346,78 @@ typedef struct msg_dat MSG_DAT; #define krb4_swab32(val) ((((val)>>24)&0xFF) | (((val)>>8)&0xFF00) | \ (((val)<<8)&0xFF0000) | ((val)<<24)) +/* + * Macros to encode integers into buffers in big-endian order. These + * take a parameter that is a moving pointer of type (unsigned char *) + * into the buffer, and assume that the caller has already + * bounds-checked. + */ +#define KRB4_PUT32(p, val) \ +do { \ + *(p)++ = ((unsigned KRB4_32)(val) >> 24) & 0xff; \ + *(p)++ = ((unsigned KRB4_32)(val) >> 16) & 0xff; \ + *(p)++ = ((unsigned KRB4_32)(val) >> 8) & 0xff; \ + *(p)++ = (unsigned KRB4_32)(val) & 0xff; \ +} while (0) + +#define KRB4_PUT16(p, val) \ +do { \ + *(p)++ = ((unsigned KRB4_32)(val) >> 8) & 0xff; \ + *(p)++ = (unsigned KRB4_32)(val) & 0xff; \ +} while (0) + +/* + * Macros to get integers from a buffer. These take a parameter that + * is a moving pointer of type (unsigned char *) into the buffer, and + * assume that the caller has already bounds-checked. In addition, + * they assume that val is an unsigned type; ANSI leaves the semantics + * of unsigned -> signed conversion as implementation-defined, so it's + * unwise to depend on such. + */ +#define KRB4_GET32BE(val, p) \ +do { \ + (val) = (unsigned KRB4_32)*(p)++ << 24; \ + (val) |= (unsigned KRB4_32)*(p)++ << 16; \ + (val) |= (unsigned KRB4_32)*(p)++ << 8; \ + (val) |= (unsigned KRB4_32)*(p)++; \ +} while (0) + +#define KRB4_GET32LE(val, p) \ +do { \ + (val) = (unsigned KRB4_32)*(p)++; \ + (val) |= (unsigned KRB4_32)*(p)++ << 8; \ + (val) |= (unsigned KRB4_32)*(p)++ << 16; \ + (val) |= (unsigned KRB4_32)*(p)++ << 24; \ +} while(0) + +#define KRB4_GET32(val, p, le) \ +do { \ + if (le) \ + KRB4_GET32LE((val), (p)); \ + else \ + KRB4_GET32BE((val), (p)); \ +} while (0) + +#define KRB4_GET16BE(val, p) \ +do { \ + (val) = (unsigned KRB4_32)*(p)++ << 8; \ + (val) |= (unsigned KRB4_32)*(p)++; \ +} while (0) + +#define KRB4_GET16LE(val, p) \ +do { \ + (val) = (unsigned KRB4_32)*(p)++; \ + (val) |= (unsigned KRB4_32)*(p)++ << 8; \ +} while (0) + +#define KRB4_GET16(val, p, le) \ +do { \ + if (le) \ + KRB4_GET16LE((val), (p)); \ + else \ + KRB4_GET16BE((val), (p)); \ +} while (0) + /* Kerberos ticket flag field bit definitions */ #define K_FLAG_ORDER 0 /* bit 0 --> lsb */ #define K_FLAG_1 /* reserved */ @@ -672,6 +744,10 @@ KRB5_DLLIMP void KRB5_CALLCONV tf_close PROTOTYPE((void)); KRB5_DLLIMP unsigned KRB4_32 KRB5_CALLCONV unix_time_gmt_unixsec PROTOTYPE((unsigned KRB4_32 *)); +/* strnlen.c */ +extern int KRB5_CALLCONV krb_strnlen + PROTOTYPE((const char *, int)); + /* * Internal prototypes */ -- 2.26.2