Back to home page

LXR

 
 

    


0001 #include <linux/compiler.h>
0002 #include <linux/export.h>
0003 #include <linux/cryptohash.h>
0004 #include <linux/bitops.h>
0005 
0006 /* F, G and H are basic MD4 functions: selection, majority, parity */
0007 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
0008 #define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
0009 #define H(x, y, z) ((x) ^ (y) ^ (z))
0010 
0011 /*
0012  * The generic round function.  The application is so specific that
0013  * we don't bother protecting all the arguments with parens, as is generally
0014  * good macro practice, in favor of extra legibility.
0015  * Rotation is separate from addition to prevent recomputation
0016  */
0017 #define ROUND(f, a, b, c, d, x, s)  \
0018     (a += f(b, c, d) + x, a = rol32(a, s))
0019 #define K1 0
0020 #define K2 013240474631UL
0021 #define K3 015666365641UL
0022 
0023 /*
0024  * Basic cut-down MD4 transform.  Returns only 32 bits of result.
0025  */
0026 __u32 half_md4_transform(__u32 buf[4], __u32 const in[8])
0027 {
0028     __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
0029 
0030     /* Round 1 */
0031     ROUND(F, a, b, c, d, in[0] + K1,  3);
0032     ROUND(F, d, a, b, c, in[1] + K1,  7);
0033     ROUND(F, c, d, a, b, in[2] + K1, 11);
0034     ROUND(F, b, c, d, a, in[3] + K1, 19);
0035     ROUND(F, a, b, c, d, in[4] + K1,  3);
0036     ROUND(F, d, a, b, c, in[5] + K1,  7);
0037     ROUND(F, c, d, a, b, in[6] + K1, 11);
0038     ROUND(F, b, c, d, a, in[7] + K1, 19);
0039 
0040     /* Round 2 */
0041     ROUND(G, a, b, c, d, in[1] + K2,  3);
0042     ROUND(G, d, a, b, c, in[3] + K2,  5);
0043     ROUND(G, c, d, a, b, in[5] + K2,  9);
0044     ROUND(G, b, c, d, a, in[7] + K2, 13);
0045     ROUND(G, a, b, c, d, in[0] + K2,  3);
0046     ROUND(G, d, a, b, c, in[2] + K2,  5);
0047     ROUND(G, c, d, a, b, in[4] + K2,  9);
0048     ROUND(G, b, c, d, a, in[6] + K2, 13);
0049 
0050     /* Round 3 */
0051     ROUND(H, a, b, c, d, in[3] + K3,  3);
0052     ROUND(H, d, a, b, c, in[7] + K3,  9);
0053     ROUND(H, c, d, a, b, in[2] + K3, 11);
0054     ROUND(H, b, c, d, a, in[6] + K3, 15);
0055     ROUND(H, a, b, c, d, in[1] + K3,  3);
0056     ROUND(H, d, a, b, c, in[5] + K3,  9);
0057     ROUND(H, c, d, a, b, in[0] + K3, 11);
0058     ROUND(H, b, c, d, a, in[4] + K3, 15);
0059 
0060     buf[0] += a;
0061     buf[1] += b;
0062     buf[2] += c;
0063     buf[3] += d;
0064 
0065     return buf[1]; /* "most hashed" word */
0066 }
0067 EXPORT_SYMBOL(half_md4_transform);