summaryrefslogtreecommitdiff
path: root/sunrpc/des_impl.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /sunrpc/des_impl.c
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'sunrpc/des_impl.c')
-rw-r--r--sunrpc/des_impl.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/sunrpc/des_impl.c b/sunrpc/des_impl.c
index dc94e221ab..702bd02c77 100644
--- a/sunrpc/des_impl.c
+++ b/sunrpc/des_impl.c
@@ -6,11 +6,10 @@
/* write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,*/
/* Boston, MA 02111, USA to obtain a copy. */
#include <string.h>
-#include <stdint.h>
#include "des.h"
-static const uint32_t des_SPtrans[8][64] =
+static const unsigned long des_SPtrans[8][64] =
{
{ /* nibble 0 */
0x00820200, 0x00020000, 0x80800000, 0x80820200,
@@ -156,7 +155,7 @@ static const uint32_t des_SPtrans[8][64] =
0x00000020, 0x08208000, 0x00208020, 0x00000000,
0x08000000, 0x08200020, 0x00008000, 0x00208020}};
-static const uint32_t des_skb[8][64] =
+static const unsigned long des_skb[8][64] =
{
{ /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
0x00000000, 0x00000010, 0x20000000, 0x20000010,
@@ -353,6 +352,26 @@ static const uint32_t des_skb[8][64] =
(a)=(a)^(t)^(t>>(16-(n))))
+/* The changes to this macro may help or hinder, depending on the
+ * compiler and the achitecture. gcc2 always seems to do well :-).
+ * Inspired by Dana How <how@isl.stanford.edu>
+ * DO NOT use the alternative version on machines with 8 byte longs.
+ */
+#ifdef ALT_ECB
+#define D_ENCRYPT(L,R,S) \
+ u=((R^s[S ])<<2); \
+ t= R^s[S+1]; \
+ t=((t>>2)+(t<<30)); \
+ L^= \
+ *(const unsigned long *)(des_SP+0x0100+((t )&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
+ *(const unsigned long *)(des_SP+ ((u )&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
+ *(const unsigned long *)(des_SP+0x0600+((u>>24)&0xfc));
+#else /* original version */
#define D_ENCRYPT(L,R,S) \
u=(R^s[S ]); \
t=R^s[S+1]; \
@@ -365,20 +384,21 @@ static const uint32_t des_skb[8][64] =
des_SPtrans[2][(u>> 8)&0x3f]| \
des_SPtrans[4][(u>>16)&0x3f]| \
des_SPtrans[6][(u>>24)&0x3f];
+#endif
#define ITERATIONS 16
static const char shifts2[16] =
{0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0};
-static void des_set_key (unsigned char *, unsigned long *) internal_function;
+static void des_set_key (char *, unsigned long *) internal_function;
static void des_encrypt (unsigned long *, unsigned long *, int)
internal_function;
int _des_crypt (char *, unsigned, struct desparams *);
static void
internal_function
-des_set_key (unsigned char *key, unsigned long *schedule)
+des_set_key (char *key, unsigned long *schedule)
{
register unsigned long c, d, t, s;
register unsigned char *in;
@@ -386,7 +406,7 @@ des_set_key (unsigned char *key, unsigned long *schedule)
register int i;
k = (unsigned long *) schedule;
- in = key;
+ in = (unsigned char *) key;
c2l (in, c);
c2l (in, d);
@@ -444,6 +464,9 @@ internal_function
des_encrypt (unsigned long *buf, unsigned long *schedule, int encrypt)
{
register unsigned long l, r, t, u;
+#ifdef ALT_ECB
+ register const unsigned char *des_SP = (const unsigned char *) des_SPtrans;
+#endif
register int i;
register unsigned long *s;