+2000-11-08 Tom Yu <tlyu@mit.edu>
+
+ * 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 <tlyu@mit.edu>
* krb.h: Modify krb_{mk,rd}_{priv,safe} prototypes to align with
#endif
#include <win-mac.h>
#endif
+#ifdef __STDC__
+#include <limits.h>
+#endif
/* Windows declarations */
#ifndef KRB5_CALLCONV
#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)
#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 <limits.h>
-#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];
#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 */
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
*/