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