History

posix-arm: new directory, with tas.c from Skip Tavakkolian

R=rsc http://codereview.appspot.com/6408043

Russ Cox committed 14 years ago

Commit 2ca76dc1 parent e64d4885 files · +525 −0Browse files

Unified · Split

5 files
  1. posix-arm/Makefile +25 −0
  2. posix-arm/getcallerpc.c +8 −0
  3. posix-arm/md5block.c +268 −0
  4. posix-arm/sha1block.c +189 −0
  5. posix-arm/tas.c +35 −0
posix-arm/Makefile+25−0
@@ -0,0 +1,25 @@
1+ROOT=..
2+include ../Make.config
3+LIB=../libmachdep.a
4+
5+OFILES=\
6+ getcallerpc.$O\
7+ md5block.$O\
8+ sha1block.$O\
9+ tas.$O
10+
11+default: $(LIB)
12+$(LIB): $(OFILES)
13+ $(AR) r $(LIB) $(OFILES)
14+ $(RANLIB) $(LIB)
15+
16+%.$O: %.c
17+ $(CC) $(CFLAGS) $*.c
18+
19+%.$O: %.s
20+ $(AS) -o $*.$O $*.s
21+
22+%.s: %.spp
23+ cpp $*.spp >$*.s
24+
25+
posix-arm/getcallerpc.c+8−0
@@ -0,0 +1,8 @@
1+#include "u.h"
2+#include "libc.h"
3+
4+uintptr
5+getcallerpc(void *a)
6+{
7+ return ((uintptr*)a)[-1];
8+}
posix-arm/md5block.c+268−0
@@ -0,0 +1,268 @@
1+#include <u.h>
2+#include <libc.h>
3+#include <libsec.h>
4+
5+/*
6+ * rfc1321 requires that I include this. The code is new. The constants
7+ * all come from the rfc (hence the copyright). We trade a table for the
8+ * macros in rfc. The total size is a lot less. -- presotto
9+ *
10+ * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
11+ * rights reserved.
12+ *
13+ * License to copy and use this software is granted provided that it
14+ * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
15+ * Algorithm" in all material mentioning or referencing this software
16+ * or this function.
17+ *
18+ * License is also granted to make and use derivative works provided
19+ * that such works are identified as "derived from the RSA Data
20+ * Security, Inc. MD5 Message-Digest Algorithm" in all material
21+ * mentioning or referencing the derived work.
22+ *
23+ * RSA Data Security, Inc. makes no representations concerning either
24+ * the merchantability of this software or the suitability of this
25+ * software forany particular purpose. It is provided "as is"
26+ * without express or implied warranty of any kind.
27+ * These notices must be retained in any copies of any part of this
28+ * documentation and/or software.
29+ */
30+
31+/*
32+ * Rotate ammounts used in the algorithm
33+ */
34+enum
35+{
36+ S11= 7,
37+ S12= 12,
38+ S13= 17,
39+ S14= 22,
40+
41+ S21= 5,
42+ S22= 9,
43+ S23= 14,
44+ S24= 20,
45+
46+ S31= 4,
47+ S32= 11,
48+ S33= 16,
49+ S34= 23,
50+
51+ S41= 6,
52+ S42= 10,
53+ S43= 15,
54+ S44= 21,
55+};
56+
57+static u32int md5tab[] =
58+{
59+ /* round 1 */
60+/*[0]*/ 0xd76aa478,
61+ 0xe8c7b756,
62+ 0x242070db,
63+ 0xc1bdceee,
64+ 0xf57c0faf,
65+ 0x4787c62a,
66+ 0xa8304613,
67+ 0xfd469501,
68+ 0x698098d8,
69+ 0x8b44f7af,
70+ 0xffff5bb1,
71+ 0x895cd7be,
72+ 0x6b901122,
73+ 0xfd987193,
74+ 0xa679438e,
75+ 0x49b40821,
76+
77+ /* round 2 */
78+/*[16]*/0xf61e2562,
79+ 0xc040b340,
80+ 0x265e5a51,
81+ 0xe9b6c7aa,
82+ 0xd62f105d,
83+ 0x2441453,
84+ 0xd8a1e681,
85+ 0xe7d3fbc8,
86+ 0x21e1cde6,
87+ 0xc33707d6,
88+ 0xf4d50d87,
89+ 0x455a14ed,
90+ 0xa9e3e905,
91+ 0xfcefa3f8,
92+ 0x676f02d9,
93+ 0x8d2a4c8a,
94+
95+ /* round 3 */
96+/*[32]*/0xfffa3942,
97+ 0x8771f681,
98+ 0x6d9d6122,
99+ 0xfde5380c,
100+ 0xa4beea44,
101+ 0x4bdecfa9,
102+ 0xf6bb4b60,
103+ 0xbebfbc70,
104+ 0x289b7ec6,
105+ 0xeaa127fa,
106+ 0xd4ef3085,
107+ 0x4881d05,
108+ 0xd9d4d039,
109+ 0xe6db99e5,
110+ 0x1fa27cf8,
111+ 0xc4ac5665,
112+
113+ /* round 4 */
114+/*[48]*/0xf4292244,
115+ 0x432aff97,
116+ 0xab9423a7,
117+ 0xfc93a039,
118+ 0x655b59c3,
119+ 0x8f0ccc92,
120+ 0xffeff47d,
121+ 0x85845dd1,
122+ 0x6fa87e4f,
123+ 0xfe2ce6e0,
124+ 0xa3014314,
125+ 0x4e0811a1,
126+ 0xf7537e82,
127+ 0xbd3af235,
128+ 0x2ad7d2bb,
129+ 0xeb86d391,
130+};
131+
132+static void decode(u32int*, uchar*, ulong);
133+extern void _md5block(uchar *p, ulong len, u32int *s);
134+
135+void
136+_md5block(uchar *p, ulong len, u32int *s)
137+{
138+ u32int a, b, c, d, sh;
139+ u32int *t;
140+ uchar *end;
141+ u32int x[16];
142+
143+ for(end = p+len; p < end; p += 64){
144+ a = s[0];
145+ b = s[1];
146+ c = s[2];
147+ d = s[3];
148+
149+ decode(x, p, 64);
150+
151+ t = md5tab;
152+ sh = 0;
153+ for(; sh != 16; t += 4){
154+ a += ((c ^ d) & b) ^ d;
155+ a += x[sh] + t[0];
156+ a = (a << S11) | (a >> (32 - S11));
157+ a += b;
158+
159+ d += ((b ^ c) & a) ^ c;
160+ d += x[sh + 1] + t[1];
161+ d = (d << S12) | (d >> (32 - S12));
162+ d += a;
163+
164+ c += ((a ^ b) & d) ^ b;
165+ c += x[sh + 2] + t[2];
166+ c = (c << S13) | (c >> (32 - S13));
167+ c += d;
168+
169+ b += ((d ^ a) & c) ^ a;
170+ b += x[sh + 3] + t[3];
171+ b = (b << S14) | (b >> (32 - S14));
172+ b += c;
173+
174+ sh += 4;
175+ }
176+ sh = 1;
177+ for(; sh != 1+20*4; t += 4){
178+ a += ((b ^ c) & d) ^ c;
179+ a += x[sh & 0xf] + t[0];
180+ a = (a << S21) | (a >> (32 - S21));
181+ a += b;
182+
183+ d += ((a ^ b) & c) ^ b;
184+ d += x[(sh + 5) & 0xf] + t[1];
185+ d = (d << S22) | (d >> (32 - S22));
186+ d += a;
187+
188+ c += ((d ^ a) & b) ^ a;
189+ c += x[(sh + 10) & 0xf] + t[2];
190+ c = (c << S23) | (c >> (32 - S23));
191+ c += d;
192+
193+ b += ((c ^ d) & a) ^ d;
194+ b += x[(sh + 15) & 0xf] + t[3];
195+ b = (b << S24) | (b >> (32 - S24));
196+ b += c;
197+
198+ sh += 20;
199+ }
200+ sh = 5;
201+ for(; sh != 5+12*4; t += 4){
202+ a += b ^ c ^ d;
203+ a += x[sh & 0xf] + t[0];
204+ a = (a << S31) | (a >> (32 - S31));
205+ a += b;
206+
207+ d += a ^ b ^ c;
208+ d += x[(sh + 3) & 0xf] + t[1];
209+ d = (d << S32) | (d >> (32 - S32));
210+ d += a;
211+
212+ c += d ^ a ^ b;
213+ c += x[(sh + 6) & 0xf] + t[2];
214+ c = (c << S33) | (c >> (32 - S33));
215+ c += d;
216+
217+ b += c ^ d ^ a;
218+ b += x[(sh + 9) & 0xf] + t[3];
219+ b = (b << S34) | (b >> (32 - S34));
220+ b += c;
221+
222+ sh += 12;
223+ }
224+ sh = 0;
225+ for(; sh != 28*4; t += 4){
226+ a += c ^ (b | ~d);
227+ a += x[sh & 0xf] + t[0];
228+ a = (a << S41) | (a >> (32 - S41));
229+ a += b;
230+
231+ d += b ^ (a | ~c);
232+ d += x[(sh + 7) & 0xf] + t[1];
233+ d = (d << S42) | (d >> (32 - S42));
234+ d += a;
235+
236+ c += a ^ (d | ~b);
237+ c += x[(sh + 14) & 0xf] + t[2];
238+ c = (c << S43) | (c >> (32 - S43));
239+ c += d;
240+
241+ b += d ^ (c | ~a);
242+ b += x[(sh + 21) & 0xf] + t[3];
243+ b = (b << S44) | (b >> (32 - S44));
244+ b += c;
245+
246+ sh += 28;
247+ }
248+
249+ s[0] += a;
250+ s[1] += b;
251+ s[2] += c;
252+ s[3] += d;
253+ }
254+}
255+
256+/*
257+ * decodes input (uchar) into output (u32int). Assumes len is
258+ * a multiple of 4.
259+ */
260+static void
261+decode(u32int *output, uchar *input, ulong len)
262+{
263+ uchar *e;
264+
265+ for(e = input+len; input < e; input += 4)
266+ *output++ = input[0] | (input[1] << 8) |
267+ (input[2] << 16) | (input[3] << 24);
268+}
posix-arm/sha1block.c+189−0
@@ -0,0 +1,189 @@
1+#include <u.h>
2+#include <libc.h>
3+#include <libsec.h>
4+
5+void
6+_sha1block(uchar *p, ulong len, u32int *s)
7+{
8+ u32int a, b, c, d, e, x;
9+ uchar *end;
10+ u32int *wp, *wend;
11+ u32int w[80];
12+
13+ /* at this point, we have a multiple of 64 bytes */
14+ for(end = p+len; p < end;){
15+ a = s[0];
16+ b = s[1];
17+ c = s[2];
18+ d = s[3];
19+ e = s[4];
20+
21+ wend = w + 15;
22+ for(wp = w; wp < wend; wp += 5){
23+ wp[0] = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
24+ e += ((a<<5) | (a>>27)) + wp[0];
25+ e += 0x5a827999 + (((c^d)&b)^d);
26+ b = (b<<30)|(b>>2);
27+
28+ wp[1] = (p[4]<<24) | (p[5]<<16) | (p[6]<<8) | p[7];
29+ d += ((e<<5) | (e>>27)) + wp[1];
30+ d += 0x5a827999 + (((b^c)&a)^c);
31+ a = (a<<30)|(a>>2);
32+
33+ wp[2] = (p[8]<<24) | (p[9]<<16) | (p[10]<<8) | p[11];
34+ c += ((d<<5) | (d>>27)) + wp[2];
35+ c += 0x5a827999 + (((a^b)&e)^b);
36+ e = (e<<30)|(e>>2);
37+
38+ wp[3] = (p[12]<<24) | (p[13]<<16) | (p[14]<<8) | p[15];
39+ b += ((c<<5) | (c>>27)) + wp[3];
40+ b += 0x5a827999 + (((e^a)&d)^a);
41+ d = (d<<30)|(d>>2);
42+
43+ wp[4] = (p[16]<<24) | (p[17]<<16) | (p[18]<<8) | p[19];
44+ a += ((b<<5) | (b>>27)) + wp[4];
45+ a += 0x5a827999 + (((d^e)&c)^e);
46+ c = (c<<30)|(c>>2);
47+
48+ p += 20;
49+ }
50+
51+ wp[0] = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
52+ e += ((a<<5) | (a>>27)) + wp[0];
53+ e += 0x5a827999 + (((c^d)&b)^d);
54+ b = (b<<30)|(b>>2);
55+
56+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
57+ wp[1] = (x<<1) | (x>>31);
58+ d += ((e<<5) | (e>>27)) + wp[1];
59+ d += 0x5a827999 + (((b^c)&a)^c);
60+ a = (a<<30)|(a>>2);
61+
62+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
63+ wp[2] = (x<<1) | (x>>31);
64+ c += ((d<<5) | (d>>27)) + wp[2];
65+ c += 0x5a827999 + (((a^b)&e)^b);
66+ e = (e<<30)|(e>>2);
67+
68+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
69+ wp[3] = (x<<1) | (x>>31);
70+ b += ((c<<5) | (c>>27)) + wp[3];
71+ b += 0x5a827999 + (((e^a)&d)^a);
72+ d = (d<<30)|(d>>2);
73+
74+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
75+ wp[4] = (x<<1) | (x>>31);
76+ a += ((b<<5) | (b>>27)) + wp[4];
77+ a += 0x5a827999 + (((d^e)&c)^e);
78+ c = (c<<30)|(c>>2);
79+
80+ wp += 5;
81+ p += 4;
82+
83+ wend = w + 40;
84+ for(; wp < wend; wp += 5){
85+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
86+ wp[0] = (x<<1) | (x>>31);
87+ e += ((a<<5) | (a>>27)) + wp[0];
88+ e += 0x6ed9eba1 + (b^c^d);
89+ b = (b<<30)|(b>>2);
90+
91+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
92+ wp[1] = (x<<1) | (x>>31);
93+ d += ((e<<5) | (e>>27)) + wp[1];
94+ d += 0x6ed9eba1 + (a^b^c);
95+ a = (a<<30)|(a>>2);
96+
97+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
98+ wp[2] = (x<<1) | (x>>31);
99+ c += ((d<<5) | (d>>27)) + wp[2];
100+ c += 0x6ed9eba1 + (e^a^b);
101+ e = (e<<30)|(e>>2);
102+
103+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
104+ wp[3] = (x<<1) | (x>>31);
105+ b += ((c<<5) | (c>>27)) + wp[3];
106+ b += 0x6ed9eba1 + (d^e^a);
107+ d = (d<<30)|(d>>2);
108+
109+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
110+ wp[4] = (x<<1) | (x>>31);
111+ a += ((b<<5) | (b>>27)) + wp[4];
112+ a += 0x6ed9eba1 + (c^d^e);
113+ c = (c<<30)|(c>>2);
114+ }
115+
116+ wend = w + 60;
117+ for(; wp < wend; wp += 5){
118+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
119+ wp[0] = (x<<1) | (x>>31);
120+ e += ((a<<5) | (a>>27)) + wp[0];
121+ e += 0x8f1bbcdc + ((b&c)|((b|c)&d));
122+ b = (b<<30)|(b>>2);
123+
124+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
125+ wp[1] = (x<<1) | (x>>31);
126+ d += ((e<<5) | (e>>27)) + wp[1];
127+ d += 0x8f1bbcdc + ((a&b)|((a|b)&c));
128+ a = (a<<30)|(a>>2);
129+
130+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
131+ wp[2] = (x<<1) | (x>>31);
132+ c += ((d<<5) | (d>>27)) + wp[2];
133+ c += 0x8f1bbcdc + ((e&a)|((e|a)&b));
134+ e = (e<<30)|(e>>2);
135+
136+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
137+ wp[3] = (x<<1) | (x>>31);
138+ b += ((c<<5) | (c>>27)) + wp[3];
139+ b += 0x8f1bbcdc + ((d&e)|((d|e)&a));
140+ d = (d<<30)|(d>>2);
141+
142+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
143+ wp[4] = (x<<1) | (x>>31);
144+ a += ((b<<5) | (b>>27)) + wp[4];
145+ a += 0x8f1bbcdc + ((c&d)|((c|d)&e));
146+ c = (c<<30)|(c>>2);
147+ }
148+
149+ wend = w + 80;
150+ for(; wp < wend; wp += 5){
151+ x = wp[-3] ^ wp[-8] ^ wp[-14] ^ wp[-16];
152+ wp[0] = (x<<1) | (x>>31);
153+ e += ((a<<5) | (a>>27)) + wp[0];
154+ e += 0xca62c1d6 + (b^c^d);
155+ b = (b<<30)|(b>>2);
156+
157+ x = wp[-2] ^ wp[-7] ^ wp[-13] ^ wp[-15];
158+ wp[1] = (x<<1) | (x>>31);
159+ d += ((e<<5) | (e>>27)) + wp[1];
160+ d += 0xca62c1d6 + (a^b^c);
161+ a = (a<<30)|(a>>2);
162+
163+ x = wp[-1] ^ wp[-6] ^ wp[-12] ^ wp[-14];
164+ wp[2] = (x<<1) | (x>>31);
165+ c += ((d<<5) | (d>>27)) + wp[2];
166+ c += 0xca62c1d6 + (e^a^b);
167+ e = (e<<30)|(e>>2);
168+
169+ x = wp[0] ^ wp[-5] ^ wp[-11] ^ wp[-13];
170+ wp[3] = (x<<1) | (x>>31);
171+ b += ((c<<5) | (c>>27)) + wp[3];
172+ b += 0xca62c1d6 + (d^e^a);
173+ d = (d<<30)|(d>>2);
174+
175+ x = wp[1] ^ wp[-4] ^ wp[-10] ^ wp[-12];
176+ wp[4] = (x<<1) | (x>>31);
177+ a += ((b<<5) | (b>>27)) + wp[4];
178+ a += 0xca62c1d6 + (c^d^e);
179+ c = (c<<30)|(c>>2);
180+ }
181+
182+ /* save state */
183+ s[0] += a;
184+ s[1] += b;
185+ s[2] += c;
186+ s[3] += d;
187+ s[4] += e;
188+ }
189+}
posix-arm/tas.c+35−0
@@ -0,0 +1,35 @@
1+#include "u.h"
2+#include "libc.h"
3+
4+int
5+tas(long *x)
6+{
7+ int v, t, i = 1;
8+
9+#if ARMv5
10+ __asm__(
11+ "swp %0, %1, [%2]"
12+ : "=&r" (v)
13+ : "r" (1), "r" (x)
14+ : "memory"
15+ );
16+#else
17+ __asm__ (
18+ "1: ldrex %0, [%2]\n"
19+ " strex %1, %3, [%2]\n"
20+ " teq %1, #0\n"
21+ " bne 1b"
22+ : "=&r" (v), "=&r" (t)
23+ : "r" (x), "r" (i)
24+ : "cc");
25+#endif
26+ switch(v) {
27+ case 0:
28+ case 1:
29+ return v;
30+ default:
31+ print("canlock: corrupted 0x%lux\n", v);
32+ return 1;
33+ }
34+}
35+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t