svn commit: trunk/uClibc: libc/inet/rpc libcrypt

vda at uclibc.org vda at uclibc.org
Mon Dec 1 08:37:27 UTC 2008


Author: vda
Date: 2008-12-01 00:37:27 -0800 (Mon, 01 Dec 2008)
New Revision: 24196

Log:
rpc: ifdef out xdrrec_{get,put}long if int32 == long,
 otherwise use xdrrec_{get,put}int32 + trivial transform.
 eliminate warnings.
des: small shrink + eliminate a warning



Modified:
   trunk/uClibc/libc/inet/rpc/create_xid.c
   trunk/uClibc/libc/inet/rpc/xdr.c
   trunk/uClibc/libc/inet/rpc/xdr_intXX_t.c
   trunk/uClibc/libc/inet/rpc/xdr_rec.c
   trunk/uClibc/libcrypt/des.c


Changeset:
Modified: trunk/uClibc/libc/inet/rpc/create_xid.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/create_xid.c	2008-11-30 17:41:31 UTC (rev 24195)
+++ trunk/uClibc/libc/inet/rpc/create_xid.c	2008-12-01 08:37:27 UTC (rev 24196)
@@ -34,14 +34,13 @@
 #include <bits/uClibc_mutex.h>
 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
 
-
 static smallint is_initialized;
 static struct drand48_data __rpc_lrand48_data;
 
 u_long _create_xid (void) attribute_hidden;
 u_long _create_xid (void)
 {
-  unsigned long res;
+  long res;
 
   __UCLIBC_MUTEX_LOCK(mylock);
 

Modified: trunk/uClibc/libc/inet/rpc/xdr.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/xdr.c	2008-11-30 17:41:31 UTC (rev 24195)
+++ trunk/uClibc/libc/inet/rpc/xdr.c	2008-12-01 08:37:27 UTC (rev 24196)
@@ -104,7 +104,6 @@
 bool_t
 xdr_long (XDR *xdrs, long *lp)
 {
-
   if (xdrs->x_op == XDR_ENCODE
       && (sizeof (int32_t) == sizeof (long)
 	  || (int32_t) *lp == *lp))
@@ -237,10 +236,10 @@
     {
     case XDR_ENCODE:
       l = (u_long) * up;
-      return XDR_PUTLONG (xdrs, &l);
+      return XDR_PUTLONG (xdrs, (long *) &l);
 
     case XDR_DECODE:
-      if (!XDR_GETLONG (xdrs, &l))
+      if (!XDR_GETLONG (xdrs, (long *) &l))
 	{
 	  return FALSE;
 	}
@@ -268,19 +267,20 @@
 xdr_hyper (XDR *xdrs, quad_t *llp)
 {
   long t1;
-  unsigned long int t2;
+  unsigned long t2;
 
   if (xdrs->x_op == XDR_ENCODE)
     {
       t1 = (long) ((*llp) >> 32);
       t2 = (long) (*llp);
-      return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2));
+      return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, (long *) &t2));
     }
 
   if (xdrs->x_op == XDR_DECODE)
     {
-      if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
+      if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, (long *) &t2))
 	return FALSE;
+      /* t2 must be unsigned for this to work */
       *llp = ((quad_t) t1) << 32;
       *llp |= t2;
       return TRUE;
@@ -309,12 +309,12 @@
     {
       t1 = (unsigned long) ((*ullp) >> 32);
       t2 = (unsigned long) (*ullp);
-      return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2));
+      return (XDR_PUTLONG(xdrs, (long *) &t1) && XDR_PUTLONG(xdrs, (long *) &t2));
     }
 
   if (xdrs->x_op == XDR_DECODE)
     {
-      if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
+      if (!XDR_GETLONG(xdrs, (long *) &t1) || !XDR_GETLONG(xdrs, (long *) &t2))
 	return FALSE;
       *ullp = ((u_quad_t) t1) << 32;
       *ullp |= t2;
@@ -353,10 +353,10 @@
     {
     case XDR_ENCODE:
       l = (u_long) * usp;
-      return XDR_PUTLONG (xdrs, &l);
+      return XDR_PUTLONG (xdrs, (long *) &l);
 
     case XDR_DECODE:
-      if (!XDR_GETLONG (xdrs, &l))
+      if (!XDR_GETLONG (xdrs, (long *) &l))
 	{
 	  return FALSE;
 	}

Modified: trunk/uClibc/libc/inet/rpc/xdr_intXX_t.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/xdr_intXX_t.c	2008-11-30 17:41:31 UTC (rev 24195)
+++ trunk/uClibc/libc/inet/rpc/xdr_intXX_t.c	2008-12-01 08:37:27 UTC (rev 24196)
@@ -34,9 +34,9 @@
     case XDR_ENCODE:
       t1 = (int32_t) ((*ip) >> 32);
       t2 = (int32_t) (*ip);
-      return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
+      return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2));
     case XDR_DECODE:
-      if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
+      if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2))
         return FALSE;
       *ip = ((int64_t) t1) << 32;
       *ip |= t2;

Modified: trunk/uClibc/libc/inet/rpc/xdr_rec.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/xdr_rec.c	2008-11-30 17:41:31 UTC (rev 24195)
+++ trunk/uClibc/libc/inet/rpc/xdr_rec.c	2008-12-01 08:37:27 UTC (rev 24196)
@@ -64,20 +64,27 @@
 /* libc_hidden_proto(fputs) */
 /* libc_hidden_proto(lseek) */
 
-static bool_t xdrrec_getlong (XDR *, long *);
-static bool_t xdrrec_putlong (XDR *, const long *);
 static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int);
 static bool_t xdrrec_putbytes (XDR *, const char *, u_int);
+static bool_t xdrrec_getint32 (XDR *, int32_t *);
+static bool_t xdrrec_putint32 (XDR *, const int32_t *);
+#if ULONG_MAX != UINT_MAX
+static bool_t xdrrec_getlong (XDR *, long *);
+static bool_t xdrrec_putlong (XDR *, const long *);
+#endif
 static u_int xdrrec_getpos (const XDR *);
 static bool_t xdrrec_setpos (XDR *, u_int);
 static int32_t *xdrrec_inline (XDR *, u_int);
 static void xdrrec_destroy (XDR *);
-static bool_t xdrrec_getint32 (XDR *, int32_t *);
-static bool_t xdrrec_putint32 (XDR *, const int32_t *);
 
 static const struct xdr_ops xdrrec_ops = {
+#if ULONG_MAX == UINT_MAX
+  (bool_t (*)(XDR *, long *)) xdrrec_getint32,
+  (bool_t (*)(XDR *, const long *)) xdrrec_putint32,
+#else
   xdrrec_getlong,
   xdrrec_putlong,
+#endif
   xdrrec_getbytes,
   xdrrec_putbytes,
   xdrrec_getpos,
@@ -218,35 +225,46 @@
  */
 
 static bool_t
-xdrrec_getlong (XDR *xdrs, long *lp)
+xdrrec_getint32 (XDR *xdrs, int32_t *ip)
 {
   RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-  int32_t *buflp = (int32_t *) rstrm->in_finger;
+  int32_t *bufip = (int32_t *) rstrm->in_finger;
   int32_t mylong;
 
   /* first try the inline, fast case */
   if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
-      rstrm->in_boundry - (char *) buflp >= BYTES_PER_XDR_UNIT)
+      rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
     {
-      *lp = (int32_t) ntohl (*buflp);
+      *ip = ntohl (*bufip);
       rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
       rstrm->in_finger += BYTES_PER_XDR_UNIT;
     }
   else
     {
-      if (!xdrrec_getbytes (xdrs, (caddr_t) & mylong,
+      if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
 			    BYTES_PER_XDR_UNIT))
 	return FALSE;
-      *lp = (int32_t) ntohl (mylong);
+      *ip = ntohl (mylong);
     }
   return TRUE;
 }
 
+#if ULONG_MAX != UINT_MAX
 static bool_t
-xdrrec_putlong (XDR *xdrs, const long *lp)
+xdrrec_getlong (XDR *xdrs, long *lp)
 {
+  int32_t v;
+  bool_t r = xdrrec_getint32 (xdrs, &v);
+  *lp = v;
+  return r;
+}
+#endif
+
+static bool_t
+xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
+{
   RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-  int32_t *dest_lp = (int32_t *) rstrm->out_finger;
+  int32_t *dest_ip = (int32_t *) rstrm->out_finger;
 
   if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
     {
@@ -258,13 +276,22 @@
       rstrm->frag_sent = TRUE;
       if (!flush_out (rstrm, FALSE))
 	return FALSE;
-      dest_lp = (int32_t *) rstrm->out_finger;
+      dest_ip = (int32_t *) rstrm->out_finger;
       rstrm->out_finger += BYTES_PER_XDR_UNIT;
     }
-  *dest_lp = htonl (*lp);
+  *dest_ip = htonl (*ip);
   return TRUE;
 }
 
+#if ULONG_MAX != UINT_MAX
+static bool_t
+xdrrec_putlong (XDR *xdrs, const long *lp)
+{
+  int32_t v = *lp;
+  return xdrrec_putint32 (xdrs, &v);
+}
+#endif
+
 static bool_t	   /* must manage buffers, fragments, and records */
 xdrrec_getbytes (XDR *xdrs, caddr_t addr, u_int len)
 {
@@ -425,54 +452,6 @@
   mem_free ((caddr_t) rstrm, sizeof (RECSTREAM));
 }
 
-static bool_t
-xdrrec_getint32 (XDR *xdrs, int32_t *ip)
-{
-  RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-  int32_t *bufip = (int32_t *) rstrm->in_finger;
-  int32_t mylong;
-
-  /* first try the inline, fast case */
-  if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
-      rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
-    {
-      *ip = ntohl (*bufip);
-      rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
-      rstrm->in_finger += BYTES_PER_XDR_UNIT;
-    }
-  else
-    {
-      if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
-			    BYTES_PER_XDR_UNIT))
-	return FALSE;
-      *ip = ntohl (mylong);
-    }
-  return TRUE;
-}
-
-static bool_t
-xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
-{
-  RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
-  int32_t *dest_ip = (int32_t *) rstrm->out_finger;
-
-  if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
-    {
-      /*
-       * this case should almost never happen so the code is
-       * inefficient
-       */
-      rstrm->out_finger -= BYTES_PER_XDR_UNIT;
-      rstrm->frag_sent = TRUE;
-      if (!flush_out (rstrm, FALSE))
-	return FALSE;
-      dest_ip = (int32_t *) rstrm->out_finger;
-      rstrm->out_finger += BYTES_PER_XDR_UNIT;
-    }
-  *dest_ip = htonl (*ip);
-  return TRUE;
-}
-
 /*
  * Exported routines to manage xdr records
  */

Modified: trunk/uClibc/libcrypt/des.c
===================================================================
--- trunk/uClibc/libcrypt/des.c	2008-11-30 17:41:31 UTC (rev 24195)
+++ trunk/uClibc/libcrypt/des.c	2008-12-01 08:37:27 UTC (rev 24196)
@@ -454,33 +454,26 @@
 static int
 do_des(	u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int count)
 {
-	/*
-	 *	l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
-	 */
+	/* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. */
 	u_int32_t	l, r, *kl, *kr, *kl1, *kr1;
 	u_int32_t	f, r48l, r48r;
 	int		round;
 
 	if (count == 0) {
-		return(1);
-	} else if (count > 0) {
-		/*
-		 * Encrypting
-		 */
+		return 1;
+	}
+	if (count > 0) {
+		/* Encrypting */
 		kl1 = en_keysl;
 		kr1 = en_keysr;
 	} else {
-		/*
-		 * Decrypting
-		 */
+		/* Decrypting */
 		count = -count;
 		kl1 = de_keysl;
 		kr1 = de_keysr;
 	}
 
-	/*
-	 *	Do initial permutation (IP).
-	 */
+	/* Do initial permutation (IP). */
 	l = ip_maskl[0][l_in >> 24]
 	  | ip_maskl[1][(l_in >> 16) & 0xff]
 	  | ip_maskl[2][(l_in >> 8) & 0xff]
@@ -499,22 +492,17 @@
 	  | ip_maskr[7][r_in & 0xff];
 
 	while (count--) {
-		/*
-		 * Do each round.
-		 */
+		/* Do each round. */
 		kl = kl1;
 		kr = kr1;
 		round = 16;
-		while (round--) {
-			/*
-			 * Expand R to 48 bits (simulate the E-box).
-			 */
+		do {
+			/* Expand R to 48 bits (simulate the E-box). */
 			r48l	= ((r & 0x00000001) << 23)
 				| ((r & 0xf8000000) >> 9)
 				| ((r & 0x1f800000) >> 11)
 				| ((r & 0x01f80000) >> 13)
 				| ((r & 0x001f8000) >> 15);
-
 			r48r	= ((r & 0x0001f800) << 7)
 				| ((r & 0x00001f80) << 5)
 				| ((r & 0x000001f8) << 3)
@@ -535,19 +523,15 @@
 			  | psbox[1][m_sbox[1][r48l & 0xfff]]
 			  | psbox[2][m_sbox[2][r48r >> 12]]
 			  | psbox[3][m_sbox[3][r48r & 0xfff]];
-			/*
-			 * Now that we've permuted things, complete f().
-			 */
+			/* Now that we've permuted things, complete f(). */
 			f ^= l;
 			l = r;
 			r = f;
-		}
+		} while (--round);
 		r = l;
 		l = f;
 	}
-	/*
-	 * Do final permutation (inverse of IP).
-	 */
+	/* Do final permutation (inverse of IP). */
 	*l_out	= fp_maskl[0][l >> 24]
 		| fp_maskl[1][(l >> 16) & 0xff]
 		| fp_maskl[2][(l >> 8) & 0xff]




More information about the uClibc-cvs mailing list