summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/md4
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/md4')
-rw-r--r--src/lib/libcrypto/md4/md4.h10
-rw-r--r--src/lib/libcrypto/md4/md4_dgst.c95
-rw-r--r--src/lib/libcrypto/md4/md4_locl.h44
-rw-r--r--src/lib/libcrypto/md4/md4_one.c2
-rw-r--r--src/lib/libcrypto/md4/md4test.c8
5 files changed, 13 insertions, 146 deletions
diff --git a/src/lib/libcrypto/md4/md4.h b/src/lib/libcrypto/md4/md4.h
index 7e761efb62..5598c93a4f 100644
--- a/src/lib/libcrypto/md4/md4.h
+++ b/src/lib/libcrypto/md4/md4.h
@@ -60,6 +60,7 @@
60#define HEADER_MD4_H 60#define HEADER_MD4_H
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63#include <stddef.h>
63 64
64#ifdef __cplusplus 65#ifdef __cplusplus
65extern "C" { 66extern "C" {
@@ -101,16 +102,13 @@ typedef struct MD4state_st
101 MD4_LONG A,B,C,D; 102 MD4_LONG A,B,C,D;
102 MD4_LONG Nl,Nh; 103 MD4_LONG Nl,Nh;
103 MD4_LONG data[MD4_LBLOCK]; 104 MD4_LONG data[MD4_LBLOCK];
104 int num; 105 unsigned int num;
105 } MD4_CTX; 106 } MD4_CTX;
106 107
107#ifdef OPENSSL_FIPS
108int private_MD4_Init(MD4_CTX *c);
109#endif
110int MD4_Init(MD4_CTX *c); 108int MD4_Init(MD4_CTX *c);
111int MD4_Update(MD4_CTX *c, const void *data, unsigned long len); 109int MD4_Update(MD4_CTX *c, const void *data, size_t len);
112int MD4_Final(unsigned char *md, MD4_CTX *c); 110int MD4_Final(unsigned char *md, MD4_CTX *c);
113unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md); 111unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md);
114void MD4_Transform(MD4_CTX *c, const unsigned char *b); 112void MD4_Transform(MD4_CTX *c, const unsigned char *b);
115#ifdef __cplusplus 113#ifdef __cplusplus
116} 114}
diff --git a/src/lib/libcrypto/md4/md4_dgst.c b/src/lib/libcrypto/md4/md4_dgst.c
index ee7cc72262..cfef94af39 100644
--- a/src/lib/libcrypto/md4/md4_dgst.c
+++ b/src/lib/libcrypto/md4/md4_dgst.c
@@ -60,7 +60,7 @@
60#include "md4_locl.h" 60#include "md4_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT; 63const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
64 64
65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm 65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
66 */ 66 */
@@ -70,7 +70,7 @@ const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
70#define INIT_DATA_C (unsigned long)0x98badcfeL 70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L 71#define INIT_DATA_D (unsigned long)0x10325476L
72 72
73FIPS_NON_FIPS_MD_Init(MD4) 73int MD4_Init(MD4_CTX *c)
74 { 74 {
75 c->A=INIT_DATA_A; 75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B; 76 c->B=INIT_DATA_B;
@@ -82,84 +82,11 @@ FIPS_NON_FIPS_MD_Init(MD4)
82 return 1; 82 return 1;
83 } 83 }
84 84
85#ifndef md4_block_host_order
86void md4_block_host_order (MD4_CTX *c, const void *data, int num)
87 {
88 const MD4_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 3,0);
100 R0(D,A,B,C,X[ 1], 7,0);
101 R0(C,D,A,B,X[ 2],11,0);
102 R0(B,C,D,A,X[ 3],19,0);
103 R0(A,B,C,D,X[ 4], 3,0);
104 R0(D,A,B,C,X[ 5], 7,0);
105 R0(C,D,A,B,X[ 6],11,0);
106 R0(B,C,D,A,X[ 7],19,0);
107 R0(A,B,C,D,X[ 8], 3,0);
108 R0(D,A,B,C,X[ 9], 7,0);
109 R0(C,D,A,B,X[10],11,0);
110 R0(B,C,D,A,X[11],19,0);
111 R0(A,B,C,D,X[12], 3,0);
112 R0(D,A,B,C,X[13], 7,0);
113 R0(C,D,A,B,X[14],11,0);
114 R0(B,C,D,A,X[15],19,0);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 0], 3,0x5A827999L);
117 R1(D,A,B,C,X[ 4], 5,0x5A827999L);
118 R1(C,D,A,B,X[ 8], 9,0x5A827999L);
119 R1(B,C,D,A,X[12],13,0x5A827999L);
120 R1(A,B,C,D,X[ 1], 3,0x5A827999L);
121 R1(D,A,B,C,X[ 5], 5,0x5A827999L);
122 R1(C,D,A,B,X[ 9], 9,0x5A827999L);
123 R1(B,C,D,A,X[13],13,0x5A827999L);
124 R1(A,B,C,D,X[ 2], 3,0x5A827999L);
125 R1(D,A,B,C,X[ 6], 5,0x5A827999L);
126 R1(C,D,A,B,X[10], 9,0x5A827999L);
127 R1(B,C,D,A,X[14],13,0x5A827999L);
128 R1(A,B,C,D,X[ 3], 3,0x5A827999L);
129 R1(D,A,B,C,X[ 7], 5,0x5A827999L);
130 R1(C,D,A,B,X[11], 9,0x5A827999L);
131 R1(B,C,D,A,X[15],13,0x5A827999L);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
134 R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
135 R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
136 R2(B,C,D,A,X[12],15,0x6ED9EBA1);
137 R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
138 R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
139 R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
140 R2(B,C,D,A,X[14],15,0x6ED9EBA1);
141 R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
142 R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
143 R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
144 R2(B,C,D,A,X[13],15,0x6ED9EBA1);
145 R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
146 R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
147 R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
148 R2(B,C,D,A,X[15],15,0x6ED9EBA1);
149
150 A = c->A += A;
151 B = c->B += B;
152 C = c->C += C;
153 D = c->D += D;
154 }
155 }
156#endif
157
158#ifndef md4_block_data_order 85#ifndef md4_block_data_order
159#ifdef X 86#ifdef X
160#undef X 87#undef X
161#endif 88#endif
162void md4_block_data_order (MD4_CTX *c, const void *data_, int num) 89void md4_block_data_order (MD4_CTX *c, const void *data_, size_t num)
163 { 90 {
164 const unsigned char *data=data_; 91 const unsigned char *data=data_;
165 register unsigned MD32_REG_T A,B,C,D,l; 92 register unsigned MD32_REG_T A,B,C,D,l;
@@ -240,19 +167,3 @@ void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
240 } 167 }
241 } 168 }
242#endif 169#endif
243
244#ifdef undef
245int printit(unsigned long *l)
246 {
247 int i,ii;
248
249 for (i=0; i<2; i++)
250 {
251 for (ii=0; ii<8; ii++)
252 {
253 fprintf(stderr,"%08lx ",l[i*8+ii]);
254 }
255 fprintf(stderr,"\n");
256 }
257 }
258#endif
diff --git a/src/lib/libcrypto/md4/md4_locl.h b/src/lib/libcrypto/md4/md4_locl.h
index a8d31d7a73..c8085b0ead 100644
--- a/src/lib/libcrypto/md4/md4_locl.h
+++ b/src/lib/libcrypto/md4/md4_locl.h
@@ -65,41 +65,13 @@
65#define MD4_LONG_LOG2 2 /* default to 32 bits */ 65#define MD4_LONG_LOG2 2 /* default to 32 bits */
66#endif 66#endif
67 67
68void md4_block_host_order (MD4_CTX *c, const void *p,int num); 68void md4_block_data_order (MD4_CTX *c, const void *p,size_t num);
69void md4_block_data_order (MD4_CTX *c, const void *p,int num);
70
71#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
72/*
73 * *_block_host_order is expected to handle aligned data while
74 * *_block_data_order - unaligned. As algorithm and host (x86)
75 * are in this case of the same "endianness" these two are
76 * otherwise indistinguishable. But normally you don't want to
77 * call the same function because unaligned access in places
78 * where alignment is expected is usually a "Bad Thing". Indeed,
79 * on RISCs you get punished with BUS ERROR signal or *severe*
80 * performance degradation. Intel CPUs are in turn perfectly
81 * capable of loading unaligned data without such drastic side
82 * effect. Yes, they say it's slower than aligned load, but no
83 * exception is generated and therefore performance degradation
84 * is *incomparable* with RISCs. What we should weight here is
85 * costs of unaligned access against costs of aligning data.
86 * According to my measurements allowing unaligned access results
87 * in ~9% performance improvement on Pentium II operating at
88 * 266MHz. I won't be surprised if the difference will be higher
89 * on faster systems:-)
90 *
91 * <appro@fy.chalmers.se>
92 */
93#define md4_block_data_order md4_block_host_order
94#endif
95 69
96#define DATA_ORDER_IS_LITTLE_ENDIAN 70#define DATA_ORDER_IS_LITTLE_ENDIAN
97 71
98#define HASH_LONG MD4_LONG 72#define HASH_LONG MD4_LONG
99#define HASH_LONG_LOG2 MD4_LONG_LOG2
100#define HASH_CTX MD4_CTX 73#define HASH_CTX MD4_CTX
101#define HASH_CBLOCK MD4_CBLOCK 74#define HASH_CBLOCK MD4_CBLOCK
102#define HASH_LBLOCK MD4_LBLOCK
103#define HASH_UPDATE MD4_Update 75#define HASH_UPDATE MD4_Update
104#define HASH_TRANSFORM MD4_Transform 76#define HASH_TRANSFORM MD4_Transform
105#define HASH_FINAL MD4_Final 77#define HASH_FINAL MD4_Final
@@ -110,21 +82,7 @@ void md4_block_data_order (MD4_CTX *c, const void *p,int num);
110 ll=(c)->C; HOST_l2c(ll,(s)); \ 82 ll=(c)->C; HOST_l2c(ll,(s)); \
111 ll=(c)->D; HOST_l2c(ll,(s)); \ 83 ll=(c)->D; HOST_l2c(ll,(s)); \
112 } while (0) 84 } while (0)
113#define HASH_BLOCK_HOST_ORDER md4_block_host_order
114#if !defined(L_ENDIAN) || defined(md4_block_data_order)
115#define HASH_BLOCK_DATA_ORDER md4_block_data_order 85#define HASH_BLOCK_DATA_ORDER md4_block_data_order
116/*
117 * Little-endians (Intel and Alpha) feel better without this.
118 * It looks like memcpy does better job than generic
119 * md4_block_data_order on copying-n-aligning input data.
120 * But frankly speaking I didn't expect such result on Alpha.
121 * On the other hand I've got this with egcs-1.0.2 and if
122 * program is compiled with another (better?) compiler it
123 * might turn out other way around.
124 *
125 * <appro@fy.chalmers.se>
126 */
127#endif
128 86
129#include "md32_common.h" 87#include "md32_common.h"
130 88
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c
index 50f79352f6..bb64362638 100644
--- a/src/lib/libcrypto/md4/md4_one.c
+++ b/src/lib/libcrypto/md4/md4_one.c
@@ -65,7 +65,7 @@
65#include <openssl/ebcdic.h> 65#include <openssl/ebcdic.h>
66#endif 66#endif
67 67
68unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md) 68unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md)
69 { 69 {
70 MD4_CTX c; 70 MD4_CTX c;
71 static unsigned char m[MD4_DIGEST_LENGTH]; 71 static unsigned char m[MD4_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/md4/md4test.c b/src/lib/libcrypto/md4/md4test.c
index 21a77d96f7..56591728a1 100644
--- a/src/lib/libcrypto/md4/md4test.c
+++ b/src/lib/libcrypto/md4/md4test.c
@@ -97,16 +97,16 @@ static char *pt(unsigned char *md);
97int main(int argc, char *argv[]) 97int main(int argc, char *argv[])
98 { 98 {
99 int i,err=0; 99 int i,err=0;
100 unsigned char **P,**R; 100 char **P,**R;
101 char *p; 101 char *p;
102 unsigned char md[MD4_DIGEST_LENGTH]; 102 unsigned char md[MD4_DIGEST_LENGTH];
103 103
104 P=(unsigned char **)test; 104 P=test;
105 R=(unsigned char **)ret; 105 R=ret;
106 i=1; 106 i=1;
107 while (*P != NULL) 107 while (*P != NULL)
108 { 108 {
109 EVP_Digest(&(P[0][0]),(unsigned long)strlen((char *)*P),md,NULL,EVP_md4(), NULL); 109 EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md4(), NULL);
110 p=pt(md); 110 p=pt(md);
111 if (strcmp(p,(char *)*R) != 0) 111 if (strcmp(p,(char *)*R) != 0)
112 { 112 {