Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F154562323
D38373.id116395.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D38373.id116395.diff
View Options
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -13,7 +13,7 @@
sha0c.c sha0hl.c sha1c.c sha1hl.c \
sha224hl.c sha256c.c sha256hl.c \
sha384hl.c \
- sha512c.c sha512hl.c sha512thl.c \
+ sha512c.c sha512hl.c sha512t224hl.c sha512t256hl.c \
skein.c skein_block.c \
skein256hl.c skein512hl.c skein1024hl.c
INCS= md4.h md5.h ripemd.h sha.h sha224.h sha256.h sha384.h sha512.h \
@@ -54,6 +54,10 @@
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_224_Init.3 sha512.3 SHA512_224_Update.3
+MLINKS+=sha512.3 SHA512_224_Final.3 sha512.3 SHA512_224_End.3
+MLINKS+=sha512.3 SHA512_224_File.3 sha512.3 SHA512_224_FileChunk.3
+MLINKS+=sha512.3 SHA512_224_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
@@ -76,7 +80,9 @@
sha0.ref sha0hl.c sha1.ref sha1hl.c shadriver \
sha224.ref sha256.ref sha224hl.c sha256hl.c \
sha384hl.c sha384.ref \
- sha512.ref sha512hl.c sha512t256.ref sha512thl.c \
+ sha512.ref sha512hl.c \
+ sha512t224.ref sha512t224hl.c \
+ sha512t256.ref sha512t256hl.c \
skein256hl.c skein512hl.c skein1024hl.c \
skein256.ref skein512.ref skein1024.ref \
skeindriver
@@ -184,7 +190,14 @@
-e 's/SHA512__/SHA512_/g' \
${.ALLSRC}) > ${.TARGET}
-sha512thl.c: mdXhl.c
+sha512t224hl.c: mdXhl.c
+ (echo '#define LENGTH 28'; \
+ sed -e 's/mdX/sha512t/g' -e 's/MDX/SHA512_224_/g' \
+ -e 's/SHA512_224__/SHA512_224_/g' \
+ -e 's/SHA512_224_CTX/SHA512_CTX/g' \
+ ${.ALLSRC}) > ${.TARGET}
+
+sha512t256hl.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' \
@@ -328,6 +341,21 @@
@echo 'SHA-512 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
'72ec1ef1124a45b047e8b7c75a932195135bb61de24ec0d1914042246e0aec3a2354e093d76f3048b456764346900cb130d2a4fd5dd16abb5e30bcb850dee843' >> ${.TARGET}
+sha512t224.ref:
+ echo 'SHA-512224 test suite:' > ${.TARGET}
+ @echo 'SHA-512224 ("") =' \
+ '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4' >> ${.TARGET}
+ @echo 'SHA-512224 ("abc") =' \
+ '4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa' >> ${.TARGET}
+ @echo 'SHA-512224 ("message digest") =' \
+ 'ad1a4db188fe57064f4f24609d2a83cd0afb9b398eb2fcaeaae2c564' >> ${.TARGET}
+ @echo 'SHA-512224 ("abcdefghijklmnopqrstuvwxyz") =' \
+ 'ff83148aa07ec30655c1b40aff86141c0215fe2a54f767d3f38743d8' >> ${.TARGET}
+ @echo 'SHA-512224 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =' \
+ 'a8b4b9174b99ffc67d6f49be9981587b96441051e16e6dd036b140d3' >> ${.TARGET}
+ @echo 'SHA-512224 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
+ 'ae988faaa47e401a45f704d1272d99702458fea2ddc6582827556dd2' >> ${.TARGET}
+
sha512t256.ref:
echo 'SHA-512256 test suite:' > ${.TARGET}
@echo 'SHA-512256 ("") =' \
@@ -400,7 +428,7 @@
'cf21a613620e6c119eca31fdfaad449a8e02f95ca256c21d2a105f8e4157048f9fe1e897893ea18b64e0e37cb07d5ac947f27ba544caf7cbc1ad094e675aed77a366270f7eb7f46543bccfa61c526fd628408058ed00ed566ac35a9761d002e629c4fb0d430b2f4ad016fcc49c44d2981c4002da0eecc42144160e2eaea4855a' >> ${.TARGET}
test: md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha224.ref sha256.ref sha384.ref \
- sha512.ref sha512t256.ref skein256.ref skein512.ref skein1024.ref
+ sha512.ref sha512t224.ref sha512t256.ref skein256.ref skein512.ref skein1024.ref
@${ECHO} if any of these test fail, the code produces wrong results
@${ECHO} and should NOT be used.
${CC} ${CFLAGS} ${LDFLAGS} -DMD=4 -o mddriver ${.CURDIR}/mddriver.c libmd.a
@@ -432,6 +460,10 @@
${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=512224 -o shadriver ${.CURDIR}/shadriver.c libmd.a
+ ./shadriver | cmp sha512t224.ref -
+ @${ECHO} SHA-512t224 passed test
+ -rm -f shadriver
${CC} ${CFLAGS} ${LDFLAGS} -DSHA=512256 -o shadriver ${.CURDIR}/shadriver.c libmd.a
./shadriver | cmp sha512t256.ref -
@${ECHO} SHA-512t256 passed test
diff --git a/lib/libmd/sha512.3 b/lib/libmd/sha512.3
--- a/lib/libmd/sha512.3
+++ b/lib/libmd/sha512.3
@@ -9,7 +9,7 @@
.\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
.\" $FreeBSD$
.\"
-.Dd May 21, 2019
+.Dd February 3, 2023
.Dt SHA512 3
.Os
.Sh NAME
@@ -27,6 +27,13 @@
.Nm SHA384_File ,
.Nm SHA384_FileChunk ,
.Nm SHA384_Data ,
+.Nm SHA512_224_Init ,
+.Nm SHA512_224_Update ,
+.Nm SHA512_224_Final ,
+.Nm SHA512_224_End ,
+.Nm SHA512_224_File ,
+.Nm SHA512_224_FileChunk ,
+.Nm SHA512_224_Data
.Nm SHA512_256_Init ,
.Nm SHA512_256_Update ,
.Nm SHA512_256_Final ,
@@ -71,6 +78,20 @@
.Fn SHA384_Data "const unsigned char *data" "unsigned int len" "char *buf"
.In sha512t.h
.Ft void
+.Fn SHA512_224_Init "SHA512_CTX *context"
+.Ft void
+.Fn SHA512_224_Update "SHA512_CTX *context" "const unsigned char *data" "size_t len"
+.Ft void
+.Fn SHA512_224_Final "unsigned char digest[32]" "SHA512_CTX *context"
+.Ft "char *"
+.Fn SHA512_224_End "SHA512_CTX *context" "char *buf"
+.Ft "char *"
+.Fn SHA512_224_File "const char *filename" "char *buf"
+.Ft "char *"
+.Fn SHA512_224_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
+.Ft "char *"
+.Fn SHA512_224_Data "const unsigned char *data" "unsigned int len" "char *buf"
+.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"
@@ -167,13 +188,14 @@
argument is non-null it must point to at least 129 characters of buffer space.
.Pp
The
-.Li SHA384_
+.Li SHA384_ ,
+.Li SHA512_224 ,
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.
+truncated to 384, 224, and 256 bits respectively.
.Pp
.Fn SHA384_End
is a wrapper for
@@ -183,6 +205,14 @@
.Tn ASCII
string which represents the 384 bits in hexadecimal.
.Pp
+.Fn SHA512_224_End
+is a wrapper for
+.Fn SHA512_Final
+which converts the return value to a 57-character
+(including the terminating '\e0')
+.Tn ASCII
+string which represents the 224 bits in hexadecimal.
+.Pp
.Fn SHA512_256_End
is a wrapper for
.Fn SHA512_Final
diff --git a/lib/libmd/shadriver.c b/lib/libmd/shadriver.c
--- a/lib/libmd/shadriver.c
+++ b/lib/libmd/shadriver.c
@@ -51,6 +51,9 @@
#elif SHA == 512
#undef SHA_Data
#define SHA_Data SHA512_Data
+#elif SHA == 512224
+#undef SHA_Data
+#define SHA_Data SHA512_224_Data
#elif SHA == 512256
#undef SHA_Data
#define SHA_Data SHA512_256_Data
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 29, 10:21 PM (18 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32404017
Default Alt Text
D38373.id116395.diff (6 KB)
Attached To
Mode
D38373: libmd / md5: Add SHA-512/224.
Attached
Detach File
Event Timeline
Log In to Comment