summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/mdc2
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/mdc2')
-rw-r--r--src/lib/libcrypto/mdc2/Makefile (renamed from src/lib/libcrypto/mdc2/Makefile.ssl)33
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h (renamed from src/lib/libcrypto/mdc2/mdc2_one.c)49
-rw-r--r--src/lib/libcrypto/mdc2/mdc2test.c (renamed from src/lib/libcrypto/mdc2/mdc2dgst.c)193
3 files changed, 119 insertions, 156 deletions
diff --git a/src/lib/libcrypto/mdc2/Makefile.ssl b/src/lib/libcrypto/mdc2/Makefile
index 33f366fb08..1d064f17a6 100644
--- a/src/lib/libcrypto/mdc2/Makefile.ssl
+++ b/src/lib/libcrypto/mdc2/Makefile
@@ -1,5 +1,5 @@
1# 1#
2# SSLeay/crypto/mdc2/Makefile 2# OpenSSL/crypto/mdc2/Makefile
3# 3#
4 4
5DIR= mdc2 5DIR= mdc2
@@ -7,13 +7,7 @@ TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX= 10MAKEFILE= Makefile
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r 11AR= ar r
18 12
19CFLAGS= $(INCLUDES) $(CFLAG) 13CFLAGS= $(INCLUDES) $(CFLAG)
@@ -44,16 +38,16 @@ lib: $(LIBOBJ)
44 @touch lib 38 @touch lib
45 39
46files: 40files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
48 42
49links: 43links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) 44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) 45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) 46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54 47
55install: 48install:
56 @for i in $(EXHEADER) ; \ 49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
57 do \ 51 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ 52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ 53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
@@ -68,6 +62,7 @@ lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff 62 lint -DLINT $(INCLUDES) $(SRC)>fluff
69 63
70depend: 64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) 66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72 67
73dclean: 68dclean:
@@ -85,14 +80,14 @@ mdc2_one.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
85mdc2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 80mdc2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
86mdc2_one.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h 81mdc2_one.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h
87mdc2_one.o: ../../include/openssl/opensslconf.h 82mdc2_one.o: ../../include/openssl/opensslconf.h
88mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 83mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
89mdc2_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 84mdc2_one.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90mdc2_one.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h 85mdc2_one.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
91mdc2_one.o: ../cryptlib.h mdc2_one.c 86mdc2_one.o: ../../include/openssl/ui_compat.h ../cryptlib.h mdc2_one.c
92mdc2dgst.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 87mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
93mdc2dgst.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h 88mdc2dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/mdc2.h
94mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h 89mdc2dgst.o: ../../include/openssl/opensslconf.h
95mdc2dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 90mdc2dgst.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
96mdc2dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 91mdc2dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97mdc2dgst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h 92mdc2dgst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
98mdc2dgst.o: mdc2dgst.c 93mdc2dgst.o: mdc2dgst.c
diff --git a/src/lib/libcrypto/mdc2/mdc2_one.c b/src/lib/libcrypto/mdc2/mdc2.h
index 72647f67ed..72778a5212 100644
--- a/src/lib/libcrypto/mdc2/mdc2_one.c
+++ b/src/lib/libcrypto/mdc2/mdc2.h
@@ -1,4 +1,4 @@
1/* crypto/mdc2/mdc2_one.c */ 1/* crypto/mdc2/mdc2.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,21 +56,40 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h> 59#ifndef HEADER_MDC2_H
60#include "cryptlib.h" 60#define HEADER_MDC2_H
61#include <openssl/mdc2.h>
62 61
63unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md) 62#include <openssl/des.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MDC2
69#error MDC2 is disabled.
70#endif
71
72#define MDC2_BLOCK 8
73#define MDC2_DIGEST_LENGTH 16
74
75typedef struct mdc2_ctx_st
64 { 76 {
65 MDC2_CTX c; 77 unsigned int num;
66 static unsigned char m[MDC2_DIGEST_LENGTH]; 78 unsigned char data[MDC2_BLOCK];
79 DES_cblock h,hh;
80 int pad_type; /* either 1 or 2, default 1 */
81 } MDC2_CTX;
82
83
84int MDC2_Init(MDC2_CTX *c);
85int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len);
86int MDC2_Final(unsigned char *md, MDC2_CTX *c);
87unsigned char *MDC2(const unsigned char *d, size_t n,
88 unsigned char *md);
89
90#ifdef __cplusplus
91}
92#endif
67 93
68 if (md == NULL) md=m; 94#endif
69 if (!MDC2_Init(&c))
70 return NULL;
71 MDC2_Update(&c,d,n);
72 MDC2_Final(md,&c);
73 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
74 return(md);
75 }
76 95
diff --git a/src/lib/libcrypto/mdc2/mdc2dgst.c b/src/lib/libcrypto/mdc2/mdc2test.c
index b74bb1a759..017b31add2 100644
--- a/src/lib/libcrypto/mdc2/mdc2dgst.c
+++ b/src/lib/libcrypto/mdc2/mdc2test.c
@@ -1,4 +1,4 @@
1/* crypto/mdc2/mdc2dgst.c */ 1/* crypto/mdc2/mdc2test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -59,142 +59,91 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include <openssl/des.h>
63#include <openssl/mdc2.h>
64#include <openssl/crypto.h>
65
66#undef c2l
67#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
68 l|=((DES_LONG)(*((c)++)))<< 8L, \
69 l|=((DES_LONG)(*((c)++)))<<16L, \
70 l|=((DES_LONG)(*((c)++)))<<24L)
71 62
72#undef l2c 63#include "../e_os.h"
73#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
74 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
75 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
76 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
77 64
78static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); 65#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
79fips_md_init(MDC2) 66#define OPENSSL_NO_MDC2
80 { 67#endif
81 c->num=0;
82 c->pad_type=1;
83 memset(&(c->h[0]),0x52,MDC2_BLOCK);
84 memset(&(c->hh[0]),0x25,MDC2_BLOCK);
85 return 1;
86 }
87 68
88int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len) 69#ifdef OPENSSL_NO_MDC2
89 { 70int main(int argc, char *argv[])
90 size_t i,j; 71{
72 printf("No MDC2 support\n");
73 return(0);
74}
75#else
76#include <openssl/evp.h>
77#include <openssl/mdc2.h>
91 78
92 i=c->num; 79#ifdef CHARSET_EBCDIC
93 if (i != 0) 80#include <openssl/ebcdic.h>
94 { 81#endif
95 if (i+len < MDC2_BLOCK)
96 {
97 /* partial block */
98 memcpy(&(c->data[i]),in,len);
99 c->num+=(int)len;
100 return 1;
101 }
102 else
103 {
104 /* filled one */
105 j=MDC2_BLOCK-i;
106 memcpy(&(c->data[i]),in,j);
107 len-=j;
108 in+=j;
109 c->num=0;
110 mdc2_body(c,&(c->data[0]),MDC2_BLOCK);
111 }
112 }
113 i=len&~((size_t)MDC2_BLOCK-1);
114 if (i > 0) mdc2_body(c,in,i);
115 j=len-i;
116 if (j > 0)
117 {
118 memcpy(&(c->data[0]),&(in[i]),j);
119 c->num=(int)j;
120 }
121 return 1;
122 }
123 82
124static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len) 83static unsigned char pad1[16]={
125 { 84 0x42,0xE5,0x0C,0xD2,0x24,0xBA,0xCE,0xBA,
126 register DES_LONG tin0,tin1; 85 0x76,0x0B,0xDD,0x2B,0xD4,0x09,0x28,0x1A
127 register DES_LONG ttin0,ttin1; 86 };
128 DES_LONG d[2],dd[2];
129 DES_key_schedule k;
130 unsigned char *p;
131 size_t i;
132 87
133 for (i=0; i<len; i+=8) 88static unsigned char pad2[16]={
134 { 89 0x2E,0x46,0x79,0xB5,0xAD,0xD9,0xCA,0x75,
135 c2l(in,tin0); d[0]=dd[0]=tin0; 90 0x35,0xD8,0x7A,0xFE,0xAB,0x33,0xBE,0xE2
136 c2l(in,tin1); d[1]=dd[1]=tin1; 91 };
137 c->h[0]=(c->h[0]&0x9f)|0x40;
138 c->hh[0]=(c->hh[0]&0x9f)|0x20;
139 92
140 DES_set_odd_parity(&c->h); 93int main(int argc, char *argv[])
141 DES_set_key_unchecked(&c->h,&k); 94 {
142 DES_encrypt1(d,&k,1); 95 int ret=0;
96 unsigned char md[MDC2_DIGEST_LENGTH];
97 int i;
98 EVP_MD_CTX c;
99 static char *text="Now is the time for all ";
143 100
144 DES_set_odd_parity(&c->hh); 101#ifdef CHARSET_EBCDIC
145 DES_set_key_unchecked(&c->hh,&k); 102 ebcdic2ascii(text,text,strlen(text));
146 DES_encrypt1(dd,&k,1); 103#endif
147 104
148 ttin0=tin0^dd[0]; 105 EVP_MD_CTX_init(&c);
149 ttin1=tin1^dd[1]; 106 EVP_DigestInit_ex(&c,EVP_mdc2(), NULL);
150 tin0^=d[0]; 107 EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text));
151 tin1^=d[1]; 108 EVP_DigestFinal_ex(&c,&(md[0]),NULL);
152 109
153 p=c->h; 110 if (memcmp(md,pad1,MDC2_DIGEST_LENGTH) != 0)
154 l2c(tin0,p); 111 {
155 l2c(ttin1,p); 112 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
156 p=c->hh; 113 printf("%02X",md[i]);
157 l2c(ttin0,p); 114 printf(" <- generated\n");
158 l2c(tin1,p); 115 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
116 printf("%02X",pad1[i]);
117 printf(" <- correct\n");
118 ret=1;
159 } 119 }
160 } 120 else
121 printf("pad1 - ok\n");
161 122
162int MDC2_Final(unsigned char *md, MDC2_CTX *c) 123 EVP_DigestInit_ex(&c,EVP_mdc2(), NULL);
163 { 124 /* FIXME: use a ctl function? */
164 unsigned int i; 125 ((MDC2_CTX *)c.md_data)->pad_type=2;
165 int j; 126 EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text));
127 EVP_DigestFinal_ex(&c,&(md[0]),NULL);
166 128
167 i=c->num; 129 if (memcmp(md,pad2,MDC2_DIGEST_LENGTH) != 0)
168 j=c->pad_type;
169 if ((i > 0) || (j == 2))
170 { 130 {
171 if (j == 2) 131 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
172 c->data[i++]=0x80; 132 printf("%02X",md[i]);
173 memset(&(c->data[i]),0,MDC2_BLOCK-i); 133 printf(" <- generated\n");
174 mdc2_body(c,c->data,MDC2_BLOCK); 134 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
135 printf("%02X",pad2[i]);
136 printf(" <- correct\n");
137 ret=1;
175 } 138 }
176 memcpy(md,(char *)c->h,MDC2_BLOCK); 139 else
177 memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK); 140 printf("pad2 - ok\n");
178 return 1;
179 }
180
181#undef TEST
182 141
183#ifdef TEST 142 EVP_MD_CTX_cleanup(&c);
184main() 143#ifdef OPENSSL_SYS_NETWARE
185 { 144 if (ret) printf("ERROR: %d\n", ret);
186 unsigned char md[MDC2_DIGEST_LENGTH]; 145#endif
187 int i; 146 EXIT(ret);
188 MDC2_CTX c; 147 return(ret);
189 static char *text="Now is the time for all ";
190
191 MDC2_Init(&c);
192 MDC2_Update(&c,text,strlen(text));
193 MDC2_Final(&(md[0]),&c);
194
195 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
196 printf("%02X",md[i]);
197 printf("\n");
198 } 148 }
199
200#endif 149#endif