1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdlib.h> 11e1051a39Sopenharmony_ci#include <string.h> 12e1051a39Sopenharmony_ci#include <openssl/opensslconf.h> 13e1051a39Sopenharmony_ci#include <openssl/ripemd.h> 14e1051a39Sopenharmony_ci 15e1051a39Sopenharmony_ci/* 16e1051a39Sopenharmony_ci * DO EXAMINE COMMENTS IN crypto/md5/md5_local.h & crypto/md5/md5_dgst.c 17e1051a39Sopenharmony_ci * FOR EXPLANATIONS ON FOLLOWING "CODE." 18e1051a39Sopenharmony_ci */ 19e1051a39Sopenharmony_ci#ifdef RMD160_ASM 20e1051a39Sopenharmony_ci# if defined(__i386) || defined(__i386__) || defined(_M_IX86) 21e1051a39Sopenharmony_ci# define ripemd160_block_data_order ripemd160_block_asm_data_order 22e1051a39Sopenharmony_ci# endif 23e1051a39Sopenharmony_ci#endif 24e1051a39Sopenharmony_ci 25e1051a39Sopenharmony_civoid ripemd160_block_data_order(RIPEMD160_CTX *c, const void *p, size_t num); 26e1051a39Sopenharmony_ci 27e1051a39Sopenharmony_ci#define DATA_ORDER_IS_LITTLE_ENDIAN 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_ci#define HASH_LONG RIPEMD160_LONG 30e1051a39Sopenharmony_ci#define HASH_CTX RIPEMD160_CTX 31e1051a39Sopenharmony_ci#define HASH_CBLOCK RIPEMD160_CBLOCK 32e1051a39Sopenharmony_ci#define HASH_UPDATE RIPEMD160_Update 33e1051a39Sopenharmony_ci#define HASH_TRANSFORM RIPEMD160_Transform 34e1051a39Sopenharmony_ci#define HASH_FINAL RIPEMD160_Final 35e1051a39Sopenharmony_ci#define HASH_MAKE_STRING(c,s) do { \ 36e1051a39Sopenharmony_ci unsigned long ll; \ 37e1051a39Sopenharmony_ci ll=(c)->A; (void)HOST_l2c(ll,(s)); \ 38e1051a39Sopenharmony_ci ll=(c)->B; (void)HOST_l2c(ll,(s)); \ 39e1051a39Sopenharmony_ci ll=(c)->C; (void)HOST_l2c(ll,(s)); \ 40e1051a39Sopenharmony_ci ll=(c)->D; (void)HOST_l2c(ll,(s)); \ 41e1051a39Sopenharmony_ci ll=(c)->E; (void)HOST_l2c(ll,(s)); \ 42e1051a39Sopenharmony_ci } while (0) 43e1051a39Sopenharmony_ci#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order 44e1051a39Sopenharmony_ci 45e1051a39Sopenharmony_ci#include "crypto/md32_common.h" 46e1051a39Sopenharmony_ci 47e1051a39Sopenharmony_ci/* 48e1051a39Sopenharmony_ci * Transformed F2 and F4 are courtesy of Wei Dai 49e1051a39Sopenharmony_ci */ 50e1051a39Sopenharmony_ci#define F1(x,y,z) ((x) ^ (y) ^ (z)) 51e1051a39Sopenharmony_ci#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z)) 52e1051a39Sopenharmony_ci#define F3(x,y,z) (((~(y)) | (x)) ^ (z)) 53e1051a39Sopenharmony_ci#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y)) 54e1051a39Sopenharmony_ci#define F5(x,y,z) (((~(z)) | (y)) ^ (x)) 55e1051a39Sopenharmony_ci 56e1051a39Sopenharmony_ci#define RIPEMD160_A 0x67452301L 57e1051a39Sopenharmony_ci#define RIPEMD160_B 0xEFCDAB89L 58e1051a39Sopenharmony_ci#define RIPEMD160_C 0x98BADCFEL 59e1051a39Sopenharmony_ci#define RIPEMD160_D 0x10325476L 60e1051a39Sopenharmony_ci#define RIPEMD160_E 0xC3D2E1F0L 61e1051a39Sopenharmony_ci 62e1051a39Sopenharmony_ci#include "rmdconst.h" 63e1051a39Sopenharmony_ci 64e1051a39Sopenharmony_ci#define RIP1(a,b,c,d,e,w,s) { \ 65e1051a39Sopenharmony_ci a+=F1(b,c,d)+X(w); \ 66e1051a39Sopenharmony_ci a=ROTATE(a,s)+e; \ 67e1051a39Sopenharmony_ci c=ROTATE(c,10); } 68e1051a39Sopenharmony_ci 69e1051a39Sopenharmony_ci#define RIP2(a,b,c,d,e,w,s,K) { \ 70e1051a39Sopenharmony_ci a+=F2(b,c,d)+X(w)+K; \ 71e1051a39Sopenharmony_ci a=ROTATE(a,s)+e; \ 72e1051a39Sopenharmony_ci c=ROTATE(c,10); } 73e1051a39Sopenharmony_ci 74e1051a39Sopenharmony_ci#define RIP3(a,b,c,d,e,w,s,K) { \ 75e1051a39Sopenharmony_ci a+=F3(b,c,d)+X(w)+K; \ 76e1051a39Sopenharmony_ci a=ROTATE(a,s)+e; \ 77e1051a39Sopenharmony_ci c=ROTATE(c,10); } 78e1051a39Sopenharmony_ci 79e1051a39Sopenharmony_ci#define RIP4(a,b,c,d,e,w,s,K) { \ 80e1051a39Sopenharmony_ci a+=F4(b,c,d)+X(w)+K; \ 81e1051a39Sopenharmony_ci a=ROTATE(a,s)+e; \ 82e1051a39Sopenharmony_ci c=ROTATE(c,10); } 83e1051a39Sopenharmony_ci 84e1051a39Sopenharmony_ci#define RIP5(a,b,c,d,e,w,s,K) { \ 85e1051a39Sopenharmony_ci a+=F5(b,c,d)+X(w)+K; \ 86e1051a39Sopenharmony_ci a=ROTATE(a,s)+e; \ 87e1051a39Sopenharmony_ci c=ROTATE(c,10); } 88