diff options
| author | Paul Eggert | 2017-07-20 16:21:57 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-07-20 16:22:36 -0700 |
| commit | ffde1e9b9e9aa763e18f009e0d54345f509134db (patch) | |
| tree | 5ee0dfe4e9d9f75cd28f798f1e079ef7b0d8c5d7 | |
| parent | df26f09f0c62f678fccb7a64dfa7d24202883c2b (diff) | |
| download | emacs-ffde1e9b9e9aa763e18f009e0d54345f509134db.tar.gz emacs-ffde1e9b9e9aa763e18f009e0d54345f509134db.zip | |
Simplify recent gnutls.c changes
* src/gnutls.c (clear_storage) [HAVE_GNUTLS3_AEAD]: Remove.
All uses replaced by calls to explicit_bzero; that’s clear enough.
(gnutls_symmetric_aead) [HAVE_GNUTLS3_AEAD]: Simplify by
coalescing duplicate actions. There is no need to invoke
SAFE_FREE before calling ‘error’.
| -rw-r--r-- | src/gnutls.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/src/gnutls.c b/src/gnutls.c index 7c988408528..59694074e16 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -1891,26 +1891,6 @@ The alist key is the cipher name. */) | |||
| 1891 | return ciphers; | 1891 | return ciphers; |
| 1892 | } | 1892 | } |
| 1893 | 1893 | ||
| 1894 | #ifdef HAVE_GNUTLS3_AEAD | ||
| 1895 | |||
| 1896 | /* Zero out STORAGE (even if it will become inaccessible. It has | ||
| 1897 | STORAGE_LENGTH bytes. The goal is to improve security a bit, in | ||
| 1898 | case an Emacs module or some buggy part of Emacs attempts to | ||
| 1899 | inspect STORAGE later to retrieve a secret. | ||
| 1900 | |||
| 1901 | Calls to this function document when storage containing a secret is | ||
| 1902 | known to go out of scope. This function is not guaranteed to erase | ||
| 1903 | the secret, as copies of STORAGE may well be accessible elsewhere | ||
| 1904 | on the machine. */ | ||
| 1905 | |||
| 1906 | static void | ||
| 1907 | clear_storage (void *storage, ptrdiff_t storage_length) | ||
| 1908 | { | ||
| 1909 | explicit_bzero (storage, storage_length); | ||
| 1910 | } | ||
| 1911 | |||
| 1912 | #endif /* HAVE_GNUTLS3_AEAD */ | ||
| 1913 | |||
| 1914 | static Lisp_Object | 1894 | static Lisp_Object |
| 1915 | gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, | 1895 | gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, |
| 1916 | Lisp_Object cipher, | 1896 | Lisp_Object cipher, |
| @@ -1975,23 +1955,18 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca, | |||
| 1975 | (acipher, vdata, vsize, aead_auth_data, aead_auth_size, | 1955 | (acipher, vdata, vsize, aead_auth_data, aead_auth_size, |
| 1976 | cipher_tag_size, idata, isize, storage, &storage_length)); | 1956 | cipher_tag_size, idata, isize, storage, &storage_length)); |
| 1977 | 1957 | ||
| 1978 | if (ret < GNUTLS_E_SUCCESS) | 1958 | Lisp_Object output; |
| 1979 | { | 1959 | if (GNUTLS_E_SUCCESS <= ret) |
| 1980 | clear_storage (storage, storage_length); | 1960 | output = make_unibyte_string (storage, storage_length); |
| 1981 | SAFE_FREE (); | 1961 | explicit_bzero (storage, storage_length); |
| 1982 | gnutls_aead_cipher_deinit (acipher); | ||
| 1983 | if (encrypting) | ||
| 1984 | error ("GnuTLS AEAD cipher %s encryption failed: %s", | ||
| 1985 | gnutls_cipher_get_name (gca), emacs_gnutls_strerror (ret)); | ||
| 1986 | else | ||
| 1987 | error ("GnuTLS AEAD cipher %s decryption failed: %s", | ||
| 1988 | gnutls_cipher_get_name (gca), emacs_gnutls_strerror (ret)); | ||
| 1989 | } | ||
| 1990 | |||
| 1991 | gnutls_aead_cipher_deinit (acipher); | 1962 | gnutls_aead_cipher_deinit (acipher); |
| 1992 | 1963 | ||
| 1993 | Lisp_Object output = make_unibyte_string (storage, storage_length); | 1964 | if (ret < GNUTLS_E_SUCCESS) |
| 1994 | clear_storage (storage, storage_length); | 1965 | error ((encrypting |
| 1966 | ? "GnuTLS AEAD cipher %s encryption failed: %s" | ||
| 1967 | : "GnuTLS AEAD cipher %s decryption failed: %s"), | ||
| 1968 | gnutls_cipher_get_name (gca), emacs_gnutls_strerror (ret)); | ||
| 1969 | |||
| 1995 | SAFE_FREE (); | 1970 | SAFE_FREE (); |
| 1996 | return list2 (output, actual_iv); | 1971 | return list2 (output, actual_iv); |
| 1997 | #else | 1972 | #else |