From 1efd72e262edec98442f35e1e9bf35d19f11eeec Mon Sep 17 00:00:00 2001 From: jsing Date: Sat, 15 Jul 2023 15:37:05 +0000 Subject: [PATCH] Mop up MD32_XARRAY from md5. MD32_XARRAY was added as a workaround for a broken HP C compiler (circa 1999). Clean it up to simplify the code. No change in generated assembly. --- lib/libcrypto/md5/md5_dgst.c | 175 +++++++++++++++++------------------ 1 file changed, 84 insertions(+), 91 deletions(-) diff --git a/lib/libcrypto/md5/md5_dgst.c b/lib/libcrypto/md5/md5_dgst.c index b0eb47219a7..3cd4b1ba78f 100644 --- a/lib/libcrypto/md5/md5_dgst.c +++ b/lib/libcrypto/md5/md5_dgst.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md5_dgst.c,v 1.18 2023/07/08 10:45:57 beck Exp $ */ +/* $OpenBSD: md5_dgst.c,v 1.19 2023/07/15 15:37:05 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -166,16 +166,9 @@ void md5_block_data_order(MD5_CTX *c, const void *data_, size_t num) { const unsigned char *data = data_; - unsigned MD32_REG_T A, B,C, D, l; -#ifndef MD32_XARRAY - /* See comment in crypto/sha/sha_locl.h for details. */ - unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, - XX8, XX9, XX10, XX11, XX12, XX13, XX14, XX15; -# define X(i) XX##i -#else - MD5_LONG XX[MD5_LBLOCK]; -# define X(i) XX[i] -#endif + unsigned MD32_REG_T A, B, C, D, l; + unsigned MD32_REG_T X0, X1, X2, X3, X4, X5, X6, X7, + X8, X9, X10, X11, X12, X13, X14, X15; A = c->A; B = c->B; @@ -184,105 +177,105 @@ md5_block_data_order(MD5_CTX *c, const void *data_, size_t num) for (; num--; ) { HOST_c2l(data, l); - X( 0) = l; + X0 = l; HOST_c2l(data, l); - X( 1) = l; + X1 = l; /* Round 0 */ - R0(A, B,C, D,X( 0), 7, 0xd76aa478L); + R0(A, B, C, D, X0, 7, 0xd76aa478L); HOST_c2l(data, l); - X( 2) = l; - R0(D, A,B, C,X( 1), 12, 0xe8c7b756L); + X2 = l; + R0(D, A, B, C, X1, 12, 0xe8c7b756L); HOST_c2l(data, l); - X( 3) = l; - R0(C, D,A, B,X( 2), 17, 0x242070dbL); + X3 = l; + R0(C, D, A, B, X2, 17, 0x242070dbL); HOST_c2l(data, l); - X( 4) = l; - R0(B, C,D, A,X( 3), 22, 0xc1bdceeeL); + X4 = l; + R0(B, C, D, A, X3, 22, 0xc1bdceeeL); HOST_c2l(data, l); - X( 5) = l; - R0(A, B,C, D,X( 4), 7, 0xf57c0fafL); + X5 = l; + R0(A, B, C, D, X4, 7, 0xf57c0fafL); HOST_c2l(data, l); - X( 6) = l; - R0(D, A,B, C,X( 5), 12, 0x4787c62aL); + X6 = l; + R0(D, A, B, C, X5, 12, 0x4787c62aL); HOST_c2l(data, l); - X( 7) = l; - R0(C, D,A, B,X( 6), 17, 0xa8304613L); + X7 = l; + R0(C, D, A, B, X6, 17, 0xa8304613L); HOST_c2l(data, l); - X( 8) = l; - R0(B, C,D, A,X( 7), 22, 0xfd469501L); + X8 = l; + R0(B, C, D, A, X7, 22, 0xfd469501L); HOST_c2l(data, l); - X( 9) = l; - R0(A, B,C, D,X( 8), 7, 0x698098d8L); + X9 = l; + R0(A, B, C, D, X8, 7, 0x698098d8L); HOST_c2l(data, l); - X(10) = l; - R0(D, A,B, C,X( 9), 12, 0x8b44f7afL); + X10 = l; + R0(D, A, B, C, X9, 12, 0x8b44f7afL); HOST_c2l(data, l); - X(11) = l; - R0(C, D,A, B,X(10), 17, 0xffff5bb1L); + X11 = l; + R0(C, D, A, B, X10, 17, 0xffff5bb1L); HOST_c2l(data, l); - X(12) = l; - R0(B, C,D, A,X(11), 22, 0x895cd7beL); + X12 = l; + R0(B, C, D, A, X11, 22, 0x895cd7beL); HOST_c2l(data, l); - X(13) = l; - R0(A, B,C, D,X(12), 7, 0x6b901122L); + X13 = l; + R0(A, B, C, D, X12, 7, 0x6b901122L); HOST_c2l(data, l); - X(14) = l; - R0(D, A,B, C,X(13), 12, 0xfd987193L); + X14 = l; + R0(D, A, B, C, X13, 12, 0xfd987193L); HOST_c2l(data, l); - X(15) = l; - R0(C, D,A, B,X(14), 17, 0xa679438eL); - R0(B, C,D, A,X(15), 22, 0x49b40821L); + X15 = l; + R0(C, D, A, B, X14, 17, 0xa679438eL); + R0(B, C, D, A, X15, 22, 0x49b40821L); /* Round 1 */ - R1(A, B,C, D,X( 1), 5, 0xf61e2562L); - R1(D, A,B, C,X( 6), 9, 0xc040b340L); - R1(C, D,A, B,X(11), 14, 0x265e5a51L); - R1(B, C,D, A,X( 0), 20, 0xe9b6c7aaL); - R1(A, B,C, D,X( 5), 5, 0xd62f105dL); - R1(D, A,B, C,X(10), 9, 0x02441453L); - R1(C, D,A, B,X(15), 14, 0xd8a1e681L); - R1(B, C,D, A,X( 4), 20, 0xe7d3fbc8L); - R1(A, B,C, D,X( 9), 5, 0x21e1cde6L); - R1(D, A,B, C,X(14), 9, 0xc33707d6L); - R1(C, D,A, B,X( 3), 14, 0xf4d50d87L); - R1(B, C,D, A,X( 8), 20, 0x455a14edL); - R1(A, B,C, D,X(13), 5, 0xa9e3e905L); - R1(D, A,B, C,X( 2), 9, 0xfcefa3f8L); - R1(C, D,A, B,X( 7), 14, 0x676f02d9L); - R1(B, C,D, A,X(12), 20, 0x8d2a4c8aL); + R1(A, B, C, D, X1, 5, 0xf61e2562L); + R1(D, A, B, C, X6, 9, 0xc040b340L); + R1(C, D, A, B, X11, 14, 0x265e5a51L); + R1(B, C, D, A, X0, 20, 0xe9b6c7aaL); + R1(A, B, C, D, X5, 5, 0xd62f105dL); + R1(D, A, B, C, X10, 9, 0x02441453L); + R1(C, D, A, B, X15, 14, 0xd8a1e681L); + R1(B, C, D, A, X4, 20, 0xe7d3fbc8L); + R1(A, B, C, D, X9, 5, 0x21e1cde6L); + R1(D, A, B, C, X14, 9, 0xc33707d6L); + R1(C, D, A, B, X3, 14, 0xf4d50d87L); + R1(B, C, D, A, X8, 20, 0x455a14edL); + R1(A, B, C, D, X13, 5, 0xa9e3e905L); + R1(D, A, B, C, X2, 9, 0xfcefa3f8L); + R1(C, D, A, B, X7, 14, 0x676f02d9L); + R1(B, C, D, A, X12, 20, 0x8d2a4c8aL); /* Round 2 */ - R2(A, B,C, D,X( 5), 4, 0xfffa3942L); - R2(D, A,B, C,X( 8), 11, 0x8771f681L); - R2(C, D,A, B,X(11), 16, 0x6d9d6122L); - R2(B, C,D, A,X(14), 23, 0xfde5380cL); - R2(A, B,C, D,X( 1), 4, 0xa4beea44L); - R2(D, A,B, C,X( 4), 11, 0x4bdecfa9L); - R2(C, D,A, B,X( 7), 16, 0xf6bb4b60L); - R2(B, C,D, A,X(10), 23, 0xbebfbc70L); - R2(A, B,C, D,X(13), 4, 0x289b7ec6L); - R2(D, A,B, C,X( 0), 11, 0xeaa127faL); - R2(C, D,A, B,X( 3), 16, 0xd4ef3085L); - R2(B, C,D, A,X( 6), 23, 0x04881d05L); - R2(A, B,C, D,X( 9), 4, 0xd9d4d039L); - R2(D, A,B, C,X(12), 11, 0xe6db99e5L); - R2(C, D,A, B,X(15), 16, 0x1fa27cf8L); - R2(B, C,D, A,X( 2), 23, 0xc4ac5665L); + R2(A, B, C, D, X5, 4, 0xfffa3942L); + R2(D, A, B, C, X8, 11, 0x8771f681L); + R2(C, D, A, B, X11, 16, 0x6d9d6122L); + R2(B, C, D, A, X14, 23, 0xfde5380cL); + R2(A, B, C, D, X1, 4, 0xa4beea44L); + R2(D, A, B, C, X4, 11, 0x4bdecfa9L); + R2(C, D, A, B, X7, 16, 0xf6bb4b60L); + R2(B, C, D, A, X10, 23, 0xbebfbc70L); + R2(A, B, C, D, X13, 4, 0x289b7ec6L); + R2(D, A, B, C, X0, 11, 0xeaa127faL); + R2(C, D, A, B, X3, 16, 0xd4ef3085L); + R2(B, C, D, A, X6, 23, 0x04881d05L); + R2(A, B, C, D, X9, 4, 0xd9d4d039L); + R2(D, A, B, C, X12, 11, 0xe6db99e5L); + R2(C, D, A, B, X15, 16, 0x1fa27cf8L); + R2(B, C, D, A, X2, 23, 0xc4ac5665L); /* Round 3 */ - R3(A, B,C, D,X( 0), 6, 0xf4292244L); - R3(D, A,B, C,X( 7), 10, 0x432aff97L); - R3(C, D,A, B,X(14), 15, 0xab9423a7L); - R3(B, C,D, A,X( 5), 21, 0xfc93a039L); - R3(A, B,C, D,X(12), 6, 0x655b59c3L); - R3(D, A,B, C,X( 3), 10, 0x8f0ccc92L); - R3(C, D,A, B,X(10), 15, 0xffeff47dL); - R3(B, C,D, A,X( 1), 21, 0x85845dd1L); - R3(A, B,C, D,X( 8), 6, 0x6fa87e4fL); - R3(D, A,B, C,X(15), 10, 0xfe2ce6e0L); - R3(C, D,A, B,X( 6), 15, 0xa3014314L); - R3(B, C,D, A,X(13), 21, 0x4e0811a1L); - R3(A, B,C, D,X( 4), 6, 0xf7537e82L); - R3(D, A,B, C,X(11), 10, 0xbd3af235L); - R3(C, D,A, B,X( 2), 15, 0x2ad7d2bbL); - R3(B, C,D, A,X( 9), 21, 0xeb86d391L); + R3(A, B, C, D, X0, 6, 0xf4292244L); + R3(D, A, B, C, X7, 10, 0x432aff97L); + R3(C, D, A, B, X14, 15, 0xab9423a7L); + R3(B, C, D, A, X5, 21, 0xfc93a039L); + R3(A, B, C, D, X12, 6, 0x655b59c3L); + R3(D, A, B, C, X3, 10, 0x8f0ccc92L); + R3(C, D, A, B, X10, 15, 0xffeff47dL); + R3(B, C, D, A, X1, 21, 0x85845dd1L); + R3(A, B, C, D, X8, 6, 0x6fa87e4fL); + R3(D, A, B, C, X15, 10, 0xfe2ce6e0L); + R3(C, D, A, B, X6, 15, 0xa3014314L); + R3(B, C, D, A, X13, 21, 0x4e0811a1L); + R3(A, B, C, D, X4, 6, 0xf7537e82L); + R3(D, A, B, C, X11, 10, 0xbd3af235L); + R3(C, D, A, B, X2, 15, 0x2ad7d2bbL); + R3(B, C, D, A, X9, 21, 0xeb86d391L); A = c->A += A; B = c->B += B; -- 2.20.1