1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 * All rights reserved. 3 * 4 * This package is an SSL implementation written 5 * by Eric Young (eay@cryptsoft.com). 6 * The implementation was written so as to conform with Netscapes SSL. 7 * 8 * This library is free for commercial and non-commercial use as long as 9 * the following conditions are aheared to. The following conditions 10 * apply to all code found in this distribution, be it the RC4, RSA, 11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * included with this distribution is covered by the same copyright terms 13 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * 15 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * the code are not to be removed. 17 * If this package is used in a product, Eric Young should be given attribution 18 * as the author of the parts of the library used. 19 * This can be in the form of a textual message at program startup or 20 * in documentation (online or textual) provided with the package. 21 * 22 * Redistribution and use in source and binary forms, with or without 23 * modification, are permitted provided that the following conditions 24 * are met: 25 * 1. Redistributions of source code must retain the copyright 26 * notice, this list of conditions and the following disclaimer. 27 * 2. Redistributions in binary form must reproduce the above copyright 28 * notice, this list of conditions and the following disclaimer in the 29 * documentation and/or other materials provided with the distribution. 30 * 3. All advertising materials mentioning features or use of this software 31 * must display the following acknowledgement: 32 * "This product includes cryptographic software written by 33 * Eric Young (eay@cryptsoft.com)" 34 * The word 'cryptographic' can be left out if the rouines from the library 35 * being used are not cryptographic related :-). 36 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * the apps directory (application code) you must include an acknowledgement: 38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * 40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * SUCH DAMAGE. 51 * 52 * The licence and distribution terms for any publically available version or 53 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * copied and put under another distribution licence 55 * [including the GNU Public Licence.] */ 56 57 #ifndef OPENSSL_HEADER_RIPEMD_INTERNAL_H 58 #define OPENSSL_HEADER_RIPEMD_INTERNAL_H 59 60 #include <openssl/base.h> 61 62 #if defined(__cplusplus) 63 extern "C" { 64 #endif 65 66 67 static void ripemd160_block_data_order(uint32_t h[5], const uint8_t *data, 68 size_t num); 69 70 #define DATA_ORDER_IS_LITTLE_ENDIAN 71 72 #define HASH_LONG uint32_t 73 #define HASH_CTX RIPEMD160_CTX 74 #define HASH_CBLOCK RIPEMD160_CBLOCK 75 #define HASH_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH 76 #define HASH_UPDATE RIPEMD160_Update 77 #define HASH_TRANSFORM RIPEMD160_Transform 78 #define HASH_FINAL RIPEMD160_Final 79 #define HASH_MAKE_STRING(c, s) \ 80 do { \ 81 unsigned long ll; \ 82 ll = (c)->h[0]; \ 83 HOST_l2c(ll, (s)); \ 84 ll = (c)->h[1]; \ 85 HOST_l2c(ll, (s)); \ 86 ll = (c)->h[2]; \ 87 HOST_l2c(ll, (s)); \ 88 ll = (c)->h[3]; \ 89 HOST_l2c(ll, (s)); \ 90 ll = (c)->h[4]; \ 91 HOST_l2c(ll, (s)); \ 92 } while (0) 93 #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order 94 95 #include "../../crypto/fipsmodule/digest/md32_common.h" 96 97 // Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com> 98 #define F1(x, y, z) ((x) ^ (y) ^ (z)) 99 #define F2(x, y, z) ((((y) ^ (z)) & (x)) ^ (z)) 100 #define F3(x, y, z) (((~(y)) | (x)) ^ (z)) 101 #define F4(x, y, z) ((((x) ^ (y)) & (z)) ^ (y)) 102 #define F5(x, y, z) (((~(z)) | (y)) ^ (x)) 103 104 #define RIPEMD160_A 0x67452301L 105 #define RIPEMD160_B 0xEFCDAB89L 106 #define RIPEMD160_C 0x98BADCFEL 107 #define RIPEMD160_D 0x10325476L 108 #define RIPEMD160_E 0xC3D2E1F0L 109 110 #define ROTATE(a, n) (((a) << (n)) | (((a)&0xffffffff) >> (32 - (n)))) 111 112 #define RIP1(a, b, c, d, e, w, s) \ 113 { \ 114 a += F1(b, c, d) + X(w); \ 115 a = ROTATE(a, s) + e; \ 116 c = ROTATE(c, 10); \ 117 } 118 119 #define RIP2(a, b, c, d, e, w, s, K) \ 120 { \ 121 a += F2(b, c, d) + X(w) + K; \ 122 a = ROTATE(a, s) + e; \ 123 c = ROTATE(c, 10); \ 124 } 125 126 #define RIP3(a, b, c, d, e, w, s, K) \ 127 { \ 128 a += F3(b, c, d) + X(w) + K; \ 129 a = ROTATE(a, s) + e; \ 130 c = ROTATE(c, 10); \ 131 } 132 133 #define RIP4(a, b, c, d, e, w, s, K) \ 134 { \ 135 a += F4(b, c, d) + X(w) + K; \ 136 a = ROTATE(a, s) + e; \ 137 c = ROTATE(c, 10); \ 138 } 139 140 #define RIP5(a, b, c, d, e, w, s, K) \ 141 { \ 142 a += F5(b, c, d) + X(w) + K; \ 143 a = ROTATE(a, s) + e; \ 144 c = ROTATE(c, 10); \ 145 } 146 147 #define KL0 0x00000000L 148 #define KL1 0x5A827999L 149 #define KL2 0x6ED9EBA1L 150 #define KL3 0x8F1BBCDCL 151 #define KL4 0xA953FD4EL 152 153 #define KR0 0x50A28BE6L 154 #define KR1 0x5C4DD124L 155 #define KR2 0x6D703EF3L 156 #define KR3 0x7A6D76E9L 157 #define KR4 0x00000000L 158 159 #define WL00 0 160 #define SL00 11 161 #define WL01 1 162 #define SL01 14 163 #define WL02 2 164 #define SL02 15 165 #define WL03 3 166 #define SL03 12 167 #define WL04 4 168 #define SL04 5 169 #define WL05 5 170 #define SL05 8 171 #define WL06 6 172 #define SL06 7 173 #define WL07 7 174 #define SL07 9 175 #define WL08 8 176 #define SL08 11 177 #define WL09 9 178 #define SL09 13 179 #define WL10 10 180 #define SL10 14 181 #define WL11 11 182 #define SL11 15 183 #define WL12 12 184 #define SL12 6 185 #define WL13 13 186 #define SL13 7 187 #define WL14 14 188 #define SL14 9 189 #define WL15 15 190 #define SL15 8 191 192 #define WL16 7 193 #define SL16 7 194 #define WL17 4 195 #define SL17 6 196 #define WL18 13 197 #define SL18 8 198 #define WL19 1 199 #define SL19 13 200 #define WL20 10 201 #define SL20 11 202 #define WL21 6 203 #define SL21 9 204 #define WL22 15 205 #define SL22 7 206 #define WL23 3 207 #define SL23 15 208 #define WL24 12 209 #define SL24 7 210 #define WL25 0 211 #define SL25 12 212 #define WL26 9 213 #define SL26 15 214 #define WL27 5 215 #define SL27 9 216 #define WL28 2 217 #define SL28 11 218 #define WL29 14 219 #define SL29 7 220 #define WL30 11 221 #define SL30 13 222 #define WL31 8 223 #define SL31 12 224 225 #define WL32 3 226 #define SL32 11 227 #define WL33 10 228 #define SL33 13 229 #define WL34 14 230 #define SL34 6 231 #define WL35 4 232 #define SL35 7 233 #define WL36 9 234 #define SL36 14 235 #define WL37 15 236 #define SL37 9 237 #define WL38 8 238 #define SL38 13 239 #define WL39 1 240 #define SL39 15 241 #define WL40 2 242 #define SL40 14 243 #define WL41 7 244 #define SL41 8 245 #define WL42 0 246 #define SL42 13 247 #define WL43 6 248 #define SL43 6 249 #define WL44 13 250 #define SL44 5 251 #define WL45 11 252 #define SL45 12 253 #define WL46 5 254 #define SL46 7 255 #define WL47 12 256 #define SL47 5 257 258 #define WL48 1 259 #define SL48 11 260 #define WL49 9 261 #define SL49 12 262 #define WL50 11 263 #define SL50 14 264 #define WL51 10 265 #define SL51 15 266 #define WL52 0 267 #define SL52 14 268 #define WL53 8 269 #define SL53 15 270 #define WL54 12 271 #define SL54 9 272 #define WL55 4 273 #define SL55 8 274 #define WL56 13 275 #define SL56 9 276 #define WL57 3 277 #define SL57 14 278 #define WL58 7 279 #define SL58 5 280 #define WL59 15 281 #define SL59 6 282 #define WL60 14 283 #define SL60 8 284 #define WL61 5 285 #define SL61 6 286 #define WL62 6 287 #define SL62 5 288 #define WL63 2 289 #define SL63 12 290 291 #define WL64 4 292 #define SL64 9 293 #define WL65 0 294 #define SL65 15 295 #define WL66 5 296 #define SL66 5 297 #define WL67 9 298 #define SL67 11 299 #define WL68 7 300 #define SL68 6 301 #define WL69 12 302 #define SL69 8 303 #define WL70 2 304 #define SL70 13 305 #define WL71 10 306 #define SL71 12 307 #define WL72 14 308 #define SL72 5 309 #define WL73 1 310 #define SL73 12 311 #define WL74 3 312 #define SL74 13 313 #define WL75 8 314 #define SL75 14 315 #define WL76 11 316 #define SL76 11 317 #define WL77 6 318 #define SL77 8 319 #define WL78 15 320 #define SL78 5 321 #define WL79 13 322 #define SL79 6 323 324 #define WR00 5 325 #define SR00 8 326 #define WR01 14 327 #define SR01 9 328 #define WR02 7 329 #define SR02 9 330 #define WR03 0 331 #define SR03 11 332 #define WR04 9 333 #define SR04 13 334 #define WR05 2 335 #define SR05 15 336 #define WR06 11 337 #define SR06 15 338 #define WR07 4 339 #define SR07 5 340 #define WR08 13 341 #define SR08 7 342 #define WR09 6 343 #define SR09 7 344 #define WR10 15 345 #define SR10 8 346 #define WR11 8 347 #define SR11 11 348 #define WR12 1 349 #define SR12 14 350 #define WR13 10 351 #define SR13 14 352 #define WR14 3 353 #define SR14 12 354 #define WR15 12 355 #define SR15 6 356 357 #define WR16 6 358 #define SR16 9 359 #define WR17 11 360 #define SR17 13 361 #define WR18 3 362 #define SR18 15 363 #define WR19 7 364 #define SR19 7 365 #define WR20 0 366 #define SR20 12 367 #define WR21 13 368 #define SR21 8 369 #define WR22 5 370 #define SR22 9 371 #define WR23 10 372 #define SR23 11 373 #define WR24 14 374 #define SR24 7 375 #define WR25 15 376 #define SR25 7 377 #define WR26 8 378 #define SR26 12 379 #define WR27 12 380 #define SR27 7 381 #define WR28 4 382 #define SR28 6 383 #define WR29 9 384 #define SR29 15 385 #define WR30 1 386 #define SR30 13 387 #define WR31 2 388 #define SR31 11 389 390 #define WR32 15 391 #define SR32 9 392 #define WR33 5 393 #define SR33 7 394 #define WR34 1 395 #define SR34 15 396 #define WR35 3 397 #define SR35 11 398 #define WR36 7 399 #define SR36 8 400 #define WR37 14 401 #define SR37 6 402 #define WR38 6 403 #define SR38 6 404 #define WR39 9 405 #define SR39 14 406 #define WR40 11 407 #define SR40 12 408 #define WR41 8 409 #define SR41 13 410 #define WR42 12 411 #define SR42 5 412 #define WR43 2 413 #define SR43 14 414 #define WR44 10 415 #define SR44 13 416 #define WR45 0 417 #define SR45 13 418 #define WR46 4 419 #define SR46 7 420 #define WR47 13 421 #define SR47 5 422 423 #define WR48 8 424 #define SR48 15 425 #define WR49 6 426 #define SR49 5 427 #define WR50 4 428 #define SR50 8 429 #define WR51 1 430 #define SR51 11 431 #define WR52 3 432 #define SR52 14 433 #define WR53 11 434 #define SR53 14 435 #define WR54 15 436 #define SR54 6 437 #define WR55 0 438 #define SR55 14 439 #define WR56 5 440 #define SR56 6 441 #define WR57 12 442 #define SR57 9 443 #define WR58 2 444 #define SR58 12 445 #define WR59 13 446 #define SR59 9 447 #define WR60 9 448 #define SR60 12 449 #define WR61 7 450 #define SR61 5 451 #define WR62 10 452 #define SR62 15 453 #define WR63 14 454 #define SR63 8 455 456 #define WR64 12 457 #define SR64 8 458 #define WR65 15 459 #define SR65 5 460 #define WR66 10 461 #define SR66 12 462 #define WR67 4 463 #define SR67 9 464 #define WR68 1 465 #define SR68 12 466 #define WR69 5 467 #define SR69 5 468 #define WR70 8 469 #define SR70 14 470 #define WR71 7 471 #define SR71 6 472 #define WR72 6 473 #define SR72 8 474 #define WR73 2 475 #define SR73 13 476 #define WR74 13 477 #define SR74 6 478 #define WR75 14 479 #define SR75 5 480 #define WR76 0 481 #define SR76 15 482 #define WR77 3 483 #define SR77 13 484 #define WR78 9 485 #define SR78 11 486 #define WR79 11 487 #define SR79 11 488 489 490 #if defined(__cplusplus) 491 } // extern C 492 #endif 493 494 #endif // OPENSSL_HEADER_RIPEMD_INTERNAL_H 495