diff options
Diffstat (limited to 'src/lib/libcrypto/ripemd/rmd_locl.h')
| -rw-r--r-- | src/lib/libcrypto/ripemd/rmd_locl.h | 182 |
1 files changed, 58 insertions, 124 deletions
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h index a1feccf7c1..7b835dfbd4 100644 --- a/src/lib/libcrypto/ripemd/rmd_locl.h +++ b/src/lib/libcrypto/ripemd/rmd_locl.h | |||
| @@ -58,138 +58,72 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdlib.h> | 59 | #include <stdlib.h> |
| 60 | #include <string.h> | 60 | #include <string.h> |
| 61 | #include "ripemd.h" | 61 | #include <openssl/opensslconf.h> |
| 62 | #include <openssl/ripemd.h> | ||
| 62 | 63 | ||
| 63 | #define ULONG unsigned long | 64 | #ifndef RIPEMD160_LONG_LOG2 |
| 64 | #define UCHAR unsigned char | 65 | #define RIPEMD160_LONG_LOG2 2 /* default to 32 bits */ |
| 65 | #define UINT unsigned int | 66 | #endif |
| 66 | 67 | ||
| 67 | #ifdef NOCONST | 68 | /* |
| 68 | #define const | 69 | * DO EXAMINE COMMENTS IN crypto/md5/md5_locl.h & crypto/md5/md5_dgst.c |
| 70 | * FOR EXPLANATIONS ON FOLLOWING "CODE." | ||
| 71 | * <appro@fy.chalmers.se> | ||
| 72 | */ | ||
| 73 | #ifdef RMD160_ASM | ||
| 74 | # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) | ||
| 75 | # define ripemd160_block_host_order ripemd160_block_asm_host_order | ||
| 76 | # endif | ||
| 69 | #endif | 77 | #endif |
| 70 | 78 | ||
| 71 | #undef c2nl | 79 | void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num); |
| 72 | #define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ | 80 | void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num); |
| 73 | l|=(((unsigned long)(*((c)++)))<<16), \ | 81 | |
| 74 | l|=(((unsigned long)(*((c)++)))<< 8), \ | 82 | #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) |
| 75 | l|=(((unsigned long)(*((c)++))) )) | 83 | #define ripemd160_block_data_order ripemd160_block_host_order |
| 76 | |||
| 77 | #undef p_c2nl | ||
| 78 | #define p_c2nl(c,l,n) { \ | ||
| 79 | switch (n) { \ | ||
| 80 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 81 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 82 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 83 | case 3: l|=((unsigned long)(*((c)++))); \ | ||
| 84 | } \ | ||
| 85 | } | ||
| 86 | |||
| 87 | #undef c2nl_p | ||
| 88 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 89 | #define c2nl_p(c,l,n) { \ | ||
| 90 | l=0; \ | ||
| 91 | (c)+=n; \ | ||
| 92 | switch (n) { \ | ||
| 93 | case 3: l =((unsigned long)(*(--(c))))<< 8; \ | ||
| 94 | case 2: l|=((unsigned long)(*(--(c))))<<16; \ | ||
| 95 | case 1: l|=((unsigned long)(*(--(c))))<<24; \ | ||
| 96 | } \ | ||
| 97 | } | ||
| 98 | |||
| 99 | #undef p_c2nl_p | ||
| 100 | #define p_c2nl_p(c,l,sc,len) { \ | ||
| 101 | switch (sc) \ | ||
| 102 | { \ | ||
| 103 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 104 | if (--len == 0) break; \ | ||
| 105 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 106 | if (--len == 0) break; \ | ||
| 107 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 108 | } \ | ||
| 109 | } | ||
| 110 | |||
| 111 | #undef nl2c | ||
| 112 | #define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
| 113 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 114 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 115 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 116 | |||
| 117 | #undef c2l | ||
| 118 | #define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ | ||
| 119 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 120 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 121 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
| 122 | |||
| 123 | #undef p_c2l | ||
| 124 | #define p_c2l(c,l,n) { \ | ||
| 125 | switch (n) { \ | ||
| 126 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 127 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 128 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 129 | case 3: l|=((unsigned long)(*((c)++)))<<24; \ | ||
| 130 | } \ | ||
| 131 | } | ||
| 132 | |||
| 133 | #undef c2l_p | ||
| 134 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 135 | #define c2l_p(c,l,n) { \ | ||
| 136 | l=0; \ | ||
| 137 | (c)+=n; \ | ||
| 138 | switch (n) { \ | ||
| 139 | case 3: l =((unsigned long)(*(--(c))))<<16; \ | ||
| 140 | case 2: l|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 141 | case 1: l|=((unsigned long)(*(--(c)))); \ | ||
| 142 | } \ | ||
| 143 | } | ||
| 144 | |||
| 145 | #undef p_c2l_p | ||
| 146 | #define p_c2l_p(c,l,sc,len) { \ | ||
| 147 | switch (sc) \ | ||
| 148 | { \ | ||
| 149 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 150 | if (--len == 0) break; \ | ||
| 151 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 152 | if (--len == 0) break; \ | ||
| 153 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 154 | } \ | ||
| 155 | } | ||
| 156 | |||
| 157 | #undef l2c | ||
| 158 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 159 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 160 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 161 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
| 162 | |||
| 163 | #undef ROTATE | ||
| 164 | #if defined(WIN32) | ||
| 165 | #define ROTATE(a,n) _lrotl(a,n) | ||
| 166 | #else | ||
| 167 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
| 168 | #endif | 84 | #endif |
| 169 | 85 | ||
| 170 | /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ | 86 | #define DATA_ORDER_IS_LITTLE_ENDIAN |
| 171 | #if defined(WIN32) | 87 | |
| 172 | /* 5 instructions with rotate instruction, else 9 */ | 88 | #define HASH_LONG RIPEMD160_LONG |
| 173 | #define Endian_Reverse32(a) \ | 89 | #define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2 |
| 174 | { \ | 90 | #define HASH_CTX RIPEMD160_CTX |
| 175 | unsigned long l=(a); \ | 91 | #define HASH_CBLOCK RIPEMD160_CBLOCK |
| 176 | (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ | 92 | #define HASH_LBLOCK RIPEMD160_LBLOCK |
| 177 | } | 93 | #define HASH_UPDATE RIPEMD160_Update |
| 178 | #else | 94 | #define HASH_TRANSFORM RIPEMD160_Transform |
| 179 | /* 6 instructions with rotate instruction, else 8 */ | 95 | #define HASH_FINAL RIPEMD160_Final |
| 180 | #define Endian_Reverse32(a) \ | 96 | #define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order |
| 181 | { \ | 97 | #define HASH_MAKE_STRING(c,s) do { \ |
| 182 | unsigned long l=(a); \ | 98 | unsigned long ll; \ |
| 183 | l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ | 99 | ll=(c)->A; HOST_l2c(ll,(s)); \ |
| 184 | (a)=ROTATE(l,16L); \ | 100 | ll=(c)->B; HOST_l2c(ll,(s)); \ |
| 185 | } | 101 | ll=(c)->C; HOST_l2c(ll,(s)); \ |
| 102 | ll=(c)->D; HOST_l2c(ll,(s)); \ | ||
| 103 | ll=(c)->E; HOST_l2c(ll,(s)); \ | ||
| 104 | } while (0) | ||
| 105 | #if !defined(L_ENDIAN) || defined(ripemd160_block_data_order) | ||
| 106 | #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order | ||
| 186 | #endif | 107 | #endif |
| 187 | 108 | ||
| 109 | #include "md32_common.h" | ||
| 110 | |||
| 111 | #if 0 | ||
| 188 | #define F1(x,y,z) ((x)^(y)^(z)) | 112 | #define F1(x,y,z) ((x)^(y)^(z)) |
| 189 | #define F2(x,y,z) (((x)&(y))|((~x)&z)) | 113 | #define F2(x,y,z) (((x)&(y))|((~x)&z)) |
| 190 | #define F3(x,y,z) (((x)|(~y))^(z)) | 114 | #define F3(x,y,z) (((x)|(~y))^(z)) |
| 191 | #define F4(x,y,z) (((x)&(z))|((y)&(~(z)))) | 115 | #define F4(x,y,z) (((x)&(z))|((y)&(~(z)))) |
| 192 | #define F5(x,y,z) ((x)^((y)|(~(z)))) | 116 | #define F5(x,y,z) ((x)^((y)|(~(z)))) |
| 117 | #else | ||
| 118 | /* | ||
| 119 | * Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com> | ||
| 120 | */ | ||
| 121 | #define F1(x,y,z) ((x) ^ (y) ^ (z)) | ||
| 122 | #define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z)) | ||
| 123 | #define F3(x,y,z) (((~(y)) | (x)) ^ (z)) | ||
| 124 | #define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y)) | ||
| 125 | #define F5(x,y,z) (((~(z)) | (y)) ^ (x)) | ||
| 126 | #endif | ||
| 193 | 127 | ||
| 194 | #define RIPEMD160_A 0x67452301L | 128 | #define RIPEMD160_A 0x67452301L |
| 195 | #define RIPEMD160_B 0xEFCDAB89L | 129 | #define RIPEMD160_B 0xEFCDAB89L |
| @@ -200,27 +134,27 @@ | |||
| 200 | #include "rmdconst.h" | 134 | #include "rmdconst.h" |
| 201 | 135 | ||
| 202 | #define RIP1(a,b,c,d,e,w,s) { \ | 136 | #define RIP1(a,b,c,d,e,w,s) { \ |
| 203 | a+=F1(b,c,d)+X[w]; \ | 137 | a+=F1(b,c,d)+X(w); \ |
| 204 | a=ROTATE(a,s)+e; \ | 138 | a=ROTATE(a,s)+e; \ |
| 205 | c=ROTATE(c,10); } | 139 | c=ROTATE(c,10); } |
| 206 | 140 | ||
| 207 | #define RIP2(a,b,c,d,e,w,s,K) { \ | 141 | #define RIP2(a,b,c,d,e,w,s,K) { \ |
| 208 | a+=F2(b,c,d)+X[w]+K; \ | 142 | a+=F2(b,c,d)+X(w)+K; \ |
| 209 | a=ROTATE(a,s)+e; \ | 143 | a=ROTATE(a,s)+e; \ |
| 210 | c=ROTATE(c,10); } | 144 | c=ROTATE(c,10); } |
| 211 | 145 | ||
| 212 | #define RIP3(a,b,c,d,e,w,s,K) { \ | 146 | #define RIP3(a,b,c,d,e,w,s,K) { \ |
| 213 | a+=F3(b,c,d)+X[w]+K; \ | 147 | a+=F3(b,c,d)+X(w)+K; \ |
| 214 | a=ROTATE(a,s)+e; \ | 148 | a=ROTATE(a,s)+e; \ |
| 215 | c=ROTATE(c,10); } | 149 | c=ROTATE(c,10); } |
| 216 | 150 | ||
| 217 | #define RIP4(a,b,c,d,e,w,s,K) { \ | 151 | #define RIP4(a,b,c,d,e,w,s,K) { \ |
| 218 | a+=F4(b,c,d)+X[w]+K; \ | 152 | a+=F4(b,c,d)+X(w)+K; \ |
| 219 | a=ROTATE(a,s)+e; \ | 153 | a=ROTATE(a,s)+e; \ |
| 220 | c=ROTATE(c,10); } | 154 | c=ROTATE(c,10); } |
| 221 | 155 | ||
| 222 | #define RIP5(a,b,c,d,e,w,s,K) { \ | 156 | #define RIP5(a,b,c,d,e,w,s,K) { \ |
| 223 | a+=F5(b,c,d)+X[w]+K; \ | 157 | a+=F5(b,c,d)+X(w)+K; \ |
| 224 | a=ROTATE(a,s)+e; \ | 158 | a=ROTATE(a,s)+e; \ |
| 225 | c=ROTATE(c,10); } | 159 | c=ROTATE(c,10); } |
| 226 | 160 | ||
