1SHLIBDIR?= /lib 2 3.include <src.opts.mk> 4.include <bsd.compiler.mk> 5 6PACKAGE= runtime 7LIB= md 8SHLIB_MAJOR= 7 9SRCS= md4c.c md5c.c md4hl.c md5hl.c \ 10 rmd160c.c rmd160hl.c \ 11 sha0c.c sha0hl.c sha1c.c sha1hl.c \ 12 sha224hl.c sha256c.c sha256hl.c \ 13 sha384hl.c \ 14 sha512c.c sha512hl.c sha512t224hl.c sha512t256hl.c \ 15 skein.c skein_block.c \ 16 skein256hl.c skein512hl.c skein1024hl.c 17INCS= md4.h md5.h ripemd.h sha.h sha224.h sha256.h sha384.h sha512.h \ 18 sha512t.h skein.h skein_port.h skein_freebsd.h skein_iv.h 19 20WARNS?= 0 21 22VERSION_DEF= ${SRCTOP}/lib/libc/Versions.def 23SYMBOL_MAPS= ${.CURDIR}/Symbol.map 24 25MAN+= md4.3 md5.3 ripemd.3 sha.3 sha256.3 sha512.3 skein.3 26MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3 27MLINKS+=md4.3 MD4End.3 md4.3 MD4File.3 md4.3 MD4FileChunk.3 28MLINKS+=md4.3 MD4Data.3 29MLINKS+=md5.3 MD5Init.3 md5.3 MD5Update.3 md5.3 MD5Final.3 30MLINKS+=md5.3 MD5End.3 md5.3 MD5File.3 md5.3 MD5FileChunk.3 31MLINKS+=md5.3 MD5Data.3 32MLINKS+=ripemd.3 RIPEMD160_Init.3 ripemd.3 RIPEMD160_Update.3 33MLINKS+=ripemd.3 RIPEMD160_Final.3 ripemd.3 RIPEMD160_Data.3 34MLINKS+=ripemd.3 RIPEMD160_End.3 ripemd.3 RIPEMD160_File.3 35MLINKS+=ripemd.3 RIPEMD160_FileChunk.3 36MLINKS+=sha.3 SHA_Init.3 sha.3 SHA_Update.3 sha.3 SHA_Final.3 37MLINKS+=sha.3 SHA_End.3 sha.3 SHA_File.3 sha.3 SHA_FileChunk.3 38MLINKS+=sha.3 SHA_Data.3 39MLINKS+=sha.3 SHA1_Init.3 sha.3 SHA1_Update.3 sha.3 SHA1_Final.3 40MLINKS+=sha.3 SHA1_End.3 sha.3 SHA1_File.3 sha.3 SHA1_FileChunk.3 41MLINKS+=sha.3 SHA1_Data.3 42MLINKS+=sha256.3 SHA224_Init.3 sha256.3 SHA224_Update.3 43MLINKS+=sha256.3 SHA224_Final.3 sha256.3 SHA224_End.3 44MLINKS+=sha256.3 SHA224_File.3 sha256.3 SHA224_FileChunk.3 45MLINKS+=sha256.3 SHA224_Data.3 46MLINKS+=sha256.3 SHA256_Init.3 sha256.3 SHA256_Update.3 47MLINKS+=sha256.3 SHA256_Final.3 sha256.3 SHA256_End.3 48MLINKS+=sha256.3 SHA256_File.3 sha256.3 SHA256_FileChunk.3 49MLINKS+=sha256.3 SHA256_Data.3 50MLINKS+=sha512.3 SHA384_Init.3 sha512.3 SHA384_Update.3 51MLINKS+=sha512.3 SHA384_Final.3 sha512.3 SHA384_End.3 52MLINKS+=sha512.3 SHA384_File.3 sha512.3 SHA384_FileChunk.3 53MLINKS+=sha512.3 SHA384_Data.3 sha512.3 sha384.3 54MLINKS+=sha512.3 SHA512_Init.3 sha512.3 SHA512_Update.3 55MLINKS+=sha512.3 SHA512_Final.3 sha512.3 SHA512_End.3 56MLINKS+=sha512.3 SHA512_File.3 sha512.3 SHA512_FileChunk.3 57MLINKS+=sha512.3 SHA512_Data.3 58MLINKS+=sha512.3 SHA512_224_Init.3 sha512.3 SHA512_224_Update.3 59MLINKS+=sha512.3 SHA512_224_Final.3 sha512.3 SHA512_224_End.3 60MLINKS+=sha512.3 SHA512_224_File.3 sha512.3 SHA512_224_FileChunk.3 61MLINKS+=sha512.3 SHA512_224_Data.3 62MLINKS+=sha512.3 SHA512_256_Init.3 sha512.3 SHA512_256_Update.3 63MLINKS+=sha512.3 SHA512_256_Final.3 sha512.3 SHA512_256_End.3 64MLINKS+=sha512.3 SHA512_256_File.3 sha512.3 SHA512_256_FileChunk.3 65MLINKS+=sha512.3 SHA512_256_Data.3 66MLINKS+=skein.3 SKEIN256_Init.3 skein.3 SKEIN256_Update.3 67MLINKS+=skein.3 SKEIN256_Final.3 skein.3 SKEIN256_End.3 68MLINKS+=skein.3 SKEIN256_File.3 skein.3 SKEIN256_FileChunk.3 69MLINKS+=skein.3 SKEIN256_Data.3 skein.3 skein256.3 70MLINKS+=skein.3 SKEIN512_Init.3 skein.3 SKEIN512_Update.3 71MLINKS+=skein.3 SKEIN512_Final.3 skein.3 SKEIN512_End.3 72MLINKS+=skein.3 SKEIN512_File.3 skein.3 SKEIN512_FileChunk.3 73MLINKS+=skein.3 SKEIN512_Data.3 skein.3 skein512.3 74MLINKS+=skein.3 SKEIN1024_Init.3 skein.3 SKEIN1024_Update.3 75MLINKS+=skein.3 SKEIN1024_Final.3 skein.3 SKEIN1024_End.3 76MLINKS+=skein.3 SKEIN1024_File.3 skein.3 SKEIN1024_FileChunk.3 77MLINKS+=skein.3 SKEIN1024_Data.3 skein.3 skein1024.3 78 79CLEANFILES+= md[245]hl.c md[245].ref md[245].3 mddriver \ 80 rmd160.ref rmd160hl.c rmddriver \ 81 sha0.ref sha0hl.c sha1.ref sha1hl.c shadriver \ 82 sha224.ref sha256.ref sha224hl.c sha256hl.c \ 83 sha384hl.c sha384.ref \ 84 sha512.ref sha512hl.c \ 85 sha512t224.ref sha512t224hl.c \ 86 sha512t256.ref sha512t256hl.c \ 87 skein256hl.c skein512hl.c skein1024hl.c \ 88 skein256.ref skein512.ref skein1024.ref \ 89 skeindriver 90 91# Need src tree sys/md5.h for MD5FileChunk prototype on older systems. 92SRCS+= sys/md5.h 93CLEANDIRS= sys 94CFLAGS+= -I. 95sys/md5.h: ${SRCTOP}/sys/${.TARGET} .NOMETA 96 ln -sf ${.ALLSRC} ${.TARGET} 97 98# Define WEAK_REFS to provide weak aliases for libmd symbols 99# 100# Note that the same sources are also used internally by libcrypt, 101# in which case: 102# * macros are used to rename symbols to libcrypt internal names 103# * no weak aliases are generated 104CFLAGS+= -I${.CURDIR} -I${SRCTOP}/sys/crypto/sha2 105CFLAGS+= -I${SRCTOP}/sys/crypto/skein 106CFLAGS+= -DWEAK_REFS 107# unroll the 256 and 512 loops, half unroll the 1024 108CFLAGS.skein_block.c+= -DSKEIN_LOOP=995 109.PATH: ${.CURDIR}/${MACHINE_ARCH} ${SRCTOP}/sys/crypto/sha2 110.PATH: ${SRCTOP}/sys/crypto/skein ${SRCTOP}/sys/crypto/skein/${MACHINE_ARCH} 111.PATH: ${SRCTOP}/sys/kern 112 113USE_ASM_SOURCES?=1 114.if defined(BOOTSTRAPPING) || ${MK_MACHDEP_OPTIMIZATIONS} == no 115# Don't build ASM sources when bootstrapping to avoid toolchain dependencies 116USE_ASM_SOURCES:=0 117.endif 118 119.if ${USE_ASM_SOURCES} != 0 120.if exists(${MACHINE_ARCH}/sha.S) 121SRCS+= sha.S 122CFLAGS+= -DSHA1_ASM 123.endif 124.if exists(${MACHINE_ARCH}/rmd160.S) 125SRCS+= rmd160.S 126CFLAGS+= -DRMD160_ASM 127.endif 128.if exists(${MACHINE_ARCH}/skein_block_asm.S) 129# Fully unroll all loops in the assembly optimized version 130ACFLAGS+= -DSKEIN_LOOP=0 131SRCS+= skein_block_asm.S 132CFLAGS+= -DSKEIN_ASM -DSKEIN_USE_ASM=1792 # list of block functions to replace with assembly: 256+512+1024 = 1792 133# 20201002 Add explict Makefile dependency for r366344 (reenabled assembly 134# optimized version). SKEIN_USE_ASM determines which routines should come from 135# the assembly vs C versions, and skein_block needs to be rebuilt if it changes. 136skein_block.o skein_block.pico: Makefile 137.endif 138.if exists(${MACHINE_ARCH}/sha.S) || exists(${MACHINE_ARCH}/rmd160.S) || exists(${MACHINE_ARCH}/skein_block_asm.S) 139ACFLAGS+= -DELF -Wa,--noexecstack 140.endif 141.if ${MACHINE_CPUARCH} == "aarch64" 142SRCS+= sha256c_arm64.c 143CFLAGS+= -DARM64_SHA2 144CFLAGS.sha256c_arm64.c+= -march=armv8-a+crypto 145.if ${COMPILER_FEATURES:Maarch64-sha512} 146SRCS+= sha512c_arm64.c 147CFLAGS+= -DARM64_SHA512 148CFLAGS.sha512c_arm64.c+= -march=armv8.2-a+sha3 149.endif # aarch64-sha512 150.endif 151.endif # ${USE_ASM_SOURCES} != 0 152 153md4hl.c: mdXhl.c 154 (echo '#define LENGTH 16'; \ 155 sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' ${.ALLSRC}) > ${.TARGET} 156 157md5hl.c: mdXhl.c 158 (echo '#define LENGTH 16'; \ 159 sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' ${.ALLSRC}) > ${.TARGET} 160 161sha0hl.c: mdXhl.c 162 (echo '#define LENGTH 20'; \ 163 sed -e 's/mdX/sha/g' -e 's/MDX/SHA_/g' -e 's/SHA__/SHA_/g' \ 164 ${.ALLSRC}) > ${.TARGET} 165 166sha1hl.c: mdXhl.c 167 (echo '#define LENGTH 20'; \ 168 sed -e 's/mdX/sha/g' -e 's/MDX/SHA1_/g' -e 's/SHA1__/SHA1_/g' \ 169 ${.ALLSRC}) > ${.TARGET} 170 171sha224hl.c: mdXhl.c 172 (echo '#define LENGTH 28'; \ 173 sed -e 's/mdX/sha224/g' -e 's/MDX/SHA224_/g' \ 174 -e 's/SHA224__/SHA224_/g' \ 175 ${.ALLSRC}) > ${.TARGET} 176 177sha256hl.c: mdXhl.c 178 (echo '#define LENGTH 32'; \ 179 sed -e 's/mdX/sha256/g' -e 's/MDX/SHA256_/g' \ 180 -e 's/SHA256__/SHA256_/g' \ 181 ${.ALLSRC}) > ${.TARGET} 182 183sha384hl.c: mdXhl.c 184 (echo '#define LENGTH 48'; \ 185 sed -e 's/mdX/sha384/g' -e 's/MDX/SHA384_/g' \ 186 -e 's/SHA384__/SHA384_/g' \ 187 ${.ALLSRC}) > ${.TARGET} 188 189sha512hl.c: mdXhl.c 190 (echo '#define LENGTH 64'; \ 191 sed -e 's/mdX/sha512/g' -e 's/MDX/SHA512_/g' \ 192 -e 's/SHA512__/SHA512_/g' \ 193 ${.ALLSRC}) > ${.TARGET} 194 195sha512t224hl.c: mdXhl.c 196 (echo '#define LENGTH 28'; \ 197 sed -e 's/mdX/sha512t/g' -e 's/MDX/SHA512_224_/g' \ 198 -e 's/SHA512_224__/SHA512_224_/g' \ 199 -e 's/SHA512_224_CTX/SHA512_CTX/g' \ 200 ${.ALLSRC}) > ${.TARGET} 201 202sha512t256hl.c: mdXhl.c 203 (echo '#define LENGTH 32'; \ 204 sed -e 's/mdX/sha512t/g' -e 's/MDX/SHA512_256_/g' \ 205 -e 's/SHA512_256__/SHA512_256_/g' \ 206 -e 's/SHA512_256_CTX/SHA512_CTX/g' \ 207 ${.ALLSRC}) > ${.TARGET} 208 209rmd160hl.c: mdXhl.c 210 (echo '#define LENGTH 20'; \ 211 sed -e 's/mdX/ripemd/g' -e 's/MDX/RIPEMD160_/g' \ 212 -e 's/RIPEMD160__/RIPEMD160_/g' \ 213 ${.ALLSRC}) > ${.TARGET} 214 215skein256hl.c: mdXhl.c 216 (echo '#define LENGTH 32'; \ 217 sed -e 's/mdX/skein/g' -e 's/MDX/SKEIN256_/g' \ 218 -e 's/SKEIN256__/SKEIN256_/g' \ 219 ${.ALLSRC}) > ${.TARGET} 220 221skein512hl.c: mdXhl.c 222 (echo '#define LENGTH 64'; \ 223 sed -e 's/mdX/skein/g' -e 's/MDX/SKEIN512_/g' \ 224 -e 's/SKEIN512__/SKEIN512_/g' \ 225 ${.ALLSRC}) > ${.TARGET} 226 227skein1024hl.c: mdXhl.c 228 (echo '#define LENGTH 128'; \ 229 sed -e 's/mdX/skein/g' -e 's/MDX/SKEIN1024_/g' \ 230 -e 's/SKEIN1024__/SKEIN1024_/g' \ 231 ${.ALLSRC}) > ${.TARGET} 232 233 234.for i in 2 4 5 235md${i}.3: ${.CURDIR}/mdX.3 236 sed -e "s/mdX/md${i}/g" -e "s/MDX/MD${i}/g" ${.ALLSRC} > ${.TARGET} 237 cat ${.CURDIR}/md${i}.copyright >> ${.TARGET} 238.endfor 239 240HAS_TESTS= 241SUBDIR.${MK_TESTS}+= tests 242 243.include <bsd.lib.mk> 244