1/********************************************************************\ 2 * 3 * FILE: rmd128.h 4 * 5 * CONTENTS: Header file for a sample C-implementation of the 6 * RIPEMD-128 hash-function. This function is a 7 * plug-in substitute for RIPEMD. A 160-bit hash 8 * result is obtained using RIPEMD-160. 9 * TARGET: any computer with an ANSI C compiler 10 * 11 * AUTHOR: Antoon Bosselaers, ESAT-COSIC 12 * DATE: 1 March 1996 13 * VERSION: 1.0 14 * 15 * Copyright (c) Katholieke Universiteit Leuven 16 * 1996, All Rights Reserved 17 * 18\********************************************************************/ 19/* AKU: 20 * <> added __alpha, 21 * <> unique prefix for function names 22 * <> using tcl.h, _ANSI_ARGS_ 23 */ 24 25#ifndef RMD128H /* make sure this file is read only once */ 26#define RMD128H 27 28/********************************************************************/ 29 30#include <tcl.h> 31 32/* typedef 8, 16 and 32 bit types, resp. */ 33/* adapt these, if necessary, 34 for your operating system and compiler */ 35typedef unsigned char byte; /* unsigned 8-bit type */ 36typedef unsigned short word; /* unsigned 16-bit type */ 37 38#if defined(__alpha) || defined(__LP64__) 39typedef unsigned int dword; /* unsigned 32-bit integer (AXP) */ 40#else 41typedef unsigned long dword; /* unsigned 32-bit type */ 42#endif 43 44/********************************************************************/ 45 46/* macro definitions */ 47 48/* collect four bytes into one word: */ 49#define BYTES_TO_DWORD(strptr) \ 50 (((dword) *((strptr)+3) << 24) | \ 51 ((dword) *((strptr)+2) << 16) | \ 52 ((dword) *((strptr)+1) << 8) | \ 53 ((dword) *(strptr))) 54 55/* ROL(x, n) cyclically rotates x over n bits to the left */ 56/* x must be of an unsigned 32 bits type and 0 <= n < 32. */ 57#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 58 59/* the three basic functions F(), G() and H() */ 60#define F(x, y, z) ((x) ^ (y) ^ (z)) 61#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) 62#define H(x, y, z) (((x) | ~(y)) ^ (z)) 63#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) 64 65/* the eight basic operations FF() through III() */ 66#define FF(a, b, c, d, x, s) {\ 67 (a) += F((b), (c), (d)) + (x);\ 68 (a) = ROL((a), (s));\ 69 } 70#define GG(a, b, c, d, x, s) {\ 71 (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\ 72 (a) = ROL((a), (s));\ 73 } 74#define HH(a, b, c, d, x, s) {\ 75 (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ 76 (a) = ROL((a), (s));\ 77 } 78#define II(a, b, c, d, x, s) {\ 79 (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ 80 (a) = ROL((a), (s));\ 81 } 82#define FFF(a, b, c, d, x, s) {\ 83 (a) += F((b), (c), (d)) + (x);\ 84 (a) = ROL((a), (s));\ 85 } 86#define GGG(a, b, c, d, x, s) {\ 87 (a) += G((b), (c), (d)) + (x) + 0x6d703ef3UL;\ 88 (a) = ROL((a), (s));\ 89 } 90#define HHH(a, b, c, d, x, s) {\ 91 (a) += H((b), (c), (d)) + (x) + 0x5c4dd124UL;\ 92 (a) = ROL((a), (s));\ 93 } 94#define III(a, b, c, d, x, s) {\ 95 (a) += I((b), (c), (d)) + (x) + 0x50a28be6UL;\ 96 (a) = ROL((a), (s));\ 97 } 98 99/********************************************************************/ 100 101/* function prototypes */ 102 103void 104ripemd128_MDinit _ANSI_ARGS_ ((dword *MDbuf)); 105/* 106 * initializes MDbuffer to "magic constants" 107 */ 108 109void 110ripemd128_compress _ANSI_ARGS_ ((dword *MDbuf, dword *X)); 111/* 112 * the compression function. 113 * transforms MDbuf using message bytes X[0] through X[15] 114 */ 115 116void 117ripemd128_MDfinish _ANSI_ARGS_ ((dword *MDbuf, byte *strptr, dword lswlen, dword mswlen)); 118/* 119 * puts bytes from strptr into X and pad out; appends length 120 * and finally, compresses the last block(s) 121 * note: length in bits == 8 * (lswlen + 2^32 mswlen). 122 * note: there are (lswlen mod 64) bytes left in strptr. 123 */ 124 125#endif /* RMD128H */ 126 127/*********************** end of file rmd128.h ***********************/ 128 129