Webserver+3d print
cyclone_crypto/ripemd128.c@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file ripemd128.c |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief RIPEMD-128 hash function |
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 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | //Switch to the appropriate trace level |
Sergunb | 0:8918a71cdbe9 | 30 | #define TRACE_LEVEL CRYPTO_TRACE_LEVEL |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include <string.h> |
Sergunb | 0:8918a71cdbe9 | 34 | #include "crypto.h" |
Sergunb | 0:8918a71cdbe9 | 35 | #include "ripemd128.h" |
Sergunb | 0:8918a71cdbe9 | 36 | |
Sergunb | 0:8918a71cdbe9 | 37 | //Check crypto library configuration |
Sergunb | 0:8918a71cdbe9 | 38 | #if (RIPEMD128_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 39 | |
Sergunb | 0:8918a71cdbe9 | 40 | //RIPEMD-128 auxiliary functions |
Sergunb | 0:8918a71cdbe9 | 41 | #define F(x, y, z) ((x) ^ (y) ^ (z)) |
Sergunb | 0:8918a71cdbe9 | 42 | #define G(x, y, z) (((x) & (y)) | (~(x) & (z))) |
Sergunb | 0:8918a71cdbe9 | 43 | #define H(x, y, z) (((x) | ~(y)) ^ (z)) |
Sergunb | 0:8918a71cdbe9 | 44 | #define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) |
Sergunb | 0:8918a71cdbe9 | 45 | |
Sergunb | 0:8918a71cdbe9 | 46 | #define FF(a, b, c, d, x, s) a += F(b, c, d) + (x), a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 47 | #define GG(a, b, c, d, x, s) a += G(b, c, d) + (x) + 0x5A827999, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 48 | #define HH(a, b, c, d, x, s) a += H(b, c, d) + (x) + 0x6ED9EBA1, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 49 | #define II(a, b, c, d, x, s) a += I(b, c, d) + (x) + 0x8F1BBCDC, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 50 | |
Sergunb | 0:8918a71cdbe9 | 51 | #define FFF(a, b, c, d, x, s) a += F(b, c, d) + (x), a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 52 | #define GGG(a, b, c, d, x, s) a += G(b, c, d) + (x) + 0x6D703EF3, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 53 | #define HHH(a, b, c, d, x, s) a += H(b, c, d) + (x) + 0x5C4DD124, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 54 | #define III(a, b, c, d, x, s) a += I(b, c, d) + (x) + 0x50A28BE6, a = ROL32(a, s) |
Sergunb | 0:8918a71cdbe9 | 55 | |
Sergunb | 0:8918a71cdbe9 | 56 | //RIPEMD-128 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 | //RIPEMD-128 object identifier (1.3.36.3.2.2) |
Sergunb | 0:8918a71cdbe9 | 66 | static const uint8_t ripemd128Oid[] = {0x2B, 0x24, 0x03, 0x02, 0x02}; |
Sergunb | 0:8918a71cdbe9 | 67 | |
Sergunb | 0:8918a71cdbe9 | 68 | //Common interface for hash algorithms |
Sergunb | 0:8918a71cdbe9 | 69 | const HashAlgo ripemd128HashAlgo = |
Sergunb | 0:8918a71cdbe9 | 70 | { |
Sergunb | 0:8918a71cdbe9 | 71 | "RIPEMD-128", |
Sergunb | 0:8918a71cdbe9 | 72 | ripemd128Oid, |
Sergunb | 0:8918a71cdbe9 | 73 | sizeof(ripemd128Oid), |
Sergunb | 0:8918a71cdbe9 | 74 | sizeof(Ripemd128Context), |
Sergunb | 0:8918a71cdbe9 | 75 | RIPEMD128_BLOCK_SIZE, |
Sergunb | 0:8918a71cdbe9 | 76 | RIPEMD128_DIGEST_SIZE, |
Sergunb | 0:8918a71cdbe9 | 77 | (HashAlgoCompute) ripemd128Compute, |
Sergunb | 0:8918a71cdbe9 | 78 | (HashAlgoInit) ripemd128Init, |
Sergunb | 0:8918a71cdbe9 | 79 | (HashAlgoUpdate) ripemd128Update, |
Sergunb | 0:8918a71cdbe9 | 80 | (HashAlgoFinal) ripemd128Final |
Sergunb | 0:8918a71cdbe9 | 81 | }; |
Sergunb | 0:8918a71cdbe9 | 82 | |
Sergunb | 0:8918a71cdbe9 | 83 | |
Sergunb | 0:8918a71cdbe9 | 84 | /** |
Sergunb | 0:8918a71cdbe9 | 85 | * @brief Digest a message using RIPEMD-128 |
Sergunb | 0:8918a71cdbe9 | 86 | * @param[in] data Pointer to the message being hashed |
Sergunb | 0:8918a71cdbe9 | 87 | * @param[in] length Length of the message |
Sergunb | 0:8918a71cdbe9 | 88 | * @param[out] digest Pointer to the calculated digest |
Sergunb | 0:8918a71cdbe9 | 89 | * @return Error code |
Sergunb | 0:8918a71cdbe9 | 90 | **/ |
Sergunb | 0:8918a71cdbe9 | 91 | |
Sergunb | 0:8918a71cdbe9 | 92 | error_t ripemd128Compute(const void *data, size_t length, uint8_t *digest) |
Sergunb | 0:8918a71cdbe9 | 93 | { |
Sergunb | 0:8918a71cdbe9 | 94 | //Allocate a memory buffer to hold the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 95 | Ripemd128Context *context = cryptoAllocMem(sizeof(Ripemd128Context)); |
Sergunb | 0:8918a71cdbe9 | 96 | //Failed to allocate memory? |
Sergunb | 0:8918a71cdbe9 | 97 | if(context == NULL) |
Sergunb | 0:8918a71cdbe9 | 98 | return ERROR_OUT_OF_MEMORY; |
Sergunb | 0:8918a71cdbe9 | 99 | |
Sergunb | 0:8918a71cdbe9 | 100 | //Initialize the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 101 | ripemd128Init(context); |
Sergunb | 0:8918a71cdbe9 | 102 | //Digest the message |
Sergunb | 0:8918a71cdbe9 | 103 | ripemd128Update(context, data, length); |
Sergunb | 0:8918a71cdbe9 | 104 | //Finalize the RIPEMD-128 message digest |
Sergunb | 0:8918a71cdbe9 | 105 | ripemd128Final(context, digest); |
Sergunb | 0:8918a71cdbe9 | 106 | |
Sergunb | 0:8918a71cdbe9 | 107 | //Free previously allocated memory |
Sergunb | 0:8918a71cdbe9 | 108 | cryptoFreeMem(context); |
Sergunb | 0:8918a71cdbe9 | 109 | //Successful processing |
Sergunb | 0:8918a71cdbe9 | 110 | return NO_ERROR; |
Sergunb | 0:8918a71cdbe9 | 111 | } |
Sergunb | 0:8918a71cdbe9 | 112 | |
Sergunb | 0:8918a71cdbe9 | 113 | |
Sergunb | 0:8918a71cdbe9 | 114 | /** |
Sergunb | 0:8918a71cdbe9 | 115 | * @brief Initialize RIPEMD-128 message digest context |
Sergunb | 0:8918a71cdbe9 | 116 | * @param[in] context Pointer to the RIPEMD-128 context to initialize |
Sergunb | 0:8918a71cdbe9 | 117 | **/ |
Sergunb | 0:8918a71cdbe9 | 118 | |
Sergunb | 0:8918a71cdbe9 | 119 | void ripemd128Init(Ripemd128Context *context) |
Sergunb | 0:8918a71cdbe9 | 120 | { |
Sergunb | 0:8918a71cdbe9 | 121 | //Set initial hash value |
Sergunb | 0:8918a71cdbe9 | 122 | context->h[0] = 0x67452301; |
Sergunb | 0:8918a71cdbe9 | 123 | context->h[1] = 0xEFCDAB89; |
Sergunb | 0:8918a71cdbe9 | 124 | context->h[2] = 0x98BADCFE; |
Sergunb | 0:8918a71cdbe9 | 125 | context->h[3] = 0x10325476; |
Sergunb | 0:8918a71cdbe9 | 126 | |
Sergunb | 0:8918a71cdbe9 | 127 | //Number of bytes in the buffer |
Sergunb | 0:8918a71cdbe9 | 128 | context->size = 0; |
Sergunb | 0:8918a71cdbe9 | 129 | //Total length of the message |
Sergunb | 0:8918a71cdbe9 | 130 | context->totalSize = 0; |
Sergunb | 0:8918a71cdbe9 | 131 | } |
Sergunb | 0:8918a71cdbe9 | 132 | |
Sergunb | 0:8918a71cdbe9 | 133 | |
Sergunb | 0:8918a71cdbe9 | 134 | /** |
Sergunb | 0:8918a71cdbe9 | 135 | * @brief Update the RIPEMD-128 context with a portion of the message being hashed |
Sergunb | 0:8918a71cdbe9 | 136 | * @param[in] context Pointer to the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 137 | * @param[in] data Pointer to the buffer being hashed |
Sergunb | 0:8918a71cdbe9 | 138 | * @param[in] length Length of the buffer |
Sergunb | 0:8918a71cdbe9 | 139 | **/ |
Sergunb | 0:8918a71cdbe9 | 140 | |
Sergunb | 0:8918a71cdbe9 | 141 | void ripemd128Update(Ripemd128Context *context, const void *data, size_t length) |
Sergunb | 0:8918a71cdbe9 | 142 | { |
Sergunb | 0:8918a71cdbe9 | 143 | size_t n; |
Sergunb | 0:8918a71cdbe9 | 144 | |
Sergunb | 0:8918a71cdbe9 | 145 | //Process the incoming data |
Sergunb | 0:8918a71cdbe9 | 146 | while(length > 0) |
Sergunb | 0:8918a71cdbe9 | 147 | { |
Sergunb | 0:8918a71cdbe9 | 148 | //The buffer can hold at most 64 bytes |
Sergunb | 0:8918a71cdbe9 | 149 | n = MIN(length, 64 - context->size); |
Sergunb | 0:8918a71cdbe9 | 150 | |
Sergunb | 0:8918a71cdbe9 | 151 | //Copy the data to the buffer |
Sergunb | 0:8918a71cdbe9 | 152 | memcpy(context->buffer + context->size, data, n); |
Sergunb | 0:8918a71cdbe9 | 153 | |
Sergunb | 0:8918a71cdbe9 | 154 | //Update the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 155 | context->size += n; |
Sergunb | 0:8918a71cdbe9 | 156 | context->totalSize += n; |
Sergunb | 0:8918a71cdbe9 | 157 | //Advance the data pointer |
Sergunb | 0:8918a71cdbe9 | 158 | data = (uint8_t *) data + n; |
Sergunb | 0:8918a71cdbe9 | 159 | //Remaining bytes to process |
Sergunb | 0:8918a71cdbe9 | 160 | length -= n; |
Sergunb | 0:8918a71cdbe9 | 161 | |
Sergunb | 0:8918a71cdbe9 | 162 | //Process message in 16-word blocks |
Sergunb | 0:8918a71cdbe9 | 163 | if(context->size == 64) |
Sergunb | 0:8918a71cdbe9 | 164 | { |
Sergunb | 0:8918a71cdbe9 | 165 | //Transform the 16-word block |
Sergunb | 0:8918a71cdbe9 | 166 | ripemd128ProcessBlock(context); |
Sergunb | 0:8918a71cdbe9 | 167 | //Empty the buffer |
Sergunb | 0:8918a71cdbe9 | 168 | context->size = 0; |
Sergunb | 0:8918a71cdbe9 | 169 | } |
Sergunb | 0:8918a71cdbe9 | 170 | } |
Sergunb | 0:8918a71cdbe9 | 171 | } |
Sergunb | 0:8918a71cdbe9 | 172 | |
Sergunb | 0:8918a71cdbe9 | 173 | |
Sergunb | 0:8918a71cdbe9 | 174 | /** |
Sergunb | 0:8918a71cdbe9 | 175 | * @brief Finish the RIPEMD-128 message digest |
Sergunb | 0:8918a71cdbe9 | 176 | * @param[in] context Pointer to the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 177 | * @param[out] digest Calculated digest (optional parameter) |
Sergunb | 0:8918a71cdbe9 | 178 | **/ |
Sergunb | 0:8918a71cdbe9 | 179 | |
Sergunb | 0:8918a71cdbe9 | 180 | void ripemd128Final(Ripemd128Context *context, uint8_t *digest) |
Sergunb | 0:8918a71cdbe9 | 181 | { |
Sergunb | 0:8918a71cdbe9 | 182 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 183 | size_t paddingSize; |
Sergunb | 0:8918a71cdbe9 | 184 | uint64_t totalSize; |
Sergunb | 0:8918a71cdbe9 | 185 | |
Sergunb | 0:8918a71cdbe9 | 186 | //Length of the original message (before padding) |
Sergunb | 0:8918a71cdbe9 | 187 | totalSize = context->totalSize * 8; |
Sergunb | 0:8918a71cdbe9 | 188 | |
Sergunb | 0:8918a71cdbe9 | 189 | //Pad the message so that its length is congruent to 56 modulo 64 |
Sergunb | 0:8918a71cdbe9 | 190 | if(context->size < 56) |
Sergunb | 0:8918a71cdbe9 | 191 | paddingSize = 56 - context->size; |
Sergunb | 0:8918a71cdbe9 | 192 | else |
Sergunb | 0:8918a71cdbe9 | 193 | paddingSize = 64 + 56 - context->size; |
Sergunb | 0:8918a71cdbe9 | 194 | |
Sergunb | 0:8918a71cdbe9 | 195 | //Append padding |
Sergunb | 0:8918a71cdbe9 | 196 | ripemd128Update(context, padding, paddingSize); |
Sergunb | 0:8918a71cdbe9 | 197 | |
Sergunb | 0:8918a71cdbe9 | 198 | //Append the length of the original message |
Sergunb | 0:8918a71cdbe9 | 199 | context->x[14] = htole32((uint32_t) totalSize); |
Sergunb | 0:8918a71cdbe9 | 200 | context->x[15] = htole32((uint32_t) (totalSize >> 32)); |
Sergunb | 0:8918a71cdbe9 | 201 | |
Sergunb | 0:8918a71cdbe9 | 202 | //Calculate the message digest |
Sergunb | 0:8918a71cdbe9 | 203 | ripemd128ProcessBlock(context); |
Sergunb | 0:8918a71cdbe9 | 204 | |
Sergunb | 0:8918a71cdbe9 | 205 | //Convert from host byte order to little-endian byte order |
Sergunb | 0:8918a71cdbe9 | 206 | for(i = 0; i < 4; i++) |
Sergunb | 0:8918a71cdbe9 | 207 | context->h[i] = htole32(context->h[i]); |
Sergunb | 0:8918a71cdbe9 | 208 | |
Sergunb | 0:8918a71cdbe9 | 209 | //Copy the resulting digest |
Sergunb | 0:8918a71cdbe9 | 210 | if(digest != NULL) |
Sergunb | 0:8918a71cdbe9 | 211 | memcpy(digest, context->digest, RIPEMD128_DIGEST_SIZE); |
Sergunb | 0:8918a71cdbe9 | 212 | } |
Sergunb | 0:8918a71cdbe9 | 213 | |
Sergunb | 0:8918a71cdbe9 | 214 | |
Sergunb | 0:8918a71cdbe9 | 215 | /** |
Sergunb | 0:8918a71cdbe9 | 216 | * @brief Process message in 16-word blocks |
Sergunb | 0:8918a71cdbe9 | 217 | * @param[in] context Pointer to the RIPEMD-128 context |
Sergunb | 0:8918a71cdbe9 | 218 | **/ |
Sergunb | 0:8918a71cdbe9 | 219 | |
Sergunb | 0:8918a71cdbe9 | 220 | void ripemd128ProcessBlock(Ripemd128Context *context) |
Sergunb | 0:8918a71cdbe9 | 221 | { |
Sergunb | 0:8918a71cdbe9 | 222 | uint_t i; |
Sergunb | 0:8918a71cdbe9 | 223 | |
Sergunb | 0:8918a71cdbe9 | 224 | //Initialize the working registers |
Sergunb | 0:8918a71cdbe9 | 225 | uint32_t aa= context->h[0]; |
Sergunb | 0:8918a71cdbe9 | 226 | uint32_t bb = context->h[1]; |
Sergunb | 0:8918a71cdbe9 | 227 | uint32_t cc = context->h[2]; |
Sergunb | 0:8918a71cdbe9 | 228 | uint32_t dd = context->h[3]; |
Sergunb | 0:8918a71cdbe9 | 229 | uint32_t aaa = context->h[0]; |
Sergunb | 0:8918a71cdbe9 | 230 | uint32_t bbb = context->h[1]; |
Sergunb | 0:8918a71cdbe9 | 231 | uint32_t ccc = context->h[2]; |
Sergunb | 0:8918a71cdbe9 | 232 | uint32_t ddd = context->h[3]; |
Sergunb | 0:8918a71cdbe9 | 233 | |
Sergunb | 0:8918a71cdbe9 | 234 | //Process message in 16-word blocks |
Sergunb | 0:8918a71cdbe9 | 235 | uint32_t *x = context->x; |
Sergunb | 0:8918a71cdbe9 | 236 | |
Sergunb | 0:8918a71cdbe9 | 237 | //Convert from little-endian byte order to host byte order |
Sergunb | 0:8918a71cdbe9 | 238 | for(i = 0; i < 16; i++) |
Sergunb | 0:8918a71cdbe9 | 239 | x[i] = letoh32(x[i]); |
Sergunb | 0:8918a71cdbe9 | 240 | |
Sergunb | 0:8918a71cdbe9 | 241 | //Round 1 |
Sergunb | 0:8918a71cdbe9 | 242 | FF(aa, bb, cc, dd, x[0], 11); |
Sergunb | 0:8918a71cdbe9 | 243 | FF(dd, aa, bb, cc, x[1], 14); |
Sergunb | 0:8918a71cdbe9 | 244 | FF(cc, dd, aa, bb, x[2], 15); |
Sergunb | 0:8918a71cdbe9 | 245 | FF(bb, cc, dd, aa, x[3], 12); |
Sergunb | 0:8918a71cdbe9 | 246 | FF(aa, bb, cc, dd, x[4], 5); |
Sergunb | 0:8918a71cdbe9 | 247 | FF(dd, aa, bb, cc, x[5], 8); |
Sergunb | 0:8918a71cdbe9 | 248 | FF(cc, dd, aa, bb, x[6], 7); |
Sergunb | 0:8918a71cdbe9 | 249 | FF(bb, cc, dd, aa, x[7], 9); |
Sergunb | 0:8918a71cdbe9 | 250 | FF(aa, bb, cc, dd, x[8], 11); |
Sergunb | 0:8918a71cdbe9 | 251 | FF(dd, aa, bb, cc, x[9], 13); |
Sergunb | 0:8918a71cdbe9 | 252 | FF(cc, dd, aa, bb, x[10], 14); |
Sergunb | 0:8918a71cdbe9 | 253 | FF(bb, cc, dd, aa, x[11], 15); |
Sergunb | 0:8918a71cdbe9 | 254 | FF(aa, bb, cc, dd, x[12], 6); |
Sergunb | 0:8918a71cdbe9 | 255 | FF(dd, aa, bb, cc, x[13], 7); |
Sergunb | 0:8918a71cdbe9 | 256 | FF(cc, dd, aa, bb, x[14], 9); |
Sergunb | 0:8918a71cdbe9 | 257 | FF(bb, cc, dd, aa, x[15], 8); |
Sergunb | 0:8918a71cdbe9 | 258 | |
Sergunb | 0:8918a71cdbe9 | 259 | //Round 2 |
Sergunb | 0:8918a71cdbe9 | 260 | GG(aa, bb, cc, dd, x[7], 7); |
Sergunb | 0:8918a71cdbe9 | 261 | GG(dd, aa, bb, cc, x[4], 6); |
Sergunb | 0:8918a71cdbe9 | 262 | GG(cc, dd, aa, bb, x[13], 8); |
Sergunb | 0:8918a71cdbe9 | 263 | GG(bb, cc, dd, aa, x[1], 13); |
Sergunb | 0:8918a71cdbe9 | 264 | GG(aa, bb, cc, dd, x[10], 11); |
Sergunb | 0:8918a71cdbe9 | 265 | GG(dd, aa, bb, cc, x[6], 9); |
Sergunb | 0:8918a71cdbe9 | 266 | GG(cc, dd, aa, bb, x[15], 7); |
Sergunb | 0:8918a71cdbe9 | 267 | GG(bb, cc, dd, aa, x[3], 15); |
Sergunb | 0:8918a71cdbe9 | 268 | GG(aa, bb, cc, dd, x[12], 7); |
Sergunb | 0:8918a71cdbe9 | 269 | GG(dd, aa, bb, cc, x[0], 12); |
Sergunb | 0:8918a71cdbe9 | 270 | GG(cc, dd, aa, bb, x[9], 15); |
Sergunb | 0:8918a71cdbe9 | 271 | GG(bb, cc, dd, aa, x[5], 9); |
Sergunb | 0:8918a71cdbe9 | 272 | GG(aa, bb, cc, dd, x[2], 11); |
Sergunb | 0:8918a71cdbe9 | 273 | GG(dd, aa, bb, cc, x[14], 7); |
Sergunb | 0:8918a71cdbe9 | 274 | GG(cc, dd, aa, bb, x[11], 13); |
Sergunb | 0:8918a71cdbe9 | 275 | GG(bb, cc, dd, aa, x[8], 12); |
Sergunb | 0:8918a71cdbe9 | 276 | |
Sergunb | 0:8918a71cdbe9 | 277 | //Round 3 |
Sergunb | 0:8918a71cdbe9 | 278 | HH(aa, bb, cc, dd, x[3], 11); |
Sergunb | 0:8918a71cdbe9 | 279 | HH(dd, aa, bb, cc, x[10], 13); |
Sergunb | 0:8918a71cdbe9 | 280 | HH(cc, dd, aa, bb, x[14], 6); |
Sergunb | 0:8918a71cdbe9 | 281 | HH(bb, cc, dd, aa, x[4], 7); |
Sergunb | 0:8918a71cdbe9 | 282 | HH(aa, bb, cc, dd, x[9], 14); |
Sergunb | 0:8918a71cdbe9 | 283 | HH(dd, aa, bb, cc, x[15], 9); |
Sergunb | 0:8918a71cdbe9 | 284 | HH(cc, dd, aa, bb, x[8], 13); |
Sergunb | 0:8918a71cdbe9 | 285 | HH(bb, cc, dd, aa, x[1], 15); |
Sergunb | 0:8918a71cdbe9 | 286 | HH(aa, bb, cc, dd, x[2], 14); |
Sergunb | 0:8918a71cdbe9 | 287 | HH(dd, aa, bb, cc, x[7], 8); |
Sergunb | 0:8918a71cdbe9 | 288 | HH(cc, dd, aa, bb, x[0], 13); |
Sergunb | 0:8918a71cdbe9 | 289 | HH(bb, cc, dd, aa, x[6], 6); |
Sergunb | 0:8918a71cdbe9 | 290 | HH(aa, bb, cc, dd, x[13], 5); |
Sergunb | 0:8918a71cdbe9 | 291 | HH(dd, aa, bb, cc, x[11], 12); |
Sergunb | 0:8918a71cdbe9 | 292 | HH(cc, dd, aa, bb, x[5], 7); |
Sergunb | 0:8918a71cdbe9 | 293 | HH(bb, cc, dd, aa, x[12], 5); |
Sergunb | 0:8918a71cdbe9 | 294 | |
Sergunb | 0:8918a71cdbe9 | 295 | //Round 4 |
Sergunb | 0:8918a71cdbe9 | 296 | II(aa, bb, cc, dd, x[1], 11); |
Sergunb | 0:8918a71cdbe9 | 297 | II(dd, aa, bb, cc, x[9], 12); |
Sergunb | 0:8918a71cdbe9 | 298 | II(cc, dd, aa, bb, x[11], 14); |
Sergunb | 0:8918a71cdbe9 | 299 | II(bb, cc, dd, aa, x[10], 15); |
Sergunb | 0:8918a71cdbe9 | 300 | II(aa, bb, cc, dd, x[0], 14); |
Sergunb | 0:8918a71cdbe9 | 301 | II(dd, aa, bb, cc, x[8], 15); |
Sergunb | 0:8918a71cdbe9 | 302 | II(cc, dd, aa, bb, x[12], 9); |
Sergunb | 0:8918a71cdbe9 | 303 | II(bb, cc, dd, aa, x[4], 8); |
Sergunb | 0:8918a71cdbe9 | 304 | II(aa, bb, cc, dd, x[13], 9); |
Sergunb | 0:8918a71cdbe9 | 305 | II(dd, aa, bb, cc, x[3], 14); |
Sergunb | 0:8918a71cdbe9 | 306 | II(cc, dd, aa, bb, x[7], 5); |
Sergunb | 0:8918a71cdbe9 | 307 | II(bb, cc, dd, aa, x[15], 6); |
Sergunb | 0:8918a71cdbe9 | 308 | II(aa, bb, cc, dd, x[14], 8); |
Sergunb | 0:8918a71cdbe9 | 309 | II(dd, aa, bb, cc, x[5], 6); |
Sergunb | 0:8918a71cdbe9 | 310 | II(cc, dd, aa, bb, x[6], 5); |
Sergunb | 0:8918a71cdbe9 | 311 | II(bb, cc, dd, aa, x[2], 12); |
Sergunb | 0:8918a71cdbe9 | 312 | |
Sergunb | 0:8918a71cdbe9 | 313 | //Parallel round 1 |
Sergunb | 0:8918a71cdbe9 | 314 | III(aaa, bbb, ccc, ddd, x[5], 8); |
Sergunb | 0:8918a71cdbe9 | 315 | III(ddd, aaa, bbb, ccc, x[14], 9); |
Sergunb | 0:8918a71cdbe9 | 316 | III(ccc, ddd, aaa, bbb, x[7], 9); |
Sergunb | 0:8918a71cdbe9 | 317 | III(bbb, ccc, ddd, aaa, x[0], 11); |
Sergunb | 0:8918a71cdbe9 | 318 | III(aaa, bbb, ccc, ddd, x[9], 13); |
Sergunb | 0:8918a71cdbe9 | 319 | III(ddd, aaa, bbb, ccc, x[2], 15); |
Sergunb | 0:8918a71cdbe9 | 320 | III(ccc, ddd, aaa, bbb, x[11], 15); |
Sergunb | 0:8918a71cdbe9 | 321 | III(bbb, ccc, ddd, aaa, x[4], 5); |
Sergunb | 0:8918a71cdbe9 | 322 | III(aaa, bbb, ccc, ddd, x[13], 7); |
Sergunb | 0:8918a71cdbe9 | 323 | III(ddd, aaa, bbb, ccc, x[6], 7); |
Sergunb | 0:8918a71cdbe9 | 324 | III(ccc, ddd, aaa, bbb, x[15], 8); |
Sergunb | 0:8918a71cdbe9 | 325 | III(bbb, ccc, ddd, aaa, x[8], 11); |
Sergunb | 0:8918a71cdbe9 | 326 | III(aaa, bbb, ccc, ddd, x[1], 14); |
Sergunb | 0:8918a71cdbe9 | 327 | III(ddd, aaa, bbb, ccc, x[10], 14); |
Sergunb | 0:8918a71cdbe9 | 328 | III(ccc, ddd, aaa, bbb, x[3], 12); |
Sergunb | 0:8918a71cdbe9 | 329 | III(bbb, ccc, ddd, aaa, x[12], 6); |
Sergunb | 0:8918a71cdbe9 | 330 | |
Sergunb | 0:8918a71cdbe9 | 331 | //Parallel round 2 |
Sergunb | 0:8918a71cdbe9 | 332 | HHH(aaa, bbb, ccc, ddd, x[6], 9); |
Sergunb | 0:8918a71cdbe9 | 333 | HHH(ddd, aaa, bbb, ccc, x[11], 13); |
Sergunb | 0:8918a71cdbe9 | 334 | HHH(ccc, ddd, aaa, bbb, x[3], 15); |
Sergunb | 0:8918a71cdbe9 | 335 | HHH(bbb, ccc, ddd, aaa, x[7], 7); |
Sergunb | 0:8918a71cdbe9 | 336 | HHH(aaa, bbb, ccc, ddd, x[0], 12); |
Sergunb | 0:8918a71cdbe9 | 337 | HHH(ddd, aaa, bbb, ccc, x[13], 8); |
Sergunb | 0:8918a71cdbe9 | 338 | HHH(ccc, ddd, aaa, bbb, x[5], 9); |
Sergunb | 0:8918a71cdbe9 | 339 | HHH(bbb, ccc, ddd, aaa, x[10], 11); |
Sergunb | 0:8918a71cdbe9 | 340 | HHH(aaa, bbb, ccc, ddd, x[14], 7); |
Sergunb | 0:8918a71cdbe9 | 341 | HHH(ddd, aaa, bbb, ccc, x[15], 7); |
Sergunb | 0:8918a71cdbe9 | 342 | HHH(ccc, ddd, aaa, bbb, x[8], 12); |
Sergunb | 0:8918a71cdbe9 | 343 | HHH(bbb, ccc, ddd, aaa, x[12], 7); |
Sergunb | 0:8918a71cdbe9 | 344 | HHH(aaa, bbb, ccc, ddd, x[4], 6); |
Sergunb | 0:8918a71cdbe9 | 345 | HHH(ddd, aaa, bbb, ccc, x[9], 15); |
Sergunb | 0:8918a71cdbe9 | 346 | HHH(ccc, ddd, aaa, bbb, x[1], 13); |
Sergunb | 0:8918a71cdbe9 | 347 | HHH(bbb, ccc, ddd, aaa, x[2], 11); |
Sergunb | 0:8918a71cdbe9 | 348 | |
Sergunb | 0:8918a71cdbe9 | 349 | //Parallel round 3 |
Sergunb | 0:8918a71cdbe9 | 350 | GGG(aaa, bbb, ccc, ddd, x[15], 9); |
Sergunb | 0:8918a71cdbe9 | 351 | GGG(ddd, aaa, bbb, ccc, x[5], 7); |
Sergunb | 0:8918a71cdbe9 | 352 | GGG(ccc, ddd, aaa, bbb, x[1], 15); |
Sergunb | 0:8918a71cdbe9 | 353 | GGG(bbb, ccc, ddd, aaa, x[3], 11); |
Sergunb | 0:8918a71cdbe9 | 354 | GGG(aaa, bbb, ccc, ddd, x[7], 8); |
Sergunb | 0:8918a71cdbe9 | 355 | GGG(ddd, aaa, bbb, ccc, x[14], 6); |
Sergunb | 0:8918a71cdbe9 | 356 | GGG(ccc, ddd, aaa, bbb, x[6], 6); |
Sergunb | 0:8918a71cdbe9 | 357 | GGG(bbb, ccc, ddd, aaa, x[9], 14); |
Sergunb | 0:8918a71cdbe9 | 358 | GGG(aaa, bbb, ccc, ddd, x[11], 12); |
Sergunb | 0:8918a71cdbe9 | 359 | GGG(ddd, aaa, bbb, ccc, x[8], 13); |
Sergunb | 0:8918a71cdbe9 | 360 | GGG(ccc, ddd, aaa, bbb, x[12], 5); |
Sergunb | 0:8918a71cdbe9 | 361 | GGG(bbb, ccc, ddd, aaa, x[2], 14); |
Sergunb | 0:8918a71cdbe9 | 362 | GGG(aaa, bbb, ccc, ddd, x[10], 13); |
Sergunb | 0:8918a71cdbe9 | 363 | GGG(ddd, aaa, bbb, ccc, x[0], 13); |
Sergunb | 0:8918a71cdbe9 | 364 | GGG(ccc, ddd, aaa, bbb, x[4], 7); |
Sergunb | 0:8918a71cdbe9 | 365 | GGG(bbb, ccc, ddd, aaa, x[13], 5); |
Sergunb | 0:8918a71cdbe9 | 366 | |
Sergunb | 0:8918a71cdbe9 | 367 | //Parallel round 4 |
Sergunb | 0:8918a71cdbe9 | 368 | FFF(aaa, bbb, ccc, ddd, x[8], 15); |
Sergunb | 0:8918a71cdbe9 | 369 | FFF(ddd, aaa, bbb, ccc, x[6], 5); |
Sergunb | 0:8918a71cdbe9 | 370 | FFF(ccc, ddd, aaa, bbb, x[4], 8); |
Sergunb | 0:8918a71cdbe9 | 371 | FFF(bbb, ccc, ddd, aaa, x[1], 11); |
Sergunb | 0:8918a71cdbe9 | 372 | FFF(aaa, bbb, ccc, ddd, x[3], 14); |
Sergunb | 0:8918a71cdbe9 | 373 | FFF(ddd, aaa, bbb, ccc, x[11], 14); |
Sergunb | 0:8918a71cdbe9 | 374 | FFF(ccc, ddd, aaa, bbb, x[15], 6); |
Sergunb | 0:8918a71cdbe9 | 375 | FFF(bbb, ccc, ddd, aaa, x[0], 14); |
Sergunb | 0:8918a71cdbe9 | 376 | FFF(aaa, bbb, ccc, ddd, x[5], 6); |
Sergunb | 0:8918a71cdbe9 | 377 | FFF(ddd, aaa, bbb, ccc, x[12], 9); |
Sergunb | 0:8918a71cdbe9 | 378 | FFF(ccc, ddd, aaa, bbb, x[2], 12); |
Sergunb | 0:8918a71cdbe9 | 379 | FFF(bbb, ccc, ddd, aaa, x[13], 9); |
Sergunb | 0:8918a71cdbe9 | 380 | FFF(aaa, bbb, ccc, ddd, x[9], 12); |
Sergunb | 0:8918a71cdbe9 | 381 | FFF(ddd, aaa, bbb, ccc, x[7], 5); |
Sergunb | 0:8918a71cdbe9 | 382 | FFF(ccc, ddd, aaa, bbb, x[10], 15); |
Sergunb | 0:8918a71cdbe9 | 383 | FFF(bbb, ccc, ddd, aaa, x[14], 8); |
Sergunb | 0:8918a71cdbe9 | 384 | |
Sergunb | 0:8918a71cdbe9 | 385 | //Combine results |
Sergunb | 0:8918a71cdbe9 | 386 | ddd = context->h[1] + cc + ddd; |
Sergunb | 0:8918a71cdbe9 | 387 | context->h[1] = context->h[2] + dd + aaa; |
Sergunb | 0:8918a71cdbe9 | 388 | context->h[2] = context->h[3] + aa + bbb; |
Sergunb | 0:8918a71cdbe9 | 389 | context->h[3] = context->h[0] + bb + ccc; |
Sergunb | 0:8918a71cdbe9 | 390 | context->h[0] = ddd; |
Sergunb | 0:8918a71cdbe9 | 391 | } |
Sergunb | 0:8918a71cdbe9 | 392 | |
Sergunb | 0:8918a71cdbe9 | 393 | #endif |
Sergunb | 0:8918a71cdbe9 | 394 |