summaryrefslogtreecommitdiff
path: root/security/tripwire/patches/patch-ac
blob: 624af036e4aeebe49ba42dfe9fa6fd8d1e0401ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
$NetBSD: patch-ac,v 1.3 2002/08/20 17:19:35 seb Exp $

NetBSD defines both LITTLE_ENDIAN and BIG_ENDIAN, and sets the
definition of BYTE_ORDER accordingly.  So check the value of
BYTE_ORDER in this file. And fix build on sparc64.

--- sigs/sha/sha.c.orig	Mon Jul 25 15:46:45 1994
+++ sigs/sha/sha.c	Tue Aug 20 16:34:59 2002
@@ -46,10 +46,17 @@
 
 #include "sha.h"
 
-#if BYTEORDER == 0x1234
-#define LITTLE_ENDIAN
+#ifdef __NetBSD__
+#include <machine/endian.h>
+#elif (defined(__sun__) && defined(__svr4__))
+#define BIG_ENDIAN	4321
+#define LITTLE_ENDIAN	1234
+#if defined(__sparc__)
+#define BYTE_ORDER	BIG_ENDIAN
+#elif defined(__i386__)
+#define BYTE_ORDER	LITTLE_ENDIAN
+#endif
 #endif
-
 
 /* The SHS f()-functions */
 
@@ -148,6 +155,85 @@
     shsInfo->countLo = shsInfo->countHi = 0L;
     }
 
+#ifdef __sparc_v9__
+void expand1(LONG *W)
+{
+    LONG temp;
+    expand( 16 ); expand( 17 ); expand( 18 ); expand( 19 ); expand( 20 );
+    expand( 21 ); expand( 22 ); expand( 23 ); expand( 24 ); expand( 25 );
+    expand( 26 ); expand( 27 ); expand( 28 ); expand( 29 ); expand( 30 );
+    expand( 31 );
+}
+
+void expand2(LONG *W)
+{
+    LONG temp;
+                  expand( 32 ); expand( 33 ); expand( 34 ); expand( 35 );
+    expand( 36 ); expand( 37 ); expand( 38 ); expand( 39 ); expand( 40 );
+    expand( 41 ); expand( 42 ); expand( 43 ); expand( 44 ); expand( 45 );
+    expand( 46 ); expand( 47 );
+}
+
+void expand3(LONG *W)
+{
+    LONG temp;
+                                expand( 48 ); expand( 49 ); expand( 50 );
+    expand( 51 ); expand( 52 ); expand( 53 ); expand( 54 ); expand( 55 );
+    expand( 56 ); expand( 57 ); expand( 58 ); expand( 59 ); expand( 60 );
+    expand( 61 ); expand( 62 ); expand( 63 );
+}
+
+void expand4(LONG *W)
+{
+    LONG temp;
+                                              expand( 64 ); expand( 65 );
+    expand( 66 ); expand( 67 ); expand( 68 ); expand( 69 ); expand( 70 );
+    expand( 71 ); expand( 72 ); expand( 73 ); expand( 74 ); expand( 75 );
+    expand( 76 ); expand( 77 ); expand( 78 ); expand( 79 );
+}
+
+void do_Round1(LONG *W)
+{
+    LONG temp;
+    subRound1( 0 ); subRound1( 1 ); subRound1( 2 ); subRound1( 3 );
+    subRound1( 4 ); subRound1( 5 ); subRound1( 6 ); subRound1( 7 );
+    subRound1( 8 ); subRound1( 9 ); subRound1( 10 ); subRound1( 11 );
+    subRound1( 12 ); subRound1( 13 ); subRound1( 14 ); subRound1( 15 );
+    subRound1( 16 ); subRound1( 17 ); subRound1( 18 ); subRound1( 19 );
+}
+
+void do_Round2(LONG *W)
+{
+    LONG temp;
+    subRound2( 20 ); subRound2( 21 ); subRound2( 22 ); subRound2( 23 );
+    subRound2( 24 ); subRound2( 25 ); subRound2( 26 ); subRound2( 27 );
+    subRound2( 28 ); subRound2( 29 ); subRound2( 30 ); subRound2( 31 );
+    subRound2( 32 ); subRound2( 33 ); subRound2( 34 ); subRound2( 35 );
+    subRound2( 36 ); subRound2( 37 ); subRound2( 38 ); subRound2( 39 );
+}
+
+void do_Round3(LONG *W)
+{
+    LONG temp;
+    subRound3( 40 ); subRound3( 41 ); subRound3( 42 ); subRound3( 43 );
+    subRound3( 44 ); subRound3( 45 ); subRound3( 46 ); subRound3( 47 );
+    subRound3( 48 ); subRound3( 49 ); subRound3( 50 ); subRound3( 51 );
+    subRound3( 52 ); subRound3( 53 ); subRound3( 54 ); subRound3( 55 );
+    subRound3( 56 ); subRound3( 57 ); subRound3( 58 ); subRound3( 59 );
+}
+
+void do_Round4(LONG *W)
+{
+    LONG temp;
+    subRound4( 60 ); subRound4( 61 ); subRound4( 62 ); subRound4( 63 );
+    subRound4( 64 ); subRound4( 65 ); subRound4( 66 ); subRound4( 67 );
+    subRound4( 68 ); subRound4( 69 ); subRound4( 70 ); subRound4( 71 );
+    subRound4( 72 ); subRound4( 73 ); subRound4( 74 ); subRound4( 75 );
+    subRound4( 76 ); subRound4( 77 ); subRound4( 78 ); subRound4( 79 );
+}
+
+#endif
+
 /* Perform the SHS transformation.  Note that this code, like MD5, seems to
    break some optimizing compilers - it may be necessary to split it into
    sections, eg based on the four subrounds */
@@ -163,6 +249,9 @@
 	W[ i ] = shsInfo->data[ i ];
 
     /* Step B.  Expand the 16 words into 64 temporary data words */
+#ifdef __sparc_v9__
+    expand1(W); expand2(W); expand3(W); expand4(W);
+#else
     expand( 16 ); expand( 17 ); expand( 18 ); expand( 19 ); expand( 20 );
     expand( 21 ); expand( 22 ); expand( 23 ); expand( 24 ); expand( 25 );
     expand( 26 ); expand( 27 ); expand( 28 ); expand( 29 ); expand( 30 );
@@ -176,6 +265,7 @@
     expand( 66 ); expand( 67 ); expand( 68 ); expand( 69 ); expand( 70 );
     expand( 71 ); expand( 72 ); expand( 73 ); expand( 74 ); expand( 75 );
     expand( 76 ); expand( 77 ); expand( 78 ); expand( 79 );
+#endif
 
     /* Step C.  Set up first buffer */
     A = shsInfo->digest[ 0 ];
@@ -185,6 +275,9 @@
     E = shsInfo->digest[ 4 ];
 
     /* Step D.  Serious mangling, divided into four sub-rounds */
+#ifdef __sparc_v9__
+    do_Round1(W); do_Round2(W); do_Round3(W); do_Round4(W);
+#else
     subRound1( 0 ); subRound1( 1 ); subRound1( 2 ); subRound1( 3 );
     subRound1( 4 ); subRound1( 5 ); subRound1( 6 ); subRound1( 7 );
     subRound1( 8 ); subRound1( 9 ); subRound1( 10 ); subRound1( 11 );
@@ -205,6 +298,7 @@
     subRound4( 68 ); subRound4( 69 ); subRound4( 70 ); subRound4( 71 );
     subRound4( 72 ); subRound4( 73 ); subRound4( 74 ); subRound4( 75 );
     subRound4( 76 ); subRound4( 77 ); subRound4( 78 ); subRound4( 79 );
+#endif
 
     /* Step E.  Build message digest */
     shsInfo->digest[ 0 ] += A;
@@ -214,7 +308,7 @@
     shsInfo->digest[ 4 ] += E;
     }
 
-#ifdef LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
 
 /* When run on a little-endian CPU we need to perform byte reversal on an
    array of longwords.  It is possible to make the code endianness-
@@ -258,7 +352,7 @@
     while( count >= SHS_BLOCKSIZE )
 	{
 	memcpy( (char *) shsInfo->data, (char *) buffer, SHS_BLOCKSIZE );
-#ifdef LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
 	byteReverse( shsInfo->data, SHS_BLOCKSIZE );
 #endif /* LITTLE_ENDIAN */
 	shsTransform( shsInfo );
@@ -289,7 +383,7 @@
 	{
 	/* Two lots of padding:  Pad the first block to 64 bytes */
 	memset( ( char * ) shsInfo->data + count, 0, 64 - count );
-#ifdef LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
 	byteReverse( shsInfo->data, SHS_BLOCKSIZE );
 #endif /* LITTLE_ENDIAN */
 	shsTransform( shsInfo );
@@ -300,7 +394,7 @@
     else
 	/* Pad block to 56 bytes */
 	memset( ( char * ) shsInfo->data + count, 0, 56 - count );
-#ifdef LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
     byteReverse( shsInfo->data, SHS_BLOCKSIZE );
 #endif /* LITTLE_ENDIAN */
 
@@ -309,7 +403,7 @@
     shsInfo->data[ 15 ] = lowBitcount;
 
     shsTransform( shsInfo );
-#ifdef LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
     byteReverse( shsInfo->data, SHS_DIGESTSIZE );
 #endif /* LITTLE_ENDIAN */
     }