* des.h: Change to make KRB4_32 an int if it's at least 32 bits
authorTom Yu <tlyu@mit.edu>
Wed, 8 Nov 2000 23:13:13 +0000 (23:13 +0000)
committerTom Yu <tlyu@mit.edu>
Wed, 8 Nov 2000 23:13:13 +0000 (23:13 +0000)
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
src/include/kerberosIV/des.h
src/include/kerberosIV/krb.h

index 7bbb3341f9c877b104b2708105d3b169cf266d67..8d52c871b5cea65dbaac590f27ea30c7fdb00dbb 100644 (file)
@@ -1,3 +1,17 @@
+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
index 86556083c552a8afb1d3be436beb96320763141a..e861d72c51206fc473acef6ef5e528d0539cabb9 100644 (file)
@@ -40,6 +40,9 @@
 #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];
 
index bb5006f4d220886cbd76f3cbc4d6d98e2efcb401..73b40a2a4ee7dccd4c9487ebb8b6223d38c0e23f 100644 (file)
@@ -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
  */