Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file md5.c
Sergunb 0:8918a71cdbe9 3 * @brief MD5 (Message-Digest Algorithm)
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This file is part of CycloneCrypto Open.
Sergunb 0:8918a71cdbe9 10 *
Sergunb 0:8918a71cdbe9 11 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 12 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 13 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 14 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 15 *
Sergunb 0:8918a71cdbe9 16 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 19 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 20 *
Sergunb 0:8918a71cdbe9 21 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 22 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 24 *
Sergunb 0:8918a71cdbe9 25 * @section Description
Sergunb 0:8918a71cdbe9 26 *
Sergunb 0:8918a71cdbe9 27 * The MD5 algorithm takes as input a message of arbitrary length and produces
Sergunb 0:8918a71cdbe9 28 * as output a 128-bit message digest of the input. Refer to RFC 1321
Sergunb 0:8918a71cdbe9 29 *
Sergunb 0:8918a71cdbe9 30 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 31 * @version 1.7.6
Sergunb 0:8918a71cdbe9 32 **/
Sergunb 0:8918a71cdbe9 33
Sergunb 0:8918a71cdbe9 34 //Switch to the appropriate trace level
Sergunb 0:8918a71cdbe9 35 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
Sergunb 0:8918a71cdbe9 36
Sergunb 0:8918a71cdbe9 37 //Dependencies
Sergunb 0:8918a71cdbe9 38 #include <string.h>
Sergunb 0:8918a71cdbe9 39 #include "crypto.h"
Sergunb 0:8918a71cdbe9 40 #include "md5.h"
Sergunb 0:8918a71cdbe9 41
Sergunb 0:8918a71cdbe9 42 //Check crypto library configuration
Sergunb 0:8918a71cdbe9 43 #if (MD5_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 44
Sergunb 0:8918a71cdbe9 45 //MD5 auxiliary functions
Sergunb 0:8918a71cdbe9 46 #define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
Sergunb 0:8918a71cdbe9 47 #define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
Sergunb 0:8918a71cdbe9 48 #define H(x, y, z) ((x) ^ (y) ^ (z))
Sergunb 0:8918a71cdbe9 49 #define I(x, y, z) ((y) ^ ((x) | ~(z)))
Sergunb 0:8918a71cdbe9 50
Sergunb 0:8918a71cdbe9 51 #define FF(a, b, c, d, x, s, k) a += F(b, c, d) + (x) + (k), a = ROL32(a, s) + (b)
Sergunb 0:8918a71cdbe9 52 #define GG(a, b, c, d, x, s, k) a += G(b, c, d) + (x) + (k), a = ROL32(a, s) + (b)
Sergunb 0:8918a71cdbe9 53 #define HH(a, b, c, d, x, s, k) a += H(b, c, d) + (x) + (k), a = ROL32(a, s) + (b)
Sergunb 0:8918a71cdbe9 54 #define II(a, b, c, d, x, s, k) a += I(b, c, d) + (x) + (k), a = ROL32(a, s) + (b)
Sergunb 0:8918a71cdbe9 55
Sergunb 0:8918a71cdbe9 56 //MD5 padding
Sergunb 0:8918a71cdbe9 57 static const uint8_t padding[64] =
Sergunb 0:8918a71cdbe9 58 {
Sergunb 0:8918a71cdbe9 59 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Sergunb 0:8918a71cdbe9 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Sergunb 0:8918a71cdbe9 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Sergunb 0:8918a71cdbe9 62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Sergunb 0:8918a71cdbe9 63 };
Sergunb 0:8918a71cdbe9 64
Sergunb 0:8918a71cdbe9 65 //MD5 constants
Sergunb 0:8918a71cdbe9 66 static const uint32_t k[64] =
Sergunb 0:8918a71cdbe9 67 {
Sergunb 0:8918a71cdbe9 68 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501,
Sergunb 0:8918a71cdbe9 69 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821,
Sergunb 0:8918a71cdbe9 70 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8,
Sergunb 0:8918a71cdbe9 71 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A,
Sergunb 0:8918a71cdbe9 72 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70,
Sergunb 0:8918a71cdbe9 73 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665,
Sergunb 0:8918a71cdbe9 74 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1,
Sergunb 0:8918a71cdbe9 75 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391
Sergunb 0:8918a71cdbe9 76 };
Sergunb 0:8918a71cdbe9 77
Sergunb 0:8918a71cdbe9 78 //MD5 object identifier (1.2.840.113549.2.5)
Sergunb 0:8918a71cdbe9 79 static const uint8_t md5Oid[] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05};
Sergunb 0:8918a71cdbe9 80
Sergunb 0:8918a71cdbe9 81 //Common interface for hash algorithms
Sergunb 0:8918a71cdbe9 82 const HashAlgo md5HashAlgo =
Sergunb 0:8918a71cdbe9 83 {
Sergunb 0:8918a71cdbe9 84 "MD5",
Sergunb 0:8918a71cdbe9 85 md5Oid,
Sergunb 0:8918a71cdbe9 86 sizeof(md5Oid),
Sergunb 0:8918a71cdbe9 87 sizeof(Md5Context),
Sergunb 0:8918a71cdbe9 88 MD5_BLOCK_SIZE,
Sergunb 0:8918a71cdbe9 89 MD5_DIGEST_SIZE,
Sergunb 0:8918a71cdbe9 90 (HashAlgoCompute) md5Compute,
Sergunb 0:8918a71cdbe9 91 (HashAlgoInit) md5Init,
Sergunb 0:8918a71cdbe9 92 (HashAlgoUpdate) md5Update,
Sergunb 0:8918a71cdbe9 93 (HashAlgoFinal) md5Final
Sergunb 0:8918a71cdbe9 94 };
Sergunb 0:8918a71cdbe9 95
Sergunb 0:8918a71cdbe9 96
Sergunb 0:8918a71cdbe9 97 /**
Sergunb 0:8918a71cdbe9 98 * @brief Digest a message using MD5
Sergunb 0:8918a71cdbe9 99 * @param[in] data Pointer to the message being hashed
Sergunb 0:8918a71cdbe9 100 * @param[in] length Length of the message
Sergunb 0:8918a71cdbe9 101 * @param[out] digest Pointer to the calculated digest
Sergunb 0:8918a71cdbe9 102 * @return Error code
Sergunb 0:8918a71cdbe9 103 **/
Sergunb 0:8918a71cdbe9 104
Sergunb 0:8918a71cdbe9 105 error_t md5Compute(const void *data, size_t length, uint8_t *digest)
Sergunb 0:8918a71cdbe9 106 {
Sergunb 0:8918a71cdbe9 107 //Allocate a memory buffer to hold the MD5 context
Sergunb 0:8918a71cdbe9 108 Md5Context *context = cryptoAllocMem(sizeof(Md5Context));
Sergunb 0:8918a71cdbe9 109 //Failed to allocate memory?
Sergunb 0:8918a71cdbe9 110 if(context == NULL)
Sergunb 0:8918a71cdbe9 111 return ERROR_OUT_OF_MEMORY;
Sergunb 0:8918a71cdbe9 112
Sergunb 0:8918a71cdbe9 113 //Initialize the MD5 context
Sergunb 0:8918a71cdbe9 114 md5Init(context);
Sergunb 0:8918a71cdbe9 115 //Digest the message
Sergunb 0:8918a71cdbe9 116 md5Update(context, data, length);
Sergunb 0:8918a71cdbe9 117 //Finalize the MD5 message digest
Sergunb 0:8918a71cdbe9 118 md5Final(context, digest);
Sergunb 0:8918a71cdbe9 119
Sergunb 0:8918a71cdbe9 120 //Free previously allocated memory
Sergunb 0:8918a71cdbe9 121 cryptoFreeMem(context);
Sergunb 0:8918a71cdbe9 122 //Successful processing
Sergunb 0:8918a71cdbe9 123 return NO_ERROR;
Sergunb 0:8918a71cdbe9 124 }
Sergunb 0:8918a71cdbe9 125
Sergunb 0:8918a71cdbe9 126
Sergunb 0:8918a71cdbe9 127 /**
Sergunb 0:8918a71cdbe9 128 * @brief Initialize MD5 message digest context
Sergunb 0:8918a71cdbe9 129 * @param[in] context Pointer to the MD5 context to initialize
Sergunb 0:8918a71cdbe9 130 **/
Sergunb 0:8918a71cdbe9 131
Sergunb 0:8918a71cdbe9 132 void md5Init(Md5Context *context)
Sergunb 0:8918a71cdbe9 133 {
Sergunb 0:8918a71cdbe9 134 //Set initial hash value
Sergunb 0:8918a71cdbe9 135 context->h[0] = 0x67452301;
Sergunb 0:8918a71cdbe9 136 context->h[1] = 0xEFCDAB89;
Sergunb 0:8918a71cdbe9 137 context->h[2] = 0x98BADCFE;
Sergunb 0:8918a71cdbe9 138 context->h[3] = 0x10325476;
Sergunb 0:8918a71cdbe9 139
Sergunb 0:8918a71cdbe9 140 //Number of bytes in the buffer
Sergunb 0:8918a71cdbe9 141 context->size = 0;
Sergunb 0:8918a71cdbe9 142 //Total length of the message
Sergunb 0:8918a71cdbe9 143 context->totalSize = 0;
Sergunb 0:8918a71cdbe9 144 }
Sergunb 0:8918a71cdbe9 145
Sergunb 0:8918a71cdbe9 146
Sergunb 0:8918a71cdbe9 147 /**
Sergunb 0:8918a71cdbe9 148 * @brief Update the MD5 context with a portion of the message being hashed
Sergunb 0:8918a71cdbe9 149 * @param[in] context Pointer to the MD5 context
Sergunb 0:8918a71cdbe9 150 * @param[in] data Pointer to the buffer being hashed
Sergunb 0:8918a71cdbe9 151 * @param[in] length Length of the buffer
Sergunb 0:8918a71cdbe9 152 **/
Sergunb 0:8918a71cdbe9 153
Sergunb 0:8918a71cdbe9 154 void md5Update(Md5Context *context, const void *data, size_t length)
Sergunb 0:8918a71cdbe9 155 {
Sergunb 0:8918a71cdbe9 156 size_t n;
Sergunb 0:8918a71cdbe9 157
Sergunb 0:8918a71cdbe9 158 //Process the incoming data
Sergunb 0:8918a71cdbe9 159 while(length > 0)
Sergunb 0:8918a71cdbe9 160 {
Sergunb 0:8918a71cdbe9 161 //The buffer can hold at most 64 bytes
Sergunb 0:8918a71cdbe9 162 n = MIN(length, 64 - context->size);
Sergunb 0:8918a71cdbe9 163
Sergunb 0:8918a71cdbe9 164 //Copy the data to the buffer
Sergunb 0:8918a71cdbe9 165 memcpy(context->buffer + context->size, data, n);
Sergunb 0:8918a71cdbe9 166
Sergunb 0:8918a71cdbe9 167 //Update the MD5 context
Sergunb 0:8918a71cdbe9 168 context->size += n;
Sergunb 0:8918a71cdbe9 169 context->totalSize += n;
Sergunb 0:8918a71cdbe9 170 //Advance the data pointer
Sergunb 0:8918a71cdbe9 171 data = (uint8_t *) data + n;
Sergunb 0:8918a71cdbe9 172 //Remaining bytes to process
Sergunb 0:8918a71cdbe9 173 length -= n;
Sergunb 0:8918a71cdbe9 174
Sergunb 0:8918a71cdbe9 175 //Process message in 16-word blocks
Sergunb 0:8918a71cdbe9 176 if(context->size == 64)
Sergunb 0:8918a71cdbe9 177 {
Sergunb 0:8918a71cdbe9 178 //Transform the 16-word block
Sergunb 0:8918a71cdbe9 179 md5ProcessBlock(context);
Sergunb 0:8918a71cdbe9 180 //Empty the buffer
Sergunb 0:8918a71cdbe9 181 context->size = 0;
Sergunb 0:8918a71cdbe9 182 }
Sergunb 0:8918a71cdbe9 183 }
Sergunb 0:8918a71cdbe9 184 }
Sergunb 0:8918a71cdbe9 185
Sergunb 0:8918a71cdbe9 186
Sergunb 0:8918a71cdbe9 187 /**
Sergunb 0:8918a71cdbe9 188 * @brief Finish the MD5 message digest
Sergunb 0:8918a71cdbe9 189 * @param[in] context Pointer to the MD5 context
Sergunb 0:8918a71cdbe9 190 * @param[out] digest Calculated digest (optional parameter)
Sergunb 0:8918a71cdbe9 191 **/
Sergunb 0:8918a71cdbe9 192
Sergunb 0:8918a71cdbe9 193 void md5Final(Md5Context *context, uint8_t *digest)
Sergunb 0:8918a71cdbe9 194 {
Sergunb 0:8918a71cdbe9 195 uint_t i;
Sergunb 0:8918a71cdbe9 196 size_t paddingSize;
Sergunb 0:8918a71cdbe9 197 uint64_t totalSize;
Sergunb 0:8918a71cdbe9 198
Sergunb 0:8918a71cdbe9 199 //Length of the original message (before padding)
Sergunb 0:8918a71cdbe9 200 totalSize = context->totalSize * 8;
Sergunb 0:8918a71cdbe9 201
Sergunb 0:8918a71cdbe9 202 //Pad the message so that its length is congruent to 56 modulo 64
Sergunb 0:8918a71cdbe9 203 if(context->size < 56)
Sergunb 0:8918a71cdbe9 204 paddingSize = 56 - context->size;
Sergunb 0:8918a71cdbe9 205 else
Sergunb 0:8918a71cdbe9 206 paddingSize = 64 + 56 - context->size;
Sergunb 0:8918a71cdbe9 207
Sergunb 0:8918a71cdbe9 208 //Append padding
Sergunb 0:8918a71cdbe9 209 md5Update(context, padding, paddingSize);
Sergunb 0:8918a71cdbe9 210
Sergunb 0:8918a71cdbe9 211 //Append the length of the original message
Sergunb 0:8918a71cdbe9 212 context->x[14] = htole32((uint32_t) totalSize);
Sergunb 0:8918a71cdbe9 213 context->x[15] = htole32((uint32_t) (totalSize >> 32));
Sergunb 0:8918a71cdbe9 214
Sergunb 0:8918a71cdbe9 215 //Calculate the message digest
Sergunb 0:8918a71cdbe9 216 md5ProcessBlock(context);
Sergunb 0:8918a71cdbe9 217
Sergunb 0:8918a71cdbe9 218 //Convert from host byte order to little-endian byte order
Sergunb 0:8918a71cdbe9 219 for(i = 0; i < 4; i++)
Sergunb 0:8918a71cdbe9 220 context->h[i] = htole32(context->h[i]);
Sergunb 0:8918a71cdbe9 221
Sergunb 0:8918a71cdbe9 222 //Copy the resulting digest
Sergunb 0:8918a71cdbe9 223 if(digest != NULL)
Sergunb 0:8918a71cdbe9 224 memcpy(digest, context->digest, MD5_DIGEST_SIZE);
Sergunb 0:8918a71cdbe9 225 }
Sergunb 0:8918a71cdbe9 226
Sergunb 0:8918a71cdbe9 227
Sergunb 0:8918a71cdbe9 228 /**
Sergunb 0:8918a71cdbe9 229 * @brief Process message in 16-word blocks
Sergunb 0:8918a71cdbe9 230 * @param[in] context Pointer to the MD5 context
Sergunb 0:8918a71cdbe9 231 **/
Sergunb 0:8918a71cdbe9 232
Sergunb 0:8918a71cdbe9 233 void md5ProcessBlock(Md5Context *context)
Sergunb 0:8918a71cdbe9 234 {
Sergunb 0:8918a71cdbe9 235 uint_t i;
Sergunb 0:8918a71cdbe9 236
Sergunb 0:8918a71cdbe9 237 //Initialize the 4 working registers
Sergunb 0:8918a71cdbe9 238 uint32_t a = context->h[0];
Sergunb 0:8918a71cdbe9 239 uint32_t b = context->h[1];
Sergunb 0:8918a71cdbe9 240 uint32_t c = context->h[2];
Sergunb 0:8918a71cdbe9 241 uint32_t d = context->h[3];
Sergunb 0:8918a71cdbe9 242
Sergunb 0:8918a71cdbe9 243 //Process message in 16-word blocks
Sergunb 0:8918a71cdbe9 244 uint32_t *x = context->x;
Sergunb 0:8918a71cdbe9 245
Sergunb 0:8918a71cdbe9 246 //Convert from little-endian byte order to host byte order
Sergunb 0:8918a71cdbe9 247 for(i = 0; i < 16; i++)
Sergunb 0:8918a71cdbe9 248 x[i] = letoh32(x[i]);
Sergunb 0:8918a71cdbe9 249
Sergunb 0:8918a71cdbe9 250 //Round 1
Sergunb 0:8918a71cdbe9 251 FF(a, b, c, d, x[0], 7, k[0]);
Sergunb 0:8918a71cdbe9 252 FF(d, a, b, c, x[1], 12, k[1]);
Sergunb 0:8918a71cdbe9 253 FF(c, d, a, b, x[2], 17, k[2]);
Sergunb 0:8918a71cdbe9 254 FF(b, c, d, a, x[3], 22, k[3]);
Sergunb 0:8918a71cdbe9 255 FF(a, b, c, d, x[4], 7, k[4]);
Sergunb 0:8918a71cdbe9 256 FF(d, a, b, c, x[5], 12, k[5]);
Sergunb 0:8918a71cdbe9 257 FF(c, d, a, b, x[6], 17, k[6]);
Sergunb 0:8918a71cdbe9 258 FF(b, c, d, a, x[7], 22, k[7]);
Sergunb 0:8918a71cdbe9 259 FF(a, b, c, d, x[8], 7, k[8]);
Sergunb 0:8918a71cdbe9 260 FF(d, a, b, c, x[9], 12, k[9]);
Sergunb 0:8918a71cdbe9 261 FF(c, d, a, b, x[10], 17, k[10]);
Sergunb 0:8918a71cdbe9 262 FF(b, c, d, a, x[11], 22, k[11]);
Sergunb 0:8918a71cdbe9 263 FF(a, b, c, d, x[12], 7, k[12]);
Sergunb 0:8918a71cdbe9 264 FF(d, a, b, c, x[13], 12, k[13]);
Sergunb 0:8918a71cdbe9 265 FF(c, d, a, b, x[14], 17, k[14]);
Sergunb 0:8918a71cdbe9 266 FF(b, c, d, a, x[15], 22, k[15]);
Sergunb 0:8918a71cdbe9 267
Sergunb 0:8918a71cdbe9 268 //Round 2
Sergunb 0:8918a71cdbe9 269 GG(a, b, c, d, x[1], 5, k[16]);
Sergunb 0:8918a71cdbe9 270 GG(d, a, b, c, x[6], 9, k[17]);
Sergunb 0:8918a71cdbe9 271 GG(c, d, a, b, x[11], 14, k[18]);
Sergunb 0:8918a71cdbe9 272 GG(b, c, d, a, x[0], 20, k[19]);
Sergunb 0:8918a71cdbe9 273 GG(a, b, c, d, x[5], 5, k[20]);
Sergunb 0:8918a71cdbe9 274 GG(d, a, b, c, x[10], 9, k[21]);
Sergunb 0:8918a71cdbe9 275 GG(c, d, a, b, x[15], 14, k[22]);
Sergunb 0:8918a71cdbe9 276 GG(b, c, d, a, x[4], 20, k[23]);
Sergunb 0:8918a71cdbe9 277 GG(a, b, c, d, x[9], 5, k[24]);
Sergunb 0:8918a71cdbe9 278 GG(d, a, b, c, x[14], 9, k[25]);
Sergunb 0:8918a71cdbe9 279 GG(c, d, a, b, x[3], 14, k[26]);
Sergunb 0:8918a71cdbe9 280 GG(b, c, d, a, x[8], 20, k[27]);
Sergunb 0:8918a71cdbe9 281 GG(a, b, c, d, x[13], 5, k[28]);
Sergunb 0:8918a71cdbe9 282 GG(d, a, b, c, x[2], 9, k[29]);
Sergunb 0:8918a71cdbe9 283 GG(c, d, a, b, x[7], 14, k[30]);
Sergunb 0:8918a71cdbe9 284 GG(b, c, d, a, x[12], 20, k[31]);
Sergunb 0:8918a71cdbe9 285
Sergunb 0:8918a71cdbe9 286 //Round 3
Sergunb 0:8918a71cdbe9 287 HH(a, b, c, d, x[5], 4, k[32]);
Sergunb 0:8918a71cdbe9 288 HH(d, a, b, c, x[8], 11, k[33]);
Sergunb 0:8918a71cdbe9 289 HH(c, d, a, b, x[11], 16, k[34]);
Sergunb 0:8918a71cdbe9 290 HH(b, c, d, a, x[14], 23, k[35]);
Sergunb 0:8918a71cdbe9 291 HH(a, b, c, d, x[1], 4, k[36]);
Sergunb 0:8918a71cdbe9 292 HH(d, a, b, c, x[4], 11, k[37]);
Sergunb 0:8918a71cdbe9 293 HH(c, d, a, b, x[7], 16, k[38]);
Sergunb 0:8918a71cdbe9 294 HH(b, c, d, a, x[10], 23, k[39]);
Sergunb 0:8918a71cdbe9 295 HH(a, b, c, d, x[13], 4, k[40]);
Sergunb 0:8918a71cdbe9 296 HH(d, a, b, c, x[0], 11, k[41]);
Sergunb 0:8918a71cdbe9 297 HH(c, d, a, b, x[3], 16, k[42]);
Sergunb 0:8918a71cdbe9 298 HH(b, c, d, a, x[6], 23, k[43]);
Sergunb 0:8918a71cdbe9 299 HH(a, b, c, d, x[9], 4, k[44]);
Sergunb 0:8918a71cdbe9 300 HH(d, a, b, c, x[12], 11, k[45]);
Sergunb 0:8918a71cdbe9 301 HH(c, d, a, b, x[15], 16, k[46]);
Sergunb 0:8918a71cdbe9 302 HH(b, c, d, a, x[2], 23, k[47]);
Sergunb 0:8918a71cdbe9 303
Sergunb 0:8918a71cdbe9 304 //Round 4
Sergunb 0:8918a71cdbe9 305 II(a, b, c, d, x[0], 6, k[48]);
Sergunb 0:8918a71cdbe9 306 II(d, a, b, c, x[7], 10, k[49]);
Sergunb 0:8918a71cdbe9 307 II(c, d, a, b, x[14], 15, k[50]);
Sergunb 0:8918a71cdbe9 308 II(b, c, d, a, x[5], 21, k[51]);
Sergunb 0:8918a71cdbe9 309 II(a, b, c, d, x[12], 6, k[52]);
Sergunb 0:8918a71cdbe9 310 II(d, a, b, c, x[3], 10, k[53]);
Sergunb 0:8918a71cdbe9 311 II(c, d, a, b, x[10], 15, k[54]);
Sergunb 0:8918a71cdbe9 312 II(b, c, d, a, x[1], 21, k[55]);
Sergunb 0:8918a71cdbe9 313 II(a, b, c, d, x[8], 6, k[56]);
Sergunb 0:8918a71cdbe9 314 II(d, a, b, c, x[15], 10, k[57]);
Sergunb 0:8918a71cdbe9 315 II(c, d, a, b, x[6], 15, k[58]);
Sergunb 0:8918a71cdbe9 316 II(b, c, d, a, x[13], 21, k[59]);
Sergunb 0:8918a71cdbe9 317 II(a, b, c, d, x[4], 6, k[60]);
Sergunb 0:8918a71cdbe9 318 II(d, a, b, c, x[11], 10, k[61]);
Sergunb 0:8918a71cdbe9 319 II(c, d, a, b, x[2], 15, k[62]);
Sergunb 0:8918a71cdbe9 320 II(b, c, d, a, x[9], 21, k[63]);
Sergunb 0:8918a71cdbe9 321
Sergunb 0:8918a71cdbe9 322 //Update the hash value
Sergunb 0:8918a71cdbe9 323 context->h[0] += a;
Sergunb 0:8918a71cdbe9 324 context->h[1] += b;
Sergunb 0:8918a71cdbe9 325 context->h[2] += c;
Sergunb 0:8918a71cdbe9 326 context->h[3] += d;
Sergunb 0:8918a71cdbe9 327 }
Sergunb 0:8918a71cdbe9 328
Sergunb 0:8918a71cdbe9 329 #endif
Sergunb 0:8918a71cdbe9 330