diff options
author | beck <> | 1999-09-29 04:37:45 +0000 |
---|---|---|
committer | beck <> | 1999-09-29 04:37:45 +0000 |
commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/md5/md5_locl.h | |
parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/md5/md5_locl.h')
-rw-r--r-- | src/lib/libcrypto/md5/md5_locl.h | 160 |
1 files changed, 67 insertions, 93 deletions
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h index dbbe1b71ca..9d04696dbd 100644 --- a/src/lib/libcrypto/md5/md5_locl.h +++ b/src/lib/libcrypto/md5/md5_locl.h | |||
@@ -56,102 +56,84 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | /* On sparc, this actually slows things down :-( */ | ||
60 | #if defined(sun) | ||
61 | #undef B_ENDIAN | ||
62 | #endif | ||
63 | |||
64 | #include <stdlib.h> | 59 | #include <stdlib.h> |
65 | #include <string.h> | 60 | #include <string.h> |
66 | #include "md5.h" | 61 | #include <openssl/opensslconf.h> |
67 | 62 | #include <openssl/md5.h> | |
68 | #define ULONG unsigned long | ||
69 | #define UCHAR unsigned char | ||
70 | #define UINT unsigned int | ||
71 | 63 | ||
72 | #if defined(NOCONST) | 64 | #ifndef MD5_LONG_LOG2 |
73 | #define const | 65 | #define MD5_LONG_LOG2 2 /* default to 32 bits */ |
74 | #endif | 66 | #endif |
75 | 67 | ||
76 | #undef c2l | 68 | #ifdef MD5_ASM |
77 | #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ | 69 | # if defined(__i386) || defined(_M_IX86) |
78 | l|=(((unsigned long)(*((c)++)))<< 8), \ | 70 | # define md5_block_host_order md5_block_asm_host_order |
79 | l|=(((unsigned long)(*((c)++)))<<16), \ | 71 | # elif defined(__sparc) && defined(ULTRASPARC) |
80 | l|=(((unsigned long)(*((c)++)))<<24)) | 72 | void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num); |
81 | 73 | # define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned | |
82 | #undef p_c2l | 74 | # endif |
83 | #define p_c2l(c,l,n) { \ | 75 | #endif |
84 | switch (n) { \ | ||
85 | case 0: l =((unsigned long)(*((c)++))); \ | ||
86 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
87 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
88 | case 3: l|=((unsigned long)(*((c)++)))<<24; \ | ||
89 | } \ | ||
90 | } | ||
91 | |||
92 | /* NOTE the pointer is not incremented at the end of this */ | ||
93 | #undef c2l_p | ||
94 | #define c2l_p(c,l,n) { \ | ||
95 | l=0; \ | ||
96 | (c)+=n; \ | ||
97 | switch (n) { \ | ||
98 | case 3: l =((unsigned long)(*(--(c))))<<16; \ | ||
99 | case 2: l|=((unsigned long)(*(--(c))))<< 8; \ | ||
100 | case 1: l|=((unsigned long)(*(--(c)))) ; \ | ||
101 | } \ | ||
102 | } | ||
103 | 76 | ||
104 | #undef p_c2l_p | 77 | void md5_block_host_order (MD5_CTX *c, const void *p,int num); |
105 | #define p_c2l_p(c,l,sc,len) { \ | 78 | void md5_block_data_order (MD5_CTX *c, const void *p,int num); |
106 | switch (sc) \ | ||
107 | { \ | ||
108 | case 0: l =((unsigned long)(*((c)++))); \ | ||
109 | if (--len == 0) break; \ | ||
110 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
111 | if (--len == 0) break; \ | ||
112 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
113 | } \ | ||
114 | } | ||
115 | 79 | ||
116 | #undef l2c | 80 | #if defined(__i386) || defined(_M_IX86) |
117 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | 81 | /* |
118 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | 82 | * *_block_host_order is expected to handle aligned data while |
119 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | 83 | * *_block_data_order - unaligned. As algorithm and host (x86) |
120 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | 84 | * are in this case of the same "endianess" these two are |
85 | * otherwise indistinguishable. But normally you don't want to | ||
86 | * call the same function because unaligned access in places | ||
87 | * where alignment is expected is usually a "Bad Thing". Indeed, | ||
88 | * on RISCs you get punished with BUS ERROR signal or *severe* | ||
89 | * performance degradation. Intel CPUs are in turn perfectly | ||
90 | * capable of loading unaligned data without such drastic side | ||
91 | * effect. Yes, they say it's slower than aligned load, but no | ||
92 | * exception is generated and therefore performance degradation | ||
93 | * is *incomparable* with RISCs. What we should weight here is | ||
94 | * costs of unaligned access against costs of aligning data. | ||
95 | * According to my measurements allowing unaligned access results | ||
96 | * in ~9% performance improvement on Pentium II operating at | ||
97 | * 266MHz. I won't be surprised if the difference will be higher | ||
98 | * on faster systems:-) | ||
99 | * | ||
100 | * <appro@fy.chalmers.se> | ||
101 | */ | ||
102 | #define md5_block_data_order md5_block_host_order | ||
103 | #endif | ||
121 | 104 | ||
122 | /* NOTE - c is not incremented as per l2c */ | 105 | #define DATA_ORDER_IS_LITTLE_ENDIAN |
123 | #undef l2cn | 106 | |
124 | #define l2cn(l1,l2,c,n) { \ | 107 | #define HASH_LONG MD5_LONG |
125 | c+=n; \ | 108 | #define HASH_LONG_LOG2 MD5_LONG_LOG2 |
126 | switch (n) { \ | 109 | #define HASH_CTX MD5_CTX |
127 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | 110 | #define HASH_CBLOCK MD5_CBLOCK |
128 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | 111 | #define HASH_LBLOCK MD5_LBLOCK |
129 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | 112 | #define HASH_UPDATE MD5_Update |
130 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | 113 | #define HASH_TRANSFORM MD5_Transform |
131 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | 114 | #define HASH_FINAL MD5_Final |
132 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | 115 | #define HASH_BLOCK_HOST_ORDER md5_block_host_order |
133 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | 116 | #if !defined(L_ENDIAN) || defined(md5_block_data_order) |
134 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | 117 | #define HASH_BLOCK_DATA_ORDER md5_block_data_order |
135 | } \ | 118 | /* |
136 | } | 119 | * Little-endians (Intel and Alpha) feel better without this. |
120 | * It looks like memcpy does better job than generic | ||
121 | * md5_block_data_order on copying-n-aligning input data. | ||
122 | * But franlky speaking I didn't expect such result on Alpha. | ||
123 | * On the other hand I've got this with egcs-1.0.2 and if | ||
124 | * program is compiled with another (better?) compiler it | ||
125 | * might turn out other way around. | ||
126 | * | ||
127 | * <appro@fy.chalmers.se> | ||
128 | */ | ||
129 | #endif | ||
137 | 130 | ||
138 | /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ | 131 | #ifndef FLAT_INC |
139 | #if defined(WIN32) | 132 | #include "../md32_common.h" |
140 | /* 5 instructions with rotate instruction, else 9 */ | ||
141 | #define Endian_Reverse32(a) \ | ||
142 | { \ | ||
143 | unsigned long l=(a); \ | ||
144 | (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ | ||
145 | } | ||
146 | #else | 133 | #else |
147 | /* 6 instructions with rotate instruction, else 8 */ | 134 | #include "md32_common.h" |
148 | #define Endian_Reverse32(a) \ | ||
149 | { \ | ||
150 | unsigned long l=(a); \ | ||
151 | l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ | ||
152 | (a)=ROTATE(l,16L); \ | ||
153 | } | ||
154 | #endif | 135 | #endif |
136 | |||
155 | /* | 137 | /* |
156 | #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) | 138 | #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) |
157 | #define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) | 139 | #define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) |
@@ -166,14 +148,6 @@ | |||
166 | #define H(b,c,d) ((b) ^ (c) ^ (d)) | 148 | #define H(b,c,d) ((b) ^ (c) ^ (d)) |
167 | #define I(b,c,d) (((~(d)) | (b)) ^ (c)) | 149 | #define I(b,c,d) (((~(d)) | (b)) ^ (c)) |
168 | 150 | ||
169 | #undef ROTATE | ||
170 | #if defined(WIN32) | ||
171 | #define ROTATE(a,n) _lrotl(a,n) | ||
172 | #else | ||
173 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
174 | #endif | ||
175 | |||
176 | |||
177 | #define R0(a,b,c,d,k,s,t) { \ | 151 | #define R0(a,b,c,d,k,s,t) { \ |
178 | a+=((k)+(t)+F((b),(c),(d))); \ | 152 | a+=((k)+(t)+F((b),(c),(d))); \ |
179 | a=ROTATE(a,s); \ | 153 | a=ROTATE(a,s); \ |