From 0c33764564b06caff7d5987607561140ed889404 Mon Sep 17 00:00:00 2001 From: jsing Date: Tue, 26 Mar 2024 06:58:58 +0000 Subject: [PATCH] Reorder functions expanded from md32_common.h. No functional change. --- lib/libcrypto/md4/md4.c | 205 ++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 103 deletions(-) diff --git a/lib/libcrypto/md4/md4.c b/lib/libcrypto/md4/md4.c index 94de2912601..717268b72a5 100644 --- a/lib/libcrypto/md4/md4.c +++ b/lib/libcrypto/md4/md4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md4.c,v 1.10 2024/03/26 06:54:20 jsing Exp $ */ +/* $OpenBSD: md4.c,v 1.11 2024/03/26 06:58:58 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -92,108 +92,6 @@ __END_HIDDEN_DECLS #include "md32_common.h" -int -MD4_Update(MD4_CTX *c, const void *data_, size_t len) -{ - const unsigned char *data = data_; - unsigned char *p; - MD4_LONG l; - size_t n; - - if (len == 0) - return 1; - - l = (c->Nl + (((MD4_LONG)len) << 3))&0xffffffffUL; - /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to - * Wei Dai for pointing it out. */ - if (l < c->Nl) /* overflow */ - c->Nh++; - c->Nh+=(MD4_LONG)(len>>29); /* might cause compiler warning on 16-bit */ - c->Nl = l; - - n = c->num; - if (n != 0) { - p = (unsigned char *)c->data; - - if (len >= MD4_CBLOCK || len + n >= MD4_CBLOCK) { - memcpy (p + n, data, MD4_CBLOCK - n); - md4_block_data_order (c, p, 1); - n = MD4_CBLOCK - n; - data += n; - len -= n; - c->num = 0; - memset(p, 0, MD4_CBLOCK); /* keep it zeroed */ - } else { - memcpy(p + n, data, len); - c->num += (unsigned int)len; - return 1; - } - } - - n = len / MD4_CBLOCK; - if (n > 0) { - md4_block_data_order(c, data, n); - n *= MD4_CBLOCK; - data += n; - len -= n; - } - - if (len != 0) { - p = (unsigned char *)c->data; - c->num = (unsigned int)len; - memcpy(p, data, len); - } - return 1; -} - -void -MD4_Transform(MD4_CTX *c, const unsigned char *data) -{ - md4_block_data_order(c, data, 1); -} - -int -MD4_Final(unsigned char *md, MD4_CTX *c) -{ - unsigned char *p = (unsigned char *)c->data; - size_t n = c->num; - - p[n] = 0x80; /* there is always room for one */ - n++; - - if (n > (MD4_CBLOCK - 8)) { - memset(p + n, 0, MD4_CBLOCK - n); - n = 0; - md4_block_data_order(c, p, 1); - } - memset(p + n, 0, MD4_CBLOCK - 8 - n); - - p += MD4_CBLOCK - 8; -#if defined(DATA_ORDER_IS_BIG_ENDIAN) - HOST_l2c(c->Nh, p); - HOST_l2c(c->Nl, p); -#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) - HOST_l2c(c->Nl, p); - HOST_l2c(c->Nh, p); -#endif - p -= MD4_CBLOCK; - md4_block_data_order(c, p, 1); - c->num = 0; - memset(p, 0, MD4_CBLOCK); - -#ifndef HASH_MAKE_STRING -#error "HASH_MAKE_STRING must be defined!" -#else - HASH_MAKE_STRING(c, md); -#endif - - return 1; -} - -LCRYPTO_ALIAS(MD4_Update); -LCRYPTO_ALIAS(MD4_Final); -LCRYPTO_ALIAS(MD4_Transform); - /* #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) #define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z)))) @@ -349,6 +247,107 @@ MD4_Init(MD4_CTX *c) } LCRYPTO_ALIAS(MD4_Init); +int +MD4_Update(MD4_CTX *c, const void *data_, size_t len) +{ + const unsigned char *data = data_; + unsigned char *p; + MD4_LONG l; + size_t n; + + if (len == 0) + return 1; + + l = (c->Nl + (((MD4_LONG)len) << 3))&0xffffffffUL; + /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to + * Wei Dai for pointing it out. */ + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(MD4_LONG)(len>>29); /* might cause compiler warning on 16-bit */ + c->Nl = l; + + n = c->num; + if (n != 0) { + p = (unsigned char *)c->data; + + if (len >= MD4_CBLOCK || len + n >= MD4_CBLOCK) { + memcpy (p + n, data, MD4_CBLOCK - n); + md4_block_data_order (c, p, 1); + n = MD4_CBLOCK - n; + data += n; + len -= n; + c->num = 0; + memset(p, 0, MD4_CBLOCK); /* keep it zeroed */ + } else { + memcpy(p + n, data, len); + c->num += (unsigned int)len; + return 1; + } + } + + n = len / MD4_CBLOCK; + if (n > 0) { + md4_block_data_order(c, data, n); + n *= MD4_CBLOCK; + data += n; + len -= n; + } + + if (len != 0) { + p = (unsigned char *)c->data; + c->num = (unsigned int)len; + memcpy(p, data, len); + } + return 1; +} +LCRYPTO_ALIAS(MD4_Update); + +void +MD4_Transform(MD4_CTX *c, const unsigned char *data) +{ + md4_block_data_order(c, data, 1); +} +LCRYPTO_ALIAS(MD4_Transform); + +int +MD4_Final(unsigned char *md, MD4_CTX *c) +{ + unsigned char *p = (unsigned char *)c->data; + size_t n = c->num; + + p[n] = 0x80; /* there is always room for one */ + n++; + + if (n > (MD4_CBLOCK - 8)) { + memset(p + n, 0, MD4_CBLOCK - n); + n = 0; + md4_block_data_order(c, p, 1); + } + memset(p + n, 0, MD4_CBLOCK - 8 - n); + + p += MD4_CBLOCK - 8; +#if defined(DATA_ORDER_IS_BIG_ENDIAN) + HOST_l2c(c->Nh, p); + HOST_l2c(c->Nl, p); +#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) + HOST_l2c(c->Nl, p); + HOST_l2c(c->Nh, p); +#endif + p -= MD4_CBLOCK; + md4_block_data_order(c, p, 1); + c->num = 0; + memset(p, 0, MD4_CBLOCK); + +#ifndef HASH_MAKE_STRING +#error "HASH_MAKE_STRING must be defined!" +#else + HASH_MAKE_STRING(c, md); +#endif + + return 1; +} +LCRYPTO_ALIAS(MD4_Final); + unsigned char * MD4(const unsigned char *d, size_t n, unsigned char *md) { -- 2.20.1