; Fix documentation of secure-hash functions
authorEli Zaretskii <eliz@gnu.org>
Mon, 19 Aug 2024 14:51:50 +0000 (17:51 +0300)
committerEli Zaretskii <eliz@gnu.org>
Mon, 19 Aug 2024 14:51:50 +0000 (17:51 +0300)
* src/fns.c (Fsecure_hash):
* doc/lispref/text.texi (Checksum/Hash):
* lisp/subr.el (sha1): Fix documentation wrt to the number of
bytes 'secure-hash' and its variants return when BINARY is
non-nil.  Reported by Pip Cet <pipcet@protonmail.com>.

doc/lispref/text.texi
lisp/subr.el
src/fns.c

index 196fe89a09206f042391d082fbf8881a938b9c96..278b53d7f65aef0a6441eed57323a8f1f163621c 100644 (file)
@@ -4992,22 +4992,22 @@ of the returned string depends on @var{algorithm}:
 
 @itemize
 @item
-For @code{md5}: 32 characters (32 bytes if @var{binary} is
+For @code{md5}: 32 characters (16 bytes if @var{binary} is
 non-@code{nil}).
 @item
-For @code{sha1}: 40 characters (40 bytes if @var{binary} is
+For @code{sha1}: 40 characters (20 bytes if @var{binary} is
 non-@code{nil}).
 @item
-For @code{sha224}: 56 characters (56 bytes if @var{binary} is
+For @code{sha224}: 56 characters (28 bytes if @var{binary} is
 non-@code{nil}).
 @item
-For @code{sha256}: 64 characters (64 bytes if @var{binary} is
+For @code{sha256}: 64 characters (32 bytes if @var{binary} is
 non-@code{nil}).
 @item
-For @code{sha384}: 96 characters (96 bytes if @var{binary} is
+For @code{sha384}: 96 characters (48 bytes if @var{binary} is
 non-@code{nil}).
 @item
-For @code{sha512}: 128 characters (128 bytes if @var{binary} is
+For @code{sha512}: 128 characters (64 bytes if @var{binary} is
 non-@code{nil}).
 @end itemize
 
@@ -5062,7 +5062,7 @@ This function is equivalent to calling @code{secure-hash} like this:
 @end lisp
 
 It returns a 40-character string if @var{binary} is @code{nil}, or a
-40-byte unibyte string otherwise.
+20-byte unibyte string otherwise.
 @end defun
 
 @node Suspicious Text
index a8e3df14cd310b1e0dbded1067bdfccf54ec43a5..28ba30f584e7754fc41dec7286dfcef1065a672e 100644 (file)
@@ -4481,7 +4481,7 @@ Otherwise, return nil."
   "Return the SHA-1 (Secure Hash Algorithm) of an OBJECT.
 OBJECT is either a string or a buffer.  Optional arguments START and
 END are character positions specifying which portion of OBJECT for
-computing the hash.  If BINARY is non-nil, return a 40-byte unibyte
+computing the hash.  If BINARY is non-nil, return a 20-byte unibyte
 string; otherwise return a 40-character string.
 
 Note that SHA-1 is not collision resistant and should not be used
index cb3e25811ea52f55c86c2059a506966a8fe53c75..6133c20573aceabbd79fccfabe2655d806944487 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -6402,7 +6402,9 @@ whole OBJECT.
 
 The full list of algorithms can be obtained with `secure-hash-algorithms'.
 
-If BINARY is non-nil, returns a string in binary form.
+If BINARY is non-nil, returns a string in binary form.  In this case,
+the function returns a unibyte string whose length is half the number
+of characters it returns when BINARY is nil.
 
 Note that MD5 and SHA-1 are not collision resistant and should not be
 used for anything security-related.  For these applications, use one