Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

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