]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
SHA512 : Change SHA512_Final() so that it handles 192 bits.
authorslontis <shane.lontis@oracle.com>
Fri, 17 Oct 2025 05:15:03 +0000 (16:15 +1100)
committerslontis <shane.lontis@oracle.com>
Tue, 17 Feb 2026 01:16:50 +0000 (12:16 +1100)
SLH-DSA uses SHA-512 truncated to n when (n = 24 or 32).

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28941)

crypto/sha/sha512.c

index 45b8e7c3321ff4807ecf5af27fec722cc9fcc891..09bf21771ae12ded79010e5721c25cf75aae5fe1 100644 (file)
@@ -196,6 +196,20 @@ int SHA512_Final(unsigned char *md, SHA512_CTX *c)
         return 0;
 
     switch (c->md_len) {
+    case SHA256_192_DIGEST_LENGTH:
+        for (n = 0; n < SHA256_192_DIGEST_LENGTH / 8; n++) {
+            SHA_LONG64 t = c->h[n];
+
+            *(md++) = (unsigned char)(t >> 56);
+            *(md++) = (unsigned char)(t >> 48);
+            *(md++) = (unsigned char)(t >> 40);
+            *(md++) = (unsigned char)(t >> 32);
+            *(md++) = (unsigned char)(t >> 24);
+            *(md++) = (unsigned char)(t >> 16);
+            *(md++) = (unsigned char)(t >> 8);
+            *(md++) = (unsigned char)(t);
+        }
+        break;
     /* Let compiler decide if it's appropriate to unroll... */
     case SHA224_DIGEST_LENGTH:
         for (n = 0; n < SHA224_DIGEST_LENGTH / 8; n++) {