diff options
| author | Collin Funk | 2026-02-23 00:20:46 -0800 |
|---|---|---|
| committer | Paul Eggert | 2026-02-23 00:22:17 -0800 |
| commit | 29440eedac7968580e35e751c6cdf94af337a95a (patch) | |
| tree | 511fa2df3d1459c9e3d53d088856194d2123af38 /src | |
| parent | ccaa4a07f093428241cbcc81379c3ea3d84b38ee (diff) | |
| download | emacs-29440eedac7968580e35e751c6cdf94af337a95a.tar.gz emacs-29440eedac7968580e35e751c6cdf94af337a95a.zip | |
Add SHA-3 support to secure-hash
* admin/merge-gnulib (GNULIB_MODULES): Add crypto/sha3-buffer.
* lib/sha3.c: New file, imported by running admin/merge-gnulib.
* lib/sha3.h: Likewise.
* m4/sha3.m4: Likewise.
* lib/gnulib.mk.in: Updated by admin/merge-gnulib.
* m4/gnulib-comp.m4: Likewise.
* src/fns.c: Include sha3.h
(Fsecure_hash_algorithms): Add Qsha3_224, Qsha3_256, Qsha3_384, and
Qsha3_512.
(secure_hash): Likewise.
(Fsecure_hash): List the SHA-3 algorithms in the docstring.
(syms_of_fns): Define Qsha3_224, Qsha3_256, Qsha3_384, and Qsha3_512.
* test/lisp/net/gnutls-tests.el (gnutls-tests-internal-macs-upcased):
Filter out the new SHA-3 algorithms since they are currently not
implemented in gnutls.
* test/src/fns-tests.el (test-secure-hash): Add test cases for the new
algorithms.
* doc/lispref/text.texi (Checksum/Hash): List the SHA-3 algorithms.
Mention that they are considered secure.
* etc/NEWS: Mention the new feature.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 58 |
1 files changed, 44 insertions, 14 deletions
| @@ -6014,13 +6014,14 @@ DEFUN ("internal--hash-table-index-size", | |||
| 6014 | 6014 | ||
| 6015 | 6015 | ||
| 6016 | /************************************************************************ | 6016 | /************************************************************************ |
| 6017 | MD5, SHA-1, and SHA-2 | 6017 | MD5, SHA-1, SHA-2, and SHA-3 |
| 6018 | ************************************************************************/ | 6018 | ************************************************************************/ |
| 6019 | 6019 | ||
| 6020 | #include "md5.h" | 6020 | #include "md5.h" |
| 6021 | #include "sha1.h" | 6021 | #include "sha1.h" |
| 6022 | #include "sha256.h" | 6022 | #include "sha256.h" |
| 6023 | #include "sha512.h" | 6023 | #include "sha512.h" |
| 6024 | #include "sha3.h" | ||
| 6024 | 6025 | ||
| 6025 | /* Store into HEXBUF an unterminated hexadecimal character string | 6026 | /* Store into HEXBUF an unterminated hexadecimal character string |
| 6026 | representing DIGEST, which is binary data of size DIGEST_SIZE bytes. | 6027 | representing DIGEST, which is binary data of size DIGEST_SIZE bytes. |
| @@ -6051,7 +6052,8 @@ DEFUN ("secure-hash-algorithms", Fsecure_hash_algorithms, | |||
| 6051 | doc: /* Return a list of all the supported `secure-hash' algorithms. */) | 6052 | doc: /* Return a list of all the supported `secure-hash' algorithms. */) |
| 6052 | (void) | 6053 | (void) |
| 6053 | { | 6054 | { |
| 6054 | return list (Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512); | 6055 | return list (Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512, |
| 6056 | Qsha3_224, Qsha3_256, Qsha3_384, Qsha3_512); | ||
| 6055 | } | 6057 | } |
| 6056 | 6058 | ||
| 6057 | /* Extract data from a string or a buffer. SPEC is a list of | 6059 | /* Extract data from a string or a buffer. SPEC is a list of |
| @@ -6290,6 +6292,26 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, | |||
| 6290 | digest_size = SHA512_DIGEST_SIZE; | 6292 | digest_size = SHA512_DIGEST_SIZE; |
| 6291 | hash_func = sha512_buffer; | 6293 | hash_func = sha512_buffer; |
| 6292 | } | 6294 | } |
| 6295 | else if (EQ (algorithm, Qsha3_224)) | ||
| 6296 | { | ||
| 6297 | digest_size = SHA3_224_DIGEST_SIZE; | ||
| 6298 | hash_func = sha3_224_buffer; | ||
| 6299 | } | ||
| 6300 | else if (EQ (algorithm, Qsha3_256)) | ||
| 6301 | { | ||
| 6302 | digest_size = SHA3_256_DIGEST_SIZE; | ||
| 6303 | hash_func = sha3_256_buffer; | ||
| 6304 | } | ||
| 6305 | else if (EQ (algorithm, Qsha3_384)) | ||
| 6306 | { | ||
| 6307 | digest_size = SHA3_384_DIGEST_SIZE; | ||
| 6308 | hash_func = sha3_384_buffer; | ||
| 6309 | } | ||
| 6310 | else if (EQ (algorithm, Qsha3_512)) | ||
| 6311 | { | ||
| 6312 | digest_size = SHA3_512_DIGEST_SIZE; | ||
| 6313 | hash_func = sha3_512_buffer; | ||
| 6314 | } | ||
| 6293 | else | 6315 | else |
| 6294 | error ("Invalid algorithm arg: %s", SDATA (Fsymbol_name (algorithm))); | 6316 | error ("Invalid algorithm arg: %s", SDATA (Fsymbol_name (algorithm))); |
| 6295 | 6317 | ||
| @@ -6351,12 +6373,16 @@ anything security-related. See `secure-hash' for alternatives. */) | |||
| 6351 | DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0, | 6373 | DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0, |
| 6352 | doc: /* Return the secure hash of OBJECT, a buffer or string. | 6374 | doc: /* Return the secure hash of OBJECT, a buffer or string. |
| 6353 | ALGORITHM is a symbol specifying the hash to use: | 6375 | ALGORITHM is a symbol specifying the hash to use: |
| 6354 | - md5 corresponds to MD5, produces a 32-character signature | 6376 | - md5 corresponds to MD5, produces a 32-character signature |
| 6355 | - sha1 corresponds to SHA-1, produces a 40-character signature | 6377 | - sha1 corresponds to SHA-1, produces a 40-character signature |
| 6356 | - sha224 corresponds to SHA-2 (SHA-224), produces a 56-character signature | 6378 | - sha224 corresponds to SHA-2 (SHA-224), produces a 56-character signature |
| 6357 | - sha256 corresponds to SHA-2 (SHA-256), produces a 64-character signature | 6379 | - sha256 corresponds to SHA-2 (SHA-256), produces a 64-character signature |
| 6358 | - sha384 corresponds to SHA-2 (SHA-384), produces a 96-character signature | 6380 | - sha384 corresponds to SHA-2 (SHA-384), produces a 96-character signature |
| 6359 | - sha512 corresponds to SHA-2 (SHA-512), produces a 128-character signature | 6381 | - sha512 corresponds to SHA-2 (SHA-512), produces a 128-character signature |
| 6382 | - sha3-224 corresponds to SHA-3 (SHA3-224), produces a 56-character signature | ||
| 6383 | - sha3-256 corresponds to SHA-3 (SHA3-256), produces a 64-character signature | ||
| 6384 | - sha3-384 corresponds to SHA-3 (SHA3-384), produces a 96-character signature | ||
| 6385 | - sha3-512 corresponds to SHA-3 (SHA3-512), produces a 128-character signature | ||
| 6360 | 6386 | ||
| 6361 | The two optional arguments START and END are positions specifying for | 6387 | The two optional arguments START and END are positions specifying for |
| 6362 | which part of OBJECT to compute the hash. If nil or omitted, uses the | 6388 | which part of OBJECT to compute the hash. If nil or omitted, uses the |
| @@ -6718,12 +6744,16 @@ syms_of_fns (void) | |||
| 6718 | /* Crypto and hashing stuff. */ | 6744 | /* Crypto and hashing stuff. */ |
| 6719 | DEFSYM (Qiv_auto, "iv-auto"); | 6745 | DEFSYM (Qiv_auto, "iv-auto"); |
| 6720 | 6746 | ||
| 6721 | DEFSYM (Qmd5, "md5"); | 6747 | DEFSYM (Qmd5, "md5"); |
| 6722 | DEFSYM (Qsha1, "sha1"); | 6748 | DEFSYM (Qsha1, "sha1"); |
| 6723 | DEFSYM (Qsha224, "sha224"); | 6749 | DEFSYM (Qsha224, "sha224"); |
| 6724 | DEFSYM (Qsha256, "sha256"); | 6750 | DEFSYM (Qsha256, "sha256"); |
| 6725 | DEFSYM (Qsha384, "sha384"); | 6751 | DEFSYM (Qsha384, "sha384"); |
| 6726 | DEFSYM (Qsha512, "sha512"); | 6752 | DEFSYM (Qsha512, "sha512"); |
| 6753 | DEFSYM (Qsha3_224, "sha3-224"); | ||
| 6754 | DEFSYM (Qsha3_256, "sha3-256"); | ||
| 6755 | DEFSYM (Qsha3_384, "sha3-384"); | ||
| 6756 | DEFSYM (Qsha3_512, "sha3-512"); | ||
| 6727 | 6757 | ||
| 6728 | /* Miscellaneous stuff. */ | 6758 | /* Miscellaneous stuff. */ |
| 6729 | 6759 | ||