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