summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/inet/rpc/create_xid.c3
-rw-r--r--libc/inet/rpc/xdr.c20
-rw-r--r--libc/inet/rpc/xdr_intXX_t.c4
-rw-r--r--libc/inet/rpc/xdr_rec.c103
-rw-r--r--libcrypt/des.c42
5 files changed, 67 insertions, 105 deletions
diff --git a/libc/inet/rpc/create_xid.c b/libc/inet/rpc/create_xid.c
index be24d660c..0f045b9c1 100644
--- a/libc/inet/rpc/create_xid.c
+++ b/libc/inet/rpc/create_xid.c
@@ -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);
diff --git a/libc/inet/rpc/xdr.c b/libc/inet/rpc/xdr.c
index 11e52136d..f76cc6a88 100644
--- a/libc/inet/rpc/xdr.c
+++ b/libc/inet/rpc/xdr.c
@@ -104,7 +104,6 @@ libc_hidden_def(xdr_void)
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 @@ xdr_u_int (XDR *xdrs, u_int *up)
{
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 @@ bool_t
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 @@ xdr_u_hyper (XDR *xdrs, u_quad_t *ullp)
{
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 @@ xdr_u_short (XDR *xdrs, u_short *usp)
{
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;
}
diff --git a/libc/inet/rpc/xdr_intXX_t.c b/libc/inet/rpc/xdr_intXX_t.c
index d36d1623b..ff2177584 100644
--- a/libc/inet/rpc/xdr_intXX_t.c
+++ b/libc/inet/rpc/xdr_intXX_t.c
@@ -34,9 +34,9 @@ xdr_int64_t (XDR *xdrs, int64_t *ip)
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;
diff --git a/libc/inet/rpc/xdr_rec.c b/libc/inet/rpc/xdr_rec.c
index af5eb5217..43dff2206 100644
--- a/libc/inet/rpc/xdr_rec.c
+++ b/libc/inet/rpc/xdr_rec.c
@@ -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 @@ libc_hidden_def(xdrrec_create)
*/
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 @@ xdrrec_putlong (XDR *xdrs, const long *lp)
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 @@ xdrrec_destroy (XDR *xdrs)
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
*/
diff --git a/libcrypt/des.c b/libcrypt/des.c
index eb1e13fec..6af65b615 100644
--- a/libcrypt/des.c
+++ b/libcrypt/des.c
@@ -454,33 +454,26 @@ des_setkey(const char *key)
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 @@ do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int
| 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 @@ do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int
| 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]