X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fmdc2%2Fmdc2dgst.c;h=4aa406edc3bab41e2dc9d46db2879b392a6c0b20;hp=3f3d11a1a28ad66cff0bcc49a9102a9cacd7be98;hb=16ab8a93bc96cacc1b5376cc084f70122368ee1f;hpb=78414a6a897db42c9bcf06aa21c705811ab33921 diff --git a/crypto/mdc2/mdc2dgst.c b/crypto/mdc2/mdc2dgst.c index 3f3d11a1a2..4aa406edc3 100644 --- a/crypto/mdc2/mdc2dgst.c +++ b/crypto/mdc2/mdc2dgst.c @@ -59,8 +59,8 @@ #include #include #include -#include "des.h" -#include "mdc2.h" +#include +#include #undef c2l #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ @@ -74,27 +74,19 @@ *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ *((c)++)=(unsigned char)(((l)>>24L)&0xff)) -#ifndef NOPROTO -static void mdc2_body(MDC2_CTX *c, unsigned char *in, unsigned int len); -#else -static void mdc2_body(); -#endif - -void MDC2_Init(c) -MDC2_CTX *c; +static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); +int MDC2_Init(MDC2_CTX *c) { c->num=0; c->pad_type=1; memset(&(c->h[0]),0x52,MDC2_BLOCK); memset(&(c->hh[0]),0x25,MDC2_BLOCK); + return 1; } -void MDC2_Update(c,in,len) -MDC2_CTX *c; -register unsigned char *in; -unsigned long len; +int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len) { - int i,j; + size_t i,j; i=c->num; if (i != 0) @@ -102,9 +94,9 @@ unsigned long len; if (i+len < MDC2_BLOCK) { /* partial block */ - memcpy(&(c->data[i]),in,(int)len); + memcpy(&(c->data[i]),in,len); c->num+=(int)len; - return; + return 1; } else { @@ -117,64 +109,59 @@ unsigned long len; mdc2_body(c,&(c->data[0]),MDC2_BLOCK); } } - i=(int)(len&(unsigned long)~(MDC2_BLOCK-1)); + i=len&~((size_t)MDC2_BLOCK-1); if (i > 0) mdc2_body(c,in,i); - j=(int)len-i; + j=len-i; if (j > 0) { memcpy(&(c->data[0]),&(in[i]),j); - c->num=j; + c->num=(int)j; } + return 1; } -static void mdc2_body(c,in,len) -MDC2_CTX *c; -unsigned char *in; -unsigned int len; +static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len) { register DES_LONG tin0,tin1; register DES_LONG ttin0,ttin1; DES_LONG d[2],dd[2]; - des_cblock *h,*hh; - des_key_schedule k; + DES_key_schedule k; unsigned char *p; - unsigned int i; - - h= (des_cblock *)&(c->h[0]); - hh= (des_cblock *)&(c->hh[0]); + size_t i; for (i=0; ih[0]=(c->h[0]&0x9f)|0x40; + c->hh[0]=(c->hh[0]&0x9f)|0x20; - des_set_key(h,k); - des_encrypt((DES_LONG *)d,k,1); + DES_set_odd_parity(&c->h); + DES_set_key_unchecked(&c->h,&k); + DES_encrypt1(d,&k,1); - des_set_key(hh,k); - des_encrypt((DES_LONG *)dd,k,1); + DES_set_odd_parity(&c->hh); + DES_set_key_unchecked(&c->hh,&k); + DES_encrypt1(dd,&k,1); ttin0=tin0^dd[0]; ttin1=tin1^dd[1]; tin0^=d[0]; tin1^=d[1]; - p=(unsigned char *)h; + p=c->h; l2c(tin0,p); l2c(ttin1,p); - p=(unsigned char *)hh; + p=c->hh; l2c(ttin0,p); l2c(tin1,p); } } -void MDC2_Final(md,c) -unsigned char *md; -MDC2_CTX *c; +int MDC2_Final(unsigned char *md, MDC2_CTX *c) { - int i,j; + unsigned int i; + int j; i=c->num; j=c->pad_type; @@ -187,6 +174,7 @@ MDC2_CTX *c; } memcpy(md,(char *)c->h,MDC2_BLOCK); memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK); + return 1; } #undef TEST