[Midnightbsd-cvs] src [10664] trunk/lib/libmd: sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 15:31:22 EDT 2018


Revision: 10664
          http://svnweb.midnightbsd.org/src/?rev=10664
Author:   laffer1
Date:     2018-06-09 15:31:21 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync

Modified Paths:
--------------
    trunk/lib/libmd/Makefile
    trunk/lib/libmd/i386/rmd160.S
    trunk/lib/libmd/i386/sha.S
    trunk/lib/libmd/md4.copyright
    trunk/lib/libmd/md4.h
    trunk/lib/libmd/md4c.c
    trunk/lib/libmd/md5.copyright
    trunk/lib/libmd/md5.h
    trunk/lib/libmd/md5c.c
    trunk/lib/libmd/mdX.3
    trunk/lib/libmd/mdXhl.c
    trunk/lib/libmd/mddriver.c
    trunk/lib/libmd/ripemd.3
    trunk/lib/libmd/ripemd.h
    trunk/lib/libmd/rmd160c.c
    trunk/lib/libmd/rmd_locl.h
    trunk/lib/libmd/rmdconst.h
    trunk/lib/libmd/rmddriver.c
    trunk/lib/libmd/sha.3
    trunk/lib/libmd/sha.h
    trunk/lib/libmd/sha0c.c
    trunk/lib/libmd/sha1c.c
    trunk/lib/libmd/sha256.3
    trunk/lib/libmd/sha512.3
    trunk/lib/libmd/sha_locl.h
    trunk/lib/libmd/shadriver.c

Removed Paths:
-------------
    trunk/lib/libmd/md2.copyright
    trunk/lib/libmd/md2.h
    trunk/lib/libmd/md2c.c
    trunk/lib/libmd/sha256.h
    trunk/lib/libmd/sha256c.c
    trunk/lib/libmd/sha512.h
    trunk/lib/libmd/sha512c.c

Property Changed:
----------------
    trunk/lib/libmd/i386/rmd160.S
    trunk/lib/libmd/i386/sha.S
    trunk/lib/libmd/md4.copyright
    trunk/lib/libmd/md5.copyright
    trunk/lib/libmd/mdX.3
    trunk/lib/libmd/ripemd.3
    trunk/lib/libmd/sha.3
    trunk/lib/libmd/sha256.3
    trunk/lib/libmd/sha512.3

Modified: trunk/lib/libmd/Makefile
===================================================================
--- trunk/lib/libmd/Makefile	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/Makefile	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,20 +1,20 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/lib/libmd/Makefile 315731 2017-03-22 18:35:48Z bdrewery $
 
 LIB=	md
+SHLIB_MAJOR= 6
 SHLIBDIR?= /lib
-SRCS=	md2c.c md4c.c md5c.c md2hl.c md4hl.c md5hl.c \
+SRCS=	md4c.c md5c.c md4hl.c md5hl.c \
 	rmd160c.c rmd160hl.c \
 	sha0c.c sha0hl.c sha1c.c sha1hl.c \
 	sha256c.c sha256hl.c \
-	sha512c.c sha512hl.c
-INCS=	md2.h md4.h md5.h ripemd.h sha.h sha256.h sha512.h
+	sha384hl.c \
+	sha512c.c sha512hl.c sha512thl.c
+INCS=	md4.h md5.h ripemd.h sha.h sha256.h sha384.h sha512.h sha512t.h
 
 WARNS?=	0
 
-MAN+=	md2.3 md4.3 md5.3 ripemd.3 sha.3 sha256.3 sha512.3
-MLINKS+=md2.3 MD2Init.3 md2.3 MD2Update.3 md2.3 MD2Final.3
-MLINKS+=md2.3 MD2End.3  md2.3 MD2File.3   md2.3 MD2FileChunk.3
-MLINKS+=md2.3 MD2Data.3
+MAN+=	md4.3 md5.3 ripemd.3 sha.3 sha256.3 sha512.3
 MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3
 MLINKS+=md4.3 MD4End.3  md4.3 MD4File.3   md4.3 MD4FileChunk.3
 MLINKS+=md4.3 MD4Data.3
@@ -35,18 +35,41 @@
 MLINKS+=sha256.3 SHA256_Final.3 sha256.3 SHA256_End.3
 MLINKS+=sha256.3 SHA256_File.3  sha256.3 SHA256_FileChunk.3
 MLINKS+=sha256.3 SHA256_Data.3
+MLINKS+=sha512.3 SHA384_Init.3  sha512.3 SHA384_Update.3
+MLINKS+=sha512.3 SHA384_Final.3 sha512.3 SHA384_End.3
+MLINKS+=sha512.3 SHA384_File.3  sha512.3 SHA384_FileChunk.3
+MLINKS+=sha512.3 SHA384_Data.3  sha512.3 sha384.3
 MLINKS+=sha512.3 SHA512_Init.3  sha512.3 SHA512_Update.3
 MLINKS+=sha512.3 SHA512_Final.3 sha512.3 SHA512_End.3
 MLINKS+=sha512.3 SHA512_File.3  sha512.3 SHA512_FileChunk.3
 MLINKS+=sha512.3 SHA512_Data.3
+MLINKS+=sha512.3 SHA512_256_Init.3  sha512.3 SHA512_256_Update.3
+MLINKS+=sha512.3 SHA512_256_Final.3 sha512.3 SHA512_256_End.3
+MLINKS+=sha512.3 SHA512_256_File.3  sha512.3 SHA512_256_FileChunk.3
+MLINKS+=sha512.3 SHA512_256_Data.3
 CLEANFILES+=	md[245]hl.c md[245].ref md[245].3 mddriver \
 		rmd160.ref rmd160hl.c rmddriver \
 		sha0.ref sha0hl.c sha1.ref sha1hl.c shadriver \
-		sha256.ref sha256hl.c sha512.ref sha512hl.c
+		sha256.ref sha256hl.c sha384hl.c sha384.ref \
+		sha512.ref sha512hl.c sha512t256.ref sha512thl.c
 
-CFLAGS+= -I${.CURDIR}
-.PATH: ${.CURDIR}/${MACHINE_ARCH}
+# Need src tree sys/md5.h for MD5FileChunk prototype on older systems.
+SRCS+=		sys/md5.h
+CLEANDIRS=	sys
+CFLAGS+=	-I.
+sys/md5.h: ${.CURDIR}/../../sys/${.TARGET} .NOMETA
+	ln -sf ${.ALLSRC} ${.TARGET}
 
+# Define WEAK_REFS to provide weak aliases for libmd symbols
+#
+# Note that the same sources are also used internally by libcrypt,
+# in which case:
+#   * macros are used to rename symbols to libcrypt internal names
+#   * no weak aliases are generated
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../sys/crypto/sha2
+CFLAGS+= -DWEAK_REFS
+.PATH: ${.CURDIR}/${MACHINE_ARCH} ${.CURDIR}/../../sys/crypto/sha2
+
 .if exists(${MACHINE_ARCH}/sha.S)
 SRCS+=	sha.S
 CFLAGS+= -DSHA1_ASM
@@ -59,10 +82,6 @@
 ACFLAGS+= -DELF -Wa,--noexecstack
 .endif
 
-md2hl.c: mdXhl.c
-	(echo '#define LENGTH 16'; \
-		sed -e 's/mdX/md2/g' -e 's/MDX/MD2/g' ${.ALLSRC}) > ${.TARGET}
-
 md4hl.c: mdXhl.c
 	(echo '#define LENGTH 16'; \
 		sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' ${.ALLSRC}) > ${.TARGET}
@@ -87,6 +106,12 @@
 			-e  's/SHA256__/SHA256_/g' \
 		${.ALLSRC}) > ${.TARGET}
 
+sha384hl.c: mdXhl.c
+	(echo '#define LENGTH 48'; \
+		sed -e 's/mdX/sha384/g' -e 's/MDX/SHA384_/g'	\
+			-e  's/SHA384__/SHA384_/g' \
+		${.ALLSRC}) > ${.TARGET}
+
 sha512hl.c: mdXhl.c
 	(echo '#define LENGTH 64'; \
 		sed -e 's/mdX/sha512/g' -e 's/MDX/SHA512_/g'	\
@@ -93,6 +118,13 @@
 			-e  's/SHA512__/SHA512_/g' \
 		${.ALLSRC}) > ${.TARGET}
 
+sha512thl.c: mdXhl.c
+	(echo '#define LENGTH 32'; \
+		sed -e 's/mdX/sha512t/g' -e 's/MDX/SHA512_256_/g'	\
+			-e  's/SHA512_256__/SHA512_256_/g' \
+			-e 's/SHA512_256_CTX/SHA512_CTX/g' \
+		${.ALLSRC}) > ${.TARGET}
+
 rmd160hl.c: mdXhl.c
 	(echo '#define LENGTH 20'; \
 		sed -e 's/mdX/ripemd/g' -e 's/MDX/RIPEMD160_/g' \
@@ -105,16 +137,6 @@
 	cat ${.CURDIR}/md${i}.copyright >> ${.TARGET}
 .endfor
 
-md2.ref:
-	echo 'MD2 test suite:' > ${.TARGET}
-	@echo 'MD2 ("") = 8350e5a3e24c153df2275c9f80692773' >> ${.TARGET}
-	@echo 'MD2 ("a") = 32ec01ec4a6dac72c0ab96fb34c0b5d1' >> ${.TARGET}
-	@echo 'MD2 ("abc") = da853b0d3f88d99b30283a69e6ded6bb' >> ${.TARGET}
-	@echo 'MD2 ("message digest") = ab4f496bfb2a530b219ff33031fe06b0' >> ${.TARGET}
-	@echo 'MD2 ("abcdefghijklmnopqrstuvwxyz") = 4e8ddff3650292ab5a4108c3aa47940b' >> ${.TARGET}
-	@echo 'MD2 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = da33def2a42df13975352846c30338cd' >> ${.TARGET}
-	@echo 'MD2 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = d5976f79d83d3a0dc9806c3c66f3efd8' >> ${.TARGET}
-
 md4.ref:
 	echo 'MD4 test suite:' > ${.TARGET}
 	@echo 'MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0' >> ${.TARGET}
@@ -177,6 +199,21 @@
 	@echo 'SHA-256 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
 		'f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e' >> ${.TARGET}
 
+sha384.ref:
+	echo 'SHA-384 test suite:' > ${.TARGET}
+	@echo 'SHA-384 ("") =' \
+		'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b' >> ${.TARGET}
+	@echo 'SHA-384 ("abc") =' \
+		'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7' >> ${.TARGET}
+	@echo 'SHA-384 ("message digest") =' \
+		'473ed35167ec1f5d8e550368a3db39be54639f828868e9454c239fc8b52e3c61dbd0d8b4de1390c256dcbb5d5fd99cd5' >> ${.TARGET}
+	@echo 'SHA-384 ("abcdefghijklmnopqrstuvwxyz") =' \
+		'feb67349df3db6f5924815d6c3dc133f091809213731fe5c7b5f4999e463479ff2877f5f2936fa63bb43784b12f3ebb4' >> ${.TARGET}
+	@echo 'SHA-384 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =' \
+		'1761336e3f7cbfe51deb137f026f89e01a448e3b1fafa64039c1464ee8732f11a5341a6f41e0c202294736ed64db1a84' >> ${.TARGET}
+	@echo 'SHA-384 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
+		'b12932b0627d1c060942f5447764155655bd4da0c9afa6dd9b9ef53129af1b8fb0195996d2de9ca0df9d821ffee67026' >> ${.TARGET}
+
 sha512.ref:
 	echo 'SHA-512 test suite:' > ${.TARGET}
 	@echo 'SHA-512 ("") =' \
@@ -192,6 +229,21 @@
 	@echo 'SHA-512 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
 		'72ec1ef1124a45b047e8b7c75a932195135bb61de24ec0d1914042246e0aec3a2354e093d76f3048b456764346900cb130d2a4fd5dd16abb5e30bcb850dee843' >> ${.TARGET}
 
+sha512t256.ref:
+	echo 'SHA-512256 test suite:' > ${.TARGET}
+	@echo 'SHA-512256 ("") =' \
+		'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a' >> ${.TARGET}
+	@echo 'SHA-512256 ("abc") =' \
+		'53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23' >> ${.TARGET}
+	@echo 'SHA-512256 ("message digest") =' \
+		'0cf471fd17ed69d990daf3433c89b16d63dec1bb9cb42a6094604ee5d7b4e9fb' >> ${.TARGET}
+	@echo 'SHA-512256 ("abcdefghijklmnopqrstuvwxyz") =' \
+		'fc3189443f9c268f626aea08a756abe7b726b05f701cb08222312ccfd6710a26' >> ${.TARGET}
+	@echo 'SHA-512256 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =' \
+		'cdf1cc0effe26ecc0c13758f7b4a48e000615df241284185c39eb05d355bb9c8' >> ${.TARGET}
+	@echo 'SHA-512256 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
+		'2c9fdbc0c90bdd87612ee8455474f9044850241dc105b1e8b94b8ddf5fac9148' >> ${.TARGET}
+
 rmd160.ref:
 	echo 'RIPEMD160 test suite:' > ${.TARGET}
 	@echo 'RIPEMD160 ("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31' >> ${.TARGET}
@@ -205,12 +257,10 @@
 	@echo 'RIPEMD160 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
 		'9b752e45573d4b39f4dbd3323cab82bf63326bfb' >> ${.TARGET}
 
-test:	md2.ref md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha256.ref sha512.ref
+test:	md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha256.ref sha384.ref \
+		sha512.ref sha512t256.ref
 	@${ECHO} if any of these test fail, the code produces wrong results
 	@${ECHO} and should NOT be used.
-	${CC} ${CFLAGS} ${LDFLAGS} -DMD=2 -o mddriver ${.CURDIR}/mddriver.c ./libmd.a
-	./mddriver | cmp md2.ref -
-	@${ECHO} MD2 passed test
 	${CC} ${CFLAGS} ${LDFLAGS} -DMD=4 -o mddriver ${.CURDIR}/mddriver.c libmd.a
 	./mddriver | cmp md4.ref -
 	@${ECHO} MD4 passed test
@@ -231,9 +281,15 @@
 	${CC} ${CFLAGS} ${LDFLAGS} -DSHA=256 -o shadriver ${.CURDIR}/shadriver.c libmd.a
 	./shadriver | cmp sha256.ref -
 	@${ECHO} SHA-256 passed test
+	${CC} ${CFLAGS} ${LDFLAGS} -DSHA=384 -o shadriver ${.CURDIR}/shadriver.c libmd.a
+	./shadriver | cmp sha384.ref -
+	@${ECHO} SHA-384 passed test
 	${CC} ${CFLAGS} ${LDFLAGS} -DSHA=512 -o shadriver ${.CURDIR}/shadriver.c libmd.a
 	./shadriver | cmp sha512.ref -
 	@${ECHO} SHA-512 passed test
+	${CC} ${CFLAGS} ${LDFLAGS} -DSHA=512256 -o shadriver ${.CURDIR}/shadriver.c libmd.a
+	./shadriver | cmp sha512t256.ref -
+	@${ECHO} SHA-512t256 passed test
 	-rm -f shadriver
 
 .include <bsd.lib.mk>

Modified: trunk/lib/libmd/i386/rmd160.S
===================================================================
--- trunk/lib/libmd/i386/rmd160.S	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/i386/rmd160.S	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* $FreeBSD$ */
 /* Run the C pre-processor over this file with one of the following defined
  * ELF - elf object files,


Property changes on: trunk/lib/libmd/i386/rmd160.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/i386/sha.S
===================================================================
--- trunk/lib/libmd/i386/sha.S	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/i386/sha.S	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* $FreeBSD$ */
 /* -*- Fundamental -*- Emacs' assembler mode hoses this file */
 #ifndef PIC


Property changes on: trunk/lib/libmd/i386/sha.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Deleted: trunk/lib/libmd/md2.copyright
===================================================================
--- trunk/lib/libmd/md2.copyright	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md2.copyright	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,17 +0,0 @@
-.\" $MidnightBSD$
-Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
-rights reserved.
-.Pp
-License to copy and use this software is granted for
-non-commercial Internet Privacy-Enhanced Mail provided that it is
-identified as the "RSA Data Security, Inc. MD2 Message Digest
-Algorithm" in all material mentioning or referencing this software
-or this function.
-.Pp
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-.Pp
-These notices must be retained in any copies of any part of this
-documentation and/or software.

Deleted: trunk/lib/libmd/md2.h
===================================================================
--- trunk/lib/libmd/md2.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md2.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,46 +0,0 @@
-/* MD2.H - header file for MD2C.C
- * $MidnightBSD$
- */
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
-   rights reserved.
-
-   License to copy and use this software is granted for
-   non-commercial Internet Privacy-Enhanced Mail provided that it is
-   identified as the "RSA Data Security, Inc. MD2 Message Digest
-   Algorithm" in all material mentioning or referencing this software
-   or this function.
-
-   RSA Data Security, Inc. makes no representations concerning either
-   the merchantability of this software or the suitability of this
-   software for any particular purpose. It is provided "as is"
-   without express or implied warranty of any kind.
-
-   These notices must be retained in any copies of any part of this
-   documentation and/or software.
- */
-
-#ifndef _MD2_H_
-#define _MD2_H_
-
-typedef struct MD2Context {
-  unsigned char state[16];	/* state */
-  unsigned char checksum[16];	/* checksum */
-  unsigned int count;		/* number of bytes, modulo 16 */
-  unsigned char buffer[16];	/* input buffer */
-} MD2_CTX;
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-void   MD2Init(MD2_CTX *);
-void   MD2Update(MD2_CTX *, const void *, unsigned int);
-void   MD2Pad(MD2_CTX *);
-void   MD2Final(unsigned char [16], MD2_CTX *);
-char * MD2End(MD2_CTX *, char *);
-char * MD2File(const char *, char *);
-char * MD2FileChunk(const char *, char *, off_t, off_t);
-char * MD2Data(const void *, unsigned int, char *);
-__END_DECLS
-
-#endif /* _MD2_H_ */

Deleted: trunk/lib/libmd/md2c.c
===================================================================
--- trunk/lib/libmd/md2c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md2c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,211 +0,0 @@
-/* MD2C.C - RSA Data Security, Inc., MD2 message-digest algorithm
- */
-
-#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
-   rights reserved.
-
-   License to copy and use this software is granted for
-   non-commercial Internet Privacy-Enhanced Mail provided that it is
-   identified as the "RSA Data Security, Inc. MD2 Message Digest
-   Algorithm" in all material mentioning or referencing this software
-   or this function.
-
-   RSA Data Security, Inc. makes no representations concerning either
-   the merchantability of this software or the suitability of this
-   software for any particular purpose. It is provided "as is"
-   without express or implied warranty of any kind.
-
-   These notices must be retained in any copies of any part of this
-   documentation and/or software.
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include "md2.h"
-
-
-typedef unsigned char *POINTER;
-typedef u_int16_t UINT2;
-typedef u_int32_t UINT4;
-
-#define PROTO_LIST(list) list
-
-static void MD2Transform PROTO_LIST
-  ((unsigned char [16], unsigned char [16], const unsigned char [16]));
-
-/* Permutation of 0..255 constructed from the digits of pi. It gives a
-   "random" nonlinear byte substitution operation.
- */
-static unsigned char PI_SUBST[256] = {
-  41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
-  19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
-  76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
-  138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
-  245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
-  148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
-  39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
-  181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
-  150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
-  112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
-  96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
-  85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
-  234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
-  129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
-  8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
-  203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
-  166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
-  31, 26, 219, 153, 141, 51, 159, 17, 131, 20
-};
-
-static unsigned char *PADDING[] = {
-  (unsigned char *)"",
-  (unsigned char *)"\001",
-  (unsigned char *)"\002\002",
-  (unsigned char *)"\003\003\003",
-  (unsigned char *)"\004\004\004\004",
-  (unsigned char *)"\005\005\005\005\005",
-  (unsigned char *)"\006\006\006\006\006\006",
-  (unsigned char *)"\007\007\007\007\007\007\007",
-  (unsigned char *)"\010\010\010\010\010\010\010\010",
-  (unsigned char *)"\011\011\011\011\011\011\011\011\011",
-  (unsigned char *)"\012\012\012\012\012\012\012\012\012\012",
-  (unsigned char *)"\013\013\013\013\013\013\013\013\013\013\013",
-  (unsigned char *)"\014\014\014\014\014\014\014\014\014\014\014\014",
-  (unsigned char *)
-    "\015\015\015\015\015\015\015\015\015\015\015\015\015",
-  (unsigned char *)
-    "\016\016\016\016\016\016\016\016\016\016\016\016\016\016",
-  (unsigned char *)
-    "\017\017\017\017\017\017\017\017\017\017\017\017\017\017\017",
-  (unsigned char *)
-    "\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020"
-};
-
-/* MD2 initialization. Begins an MD2 operation, writing a new context.
- */
-void MD2Init (context)
-MD2_CTX *context;                                        /* context */
-{
-  context->count = 0;
-  memset ((POINTER)context->state, 0, sizeof (context->state));
-  memset
-    ((POINTER)context->checksum, 0, sizeof (context->checksum));
-}
-
-/* MD2 block update operation. Continues an MD2 message-digest
-     operation, processing another message block, and updating the
-     context.
- */
-void MD2Update (context, in, inputLen)
-MD2_CTX *context;                                        /* context */
-const void *in;                                /* input block */
-unsigned int inputLen;                     /* length of input block */
-{
-  unsigned int i, idx, partLen;
-  const unsigned char *input = in;
-
-  /* Update number of bytes mod 16 */
-  idx = context->count;
-  context->count = (idx + inputLen) & 0xf;
-
-  partLen = 16 - idx;
-
-  /* Transform as many times as possible.
-    */
-  if (inputLen >= partLen) {
-    memcpy
-      ((POINTER)&context->buffer[idx], (POINTER)input, partLen);
-    MD2Transform (context->state, context->checksum, context->buffer);
-
-    for (i = partLen; i + 15 < inputLen; i += 16)
-      MD2Transform (context->state, context->checksum, &input[i]);
-
-    idx = 0;
-  }
-  else
-    i = 0;
-
-  /* Buffer remaining input */
-  memcpy
-    ((POINTER)&context->buffer[idx], (POINTER)&input[i],
-     inputLen-i);
-}
-
-/* MD2 padding.
- */
-void MD2Pad (context)
-MD2_CTX *context;                                        /* context */
-{
-  unsigned int idx, padLen;
-
-  /* Pad out to multiple of 16.
-   */
-  idx = context->count;
-  padLen = 16 - idx;
-  MD2Update (context, PADDING[padLen], padLen);
-
-  /* Extend with checksum */
-  MD2Update (context, context->checksum, 16);
-}
-
-/* MD2 finalization. Ends an MD2 message-digest operation, writing the
-     message digest and zeroizing the context.
- */
-void MD2Final (digest, context)
-unsigned char digest[16];                         /* message digest */
-MD2_CTX *context;                                        /* context */
-{
-  /* Do padding */
-  MD2Pad (context);
-
-  /* Store state in digest */
-  memcpy ((POINTER)digest, (POINTER)context->state, 16);
-
-  /* Zeroize sensitive information.
-   */
-  memset ((POINTER)context, 0, sizeof (*context));
-}
-
-/* MD2 basic transformation. Transforms state and updates checksum
-     based on block.
- */
-static void MD2Transform (state, checksum, block)
-unsigned char state[16];
-unsigned char checksum[16];
-const unsigned char block[16];
-{
-  unsigned int i, j, t;
-  unsigned char x[48];
-
-  /* Form encryption block from state, block, state ^ block.
-   */
-  memcpy ((POINTER)x, (POINTER)state, 16);
-  memcpy ((POINTER)x+16, (POINTER)block, 16);
-  for (i = 0; i < 16; i++)
-    x[i+32] = state[i] ^ block[i];
-
-  /* Encrypt block (18 rounds).
-   */
-  t = 0;
-  for (i = 0; i < 18; i++) {
-    for (j = 0; j < 48; j++)
-      t = x[j] ^= PI_SUBST[t];
-    t = (t + i) & 0xff;
-  }
-
-  /* Save new state */
-  memcpy ((POINTER)state, (POINTER)x, 16);
-
-  /* Update checksum.
-   */
-  t = checksum[15];
-  for (i = 0; i < 16; i++)
-    t = checksum[i] ^= PI_SUBST[block[i] ^ t];
-
-  /* Zeroize sensitive information.
-   */
-  memset ((POINTER)x, 0, sizeof (x));
-}

Modified: trunk/lib/libmd/md4.copyright
===================================================================
--- trunk/lib/libmd/md4.copyright	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md4.copyright	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,4 +1,4 @@
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/md4.copyright 50476 1999-08-28 00:22:10Z peter $
 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
 rights reserved.
 .Pp


Property changes on: trunk/lib/libmd/md4.copyright
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/md4.h
===================================================================
--- trunk/lib/libmd/md4.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md4.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /* MD4.H - header file for MD4C.C
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libmd/md4.h 314157 2017-02-23 18:54:33Z avg $
  */
 
 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
@@ -35,6 +36,34 @@
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef MD4Init
+#define MD4Init		_libmd_MD4Init
+#endif
+#ifndef MD4Update
+#define MD4Update	_libmd_MD4Update
+#endif
+#ifndef MD4Pad
+#define MD4Pad		_libmd_MD4Pad
+#endif
+#ifndef MD4Final
+#define MD4Final	_libmd_MD4Final
+#endif
+#ifndef MD4End
+#define MD4End		_libmd_MD4End
+#endif
+#ifndef MD4File
+#define MD4File		_libmd_MD4File
+#endif
+#ifndef MD4FileChunk
+#define MD4FileChunk	_libmd_MD4FileChunk
+#endif
+#ifndef MD4Data
+#define MD4Data		_libmd_MD4Data
+#endif
+
 void   MD4Init(MD4_CTX *);
 void   MD4Update(MD4_CTX *, const void *, unsigned int);
 void   MD4Pad(MD4_CTX *);

Modified: trunk/lib/libmd/md4c.c
===================================================================
--- trunk/lib/libmd/md4c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md4c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,8 +1,9 @@
+/* $MidnightBSD$ */
 /* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/md4c.c 314184 2017-02-23 22:10:37Z avg $");
 
 /* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
 
@@ -290,3 +291,18 @@
     output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
       (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
 }
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+   activated in the context of compiling these sources for internal
+   use in libcrypt.
+ */
+#undef MD4Init
+__weak_reference(_libmd_MD4Init, MD4Init);
+#undef MD4Update
+__weak_reference(_libmd_MD4Update, MD4Update);
+#undef MD4Pad
+__weak_reference(_libmd_MD4Pad, MD4Pad);
+#undef MD4Final
+__weak_reference(_libmd_MD4Final, MD4Final);
+#endif

Modified: trunk/lib/libmd/md5.copyright
===================================================================
--- trunk/lib/libmd/md5.copyright	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md5.copyright	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,4 +1,4 @@
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/md5.copyright 50476 1999-08-28 00:22:10Z peter $
 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
 rights reserved.
 .Pp


Property changes on: trunk/lib/libmd/md5.copyright
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/md5.h
===================================================================
--- trunk/lib/libmd/md5.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md5.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,4 +1,42 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/lib/libmd/md5.h 314157 2017-02-23 18:54:33Z avg $ */
+
 #ifndef _MD5_H_
 #define _MD5_H_
+
+#ifndef _KERNEL
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef MD5Init
+#define MD5Init		_libmd_MD5Init
+#endif
+#ifndef MD5Update
+#define MD5Update	_libmd_MD5Update
+#endif
+#ifndef MD5Pad
+#define MD5Pad		_libmd_MD5Pad
+#endif
+#ifndef MD5Final
+#define MD5Final	_libmd_MD5Final
+#endif
+#ifndef MD5Transform
+#define MD5Transform	_libmd_MD5Transform
+#endif
+#ifndef MD5End
+#define MD5End		_libmd_MD5End
+#endif
+#ifndef MD5File
+#define MD5File		_libmd_MD5File
+#endif
+#ifndef MD5FileChunk
+#define MD5FileChunk	_libmd_MD5FileChunk
+#endif
+#ifndef MD5Data
+#define MD5Data		_libmd_MD5Data
+#endif
+
+#endif
+
 #include <sys/md5.h>
 #endif /* _MD5_H_ */

Modified: trunk/lib/libmd/md5c.c
===================================================================
--- trunk/lib/libmd/md5c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/md5c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
  *
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/md5c.c 314184 2017-02-23 22:10:37Z avg $");
 
 #include <sys/types.h>
 
@@ -39,7 +40,7 @@
 
 #include <machine/endian.h>
 #include <sys/endian.h>
-#include <sys/md5.h>
+#include "md5.h"
 
 static void MD5Transform(u_int32_t [4], const unsigned char [64]);
 
@@ -335,3 +336,20 @@
 	/* Zeroize sensitive information. */
 	memset ((void *)x, 0, sizeof (x));
 }
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+   activated in the context of compiling these sources for internal
+   use in libcrypt.
+ */
+#undef MD5Init
+__weak_reference(_libmd_MD5Init, MD5Init);
+#undef MD5Update
+__weak_reference(_libmd_MD5Update, MD5Update);
+#undef MD5Pad
+__weak_reference(_libmd_MD5Pad, MD5Pad);
+#undef MD5Final
+__weak_reference(_libmd_MD5Final, MD5Final);
+#undef MD5Transform
+__weak_reference(_libmd_MD5Transform, MD5Transform);
+#endif

Modified: trunk/lib/libmd/mdX.3
===================================================================
--- trunk/lib/libmd/mdX.3	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/mdX.3	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" ----------------------------------------------------------------------------
 .\" "THE BEER-WARE LICENSE" (Revision 42):
@@ -6,7 +7,7 @@
 .\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
 .\" ----------------------------------------------------------------------------
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/mdX.3 234746 2012-04-28 02:48:51Z obrien $
 .\"
 .Dd February 11, 1999
 .Dt MDX 3
@@ -52,8 +53,7 @@
 .Dq fingerprint
 of the input-data, which does not disclose the actual input.
 .Pp
-MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle.
-MD2 can only be used for Privacy-Enhanced Mail.
+MD4 is the fastest and MD5 is somewhat slower.
 MD4 has now been broken; it should only be used where necessary for
 backward compatibility.
 MD5 has not yet (1999-02-11) been broken, but sufficient attacks have been
@@ -144,16 +144,10 @@
 .Fa buf
 argument is non-null it must point to at least 33 characters of buffer space.
 .Sh SEE ALSO
-.Xr md2 3 ,
 .Xr md4 3 ,
 .Xr md5 3 ,
 .Xr sha 3
 .Rs
-.%A B. Kaliski
-.%T The MD2 Message-Digest Algorithm
-.%O RFC 1319
-.Re
-.Rs
 .%A R. Rivest
 .%T The MD4 Message-Digest Algorithm
 .%O RFC 1186
@@ -192,6 +186,3 @@
 No method is known to exist which finds two files having the same hash value,
 nor to find a file with a specific hash value.
 There is on the other hand no guarantee that such a method does not exist.
-.Pp
-MD2 has only been licensed for use in Privacy Enhanced Mail.
-Use MD4 or MD5 if that is not what you are doing.


Property changes on: trunk/lib/libmd/mdX.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/mdXhl.c
===================================================================
--- trunk/lib/libmd/mdXhl.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/mdXhl.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* mdXhl.c * ----------------------------------------------------------------------------
  * "THE BEER-WARE LICENSE" (Revision 42):
  * <phk at FreeBSD.org> wrote this file.  As long as you retain this notice you
@@ -7,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/mdXhl.c 314184 2017-02-23 22:10:37Z avg $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -74,7 +75,7 @@
 			i = read(f, buffer, sizeof(buffer));
 		else
 			i = read(f, buffer, n);
-		if (i < 0) 
+		if (i <= 0) 
 			break;
 		MDXUpdate(&ctx, buffer, i);
 		n -= i;
@@ -96,3 +97,18 @@
 	MDXUpdate(&ctx,data,len);
 	return (MDXEnd(&ctx, buf));
 }
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+   activated in the context of compiling these sources for internal
+   use in libcrypt.
+ */
+#undef MDXEnd
+__weak_reference(_libmd_MDXEnd, MDXEnd);
+#undef MDXFile
+__weak_reference(_libmd_MDXFile, MDXFile);
+#undef MDXFileChunk
+__weak_reference(_libmd_MDXFileChunk, MDXFileChunk);
+#undef MDXData
+__weak_reference(_libmd_MDXData, MDXData);
+#endif

Modified: trunk/lib/libmd/mddriver.c
===================================================================
--- trunk/lib/libmd/mddriver.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/mddriver.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* MDDRIVER.C - test driver for MD2, MD4 and MD5 */
 
 /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
@@ -12,7 +13,7 @@
  * documentation and/or software. */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/mddriver.c 220496 2011-04-09 13:56:29Z markm $");
 
 #include <sys/types.h>
 

Modified: trunk/lib/libmd/ripemd.3
===================================================================
--- trunk/lib/libmd/ripemd.3	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/ripemd.3	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" ----------------------------------------------------------------------------
 .\" "THE BEER-WARE LICENSE" (Revision 42):
@@ -7,9 +8,9 @@
 .\" ----------------------------------------------------------------------------
 .\"
 .\" 	From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/ripemd.3 263955 2014-03-31 00:28:54Z gjb $
 .\"
-.Dd February 26, 1999
+.Dd March 28, 2014
 .Dt RIPEMD 3
 .Os
 .Sh NAME
@@ -123,7 +124,6 @@
 .Fa buf
 argument is non-null it must point to at least 41 characters of buffer space.
 .Sh SEE ALSO
-.Xr md2 3 ,
 .Xr md4 3 ,
 .Xr md5 3 ,
 .Xr sha 3


Property changes on: trunk/lib/libmd/ripemd.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/ripemd.h
===================================================================
--- trunk/lib/libmd/ripemd.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/ripemd.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/ripemd/ripemd.h */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.
@@ -57,7 +58,7 @@
  */
 
 /*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libmd/ripemd.h 314157 2017-02-23 18:54:33Z avg $
  */
 
 #ifndef HEADER_RIPEMD_H
@@ -81,6 +82,41 @@
 } RIPEMD160_CTX;
 
 __BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef RIPEMD160_Init
+#define RIPEMD160_Init		_libmd_RIPEMD160_Init
+#endif
+#ifndef RIPEMD160_Update
+#define RIPEMD160_Update	_libmd_RIPEMD160_Update
+#endif
+#ifndef RIPEMD160_Final
+#define RIPEMD160_Final		_libmd_RIPEMD160_Final
+#endif
+#ifndef RIPEMD160_End
+#define RIPEMD160_End		_libmd_RIPEMD160_End
+#endif
+#ifndef RIPEMD160_File
+#define RIPEMD160_File		_libmd_RIPEMD160_File
+#endif
+#ifndef RIPEMD160_FileChunk
+#define RIPEMD160_FileChunk	_libmd_RIPEMD160_FileChunk
+#endif
+#ifndef RIPEMD160_Data
+#define RIPEMD160_Data		_libmd_RIPEMD160_Data
+#endif
+
+#ifndef RIPEMD160_Transform
+#define RIPEMD160_Transform	_libmd_RIPEMD160_Transform
+#endif
+#ifndef RMD160_version
+#define RMD160_version		_libmd_RMD160_version
+#endif
+#ifndef ripemd160_block
+#define ripemd160_block		_libmd_ripemd160_block
+#endif
+
 void	RIPEMD160_Init(RIPEMD160_CTX *c);
 void	RIPEMD160_Update(RIPEMD160_CTX *c, const void *data,
 			 size_t len);

Modified: trunk/lib/libmd/rmd160c.c
===================================================================
--- trunk/lib/libmd/rmd160c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/rmd160c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/ripemd/rmd_dgst.c */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.
@@ -57,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/rmd160c.c 314184 2017-02-23 22:10:37Z avg $");
 
 #include <sys/types.h>
 
@@ -545,3 +546,22 @@
 		}
 	}
 #endif
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+   activated in the context of compiling these sources for internal
+   use in libcrypt.
+ */
+#undef RIPEMD160_Init
+__weak_reference(_libmd_RIPEMD160_Init, RIPEMD160_Init);
+#undef RIPEMD160_Update
+__weak_reference(_libmd_RIPEMD160_Update, RIPEMD160_Update);
+#undef RIPEMD160_Final
+__weak_reference(_libmd_RIPEMD160_Final, RIPEMD160_Final);
+#undef RIPEMD160_Transform
+__weak_reference(_libmd_RIPEMD160_Transform, RIPEMD160_Transform);
+#undef RMD160_version
+__weak_reference(_libmd_RMD160_version, RMD160_version);
+#undef ripemd160_block
+__weak_reference(_libmd_ripemd160_block, ripemd160_block);
+#endif

Modified: trunk/lib/libmd/rmd_locl.h
===================================================================
--- trunk/lib/libmd/rmd_locl.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/rmd_locl.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/ripemd/rmd_locl.h */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.

Modified: trunk/lib/libmd/rmdconst.h
===================================================================
--- trunk/lib/libmd/rmdconst.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/rmdconst.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/ripemd/rmdconst.h */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.

Modified: trunk/lib/libmd/rmddriver.c
===================================================================
--- trunk/lib/libmd/rmddriver.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/rmddriver.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* RIPEMD160DRIVER.C - test driver for RIPEMD160 */
 
 /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
@@ -12,7 +13,7 @@
  * documentation and/or software. */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/rmddriver.c 220496 2011-04-09 13:56:29Z markm $");
 
 #include <sys/types.h>
 

Modified: trunk/lib/libmd/sha.3
===================================================================
--- trunk/lib/libmd/sha.3	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha.3	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" ----------------------------------------------------------------------------
 .\" "THE BEER-WARE LICENSE" (Revision 42):
@@ -7,9 +8,9 @@
 .\" ----------------------------------------------------------------------------
 .\"
 .\" 	From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/sha.3 263955 2014-03-31 00:28:54Z gjb $
 .\"
-.Dd February 25, 1999
+.Dd March 28, 2014
 .Dt SHA 3
 .Os
 .Sh NAME
@@ -154,7 +155,6 @@
 .Fa buf
 argument is non-null it must point to at least 41 characters of buffer space.
 .Sh SEE ALSO
-.Xr md2 3 ,
 .Xr md4 3 ,
 .Xr md5 3 ,
 .Xr ripemd 3 ,


Property changes on: trunk/lib/libmd/sha.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libmd/sha.h
===================================================================
--- trunk/lib/libmd/sha.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.
  *
@@ -54,7 +55,7 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.]
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libmd/sha.h 314157 2017-02-23 18:54:33Z avg $
  */
 
 #ifndef _SHA_H_
@@ -79,6 +80,73 @@
 #define	SHA1_CTX	SHA_CTX
 
 __BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef SHA_Init
+#define SHA_Init	_libmd_SHA_Init
+#endif
+#ifndef SHA_Update
+#define SHA_Update	_libmd_SHA_Update
+#endif
+#ifndef SHA_Final
+#define SHA_Final	_libmd_SHA_Final
+#endif
+#ifndef SHA_End
+#define SHA_End		_libmd_SHA_End
+#endif
+#ifndef SHA_File
+#define SHA_File	_libmd_SHA_File
+#endif
+#ifndef SHA_FileChunk
+#define SHA_FileChunk	_libmd_SHA_FileChunk
+#endif
+#ifndef SHA_Data
+#define SHA_Data	_libmd_SHA_Data
+#endif
+
+#ifndef SHA_Transform
+#define SHA_Transform	_libmd_SHA_Transform
+#endif
+#ifndef SHA_version
+#define SHA_version	_libmd_SHA_version
+#endif
+#ifndef sha_block
+#define sha_block	_libmd_sha_block
+#endif
+
+#ifndef SHA1_Init
+#define SHA1_Init	_libmd_SHA1_Init
+#endif
+#ifndef SHA1_Update
+#define SHA1_Update	_libmd_SHA1_Update
+#endif
+#ifndef SHA1_Final
+#define SHA1_Final	_libmd_SHA1_Final
+#endif
+#ifndef SHA1_End
+#define SHA1_End	_libmd_SHA1_End
+#endif
+#ifndef SHA1_File
+#define SHA1_File	_libmd_SHA1_File
+#endif
+#ifndef SHA1_FileChunk
+#define SHA1_FileChunk	_libmd_SHA1_FileChunk
+#endif
+#ifndef SHA1_Data
+#define SHA1_Data	_libmd_SHA1_Data
+#endif
+
+#ifndef SHA1_Transform
+#define SHA1_Transform	_libmd_SHA1_Transform
+#endif
+#ifndef SHA1_version
+#define SHA1_version	_libmd_SHA1_version
+#endif
+#ifndef sha1_block
+#define sha1_block	_libmd_sha1_block
+#endif
+
 void	SHA_Init(SHA_CTX *c);
 void	SHA_Update(SHA_CTX *c, const void *data, size_t len);
 void	SHA_Final(unsigned char *md, SHA_CTX *c);
@@ -86,6 +154,7 @@
 char   *SHA_File(const char *, char *);
 char   *SHA_FileChunk(const char *, char *, off_t, off_t);
 char   *SHA_Data(const void *, unsigned int, char *);
+
 void	SHA1_Init(SHA_CTX *c);
 void	SHA1_Update(SHA_CTX *c, const void *data, size_t len);
 void	SHA1_Final(unsigned char *md, SHA_CTX *c);

Modified: trunk/lib/libmd/sha0c.c
===================================================================
--- trunk/lib/libmd/sha0c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha0c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/sha/sha_dgst.c */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.
@@ -57,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/sha0c.c 154479 2006-01-17 15:35:57Z phk $");
 
 #include <sys/types.h>
 

Modified: trunk/lib/libmd/sha1c.c
===================================================================
--- trunk/lib/libmd/sha1c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha1c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/sha/sha1dgst.c */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.
@@ -57,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/sha1c.c 314184 2017-02-23 22:10:37Z avg $");
 
 #include <sys/types.h>
 
@@ -488,3 +489,33 @@
 /*	memset((char *)&c,0,sizeof(c));*/
 	}
 
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+   activated in the context of compiling these sources for internal
+   use in libcrypt.
+ */
+#undef SHA_Init
+__weak_reference(_libmd_SHA_Init, SHA_Init);
+#undef SHA_Update
+__weak_reference(_libmd_SHA_Update, SHA_Update);
+#undef SHA_Final
+__weak_reference(_libmd_SHA_Final, SHA_Final);
+#undef SHA_Transform
+__weak_reference(_libmd_SHA_Transform, SHA_Transform);
+#undef SHA_version
+__weak_reference(_libmd_SHA_version, SHA_version);
+#undef sha_block
+__weak_reference(_libmd_sha_block, sha_block);
+#undef SHA1_Init
+__weak_reference(_libmd_SHA1_Init, SHA1_Init);
+#undef SHA1_Update
+__weak_reference(_libmd_SHA1_Update, SHA1_Update);
+#undef SHA1_Final
+__weak_reference(_libmd_SHA1_Final, SHA1_Final);
+#undef SHA1_Transform
+__weak_reference(_libmd_SHA1_Transform, SHA1_Transform);
+#undef SHA1_version
+__weak_reference(_libmd_SHA1_version, SHA1_version);
+#undef sha1_block
+__weak_reference(_libmd_sha1_block, sha1_block);
+#endif

Modified: trunk/lib/libmd/sha256.3
===================================================================
--- trunk/lib/libmd/sha256.3	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha256.3	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" ----------------------------------------------------------------------------
 .\" "THE BEER-WARE LICENSE" (Revision 42):
@@ -7,9 +8,9 @@
 .\" ----------------------------------------------------------------------------
 .\"
 .\" 	From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/sha256.3 263955 2014-03-31 00:28:54Z gjb $
 .\"
-.Dd September 14, 2005
+.Dd March 28, 2014
 .Dt SHA256 3
 .Os
 .Sh NAME
@@ -120,7 +121,6 @@
 .Fa buf
 argument is non-null it must point to at least 65 characters of buffer space.
 .Sh SEE ALSO
-.Xr md2 3 ,
 .Xr md4 3 ,
 .Xr md5 3 ,
 .Xr ripemd 3 ,


Property changes on: trunk/lib/libmd/sha256.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Deleted: trunk/lib/libmd/sha256.h
===================================================================
--- trunk/lib/libmd/sha256.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha256.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,50 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $MidnightBSD$
- */
-
-#ifndef _SHA256_H_
-#define _SHA256_H_
-
-#include <sys/types.h>
-
-typedef struct SHA256Context {
-	uint32_t state[8];
-	uint32_t count[2];
-	unsigned char buf[64];
-} SHA256_CTX;
-
-__BEGIN_DECLS
-void	SHA256_Init(SHA256_CTX *);
-void	SHA256_Update(SHA256_CTX *, const void *, size_t);
-void	SHA256_Final(unsigned char [32], SHA256_CTX *);
-char   *SHA256_End(SHA256_CTX *, char *);
-char   *SHA256_File(const char *, char *);
-char   *SHA256_FileChunk(const char *, char *, off_t, off_t);
-char   *SHA256_Data(const void *, unsigned int, char *);
-__END_DECLS
-
-#endif /* !_SHA256_H_ */

Deleted: trunk/lib/libmd/sha256c.c
===================================================================
--- trunk/lib/libmd/sha256c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha256c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,300 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
-
-#include <sys/endian.h>
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "sha256.h"
-
-#if BYTE_ORDER == BIG_ENDIAN
-
-/* Copy a vector of big-endian uint32_t into a vector of bytes */
-#define be32enc_vect(dst, src, len)	\
-	memcpy((void *)dst, (const void *)src, (size_t)len)
-
-/* Copy a vector of bytes into a vector of big-endian uint32_t */
-#define be32dec_vect(dst, src, len)	\
-	memcpy((void *)dst, (const void *)src, (size_t)len)
-
-#else /* BYTE_ORDER != BIG_ENDIAN */
-
-/*
- * Encode a length len/4 vector of (uint32_t) into a length len vector of
- * (unsigned char) in big-endian form.  Assumes len is a multiple of 4.
- */
-static void
-be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)
-{
-	size_t i;
-
-	for (i = 0; i < len / 4; i++)
-		be32enc(dst + i * 4, src[i]);
-}
-
-/*
- * Decode a big-endian length len vector of (unsigned char) into a length
- * len/4 vector of (uint32_t).  Assumes len is a multiple of 4.
- */
-static void
-be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len)
-{
-	size_t i;
-
-	for (i = 0; i < len / 4; i++)
-		dst[i] = be32dec(src + i * 4);
-}
-
-#endif /* BYTE_ORDER != BIG_ENDIAN */
-
-/* Elementary functions used by SHA256 */
-#define Ch(x, y, z)	((x & (y ^ z)) ^ z)
-#define Maj(x, y, z)	((x & (y | z)) | (y & z))
-#define SHR(x, n)	(x >> n)
-#define ROTR(x, n)	((x >> n) | (x << (32 - n)))
-#define S0(x)		(ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
-#define S1(x)		(ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
-#define s0(x)		(ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
-#define s1(x)		(ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
-
-/* SHA256 round function */
-#define RND(a, b, c, d, e, f, g, h, k)			\
-	t0 = h + S1(e) + Ch(e, f, g) + k;		\
-	t1 = S0(a) + Maj(a, b, c);			\
-	d += t0;					\
-	h  = t0 + t1;
-
-/* Adjusted round function for rotating state */
-#define RNDr(S, W, i, k)			\
-	RND(S[(64 - i) % 8], S[(65 - i) % 8],	\
-	    S[(66 - i) % 8], S[(67 - i) % 8],	\
-	    S[(68 - i) % 8], S[(69 - i) % 8],	\
-	    S[(70 - i) % 8], S[(71 - i) % 8],	\
-	    W[i] + k)
-
-/*
- * SHA256 block compression function.  The 256-bit state is transformed via
- * the 512-bit input block to produce a new state.
- */
-static void
-SHA256_Transform(uint32_t * state, const unsigned char block[64])
-{
-	uint32_t W[64];
-	uint32_t S[8];
-	uint32_t t0, t1;
-	int i;
-
-	/* 1. Prepare message schedule W. */
-	be32dec_vect(W, block, 64);
-	for (i = 16; i < 64; i++)
-		W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
-
-	/* 2. Initialize working variables. */
-	memcpy(S, state, 32);
-
-	/* 3. Mix. */
-	RNDr(S, W, 0, 0x428a2f98);
-	RNDr(S, W, 1, 0x71374491);
-	RNDr(S, W, 2, 0xb5c0fbcf);
-	RNDr(S, W, 3, 0xe9b5dba5);
-	RNDr(S, W, 4, 0x3956c25b);
-	RNDr(S, W, 5, 0x59f111f1);
-	RNDr(S, W, 6, 0x923f82a4);
-	RNDr(S, W, 7, 0xab1c5ed5);
-	RNDr(S, W, 8, 0xd807aa98);
-	RNDr(S, W, 9, 0x12835b01);
-	RNDr(S, W, 10, 0x243185be);
-	RNDr(S, W, 11, 0x550c7dc3);
-	RNDr(S, W, 12, 0x72be5d74);
-	RNDr(S, W, 13, 0x80deb1fe);
-	RNDr(S, W, 14, 0x9bdc06a7);
-	RNDr(S, W, 15, 0xc19bf174);
-	RNDr(S, W, 16, 0xe49b69c1);
-	RNDr(S, W, 17, 0xefbe4786);
-	RNDr(S, W, 18, 0x0fc19dc6);
-	RNDr(S, W, 19, 0x240ca1cc);
-	RNDr(S, W, 20, 0x2de92c6f);
-	RNDr(S, W, 21, 0x4a7484aa);
-	RNDr(S, W, 22, 0x5cb0a9dc);
-	RNDr(S, W, 23, 0x76f988da);
-	RNDr(S, W, 24, 0x983e5152);
-	RNDr(S, W, 25, 0xa831c66d);
-	RNDr(S, W, 26, 0xb00327c8);
-	RNDr(S, W, 27, 0xbf597fc7);
-	RNDr(S, W, 28, 0xc6e00bf3);
-	RNDr(S, W, 29, 0xd5a79147);
-	RNDr(S, W, 30, 0x06ca6351);
-	RNDr(S, W, 31, 0x14292967);
-	RNDr(S, W, 32, 0x27b70a85);
-	RNDr(S, W, 33, 0x2e1b2138);
-	RNDr(S, W, 34, 0x4d2c6dfc);
-	RNDr(S, W, 35, 0x53380d13);
-	RNDr(S, W, 36, 0x650a7354);
-	RNDr(S, W, 37, 0x766a0abb);
-	RNDr(S, W, 38, 0x81c2c92e);
-	RNDr(S, W, 39, 0x92722c85);
-	RNDr(S, W, 40, 0xa2bfe8a1);
-	RNDr(S, W, 41, 0xa81a664b);
-	RNDr(S, W, 42, 0xc24b8b70);
-	RNDr(S, W, 43, 0xc76c51a3);
-	RNDr(S, W, 44, 0xd192e819);
-	RNDr(S, W, 45, 0xd6990624);
-	RNDr(S, W, 46, 0xf40e3585);
-	RNDr(S, W, 47, 0x106aa070);
-	RNDr(S, W, 48, 0x19a4c116);
-	RNDr(S, W, 49, 0x1e376c08);
-	RNDr(S, W, 50, 0x2748774c);
-	RNDr(S, W, 51, 0x34b0bcb5);
-	RNDr(S, W, 52, 0x391c0cb3);
-	RNDr(S, W, 53, 0x4ed8aa4a);
-	RNDr(S, W, 54, 0x5b9cca4f);
-	RNDr(S, W, 55, 0x682e6ff3);
-	RNDr(S, W, 56, 0x748f82ee);
-	RNDr(S, W, 57, 0x78a5636f);
-	RNDr(S, W, 58, 0x84c87814);
-	RNDr(S, W, 59, 0x8cc70208);
-	RNDr(S, W, 60, 0x90befffa);
-	RNDr(S, W, 61, 0xa4506ceb);
-	RNDr(S, W, 62, 0xbef9a3f7);
-	RNDr(S, W, 63, 0xc67178f2);
-
-	/* 4. Mix local working variables into global state */
-	for (i = 0; i < 8; i++)
-		state[i] += S[i];
-}
-
-static unsigned char PAD[64] = {
-	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* Add padding and terminating bit-count. */
-static void
-SHA256_Pad(SHA256_CTX * ctx)
-{
-	unsigned char len[8];
-	uint32_t r, plen;
-
-	/*
-	 * Convert length to a vector of bytes -- we do this now rather
-	 * than later because the length will change after we pad.
-	 */
-	be32enc_vect(len, ctx->count, 8);
-
-	/* Add 1--64 bytes so that the resulting length is 56 mod 64 */
-	r = (ctx->count[1] >> 3) & 0x3f;
-	plen = (r < 56) ? (56 - r) : (120 - r);
-	SHA256_Update(ctx, PAD, (size_t)plen);
-
-	/* Add the terminating bit-count */
-	SHA256_Update(ctx, len, 8);
-}
-
-/* SHA-256 initialization.  Begins a SHA-256 operation. */
-void
-SHA256_Init(SHA256_CTX * ctx)
-{
-
-	/* Zero bits processed so far */
-	ctx->count[0] = ctx->count[1] = 0;
-
-	/* Magic initialization constants */
-	ctx->state[0] = 0x6A09E667;
-	ctx->state[1] = 0xBB67AE85;
-	ctx->state[2] = 0x3C6EF372;
-	ctx->state[3] = 0xA54FF53A;
-	ctx->state[4] = 0x510E527F;
-	ctx->state[5] = 0x9B05688C;
-	ctx->state[6] = 0x1F83D9AB;
-	ctx->state[7] = 0x5BE0CD19;
-}
-
-/* Add bytes into the hash */
-void
-SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len)
-{
-	uint32_t bitlen[2];
-	uint32_t r;
-	const unsigned char *src = in;
-
-	/* Number of bytes left in the buffer from previous updates */
-	r = (ctx->count[1] >> 3) & 0x3f;
-
-	/* Convert the length into a number of bits */
-	bitlen[1] = ((uint32_t)len) << 3;
-	bitlen[0] = (uint32_t)(len >> 29);
-
-	/* Update number of bits */
-	if ((ctx->count[1] += bitlen[1]) < bitlen[1])
-		ctx->count[0]++;
-	ctx->count[0] += bitlen[0];
-
-	/* Handle the case where we don't need to perform any transforms */
-	if (len < 64 - r) {
-		memcpy(&ctx->buf[r], src, len);
-		return;
-	}
-
-	/* Finish the current block */
-	memcpy(&ctx->buf[r], src, 64 - r);
-	SHA256_Transform(ctx->state, ctx->buf);
-	src += 64 - r;
-	len -= 64 - r;
-
-	/* Perform complete blocks */
-	while (len >= 64) {
-		SHA256_Transform(ctx->state, src);
-		src += 64;
-		len -= 64;
-	}
-
-	/* Copy left over data into buffer */
-	memcpy(ctx->buf, src, len);
-}
-
-/*
- * SHA-256 finalization.  Pads the input data, exports the hash value,
- * and clears the context state.
- */
-void
-SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
-{
-
-	/* Add padding */
-	SHA256_Pad(ctx);
-
-	/* Write the hash */
-	be32enc_vect(digest, ctx->state, 32);
-
-	/* Clear the context state */
-	memset((void *)ctx, 0, sizeof(*ctx));
-}

Modified: trunk/lib/libmd/sha512.3
===================================================================
--- trunk/lib/libmd/sha512.3	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha512.3	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" ----------------------------------------------------------------------------
 .\" "THE BEER-WARE LICENSE" (Revision 42):
@@ -7,9 +8,9 @@
 .\" ----------------------------------------------------------------------------
 .\"
 .\" 	From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libmd/sha512.3 314332 2017-02-27 10:40:39Z avg $
 .\"
-.Dd April 1, 2011
+.Dd April 22, 2016
 .Dt SHA512 3
 .Os
 .Sh NAME
@@ -19,8 +20,22 @@
 .Nm SHA512_End ,
 .Nm SHA512_File ,
 .Nm SHA512_FileChunk ,
-.Nm SHA512_Data
-.Nd calculate the FIPS 180-2 ``SHA-512'' message digest
+.Nm SHA512_Data ,
+.Nm SHA384_Init ,
+.Nm SHA384_Update ,
+.Nm SHA384_Final ,
+.Nm SHA384_End ,
+.Nm SHA384_File ,
+.Nm SHA384_FileChunk ,
+.Nm SHA384_Data,
+.Nm SHA512_256_Init ,
+.Nm SHA512_256_Update ,
+.Nm SHA512_256_Final ,
+.Nm SHA512_256_End ,
+.Nm SHA512_256_File ,
+.Nm SHA512_256_FileChunk ,
+.Nm SHA512_256_Data
+.Nd calculate the FIPS 180-4 ``SHA-512'' family of message digests
 .Sh LIBRARY
 .Lb libmd
 .Sh SYNOPSIS
@@ -40,6 +55,36 @@
 .Fn SHA512_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
 .Ft "char *"
 .Fn SHA512_Data "const unsigned char *data" "unsigned int len" "char *buf"
+.In sha384.h
+.Ft void
+.Fn SHA384_Init "SHA384_CTX *context"
+.Ft void
+.Fn SHA384_Update "SHA384_CTX *context" "const unsigned char *data" "size_t len"
+.Ft void
+.Fn SHA384_Final "unsigned char digest[48]" "SHA384_CTX *context"
+.Ft "char *"
+.Fn SHA384_End "SHA384_CTX *context" "char *buf"
+.Ft "char *"
+.Fn SHA384_File "const char *filename" "char *buf"
+.Ft "char *"
+.Fn SHA384_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
+.Ft "char *"
+.Fn SHA384_Data "const unsigned char *data" "unsigned int len" "char *buf"
+.In sha512t.h
+.Ft void
+.Fn SHA512_256_Init "SHA512_CTX *context"
+.Ft void
+.Fn SHA512_256_Update "SHA512_CTX *context" "const unsigned char *data" "size_t len"
+.Ft void
+.Fn SHA512_256_Final "unsigned char digest[32]" "SHA512_CTX *context"
+.Ft "char *"
+.Fn SHA512_256_End "SHA512_CTX *context" "char *buf"
+.Ft "char *"
+.Fn SHA512_256_File "const char *filename" "char *buf"
+.Ft "char *"
+.Fn SHA512_256_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
+.Ft "char *"
+.Fn SHA512_256_Data "const unsigned char *data" "unsigned int len" "char *buf"
 .Sh DESCRIPTION
 The
 .Li SHA512_
@@ -71,7 +116,7 @@
 .Fn SHA512_End
 is a wrapper for
 .Fn SHA512_Final
-which converts the return value to a 65-character
+which converts the return value to a 129-character
 (including the terminating '\e0')
 .Tn ASCII
 string which represents the 512 bits in hexadecimal.
@@ -118,9 +163,33 @@
 after use.
 If the
 .Fa buf
-argument is non-null it must point to at least 65 characters of buffer space.
+argument is non-null it must point to at least 129 characters of buffer space.
+.Pp
+The
+.Li SHA384_
+and
+.Li SHA512_256_
+functions are identical to the
+.Li SHA512_
+functions except they use a different initial hash value and the output is
+truncated to 384 bits and 256 bits respectively.
+.Pp
+.Fn SHA384_End
+is a wrapper for
+.Fn SHA384_Final
+which converts the return value to a 97-character
+(including the terminating '\e0')
+.Tn ASCII
+string which represents the 384 bits in hexadecimal.
+.Pp
+.Fn SHA512_256_End
+is a wrapper for
+.Fn SHA512_Final
+which converts the return value to a 65-character
+(including the terminating '\e0')
+.Tn ASCII
+string which represents the 256 bits in hexadecimal.
 .Sh SEE ALSO
-.Xr md2 3 ,
 .Xr md4 3 ,
 .Xr md5 3 ,
 .Xr ripemd 3 ,


Property changes on: trunk/lib/libmd/sha512.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Deleted: trunk/lib/libmd/sha512.h
===================================================================
--- trunk/lib/libmd/sha512.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha512.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,50 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $MidnightBSD$
- */
-
-#ifndef _SHA512_H_
-#define _SHA512_H_
-
-#include <sys/types.h>
-
-typedef struct SHA512Context {
-	uint64_t state[8];
-	uint64_t count[2];
-	unsigned char buf[128];
-} SHA512_CTX;
-
-__BEGIN_DECLS
-void	SHA512_Init(SHA512_CTX *);
-void	SHA512_Update(SHA512_CTX *, const void *, size_t);
-void	SHA512_Final(unsigned char [64], SHA512_CTX *);
-char   *SHA512_End(SHA512_CTX *, char *);
-char   *SHA512_File(const char *, char *);
-char   *SHA512_FileChunk(const char *, char *, off_t, off_t);
-char   *SHA512_Data(const void *, unsigned int, char *);
-__END_DECLS
-
-#endif /* !_SHA512_H_ */

Deleted: trunk/lib/libmd/sha512c.c
===================================================================
--- trunk/lib/libmd/sha512c.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha512c.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,320 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
-
-#include <sys/endian.h>
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "sha512.h"
-
-#if BYTE_ORDER == BIG_ENDIAN
-
-/* Copy a vector of big-endian uint64_t into a vector of bytes */
-#define be64enc_vect(dst, src, len)	\
-	memcpy((void *)dst, (const void *)src, (size_t)len)
-
-/* Copy a vector of bytes into a vector of big-endian uint64_t */
-#define be64dec_vect(dst, src, len)	\
-	memcpy((void *)dst, (const void *)src, (size_t)len)
-
-#else /* BYTE_ORDER != BIG_ENDIAN */
-
-/*
- * Encode a length len/4 vector of (uint64_t) into a length len vector of
- * (unsigned char) in big-endian form.  Assumes len is a multiple of 8.
- */
-static void
-be64enc_vect(unsigned char *dst, const uint64_t *src, size_t len)
-{
-	size_t i;
-
-	for (i = 0; i < len / 8; i++)
-		be64enc(dst + i * 8, src[i]);
-}
-
-/*
- * Decode a big-endian length len vector of (unsigned char) into a length
- * len/4 vector of (uint64_t).  Assumes len is a multiple of 8.
- */
-static void
-be64dec_vect(uint64_t *dst, const unsigned char *src, size_t len)
-{
-	size_t i;
-
-	for (i = 0; i < len / 8; i++)
-		dst[i] = be64dec(src + i * 8);
-}
-
-#endif /* BYTE_ORDER != BIG_ENDIAN */
-
-/* Elementary functions used by SHA512 */
-#define Ch(x, y, z)	((x & (y ^ z)) ^ z)
-#define Maj(x, y, z)	((x & (y | z)) | (y & z))
-#define SHR(x, n)	(x >> n)
-#define ROTR(x, n)	((x >> n) | (x << (64 - n)))
-#define S0(x)		(ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
-#define S1(x)		(ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
-#define s0(x)		(ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7))
-#define s1(x)		(ROTR(x, 19) ^ ROTR(x, 61) ^ SHR(x, 6))
-
-/* SHA512 round function */
-#define RND(a, b, c, d, e, f, g, h, k)			\
-	t0 = h + S1(e) + Ch(e, f, g) + k;		\
-	t1 = S0(a) + Maj(a, b, c);			\
-	d += t0;					\
-	h  = t0 + t1;
-
-/* Adjusted round function for rotating state */
-#define RNDr(S, W, i, k)			\
-	RND(S[(80 - i) % 8], S[(81 - i) % 8],	\
-	    S[(82 - i) % 8], S[(83 - i) % 8],	\
-	    S[(84 - i) % 8], S[(85 - i) % 8],	\
-	    S[(86 - i) % 8], S[(87 - i) % 8],	\
-	    W[i] + k)
-
-/*
- * SHA512 block compression function.  The 512-bit state is transformed via
- * the 512-bit input block to produce a new state.
- */
-static void
-SHA512_Transform(uint64_t * state, const unsigned char block[128])
-{
-	uint64_t W[80];
-	uint64_t S[8];
-	uint64_t t0, t1;
-	int i;
-
-	/* 1. Prepare message schedule W. */
-	be64dec_vect(W, block, 128);
-	for (i = 16; i < 80; i++)
-		W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
-
-	/* 2. Initialize working variables. */
-	memcpy(S, state, 64);
-
-	/* 3. Mix. */
-	RNDr(S, W, 0, 0x428a2f98d728ae22ULL);
-	RNDr(S, W, 1, 0x7137449123ef65cdULL);
-	RNDr(S, W, 2, 0xb5c0fbcfec4d3b2fULL);
-	RNDr(S, W, 3, 0xe9b5dba58189dbbcULL);
-	RNDr(S, W, 4, 0x3956c25bf348b538ULL);
-	RNDr(S, W, 5, 0x59f111f1b605d019ULL);
-	RNDr(S, W, 6, 0x923f82a4af194f9bULL);
-	RNDr(S, W, 7, 0xab1c5ed5da6d8118ULL);
-	RNDr(S, W, 8, 0xd807aa98a3030242ULL);
-	RNDr(S, W, 9, 0x12835b0145706fbeULL);
-	RNDr(S, W, 10, 0x243185be4ee4b28cULL);
-	RNDr(S, W, 11, 0x550c7dc3d5ffb4e2ULL);
-	RNDr(S, W, 12, 0x72be5d74f27b896fULL);
-	RNDr(S, W, 13, 0x80deb1fe3b1696b1ULL);
-	RNDr(S, W, 14, 0x9bdc06a725c71235ULL);
-	RNDr(S, W, 15, 0xc19bf174cf692694ULL);
-	RNDr(S, W, 16, 0xe49b69c19ef14ad2ULL);
-	RNDr(S, W, 17, 0xefbe4786384f25e3ULL);
-	RNDr(S, W, 18, 0x0fc19dc68b8cd5b5ULL);
-	RNDr(S, W, 19, 0x240ca1cc77ac9c65ULL);
-	RNDr(S, W, 20, 0x2de92c6f592b0275ULL);
-	RNDr(S, W, 21, 0x4a7484aa6ea6e483ULL);
-	RNDr(S, W, 22, 0x5cb0a9dcbd41fbd4ULL);
-	RNDr(S, W, 23, 0x76f988da831153b5ULL);
-	RNDr(S, W, 24, 0x983e5152ee66dfabULL);
-	RNDr(S, W, 25, 0xa831c66d2db43210ULL);
-	RNDr(S, W, 26, 0xb00327c898fb213fULL);
-	RNDr(S, W, 27, 0xbf597fc7beef0ee4ULL);
-	RNDr(S, W, 28, 0xc6e00bf33da88fc2ULL);
-	RNDr(S, W, 29, 0xd5a79147930aa725ULL);
-	RNDr(S, W, 30, 0x06ca6351e003826fULL);
-	RNDr(S, W, 31, 0x142929670a0e6e70ULL);
-	RNDr(S, W, 32, 0x27b70a8546d22ffcULL);
-	RNDr(S, W, 33, 0x2e1b21385c26c926ULL);
-	RNDr(S, W, 34, 0x4d2c6dfc5ac42aedULL);
-	RNDr(S, W, 35, 0x53380d139d95b3dfULL);
-	RNDr(S, W, 36, 0x650a73548baf63deULL);
-	RNDr(S, W, 37, 0x766a0abb3c77b2a8ULL);
-	RNDr(S, W, 38, 0x81c2c92e47edaee6ULL);
-	RNDr(S, W, 39, 0x92722c851482353bULL);
-	RNDr(S, W, 40, 0xa2bfe8a14cf10364ULL);
-	RNDr(S, W, 41, 0xa81a664bbc423001ULL);
-	RNDr(S, W, 42, 0xc24b8b70d0f89791ULL);
-	RNDr(S, W, 43, 0xc76c51a30654be30ULL);
-	RNDr(S, W, 44, 0xd192e819d6ef5218ULL);
-	RNDr(S, W, 45, 0xd69906245565a910ULL);
-	RNDr(S, W, 46, 0xf40e35855771202aULL);
-	RNDr(S, W, 47, 0x106aa07032bbd1b8ULL);
-	RNDr(S, W, 48, 0x19a4c116b8d2d0c8ULL);
-	RNDr(S, W, 49, 0x1e376c085141ab53ULL);
-	RNDr(S, W, 50, 0x2748774cdf8eeb99ULL);
-	RNDr(S, W, 51, 0x34b0bcb5e19b48a8ULL);
-	RNDr(S, W, 52, 0x391c0cb3c5c95a63ULL);
-	RNDr(S, W, 53, 0x4ed8aa4ae3418acbULL);
-	RNDr(S, W, 54, 0x5b9cca4f7763e373ULL);
-	RNDr(S, W, 55, 0x682e6ff3d6b2b8a3ULL);
-	RNDr(S, W, 56, 0x748f82ee5defb2fcULL);
-	RNDr(S, W, 57, 0x78a5636f43172f60ULL);
-	RNDr(S, W, 58, 0x84c87814a1f0ab72ULL);
-	RNDr(S, W, 59, 0x8cc702081a6439ecULL);
-	RNDr(S, W, 60, 0x90befffa23631e28ULL);
-	RNDr(S, W, 61, 0xa4506cebde82bde9ULL);
-	RNDr(S, W, 62, 0xbef9a3f7b2c67915ULL);
-	RNDr(S, W, 63, 0xc67178f2e372532bULL);
-	RNDr(S, W, 64, 0xca273eceea26619cULL);
-	RNDr(S, W, 65, 0xd186b8c721c0c207ULL);
-	RNDr(S, W, 66, 0xeada7dd6cde0eb1eULL);
-	RNDr(S, W, 67, 0xf57d4f7fee6ed178ULL);
-	RNDr(S, W, 68, 0x06f067aa72176fbaULL);
-	RNDr(S, W, 69, 0x0a637dc5a2c898a6ULL);
-	RNDr(S, W, 70, 0x113f9804bef90daeULL);
-	RNDr(S, W, 71, 0x1b710b35131c471bULL);
-	RNDr(S, W, 72, 0x28db77f523047d84ULL);
-	RNDr(S, W, 73, 0x32caab7b40c72493ULL);
-	RNDr(S, W, 74, 0x3c9ebe0a15c9bebcULL);
-	RNDr(S, W, 75, 0x431d67c49c100d4cULL);
-	RNDr(S, W, 76, 0x4cc5d4becb3e42b6ULL);
-	RNDr(S, W, 77, 0x597f299cfc657e2aULL);
-	RNDr(S, W, 78, 0x5fcb6fab3ad6faecULL);
-	RNDr(S, W, 79, 0x6c44198c4a475817ULL);
-
-	/* 4. Mix local working variables into global state */
-	for (i = 0; i < 8; i++)
-		state[i] += S[i];
-}
-
-static unsigned char PAD[128] = {
-	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* Add padding and terminating bit-count. */
-static void
-SHA512_Pad(SHA512_CTX * ctx)
-{
-	unsigned char len[16];
-	uint64_t r, plen;
-
-	/*
-	 * Convert length to a vector of bytes -- we do this now rather
-	 * than later because the length will change after we pad.
-	 */
-	be64enc_vect(len, ctx->count, 16);
-
-	/* Add 1--128 bytes so that the resulting length is 112 mod 128 */
-	r = (ctx->count[1] >> 3) & 0x7f;
-	plen = (r < 112) ? (112 - r) : (240 - r);
-	SHA512_Update(ctx, PAD, (size_t)plen);
-
-	/* Add the terminating bit-count */
-	SHA512_Update(ctx, len, 16);
-}
-
-/* SHA-512 initialization.  Begins a SHA-512 operation. */
-void
-SHA512_Init(SHA512_CTX * ctx)
-{
-
-	/* Zero bits processed so far */
-	ctx->count[0] = ctx->count[1] = 0;
-
-	/* Magic initialization constants */
-	ctx->state[0] = 0x6a09e667f3bcc908ULL;
-	ctx->state[1] = 0xbb67ae8584caa73bULL;
-	ctx->state[2] = 0x3c6ef372fe94f82bULL;
-	ctx->state[3] = 0xa54ff53a5f1d36f1ULL;
-	ctx->state[4] = 0x510e527fade682d1ULL;
-	ctx->state[5] = 0x9b05688c2b3e6c1fULL;
-	ctx->state[6] = 0x1f83d9abfb41bd6bULL;
-	ctx->state[7] = 0x5be0cd19137e2179ULL;
-}
-
-/* Add bytes into the hash */
-void
-SHA512_Update(SHA512_CTX * ctx, const void *in, size_t len)
-{
-	uint64_t bitlen[2];
-	uint64_t r;
-	const unsigned char *src = in;
-
-	/* Number of bytes left in the buffer from previous updates */
-	r = (ctx->count[1] >> 3) & 0x7f;
-
-	/* Convert the length into a number of bits */
-	bitlen[1] = ((uint64_t)len) << 3;
-	bitlen[0] = ((uint64_t)len) >> 61;
-
-	/* Update number of bits */
-	if ((ctx->count[1] += bitlen[1]) < bitlen[1])
-		ctx->count[0]++;
-	ctx->count[0] += bitlen[0];
-
-	/* Handle the case where we don't need to perform any transforms */
-	if (len < 128 - r) {
-		memcpy(&ctx->buf[r], src, len);
-		return;
-	}
-
-	/* Finish the current block */
-	memcpy(&ctx->buf[r], src, 128 - r);
-	SHA512_Transform(ctx->state, ctx->buf);
-	src += 128 - r;
-	len -= 128 - r;
-
-	/* Perform complete blocks */
-	while (len >= 128) {
-		SHA512_Transform(ctx->state, src);
-		src += 128;
-		len -= 128;
-	}
-
-	/* Copy left over data into buffer */
-	memcpy(ctx->buf, src, len);
-}
-
-/*
- * SHA-512 finalization.  Pads the input data, exports the hash value,
- * and clears the context state.
- */
-void
-SHA512_Final(unsigned char digest[64], SHA512_CTX * ctx)
-{
-
-	/* Add padding */
-	SHA512_Pad(ctx);
-
-	/* Write the hash */
-	be64enc_vect(digest, ctx->state, 64);
-
-	/* Clear the context state */
-	memset((void *)ctx, 0, sizeof(*ctx));
-}

Modified: trunk/lib/libmd/sha_locl.h
===================================================================
--- trunk/lib/libmd/sha_locl.h	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/sha_locl.h	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* crypto/sha/sha_locl.h */
 /* Copyright (C) 1995-1998 Eric Young (eay at cryptsoft.com)
  * All rights reserved.

Modified: trunk/lib/libmd/shadriver.c
===================================================================
--- trunk/lib/libmd/shadriver.c	2018-06-09 19:30:02 UTC (rev 10663)
+++ trunk/lib/libmd/shadriver.c	2018-06-09 19:31:21 UTC (rev 10664)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* SHADRIVER.C - test driver for SHA-1 (and SHA-2) */
 
 /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
@@ -12,7 +13,7 @@
  * documentation and/or software. */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libmd/shadriver.c 314332 2017-02-27 10:40:39Z avg $");
 
 #include <sys/types.h>
 
@@ -22,7 +23,9 @@
 
 #include "sha.h"
 #include "sha256.h"
+#include "sha384.h"
 #include "sha512.h"
+#include "sha512t.h"
 
 /* The following makes SHA default to SHA-1 if it has not already been
  * defined with C compiler flags. */
@@ -31,11 +34,20 @@
 #endif
 
 #if SHA == 1
+#undef SHA_Data
 #define SHA_Data SHA1_Data
 #elif SHA == 256
+#undef SHA_Data
 #define SHA_Data SHA256_Data
+#elif SHA == 384
+#undef SHA_Data
+#define SHA_Data SHA384_Data
 #elif SHA == 512
+#undef SHA_Data
 #define SHA_Data SHA512_Data
+#elif SHA == 512256
+#undef SHA_Data
+#define SHA_Data SHA512_256_Data
 #endif
 
 /* Digests a string and prints the result. */



More information about the Midnightbsd-cvs mailing list