cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:59:36 2013 +0000
Revision:
1:b211d97b0068
Parent:
0:e979170e02e7
nothing

Who changed what in which revision?

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