wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Fri Jun 05 00:11:07 2020 +0000
Revision:
17:a5f916481144
Parent:
16:8e0d178b1d1e
wolfSSL 4.4.0

Who changed what in which revision?

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