SSL/TLS Library

Dependents:  

CyaSSL is SSL/TLS library for embedded systems.

wolfssl.com

Committer:
wolfSSL
Date:
Sun Apr 20 12:40:57 2014 +0000
Revision:
0:9d17e4342598
CyaSSL SSL/TLS Library 2.9.4;

Who changed what in which revision?

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