; Fix documentation of secure-hash functions

* 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>.
This commit is contained in:
Eli Zaretskii 2024-08-19 17:51:50 +03:00
parent 21be5cadaf
commit fc7581ae2e
3 changed files with 11 additions and 9 deletions

View file

@ -4992,22 +4992,22 @@ of the returned string depends on @var{algorithm}:
@itemize @itemize
@item @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}). non-@code{nil}).
@item @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}). non-@code{nil}).
@item @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}). non-@code{nil}).
@item @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}). non-@code{nil}).
@item @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}). non-@code{nil}).
@item @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}). non-@code{nil}).
@end itemize @end itemize
@ -5062,7 +5062,7 @@ This function is equivalent to calling @code{secure-hash} like this:
@end lisp @end lisp
It returns a 40-character string if @var{binary} is @code{nil}, or a 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 @end defun
@node Suspicious Text @node Suspicious Text

View file

@ -4481,7 +4481,7 @@ Otherwise, return nil."
"Return the SHA-1 (Secure Hash Algorithm) of an OBJECT. "Return the SHA-1 (Secure Hash Algorithm) of an OBJECT.
OBJECT is either a string or a buffer. Optional arguments START and OBJECT is either a string or a buffer. Optional arguments START and
END are character positions specifying which portion of OBJECT for 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. string; otherwise return a 40-character string.
Note that SHA-1 is not collision resistant and should not be used Note that SHA-1 is not collision resistant and should not be used

View file

@ -6402,7 +6402,9 @@ whole OBJECT.
The full list of algorithms can be obtained with `secure-hash-algorithms'. 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 Note that MD5 and SHA-1 are not collision resistant and should not be
used for anything security-related. For these applications, use one used for anything security-related. For these applications, use one