This is a port of cyaSSL 2.7.0.
Dependents: CyaSSL_DTLS_Cellular CyaSSL_DTLS_Ethernet
ctaocrypt/src/ripemd.c@0:714293de3836, 2013-09-05 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 05 10:33:04 2013 +0000
- Revision:
- 0:714293de3836
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:714293de3836 | 1 | /* ripemd.c |
ashleymills | 0:714293de3836 | 2 | * |
ashleymills | 0:714293de3836 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
ashleymills | 0:714293de3836 | 4 | * |
ashleymills | 0:714293de3836 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:714293de3836 | 6 | * |
ashleymills | 0:714293de3836 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:714293de3836 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:714293de3836 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:714293de3836 | 10 | * (at your option) any later version. |
ashleymills | 0:714293de3836 | 11 | * |
ashleymills | 0:714293de3836 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:714293de3836 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:714293de3836 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:714293de3836 | 15 | * GNU General Public License for more details. |
ashleymills | 0:714293de3836 | 16 | * |
ashleymills | 0:714293de3836 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:714293de3836 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:714293de3836 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:714293de3836 | 20 | */ |
ashleymills | 0:714293de3836 | 21 | |
ashleymills | 0:714293de3836 | 22 | |
ashleymills | 0:714293de3836 | 23 | #ifdef HAVE_CONFIG_H |
ashleymills | 0:714293de3836 | 24 | #include <config.h> |
ashleymills | 0:714293de3836 | 25 | #endif |
ashleymills | 0:714293de3836 | 26 | |
ashleymills | 0:714293de3836 | 27 | #include <cyassl/ctaocrypt/settings.h> |
ashleymills | 0:714293de3836 | 28 | |
ashleymills | 0:714293de3836 | 29 | #ifdef CYASSL_RIPEMD |
ashleymills | 0:714293de3836 | 30 | |
ashleymills | 0:714293de3836 | 31 | #include <cyassl/ctaocrypt/ripemd.h> |
ashleymills | 0:714293de3836 | 32 | #ifdef NO_INLINE |
ashleymills | 0:714293de3836 | 33 | #include <cyassl/ctaocrypt/misc.h> |
ashleymills | 0:714293de3836 | 34 | #else |
ashleymills | 0:714293de3836 | 35 | #include <ctaocrypt/src/misc.c> |
ashleymills | 0:714293de3836 | 36 | #endif |
ashleymills | 0:714293de3836 | 37 | |
ashleymills | 0:714293de3836 | 38 | |
ashleymills | 0:714293de3836 | 39 | #ifndef min |
ashleymills | 0:714293de3836 | 40 | |
ashleymills | 0:714293de3836 | 41 | static INLINE word32 min(word32 a, word32 b) |
ashleymills | 0:714293de3836 | 42 | { |
ashleymills | 0:714293de3836 | 43 | return a > b ? b : a; |
ashleymills | 0:714293de3836 | 44 | } |
ashleymills | 0:714293de3836 | 45 | |
ashleymills | 0:714293de3836 | 46 | #endif /* min */ |
ashleymills | 0:714293de3836 | 47 | |
ashleymills | 0:714293de3836 | 48 | |
ashleymills | 0:714293de3836 | 49 | void InitRipeMd(RipeMd* ripemd) |
ashleymills | 0:714293de3836 | 50 | { |
ashleymills | 0:714293de3836 | 51 | ripemd->digest[0] = 0x67452301L; |
ashleymills | 0:714293de3836 | 52 | ripemd->digest[1] = 0xEFCDAB89L; |
ashleymills | 0:714293de3836 | 53 | ripemd->digest[2] = 0x98BADCFEL; |
ashleymills | 0:714293de3836 | 54 | ripemd->digest[3] = 0x10325476L; |
ashleymills | 0:714293de3836 | 55 | ripemd->digest[4] = 0xC3D2E1F0L; |
ashleymills | 0:714293de3836 | 56 | |
ashleymills | 0:714293de3836 | 57 | ripemd->buffLen = 0; |
ashleymills | 0:714293de3836 | 58 | ripemd->loLen = 0; |
ashleymills | 0:714293de3836 | 59 | ripemd->hiLen = 0; |
ashleymills | 0:714293de3836 | 60 | } |
ashleymills | 0:714293de3836 | 61 | |
ashleymills | 0:714293de3836 | 62 | |
ashleymills | 0:714293de3836 | 63 | /* for all */ |
ashleymills | 0:714293de3836 | 64 | #define F(x, y, z) (x ^ y ^ z) |
ashleymills | 0:714293de3836 | 65 | #define G(x, y, z) (z ^ (x & (y^z))) |
ashleymills | 0:714293de3836 | 66 | #define H(x, y, z) (z ^ (x | ~y)) |
ashleymills | 0:714293de3836 | 67 | #define I(x, y, z) (y ^ (z & (x^y))) |
ashleymills | 0:714293de3836 | 68 | #define J(x, y, z) (x ^ (y | ~z)) |
ashleymills | 0:714293de3836 | 69 | |
ashleymills | 0:714293de3836 | 70 | #define k0 0 |
ashleymills | 0:714293de3836 | 71 | #define k1 0x5a827999 |
ashleymills | 0:714293de3836 | 72 | #define k2 0x6ed9eba1 |
ashleymills | 0:714293de3836 | 73 | #define k3 0x8f1bbcdc |
ashleymills | 0:714293de3836 | 74 | #define k4 0xa953fd4e |
ashleymills | 0:714293de3836 | 75 | #define k5 0x50a28be6 |
ashleymills | 0:714293de3836 | 76 | #define k6 0x5c4dd124 |
ashleymills | 0:714293de3836 | 77 | #define k7 0x6d703ef3 |
ashleymills | 0:714293de3836 | 78 | #define k8 0x7a6d76e9 |
ashleymills | 0:714293de3836 | 79 | #define k9 0 |
ashleymills | 0:714293de3836 | 80 | |
ashleymills | 0:714293de3836 | 81 | /* for 160 and 320 */ |
ashleymills | 0:714293de3836 | 82 | #define Subround(f, a, b, c, d, e, x, s, k) \ |
ashleymills | 0:714293de3836 | 83 | a += f(b, c, d) + x + k;\ |
ashleymills | 0:714293de3836 | 84 | a = rotlFixed((word32)a, s) + e;\ |
ashleymills | 0:714293de3836 | 85 | c = rotlFixed((word32)c, 10U) |
ashleymills | 0:714293de3836 | 86 | |
ashleymills | 0:714293de3836 | 87 | static void Transform(RipeMd* ripemd) |
ashleymills | 0:714293de3836 | 88 | { |
ashleymills | 0:714293de3836 | 89 | word32 a1, b1, c1, d1, e1, a2, b2, c2, d2, e2; |
ashleymills | 0:714293de3836 | 90 | a1 = a2 = ripemd->digest[0]; |
ashleymills | 0:714293de3836 | 91 | b1 = b2 = ripemd->digest[1]; |
ashleymills | 0:714293de3836 | 92 | c1 = c2 = ripemd->digest[2]; |
ashleymills | 0:714293de3836 | 93 | d1 = d2 = ripemd->digest[3]; |
ashleymills | 0:714293de3836 | 94 | e1 = e2 = ripemd->digest[4]; |
ashleymills | 0:714293de3836 | 95 | |
ashleymills | 0:714293de3836 | 96 | Subround(F, a1, b1, c1, d1, e1, ripemd->buffer[ 0], 11, k0); |
ashleymills | 0:714293de3836 | 97 | Subround(F, e1, a1, b1, c1, d1, ripemd->buffer[ 1], 14, k0); |
ashleymills | 0:714293de3836 | 98 | Subround(F, d1, e1, a1, b1, c1, ripemd->buffer[ 2], 15, k0); |
ashleymills | 0:714293de3836 | 99 | Subround(F, c1, d1, e1, a1, b1, ripemd->buffer[ 3], 12, k0); |
ashleymills | 0:714293de3836 | 100 | Subround(F, b1, c1, d1, e1, a1, ripemd->buffer[ 4], 5, k0); |
ashleymills | 0:714293de3836 | 101 | Subround(F, a1, b1, c1, d1, e1, ripemd->buffer[ 5], 8, k0); |
ashleymills | 0:714293de3836 | 102 | Subround(F, e1, a1, b1, c1, d1, ripemd->buffer[ 6], 7, k0); |
ashleymills | 0:714293de3836 | 103 | Subround(F, d1, e1, a1, b1, c1, ripemd->buffer[ 7], 9, k0); |
ashleymills | 0:714293de3836 | 104 | Subround(F, c1, d1, e1, a1, b1, ripemd->buffer[ 8], 11, k0); |
ashleymills | 0:714293de3836 | 105 | Subround(F, b1, c1, d1, e1, a1, ripemd->buffer[ 9], 13, k0); |
ashleymills | 0:714293de3836 | 106 | Subround(F, a1, b1, c1, d1, e1, ripemd->buffer[10], 14, k0); |
ashleymills | 0:714293de3836 | 107 | Subround(F, e1, a1, b1, c1, d1, ripemd->buffer[11], 15, k0); |
ashleymills | 0:714293de3836 | 108 | Subround(F, d1, e1, a1, b1, c1, ripemd->buffer[12], 6, k0); |
ashleymills | 0:714293de3836 | 109 | Subround(F, c1, d1, e1, a1, b1, ripemd->buffer[13], 7, k0); |
ashleymills | 0:714293de3836 | 110 | Subround(F, b1, c1, d1, e1, a1, ripemd->buffer[14], 9, k0); |
ashleymills | 0:714293de3836 | 111 | Subround(F, a1, b1, c1, d1, e1, ripemd->buffer[15], 8, k0); |
ashleymills | 0:714293de3836 | 112 | |
ashleymills | 0:714293de3836 | 113 | Subround(G, e1, a1, b1, c1, d1, ripemd->buffer[ 7], 7, k1); |
ashleymills | 0:714293de3836 | 114 | Subround(G, d1, e1, a1, b1, c1, ripemd->buffer[ 4], 6, k1); |
ashleymills | 0:714293de3836 | 115 | Subround(G, c1, d1, e1, a1, b1, ripemd->buffer[13], 8, k1); |
ashleymills | 0:714293de3836 | 116 | Subround(G, b1, c1, d1, e1, a1, ripemd->buffer[ 1], 13, k1); |
ashleymills | 0:714293de3836 | 117 | Subround(G, a1, b1, c1, d1, e1, ripemd->buffer[10], 11, k1); |
ashleymills | 0:714293de3836 | 118 | Subround(G, e1, a1, b1, c1, d1, ripemd->buffer[ 6], 9, k1); |
ashleymills | 0:714293de3836 | 119 | Subround(G, d1, e1, a1, b1, c1, ripemd->buffer[15], 7, k1); |
ashleymills | 0:714293de3836 | 120 | Subround(G, c1, d1, e1, a1, b1, ripemd->buffer[ 3], 15, k1); |
ashleymills | 0:714293de3836 | 121 | Subround(G, b1, c1, d1, e1, a1, ripemd->buffer[12], 7, k1); |
ashleymills | 0:714293de3836 | 122 | Subround(G, a1, b1, c1, d1, e1, ripemd->buffer[ 0], 12, k1); |
ashleymills | 0:714293de3836 | 123 | Subround(G, e1, a1, b1, c1, d1, ripemd->buffer[ 9], 15, k1); |
ashleymills | 0:714293de3836 | 124 | Subround(G, d1, e1, a1, b1, c1, ripemd->buffer[ 5], 9, k1); |
ashleymills | 0:714293de3836 | 125 | Subround(G, c1, d1, e1, a1, b1, ripemd->buffer[ 2], 11, k1); |
ashleymills | 0:714293de3836 | 126 | Subround(G, b1, c1, d1, e1, a1, ripemd->buffer[14], 7, k1); |
ashleymills | 0:714293de3836 | 127 | Subround(G, a1, b1, c1, d1, e1, ripemd->buffer[11], 13, k1); |
ashleymills | 0:714293de3836 | 128 | Subround(G, e1, a1, b1, c1, d1, ripemd->buffer[ 8], 12, k1); |
ashleymills | 0:714293de3836 | 129 | |
ashleymills | 0:714293de3836 | 130 | Subround(H, d1, e1, a1, b1, c1, ripemd->buffer[ 3], 11, k2); |
ashleymills | 0:714293de3836 | 131 | Subround(H, c1, d1, e1, a1, b1, ripemd->buffer[10], 13, k2); |
ashleymills | 0:714293de3836 | 132 | Subround(H, b1, c1, d1, e1, a1, ripemd->buffer[14], 6, k2); |
ashleymills | 0:714293de3836 | 133 | Subround(H, a1, b1, c1, d1, e1, ripemd->buffer[ 4], 7, k2); |
ashleymills | 0:714293de3836 | 134 | Subround(H, e1, a1, b1, c1, d1, ripemd->buffer[ 9], 14, k2); |
ashleymills | 0:714293de3836 | 135 | Subround(H, d1, e1, a1, b1, c1, ripemd->buffer[15], 9, k2); |
ashleymills | 0:714293de3836 | 136 | Subround(H, c1, d1, e1, a1, b1, ripemd->buffer[ 8], 13, k2); |
ashleymills | 0:714293de3836 | 137 | Subround(H, b1, c1, d1, e1, a1, ripemd->buffer[ 1], 15, k2); |
ashleymills | 0:714293de3836 | 138 | Subround(H, a1, b1, c1, d1, e1, ripemd->buffer[ 2], 14, k2); |
ashleymills | 0:714293de3836 | 139 | Subround(H, e1, a1, b1, c1, d1, ripemd->buffer[ 7], 8, k2); |
ashleymills | 0:714293de3836 | 140 | Subround(H, d1, e1, a1, b1, c1, ripemd->buffer[ 0], 13, k2); |
ashleymills | 0:714293de3836 | 141 | Subround(H, c1, d1, e1, a1, b1, ripemd->buffer[ 6], 6, k2); |
ashleymills | 0:714293de3836 | 142 | Subround(H, b1, c1, d1, e1, a1, ripemd->buffer[13], 5, k2); |
ashleymills | 0:714293de3836 | 143 | Subround(H, a1, b1, c1, d1, e1, ripemd->buffer[11], 12, k2); |
ashleymills | 0:714293de3836 | 144 | Subround(H, e1, a1, b1, c1, d1, ripemd->buffer[ 5], 7, k2); |
ashleymills | 0:714293de3836 | 145 | Subround(H, d1, e1, a1, b1, c1, ripemd->buffer[12], 5, k2); |
ashleymills | 0:714293de3836 | 146 | |
ashleymills | 0:714293de3836 | 147 | Subround(I, c1, d1, e1, a1, b1, ripemd->buffer[ 1], 11, k3); |
ashleymills | 0:714293de3836 | 148 | Subround(I, b1, c1, d1, e1, a1, ripemd->buffer[ 9], 12, k3); |
ashleymills | 0:714293de3836 | 149 | Subround(I, a1, b1, c1, d1, e1, ripemd->buffer[11], 14, k3); |
ashleymills | 0:714293de3836 | 150 | Subround(I, e1, a1, b1, c1, d1, ripemd->buffer[10], 15, k3); |
ashleymills | 0:714293de3836 | 151 | Subround(I, d1, e1, a1, b1, c1, ripemd->buffer[ 0], 14, k3); |
ashleymills | 0:714293de3836 | 152 | Subround(I, c1, d1, e1, a1, b1, ripemd->buffer[ 8], 15, k3); |
ashleymills | 0:714293de3836 | 153 | Subround(I, b1, c1, d1, e1, a1, ripemd->buffer[12], 9, k3); |
ashleymills | 0:714293de3836 | 154 | Subround(I, a1, b1, c1, d1, e1, ripemd->buffer[ 4], 8, k3); |
ashleymills | 0:714293de3836 | 155 | Subround(I, e1, a1, b1, c1, d1, ripemd->buffer[13], 9, k3); |
ashleymills | 0:714293de3836 | 156 | Subround(I, d1, e1, a1, b1, c1, ripemd->buffer[ 3], 14, k3); |
ashleymills | 0:714293de3836 | 157 | Subround(I, c1, d1, e1, a1, b1, ripemd->buffer[ 7], 5, k3); |
ashleymills | 0:714293de3836 | 158 | Subround(I, b1, c1, d1, e1, a1, ripemd->buffer[15], 6, k3); |
ashleymills | 0:714293de3836 | 159 | Subround(I, a1, b1, c1, d1, e1, ripemd->buffer[14], 8, k3); |
ashleymills | 0:714293de3836 | 160 | Subround(I, e1, a1, b1, c1, d1, ripemd->buffer[ 5], 6, k3); |
ashleymills | 0:714293de3836 | 161 | Subround(I, d1, e1, a1, b1, c1, ripemd->buffer[ 6], 5, k3); |
ashleymills | 0:714293de3836 | 162 | Subround(I, c1, d1, e1, a1, b1, ripemd->buffer[ 2], 12, k3); |
ashleymills | 0:714293de3836 | 163 | |
ashleymills | 0:714293de3836 | 164 | Subround(J, b1, c1, d1, e1, a1, ripemd->buffer[ 4], 9, k4); |
ashleymills | 0:714293de3836 | 165 | Subround(J, a1, b1, c1, d1, e1, ripemd->buffer[ 0], 15, k4); |
ashleymills | 0:714293de3836 | 166 | Subround(J, e1, a1, b1, c1, d1, ripemd->buffer[ 5], 5, k4); |
ashleymills | 0:714293de3836 | 167 | Subround(J, d1, e1, a1, b1, c1, ripemd->buffer[ 9], 11, k4); |
ashleymills | 0:714293de3836 | 168 | Subround(J, c1, d1, e1, a1, b1, ripemd->buffer[ 7], 6, k4); |
ashleymills | 0:714293de3836 | 169 | Subround(J, b1, c1, d1, e1, a1, ripemd->buffer[12], 8, k4); |
ashleymills | 0:714293de3836 | 170 | Subround(J, a1, b1, c1, d1, e1, ripemd->buffer[ 2], 13, k4); |
ashleymills | 0:714293de3836 | 171 | Subround(J, e1, a1, b1, c1, d1, ripemd->buffer[10], 12, k4); |
ashleymills | 0:714293de3836 | 172 | Subround(J, d1, e1, a1, b1, c1, ripemd->buffer[14], 5, k4); |
ashleymills | 0:714293de3836 | 173 | Subround(J, c1, d1, e1, a1, b1, ripemd->buffer[ 1], 12, k4); |
ashleymills | 0:714293de3836 | 174 | Subround(J, b1, c1, d1, e1, a1, ripemd->buffer[ 3], 13, k4); |
ashleymills | 0:714293de3836 | 175 | Subround(J, a1, b1, c1, d1, e1, ripemd->buffer[ 8], 14, k4); |
ashleymills | 0:714293de3836 | 176 | Subround(J, e1, a1, b1, c1, d1, ripemd->buffer[11], 11, k4); |
ashleymills | 0:714293de3836 | 177 | Subround(J, d1, e1, a1, b1, c1, ripemd->buffer[ 6], 8, k4); |
ashleymills | 0:714293de3836 | 178 | Subround(J, c1, d1, e1, a1, b1, ripemd->buffer[15], 5, k4); |
ashleymills | 0:714293de3836 | 179 | Subround(J, b1, c1, d1, e1, a1, ripemd->buffer[13], 6, k4); |
ashleymills | 0:714293de3836 | 180 | |
ashleymills | 0:714293de3836 | 181 | Subround(J, a2, b2, c2, d2, e2, ripemd->buffer[ 5], 8, k5); |
ashleymills | 0:714293de3836 | 182 | Subround(J, e2, a2, b2, c2, d2, ripemd->buffer[14], 9, k5); |
ashleymills | 0:714293de3836 | 183 | Subround(J, d2, e2, a2, b2, c2, ripemd->buffer[ 7], 9, k5); |
ashleymills | 0:714293de3836 | 184 | Subround(J, c2, d2, e2, a2, b2, ripemd->buffer[ 0], 11, k5); |
ashleymills | 0:714293de3836 | 185 | Subround(J, b2, c2, d2, e2, a2, ripemd->buffer[ 9], 13, k5); |
ashleymills | 0:714293de3836 | 186 | Subround(J, a2, b2, c2, d2, e2, ripemd->buffer[ 2], 15, k5); |
ashleymills | 0:714293de3836 | 187 | Subround(J, e2, a2, b2, c2, d2, ripemd->buffer[11], 15, k5); |
ashleymills | 0:714293de3836 | 188 | Subround(J, d2, e2, a2, b2, c2, ripemd->buffer[ 4], 5, k5); |
ashleymills | 0:714293de3836 | 189 | Subround(J, c2, d2, e2, a2, b2, ripemd->buffer[13], 7, k5); |
ashleymills | 0:714293de3836 | 190 | Subround(J, b2, c2, d2, e2, a2, ripemd->buffer[ 6], 7, k5); |
ashleymills | 0:714293de3836 | 191 | Subround(J, a2, b2, c2, d2, e2, ripemd->buffer[15], 8, k5); |
ashleymills | 0:714293de3836 | 192 | Subround(J, e2, a2, b2, c2, d2, ripemd->buffer[ 8], 11, k5); |
ashleymills | 0:714293de3836 | 193 | Subround(J, d2, e2, a2, b2, c2, ripemd->buffer[ 1], 14, k5); |
ashleymills | 0:714293de3836 | 194 | Subround(J, c2, d2, e2, a2, b2, ripemd->buffer[10], 14, k5); |
ashleymills | 0:714293de3836 | 195 | Subround(J, b2, c2, d2, e2, a2, ripemd->buffer[ 3], 12, k5); |
ashleymills | 0:714293de3836 | 196 | Subround(J, a2, b2, c2, d2, e2, ripemd->buffer[12], 6, k5); |
ashleymills | 0:714293de3836 | 197 | |
ashleymills | 0:714293de3836 | 198 | Subround(I, e2, a2, b2, c2, d2, ripemd->buffer[ 6], 9, k6); |
ashleymills | 0:714293de3836 | 199 | Subround(I, d2, e2, a2, b2, c2, ripemd->buffer[11], 13, k6); |
ashleymills | 0:714293de3836 | 200 | Subround(I, c2, d2, e2, a2, b2, ripemd->buffer[ 3], 15, k6); |
ashleymills | 0:714293de3836 | 201 | Subround(I, b2, c2, d2, e2, a2, ripemd->buffer[ 7], 7, k6); |
ashleymills | 0:714293de3836 | 202 | Subround(I, a2, b2, c2, d2, e2, ripemd->buffer[ 0], 12, k6); |
ashleymills | 0:714293de3836 | 203 | Subround(I, e2, a2, b2, c2, d2, ripemd->buffer[13], 8, k6); |
ashleymills | 0:714293de3836 | 204 | Subround(I, d2, e2, a2, b2, c2, ripemd->buffer[ 5], 9, k6); |
ashleymills | 0:714293de3836 | 205 | Subround(I, c2, d2, e2, a2, b2, ripemd->buffer[10], 11, k6); |
ashleymills | 0:714293de3836 | 206 | Subround(I, b2, c2, d2, e2, a2, ripemd->buffer[14], 7, k6); |
ashleymills | 0:714293de3836 | 207 | Subround(I, a2, b2, c2, d2, e2, ripemd->buffer[15], 7, k6); |
ashleymills | 0:714293de3836 | 208 | Subround(I, e2, a2, b2, c2, d2, ripemd->buffer[ 8], 12, k6); |
ashleymills | 0:714293de3836 | 209 | Subround(I, d2, e2, a2, b2, c2, ripemd->buffer[12], 7, k6); |
ashleymills | 0:714293de3836 | 210 | Subround(I, c2, d2, e2, a2, b2, ripemd->buffer[ 4], 6, k6); |
ashleymills | 0:714293de3836 | 211 | Subround(I, b2, c2, d2, e2, a2, ripemd->buffer[ 9], 15, k6); |
ashleymills | 0:714293de3836 | 212 | Subround(I, a2, b2, c2, d2, e2, ripemd->buffer[ 1], 13, k6); |
ashleymills | 0:714293de3836 | 213 | Subround(I, e2, a2, b2, c2, d2, ripemd->buffer[ 2], 11, k6); |
ashleymills | 0:714293de3836 | 214 | |
ashleymills | 0:714293de3836 | 215 | Subround(H, d2, e2, a2, b2, c2, ripemd->buffer[15], 9, k7); |
ashleymills | 0:714293de3836 | 216 | Subround(H, c2, d2, e2, a2, b2, ripemd->buffer[ 5], 7, k7); |
ashleymills | 0:714293de3836 | 217 | Subround(H, b2, c2, d2, e2, a2, ripemd->buffer[ 1], 15, k7); |
ashleymills | 0:714293de3836 | 218 | Subround(H, a2, b2, c2, d2, e2, ripemd->buffer[ 3], 11, k7); |
ashleymills | 0:714293de3836 | 219 | Subround(H, e2, a2, b2, c2, d2, ripemd->buffer[ 7], 8, k7); |
ashleymills | 0:714293de3836 | 220 | Subround(H, d2, e2, a2, b2, c2, ripemd->buffer[14], 6, k7); |
ashleymills | 0:714293de3836 | 221 | Subround(H, c2, d2, e2, a2, b2, ripemd->buffer[ 6], 6, k7); |
ashleymills | 0:714293de3836 | 222 | Subround(H, b2, c2, d2, e2, a2, ripemd->buffer[ 9], 14, k7); |
ashleymills | 0:714293de3836 | 223 | Subround(H, a2, b2, c2, d2, e2, ripemd->buffer[11], 12, k7); |
ashleymills | 0:714293de3836 | 224 | Subround(H, e2, a2, b2, c2, d2, ripemd->buffer[ 8], 13, k7); |
ashleymills | 0:714293de3836 | 225 | Subround(H, d2, e2, a2, b2, c2, ripemd->buffer[12], 5, k7); |
ashleymills | 0:714293de3836 | 226 | Subround(H, c2, d2, e2, a2, b2, ripemd->buffer[ 2], 14, k7); |
ashleymills | 0:714293de3836 | 227 | Subround(H, b2, c2, d2, e2, a2, ripemd->buffer[10], 13, k7); |
ashleymills | 0:714293de3836 | 228 | Subround(H, a2, b2, c2, d2, e2, ripemd->buffer[ 0], 13, k7); |
ashleymills | 0:714293de3836 | 229 | Subround(H, e2, a2, b2, c2, d2, ripemd->buffer[ 4], 7, k7); |
ashleymills | 0:714293de3836 | 230 | Subround(H, d2, e2, a2, b2, c2, ripemd->buffer[13], 5, k7); |
ashleymills | 0:714293de3836 | 231 | |
ashleymills | 0:714293de3836 | 232 | Subround(G, c2, d2, e2, a2, b2, ripemd->buffer[ 8], 15, k8); |
ashleymills | 0:714293de3836 | 233 | Subround(G, b2, c2, d2, e2, a2, ripemd->buffer[ 6], 5, k8); |
ashleymills | 0:714293de3836 | 234 | Subround(G, a2, b2, c2, d2, e2, ripemd->buffer[ 4], 8, k8); |
ashleymills | 0:714293de3836 | 235 | Subround(G, e2, a2, b2, c2, d2, ripemd->buffer[ 1], 11, k8); |
ashleymills | 0:714293de3836 | 236 | Subround(G, d2, e2, a2, b2, c2, ripemd->buffer[ 3], 14, k8); |
ashleymills | 0:714293de3836 | 237 | Subround(G, c2, d2, e2, a2, b2, ripemd->buffer[11], 14, k8); |
ashleymills | 0:714293de3836 | 238 | Subround(G, b2, c2, d2, e2, a2, ripemd->buffer[15], 6, k8); |
ashleymills | 0:714293de3836 | 239 | Subround(G, a2, b2, c2, d2, e2, ripemd->buffer[ 0], 14, k8); |
ashleymills | 0:714293de3836 | 240 | Subround(G, e2, a2, b2, c2, d2, ripemd->buffer[ 5], 6, k8); |
ashleymills | 0:714293de3836 | 241 | Subround(G, d2, e2, a2, b2, c2, ripemd->buffer[12], 9, k8); |
ashleymills | 0:714293de3836 | 242 | Subround(G, c2, d2, e2, a2, b2, ripemd->buffer[ 2], 12, k8); |
ashleymills | 0:714293de3836 | 243 | Subround(G, b2, c2, d2, e2, a2, ripemd->buffer[13], 9, k8); |
ashleymills | 0:714293de3836 | 244 | Subround(G, a2, b2, c2, d2, e2, ripemd->buffer[ 9], 12, k8); |
ashleymills | 0:714293de3836 | 245 | Subround(G, e2, a2, b2, c2, d2, ripemd->buffer[ 7], 5, k8); |
ashleymills | 0:714293de3836 | 246 | Subround(G, d2, e2, a2, b2, c2, ripemd->buffer[10], 15, k8); |
ashleymills | 0:714293de3836 | 247 | Subround(G, c2, d2, e2, a2, b2, ripemd->buffer[14], 8, k8); |
ashleymills | 0:714293de3836 | 248 | |
ashleymills | 0:714293de3836 | 249 | Subround(F, b2, c2, d2, e2, a2, ripemd->buffer[12], 8, k9); |
ashleymills | 0:714293de3836 | 250 | Subround(F, a2, b2, c2, d2, e2, ripemd->buffer[15], 5, k9); |
ashleymills | 0:714293de3836 | 251 | Subround(F, e2, a2, b2, c2, d2, ripemd->buffer[10], 12, k9); |
ashleymills | 0:714293de3836 | 252 | Subround(F, d2, e2, a2, b2, c2, ripemd->buffer[ 4], 9, k9); |
ashleymills | 0:714293de3836 | 253 | Subround(F, c2, d2, e2, a2, b2, ripemd->buffer[ 1], 12, k9); |
ashleymills | 0:714293de3836 | 254 | Subround(F, b2, c2, d2, e2, a2, ripemd->buffer[ 5], 5, k9); |
ashleymills | 0:714293de3836 | 255 | Subround(F, a2, b2, c2, d2, e2, ripemd->buffer[ 8], 14, k9); |
ashleymills | 0:714293de3836 | 256 | Subround(F, e2, a2, b2, c2, d2, ripemd->buffer[ 7], 6, k9); |
ashleymills | 0:714293de3836 | 257 | Subround(F, d2, e2, a2, b2, c2, ripemd->buffer[ 6], 8, k9); |
ashleymills | 0:714293de3836 | 258 | Subround(F, c2, d2, e2, a2, b2, ripemd->buffer[ 2], 13, k9); |
ashleymills | 0:714293de3836 | 259 | Subround(F, b2, c2, d2, e2, a2, ripemd->buffer[13], 6, k9); |
ashleymills | 0:714293de3836 | 260 | Subround(F, a2, b2, c2, d2, e2, ripemd->buffer[14], 5, k9); |
ashleymills | 0:714293de3836 | 261 | Subround(F, e2, a2, b2, c2, d2, ripemd->buffer[ 0], 15, k9); |
ashleymills | 0:714293de3836 | 262 | Subround(F, d2, e2, a2, b2, c2, ripemd->buffer[ 3], 13, k9); |
ashleymills | 0:714293de3836 | 263 | Subround(F, c2, d2, e2, a2, b2, ripemd->buffer[ 9], 11, k9); |
ashleymills | 0:714293de3836 | 264 | Subround(F, b2, c2, d2, e2, a2, ripemd->buffer[11], 11, k9); |
ashleymills | 0:714293de3836 | 265 | |
ashleymills | 0:714293de3836 | 266 | c1 = ripemd->digest[1] + c1 + d2; |
ashleymills | 0:714293de3836 | 267 | ripemd->digest[1] = ripemd->digest[2] + d1 + e2; |
ashleymills | 0:714293de3836 | 268 | ripemd->digest[2] = ripemd->digest[3] + e1 + a2; |
ashleymills | 0:714293de3836 | 269 | ripemd->digest[3] = ripemd->digest[4] + a1 + b2; |
ashleymills | 0:714293de3836 | 270 | ripemd->digest[4] = ripemd->digest[0] + b1 + c2; |
ashleymills | 0:714293de3836 | 271 | ripemd->digest[0] = c1; |
ashleymills | 0:714293de3836 | 272 | } |
ashleymills | 0:714293de3836 | 273 | |
ashleymills | 0:714293de3836 | 274 | |
ashleymills | 0:714293de3836 | 275 | static INLINE void AddLength(RipeMd* ripemd, word32 len) |
ashleymills | 0:714293de3836 | 276 | { |
ashleymills | 0:714293de3836 | 277 | word32 tmp = ripemd->loLen; |
ashleymills | 0:714293de3836 | 278 | if ( (ripemd->loLen += len) < tmp) |
ashleymills | 0:714293de3836 | 279 | ripemd->hiLen++; /* carry low to high */ |
ashleymills | 0:714293de3836 | 280 | } |
ashleymills | 0:714293de3836 | 281 | |
ashleymills | 0:714293de3836 | 282 | |
ashleymills | 0:714293de3836 | 283 | void RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len) |
ashleymills | 0:714293de3836 | 284 | { |
ashleymills | 0:714293de3836 | 285 | /* do block size increments */ |
ashleymills | 0:714293de3836 | 286 | byte* local = (byte*)ripemd->buffer; |
ashleymills | 0:714293de3836 | 287 | |
ashleymills | 0:714293de3836 | 288 | while (len) { |
ashleymills | 0:714293de3836 | 289 | word32 add = min(len, RIPEMD_BLOCK_SIZE - ripemd->buffLen); |
ashleymills | 0:714293de3836 | 290 | XMEMCPY(&local[ripemd->buffLen], data, add); |
ashleymills | 0:714293de3836 | 291 | |
ashleymills | 0:714293de3836 | 292 | ripemd->buffLen += add; |
ashleymills | 0:714293de3836 | 293 | data += add; |
ashleymills | 0:714293de3836 | 294 | len -= add; |
ashleymills | 0:714293de3836 | 295 | |
ashleymills | 0:714293de3836 | 296 | if (ripemd->buffLen == RIPEMD_BLOCK_SIZE) { |
ashleymills | 0:714293de3836 | 297 | #ifdef BIG_ENDIAN_ORDER |
ashleymills | 0:714293de3836 | 298 | ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); |
ashleymills | 0:714293de3836 | 299 | #endif |
ashleymills | 0:714293de3836 | 300 | Transform(ripemd); |
ashleymills | 0:714293de3836 | 301 | AddLength(ripemd, RIPEMD_BLOCK_SIZE); |
ashleymills | 0:714293de3836 | 302 | ripemd->buffLen = 0; |
ashleymills | 0:714293de3836 | 303 | } |
ashleymills | 0:714293de3836 | 304 | } |
ashleymills | 0:714293de3836 | 305 | } |
ashleymills | 0:714293de3836 | 306 | |
ashleymills | 0:714293de3836 | 307 | |
ashleymills | 0:714293de3836 | 308 | void RipeMdFinal(RipeMd* ripemd, byte* hash) |
ashleymills | 0:714293de3836 | 309 | { |
ashleymills | 0:714293de3836 | 310 | byte* local = (byte*)ripemd->buffer; |
ashleymills | 0:714293de3836 | 311 | |
ashleymills | 0:714293de3836 | 312 | AddLength(ripemd, ripemd->buffLen); /* before adding pads */ |
ashleymills | 0:714293de3836 | 313 | |
ashleymills | 0:714293de3836 | 314 | local[ripemd->buffLen++] = 0x80; /* add 1 */ |
ashleymills | 0:714293de3836 | 315 | |
ashleymills | 0:714293de3836 | 316 | /* pad with zeros */ |
ashleymills | 0:714293de3836 | 317 | if (ripemd->buffLen > RIPEMD_PAD_SIZE) { |
ashleymills | 0:714293de3836 | 318 | XMEMSET(&local[ripemd->buffLen], 0, RIPEMD_BLOCK_SIZE - ripemd->buffLen); |
ashleymills | 0:714293de3836 | 319 | ripemd->buffLen += RIPEMD_BLOCK_SIZE - ripemd->buffLen; |
ashleymills | 0:714293de3836 | 320 | |
ashleymills | 0:714293de3836 | 321 | #ifdef BIG_ENDIAN_ORDER |
ashleymills | 0:714293de3836 | 322 | ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); |
ashleymills | 0:714293de3836 | 323 | #endif |
ashleymills | 0:714293de3836 | 324 | Transform(ripemd); |
ashleymills | 0:714293de3836 | 325 | ripemd->buffLen = 0; |
ashleymills | 0:714293de3836 | 326 | } |
ashleymills | 0:714293de3836 | 327 | XMEMSET(&local[ripemd->buffLen], 0, RIPEMD_PAD_SIZE - ripemd->buffLen); |
ashleymills | 0:714293de3836 | 328 | |
ashleymills | 0:714293de3836 | 329 | /* put lengths in bits */ |
ashleymills | 0:714293de3836 | 330 | ripemd->loLen = ripemd->loLen << 3; |
ashleymills | 0:714293de3836 | 331 | ripemd->hiLen = (ripemd->loLen >> (8*sizeof(ripemd->loLen) - 3)) + |
ashleymills | 0:714293de3836 | 332 | (ripemd->hiLen << 3); |
ashleymills | 0:714293de3836 | 333 | |
ashleymills | 0:714293de3836 | 334 | /* store lengths */ |
ashleymills | 0:714293de3836 | 335 | #ifdef BIG_ENDIAN_ORDER |
ashleymills | 0:714293de3836 | 336 | ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); |
ashleymills | 0:714293de3836 | 337 | #endif |
ashleymills | 0:714293de3836 | 338 | /* ! length ordering dependent on digest endian type ! */ |
ashleymills | 0:714293de3836 | 339 | XMEMCPY(&local[RIPEMD_PAD_SIZE], &ripemd->loLen, sizeof(word32)); |
ashleymills | 0:714293de3836 | 340 | XMEMCPY(&local[RIPEMD_PAD_SIZE + sizeof(word32)], &ripemd->hiLen, |
ashleymills | 0:714293de3836 | 341 | sizeof(word32)); |
ashleymills | 0:714293de3836 | 342 | |
ashleymills | 0:714293de3836 | 343 | Transform(ripemd); |
ashleymills | 0:714293de3836 | 344 | #ifdef BIG_ENDIAN_ORDER |
ashleymills | 0:714293de3836 | 345 | ByteReverseWords(ripemd->digest, ripemd->digest, RIPEMD_DIGEST_SIZE); |
ashleymills | 0:714293de3836 | 346 | #endif |
ashleymills | 0:714293de3836 | 347 | XMEMCPY(hash, ripemd->digest, RIPEMD_DIGEST_SIZE); |
ashleymills | 0:714293de3836 | 348 | |
ashleymills | 0:714293de3836 | 349 | InitRipeMd(ripemd); /* reset state */ |
ashleymills | 0:714293de3836 | 350 | } |
ashleymills | 0:714293de3836 | 351 | |
ashleymills | 0:714293de3836 | 352 | |
ashleymills | 0:714293de3836 | 353 | #endif /* CYASSL_RIPEMD */ |