2016-05-18 02:51:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:56:39 +08:00
|
|
|
*
|
2018-12-06 20:53:00 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:34 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:56:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-08-28 20:55:45 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/ripemd.h>
|
1998-12-21 18:56:39 +08:00
|
|
|
|
1999-08-28 20:55:45 +08:00
|
|
|
/*
|
2019-09-28 06:45:40 +08:00
|
|
|
* DO EXAMINE COMMENTS IN crypto/md5/md5_local.h & crypto/md5/md5_dgst.c
|
1999-08-28 20:55:45 +08:00
|
|
|
* FOR EXPLANATIONS ON FOLLOWING "CODE."
|
|
|
|
*/
|
|
|
|
#ifdef RMD160_ASM
|
2016-05-01 20:14:34 +08:00
|
|
|
# if defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
2006-10-11 19:55:11 +08:00
|
|
|
# define ripemd160_block_data_order ripemd160_block_asm_data_order
|
1999-08-28 20:55:45 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2004-05-15 19:29:55 +08:00
|
|
|
void ripemd160_block_data_order(RIPEMD160_CTX *c, const void *p, size_t num);
|
1999-08-28 20:55:45 +08:00
|
|
|
|
|
|
|
#define DATA_ORDER_IS_LITTLE_ENDIAN
|
|
|
|
|
|
|
|
#define HASH_LONG RIPEMD160_LONG
|
|
|
|
#define HASH_CTX RIPEMD160_CTX
|
|
|
|
#define HASH_CBLOCK RIPEMD160_CBLOCK
|
|
|
|
#define HASH_UPDATE RIPEMD160_Update
|
|
|
|
#define HASH_TRANSFORM RIPEMD160_Transform
|
|
|
|
#define HASH_FINAL RIPEMD160_Final
|
|
|
|
#define HASH_MAKE_STRING(c,s) do { \
|
1999-09-06 17:29:29 +08:00
|
|
|
unsigned long ll; \
|
2013-01-14 05:04:39 +08:00
|
|
|
ll=(c)->A; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->B; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->C; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->D; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->E; (void)HOST_l2c(ll,(s)); \
|
1999-08-28 20:55:45 +08:00
|
|
|
} while (0)
|
|
|
|
#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/md32_common.h"
|
1998-12-21 18:56:39 +08:00
|
|
|
|
1999-08-28 20:55:45 +08:00
|
|
|
/*
|
2017-10-11 05:55:09 +08:00
|
|
|
* Transformed F2 and F4 are courtesy of Wei Dai
|
1999-08-28 20:55:45 +08:00
|
|
|
*/
|
2015-02-04 00:20:56 +08:00
|
|
|
#define F1(x,y,z) ((x) ^ (y) ^ (z))
|
|
|
|
#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
|
|
|
|
#define F3(x,y,z) (((~(y)) | (x)) ^ (z))
|
|
|
|
#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
|
|
|
|
#define F5(x,y,z) (((~(z)) | (y)) ^ (x))
|
1998-12-21 18:56:39 +08:00
|
|
|
|
|
|
|
#define RIPEMD160_A 0x67452301L
|
|
|
|
#define RIPEMD160_B 0xEFCDAB89L
|
|
|
|
#define RIPEMD160_C 0x98BADCFEL
|
|
|
|
#define RIPEMD160_D 0x10325476L
|
|
|
|
#define RIPEMD160_E 0xC3D2E1F0L
|
|
|
|
|
|
|
|
#include "rmdconst.h"
|
|
|
|
|
|
|
|
#define RIP1(a,b,c,d,e,w,s) { \
|
1999-08-28 20:55:45 +08:00
|
|
|
a+=F1(b,c,d)+X(w); \
|
1998-12-21 18:56:39 +08:00
|
|
|
a=ROTATE(a,s)+e; \
|
|
|
|
c=ROTATE(c,10); }
|
|
|
|
|
|
|
|
#define RIP2(a,b,c,d,e,w,s,K) { \
|
1999-08-28 20:55:45 +08:00
|
|
|
a+=F2(b,c,d)+X(w)+K; \
|
1998-12-21 18:56:39 +08:00
|
|
|
a=ROTATE(a,s)+e; \
|
|
|
|
c=ROTATE(c,10); }
|
|
|
|
|
|
|
|
#define RIP3(a,b,c,d,e,w,s,K) { \
|
1999-08-28 20:55:45 +08:00
|
|
|
a+=F3(b,c,d)+X(w)+K; \
|
1998-12-21 18:56:39 +08:00
|
|
|
a=ROTATE(a,s)+e; \
|
|
|
|
c=ROTATE(c,10); }
|
|
|
|
|
|
|
|
#define RIP4(a,b,c,d,e,w,s,K) { \
|
1999-08-28 20:55:45 +08:00
|
|
|
a+=F4(b,c,d)+X(w)+K; \
|
1998-12-21 18:56:39 +08:00
|
|
|
a=ROTATE(a,s)+e; \
|
|
|
|
c=ROTATE(c,10); }
|
|
|
|
|
|
|
|
#define RIP5(a,b,c,d,e,w,s,K) { \
|
1999-08-28 20:55:45 +08:00
|
|
|
a+=F5(b,c,d)+X(w)+K; \
|
1998-12-21 18:56:39 +08:00
|
|
|
a=ROTATE(a,s)+e; \
|
|
|
|
c=ROTATE(c,10); }
|