1/********************************************************************\ 2 * FILE: rmd160.h 3 * CONTENTS: Header file for a sample C-implementation of the 4 * RIPEMD-160 hash-function. 5 * AUTHOR: Antoon Bosselaers, Dept. Electrical Eng.-ESAT/COSIC 6 * DATE: 1 March 1996 VERSION: 1.0 7\********************************************************************/ 8 9#ifndef RMD160H /* make sure this file is read only once */ 10#define RMD160H 11 12/********************************************************************/ 13/* Type definitions of an 8 and a 32-bit integer type, respectively. 14 Adapt these, if necessary, for your operating system and compiler 15*/ 16typedef unsigned char byte; /* unsigned 8-bit integer */ 17typedef unsigned long word; /* unsigned 32-bit integer */ 18 19/********************************************************************/ 20/* Macro definitions */ 21 22/* ROL(x, n) cyclically rotates x over n bits to the left 23 x must be of an unsigned 32 bits type and 0 <= n < 32. 24*/ 25#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 26 27/* The five basic RIPEMD-160 functions F1(), F2(), F3(), F4(), and F5() 28*/ 29#define F1(x, y, z) ((x) ^ (y) ^ (z)) 30#define F2(x, y, z) (((x) & (y)) | (~(x) & (z))) 31#define F3(x, y, z) (((x) | ~(y)) ^ (z)) 32#define F4(x, y, z) (((x) & (z)) | ((y) & ~(z))) 33#define F5(x, y, z) ((x) ^ ((y) | ~(z))) 34 35/* The ten basic RIPEMD-160 transformations FF1() through FFF5() 36*/ 37#define FF1(a, b, c, d, e, x, s) {\ 38 (a) += F1((b), (c), (d)) + (x);\ 39 (a) = ROL((a), (s)) + (e);\ 40 (c) = ROL((c), 10);\ 41 } 42#define FF2(a, b, c, d, e, x, s) {\ 43 (a) += F2((b), (c), (d)) + (x) + 0x5a827999UL;\ 44 (a) = ROL((a), (s)) + (e);\ 45 (c) = ROL((c), 10);\ 46 } 47#define FF3(a, b, c, d, e, x, s) {\ 48 (a) += F3((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ 49 (a) = ROL((a), (s)) + (e);\ 50 (c) = ROL((c), 10);\ 51 } 52#define FF4(a, b, c, d, e, x, s) {\ 53 (a) += F4((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ 54 (a) = ROL((a), (s)) + (e);\ 55 (c) = ROL((c), 10);\ 56 } 57#define FF5(a, b, c, d, e, x, s) {\ 58 (a) += F5((b), (c), (d)) + (x) + 0xa953fd4eUL;\ 59 (a) = ROL((a), (s)) + (e);\ 60 (c) = ROL((c), 10);\ 61 } 62#define FFF1(a, b, c, d, e, x, s) {\ 63 (a) += F1((b), (c), (d)) + (x);\ 64 (a) = ROL((a), (s)) + (e);\ 65 (c) = ROL((c), 10);\ 66 } 67#define FFF2(a, b, c, d, e, x, s) {\ 68 (a) += F2((b), (c), (d)) + (x) + 0x7a6d76e9UL;\ 69 (a) = ROL((a), (s)) + (e);\ 70 (c) = ROL((c), 10);\ 71 } 72#define FFF3(a, b, c, d, e, x, s) {\ 73 (a) += F3((b), (c), (d)) + (x) + 0x6d703ef3UL;\ 74 (a) = ROL((a), (s)) + (e);\ 75 (c) = ROL((c), 10);\ 76 } 77#define FFF4(a, b, c, d, e, x, s) {\ 78 (a) += F4((b), (c), (d)) + (x) + 0x5c4dd124UL;\ 79 (a) = ROL((a), (s)) + (e);\ 80 (c) = ROL((c), 10);\ 81 } 82#define FFF5(a, b, c, d, e, x, s) {\ 83 (a) += F5((b), (c), (d)) + (x) + 0x50a28be6UL;\ 84 (a) = ROL((a), (s)) + (e);\ 85 (c) = ROL((c), 10);\ 86 } 87 88/********************************************************************/ 89/* Function prototypes */ 90 91void MDinit(word *MDbuf); 92void MDcompress(word *MDbuf, word *X); 93void MDfinish(word *MDbuf, byte *string, word lswlen, word mswlen); 94 95#endif /* RMD160H */ 96 97/*********************** end of file rmd160.h ***********************/ 98 99