Mercurial > hg > toybox
annotate toys/lsb/md5sum.c @ 694:786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 38e07dba9b20 |
children | 5bdd2ee6f3c4 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
685
diff
changeset
|
1 /* md5sum.c - Calculate RFC 1321 md5 hash and sha1 hash. |
680
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2012 Rob Landley <rob@landley.net> |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/md5sum.html |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 * and http://www.ietf.org/rfc/rfc1321.txt |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 * |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 * They're combined this way to share infrastructure, and because md5sum is |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 * and LSB standard command, sha1sum is just a good idea. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 USE_MD5SUM(NEWTOY(md5sum, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 USE_MD5SUM_SHA1SUM(OLDTOY(sha1sum, md5sum, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 config MD5SUM |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 bool "md5sum" |
685
38e07dba9b20
Make sha1sum and md5sum default to y.
Rob Landley <rob@landley.net>
parents:
680
diff
changeset
|
16 default y |
680
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 help |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 usage: md5sum [FILE]... |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 Calculate md5 hash for each input file, reading from stdin if none. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 Output one hash (16 hex digits) for each input file, followed by |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 filename. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 config MD5SUM_SHA1SUM |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 bool "sha1sum" |
685
38e07dba9b20
Make sha1sum and md5sum default to y.
Rob Landley <rob@landley.net>
parents:
680
diff
changeset
|
26 default y |
680
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 depends on MD5SUM |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 help |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 usage: sha1sum [FILE]... |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 calculate sha1 hash for each input file, reading from stdin if one. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 Output one hash (20 hex digits) for each input file, followed by |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 filename. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 */ |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 #define FOR_md5sum |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 #include "toys.h" |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 GLOBALS( |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 unsigned state[5]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 unsigned oldstate[5]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 uint64_t count; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 union { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 char c[64]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 unsigned i[16]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 } buffer; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 ) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 // for(i=0; i<64; i++) md5table[i] = abs(sin(i+1))*(1<<32); But calculating |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 // that involves not just floating point but pulling in -lm (and arguing with |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 // C about whether 1<<32 is a valid thing to do on 32 bit platforms) so: |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 static uint32_t md5table[64] = { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 }; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 // Mix next 64 bytes of data into md5 hash |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 static void md5_transform(void) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 unsigned x[4], *b = (unsigned *)TT.buffer.c; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 int i; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 memcpy(x, TT.state, sizeof(x)); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 for (i=0; i<64; i++) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 unsigned int in, a, rot, temp; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 a = (-i)&3; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 if (i<16) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 in = i; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 rot = 7+(5*(i&3)); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 temp = x[(a+1)&3]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 temp = (temp & x[(a+2)&3]) | ((~temp) & x[(a+3)&3]); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 } else if (i<32) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 in = (1+(5*i))&15; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 temp = (i&3)+1; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 rot = temp*5; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 if (temp&2) rot--; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 temp = x[(a+3)&3]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 temp = (x[(a+1)&3] & temp) | (x[(a+2)&3] & ~temp); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 } else if (i<48) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 in = (5+(3*(i&15)))&15; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 rot = i&3; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 rot = 4+(5*rot)+((rot+1)&6); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 temp = x[(a+1)&3] ^ x[(a+2)&3] ^ x[(a+3)&3]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 } else { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 in = (7*(i&15))&15; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 rot = (i&3)+1; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 rot = (5*rot)+(((rot+2)&2)>>1); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 temp = x[(a+2)&3] ^ (x[(a+1)&3] | ~x[(a+3)&3]); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 temp += x[a] + b[in] + md5table[i]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 x[a] = x[(a+1)&3] + ((temp<<rot) | (temp>>(32-rot))); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 for (i=0; i<4; i++) TT.state[i] += x[i]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 // Mix next 64 bytes of data into sha1 hash. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 static const unsigned rconsts[]={0x5A827999,0x6ED9EBA1,0x8F1BBCDC,0xCA62C1D6}; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 static void sha1_transform(void) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 int i, j, k, count; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 unsigned *block = TT.buffer.i; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 unsigned *rot[5], *temp; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 // Copy context->state[] to working vars |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 for (i=0; i<5; i++) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 TT.oldstate[i] = TT.state[i]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 rot[i] = TT.state + i; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 // 4 rounds of 20 operations each. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 for (i=count=0; i<4; i++) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 for (j=0; j<20; j++) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 unsigned work; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 work = *rot[2] ^ *rot[3]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 if (!i) work = (work & *rot[1]) ^ *rot[3]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 else { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 if (i==2) work = ((*rot[1]|*rot[2])&*rot[3])|(*rot[1]&*rot[2]); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 else work ^= *rot[1]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 if (!i && j<16) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 work += block[count] = (rol(block[count],24)&0xFF00FF00) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 | (rol(block[count],8)&0x00FF00FF); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 else |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 work += block[count&15] = rol(block[(count+13)&15] |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 ^ block[(count+8)&15] ^ block[(count+2)&15] ^ block[count&15], 1); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 *rot[4] += work + rol(*rot[0],5) + rconsts[i]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 *rot[1] = rol(*rot[1],30); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 // Rotate by one for next time. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 temp = rot[4]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 for (k=4; k; k--) rot[k] = rot[k-1]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 *rot = temp; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 count++; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 // Add the previous values of state[] |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 for (i=0; i<5; i++) TT.state[i] += TT.oldstate[i]; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 // Fill the 64-byte working buffer and call transform() when full. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 static void hash_update(char *data, unsigned int len, void (*transform)(void)) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 unsigned int i, j; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 j = TT.count & 63; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 TT.count += len; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 // Enough data to process a frame? |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 if ((j + len) > 63) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 i = 64-j; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 memcpy(TT.buffer.c + j, data, i); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 transform(); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 for ( ; i + 63 < len; i += 64) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 memcpy(TT.buffer.c, data + i, 64); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 transform(); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 j = 0; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 } else i = 0; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 // Grab remaining chunk |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 memcpy(TT.buffer.c + j, data + i, len - i); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
179 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 // Callback for loopfiles() |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 static void do_hash(int fd, char *name) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 uint64_t count; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 int i, sha1=toys.which->name[0]=='s';; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 char buf; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 void (*transform)(void); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 /* SHA1 initialization constants (md5sum uses first 4) */ |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
191 TT.state[0] = 0x67452301; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 TT.state[1] = 0xEFCDAB89; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 TT.state[2] = 0x98BADCFE; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 TT.state[3] = 0x10325476; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 TT.state[4] = 0xC3D2E1F0; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
196 TT.count = 0; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
197 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 transform = sha1 ? sha1_transform : md5_transform; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 for (;;) { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
200 i = read(fd, toybuf, sizeof(toybuf)); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 if (i<1) break; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 hash_update(toybuf, i, transform); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
203 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 count = TT.count << 3; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
207 // End the message by appending a "1" bit to the data, ending with the |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
208 // message size (in bits, big endian), and adding enough zero bits in |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 // between to pad to the end of the next 64-byte frame. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
210 // |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 // Since our input up to now has been in whole bytes, we can deal with |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 // bytes here too. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 buf = 0x80; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 do { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 hash_update(&buf, 1, transform); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 buf = 0; |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 } while ((TT.count & 63) != 56); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 if (sha1) count=bswap_64(count); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
685
diff
changeset
|
220 for (i = 0; i < 8; i++) TT.buffer.c[56+i] = count >> (8*i); |
680
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 transform(); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 if (sha1) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
224 for (i = 0; i < 20; i++) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 printf("%02x", 255&(TT.state[i>>2] >> ((3-(i & 3)) * 8))); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 else for (i=0; i<4; i++) printf("%08x", SWAP_BE32(TT.state[i])); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
228 // Wipe variables. Cryptographer paranoia. |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
229 memset(&TT, 0, sizeof(TT)); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
230 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
231 printf(" %s\n", name); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
232 } |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 void md5sum_main(void) |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 { |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 loopfiles(toys.optargs, do_hash); |
ff2cf02d9703
Add md5sum in lsb, combine sha1sum (mostly shared infrastructure). Downside: current infrastructure can't give them different help text. Hmmm...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 } |