diff options
| author | Ted Zlatanov | 2017-07-14 11:04:19 -0400 |
|---|---|---|
| committer | Ted Zlatanov | 2017-07-14 11:06:16 -0400 |
| commit | 583995c62dd424775dda33d5134ce04bee2ae685 (patch) | |
| tree | 732251c7c468b20a70d20578b778946cf49f77fe /doc | |
| parent | 0f3cc0b8245dfd7a9f6fcc95ec148be03fde8931 (diff) | |
| download | emacs-583995c62dd424775dda33d5134ce04bee2ae685.tar.gz emacs-583995c62dd424775dda33d5134ce04bee2ae685.zip | |
GnuTLS HMAC and symmetric cipher support
* etc/NEWS: Add news for new feature.
* doc/lispref/text.texi (GnuTLS Cryptography): Add
documentation.
* configure.ac: Add macros HAVE_GNUTLS3_DIGEST,
HAVE_GNUTLS3_CIPHER, HAVE_GNUTLS3_AEAD, HAVE_GNUTLS3_HMAC.
* src/fns.c (Fsecure_hash_algorithms): Add function to list
supported `secure-hash' algorithms.
(extract_data_from_object): Add data extraction function that
can operate on buffers and strings.
(secure_hash): Use it.
(Fsecure_hash): Mention `secure-hash-algorithms'.
* src/gnutls.h: Include gnutls/crypto.h.
* src/gnutls.c (Fgnutls_ciphers, gnutls_symmetric_aead)
(gnutls_symmetric, Fgnutls_symmetric_encrypt, Fgnutls_symmetric_decrypt)
(Fgnutls_macs, Fgnutls_digests, Fgnutls_hash_mac, Fgnutls_hash_digest)
(Fgnutls_available_p): Implement GnuTLS cryptographic integration.
* test/lisp/net/gnutls-tests.el: Add tests.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/text.texi | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 9696c73c484..fd6ddc98fed 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -57,6 +57,7 @@ the character after point. | |||
| 57 | * Decompression:: Dealing with compressed data. | 57 | * Decompression:: Dealing with compressed data. |
| 58 | * Base 64:: Conversion to or from base 64 encoding. | 58 | * Base 64:: Conversion to or from base 64 encoding. |
| 59 | * Checksum/Hash:: Computing cryptographic hashes. | 59 | * Checksum/Hash:: Computing cryptographic hashes. |
| 60 | * GnuTLS Cryptography:: Cryptographic algorithms imported from GnuTLS. | ||
| 60 | * Parsing HTML/XML:: Parsing HTML and XML. | 61 | * Parsing HTML/XML:: Parsing HTML and XML. |
| 61 | * Atomic Changes:: Installing several buffer changes atomically. | 62 | * Atomic Changes:: Installing several buffer changes atomically. |
| 62 | * Change Hooks:: Supplying functions to be run when text is changed. | 63 | * Change Hooks:: Supplying functions to be run when text is changed. |
| @@ -4436,6 +4437,11 @@ similar theoretical weakness also exists in SHA-1. Therefore, for | |||
| 4436 | security-related applications you should use the other hash types, | 4437 | security-related applications you should use the other hash types, |
| 4437 | such as SHA-2. | 4438 | such as SHA-2. |
| 4438 | 4439 | ||
| 4440 | @defun secure-hash-algorithms | ||
| 4441 | This function returns a list of symbols representing algorithms that | ||
| 4442 | @code{secure-hash} can use. | ||
| 4443 | @end defun | ||
| 4444 | |||
| 4439 | @defun secure-hash algorithm object &optional start end binary | 4445 | @defun secure-hash algorithm object &optional start end binary |
| 4440 | This function returns a hash for @var{object}. The argument | 4446 | This function returns a hash for @var{object}. The argument |
| 4441 | @var{algorithm} is a symbol stating which hash to compute: one of | 4447 | @var{algorithm} is a symbol stating which hash to compute: one of |
| @@ -4494,6 +4500,195 @@ It should be somewhat more efficient on larger buffers than | |||
| 4494 | @c according to what we find useful. | 4500 | @c according to what we find useful. |
| 4495 | @end defun | 4501 | @end defun |
| 4496 | 4502 | ||
| 4503 | @node GnuTLS Cryptography | ||
| 4504 | @section GnuTLS Cryptography | ||
| 4505 | @cindex MD5 checksum | ||
| 4506 | @cindex SHA hash | ||
| 4507 | @cindex hash, cryptographic | ||
| 4508 | @cindex cryptographic hash | ||
| 4509 | @cindex AEAD cipher | ||
| 4510 | @cindex cipher, AEAD | ||
| 4511 | @cindex symmetric cipher | ||
| 4512 | @cindex cipher, symmetric | ||
| 4513 | |||
| 4514 | If compiled with GnuTLS, Emacs offers built-in cryptographic support. | ||
| 4515 | Following the GnuTLS API terminology, the available tools are digests, | ||
| 4516 | MACs, symmetric ciphers, and AEAD ciphers. | ||
| 4517 | |||
| 4518 | The terms used herein, such as IV (Initialization Vector), require | ||
| 4519 | some familiarity with cryptography and will not be defined in detail. | ||
| 4520 | Please consult @uref{https://www.gnutls.org/} for specific | ||
| 4521 | documentation which may help you understand the terminology and | ||
| 4522 | structure of the GnuTLS library. | ||
| 4523 | |||
| 4524 | @node Format of GnuTLS Cryptography Inputs | ||
| 4525 | @subsection Format of GnuTLS Cryptography Inputs | ||
| 4526 | @cindex format of gnutls cryptography inputs | ||
| 4527 | @cindex gnutls cryptography inputs format | ||
| 4528 | |||
| 4529 | The inputs to GnuTLS cryptographic functions can be specified in | ||
| 4530 | several ways, both as primitive Emacs Lisp types or as lists. | ||
| 4531 | |||
| 4532 | The list form is currently similar to how @code{md5} and | ||
| 4533 | @code{secure-hash} operate. | ||
| 4534 | |||
| 4535 | @table @code | ||
| 4536 | @item @var{buffer} | ||
| 4537 | Simply passing a buffer as input means the whole buffer should be used. | ||
| 4538 | |||
| 4539 | @item @var{string} | ||
| 4540 | A string as input will be used directly. It may be modified by the | ||
| 4541 | function (unlike most other Emacs Lisp functions) to reduce the chance | ||
| 4542 | of exposing sensitive data after the function does its work. | ||
| 4543 | |||
| 4544 | @item (@var{buffer-or-string} @var{start} @var{end} @var{coding-system} @var{noerror}) | ||
| 4545 | This specifies a buffer or a string as described above, but an | ||
| 4546 | optional range can be specified with @var{start} and @var{end}. | ||
| 4547 | |||
| 4548 | In addition an optional @var{coding-system} can be specified if needed. | ||
| 4549 | |||
| 4550 | The last optional item, @var{noerror}, overrides the normal error when | ||
| 4551 | the text can't be encoded using the specified or chosen coding system. | ||
| 4552 | When @var{noerror} is non-@code{nil}, this function silently uses | ||
| 4553 | @code{raw-text} coding instead. | ||
| 4554 | |||
| 4555 | @item (@code{iv-auto} @var{length}) | ||
| 4556 | This will generate an IV (Initialization Vector) of the specified | ||
| 4557 | length using the GnuTLS @code{GNUTLS_RND_NONCE} generator and pass it | ||
| 4558 | to the function. This ensures that the IV is unpredictable and | ||
| 4559 | unlikely to be reused in the same session. The actual value of the IV | ||
| 4560 | is returned by the function as described below. | ||
| 4561 | |||
| 4562 | @end table | ||
| 4563 | |||
| 4564 | @node GnuTLS Cryptographic Functions | ||
| 4565 | @subsection GnuTLS Cryptographic Functions | ||
| 4566 | @cindex gnutls cryptographic functions | ||
| 4567 | |||
| 4568 | @defun gnutls-digests | ||
| 4569 | This function returns the alist of the GnuTLS digest algorithms. | ||
| 4570 | |||
| 4571 | Each entry has a key which represents the algorithm, followed by a | ||
| 4572 | plist with internal details about the algorithm. The plist will have | ||
| 4573 | @code{:type gnutls-digest-algorithm} and also will have the key | ||
| 4574 | @code{:digest-algorithm-length 64} to indicate the size, in bytes, of | ||
| 4575 | the resulting digest. | ||
| 4576 | |||
| 4577 | There is a name parallel between GnuTLS MAC and digest algorithms but | ||
| 4578 | they are separate things internally and should not be mixed. | ||
| 4579 | @end defun | ||
| 4580 | |||
| 4581 | @defun gnutls-hash-digest digest-method input | ||
| 4582 | The @var{digest-method} can be the whole plist from | ||
| 4583 | @code{gnutls-digests}, or just the symbol key, or a string with the | ||
| 4584 | name of that symbol. | ||
| 4585 | |||
| 4586 | The @var{input} can be specified as a buffer or string or in other | ||
| 4587 | ways (@pxref{Format of GnuTLS Cryptography Inputs}). | ||
| 4588 | |||
| 4589 | This function returns @code{nil} on error, and signals a Lisp error if | ||
| 4590 | the @var{digest-method} or @var{input} are invalid. On success, it | ||
| 4591 | returns a list of a binary string (the output) and the IV used. | ||
| 4592 | @end defun | ||
| 4593 | |||
| 4594 | @defun gnutls-macs | ||
| 4595 | This function returns the alist of the GnuTLS MAC algorithms. | ||
| 4596 | |||
| 4597 | Each entry has a key which represents the algorithm, followed by a | ||
| 4598 | plist with internal details about the algorithm. The plist will have | ||
| 4599 | @code{:type gnutls-mac-algorithm} and also will have the keys | ||
| 4600 | @code{:mac-algorithm-length} @code{:mac-algorithm-keysize} | ||
| 4601 | @code{:mac-algorithm-noncesize} to indicate the size, in bytes, of the | ||
| 4602 | resulting hash, the key, and the nonce respectively. | ||
| 4603 | |||
| 4604 | The nonce is currently unused and only some MACs support it. | ||
| 4605 | |||
| 4606 | There is a name parallel between GnuTLS MAC and digest algorithms but | ||
| 4607 | they are separate things internally and should not be mixed. | ||
| 4608 | @end defun | ||
| 4609 | |||
| 4610 | @defun gnutls-hash-mac hash-method key input | ||
| 4611 | The @var{hash-method} can be the whole plist from | ||
| 4612 | @code{gnutls-macs}, or just the symbol key, or a string with the | ||
| 4613 | name of that symbol. | ||
| 4614 | |||
| 4615 | The @var{key} can be specified as a buffer or string or in other ways | ||
| 4616 | (@pxref{Format of GnuTLS Cryptography Inputs}). The @var{key} will be | ||
| 4617 | wiped after use if it's a string. | ||
| 4618 | |||
| 4619 | The @var{input} can be specified as a buffer or string or in other | ||
| 4620 | ways (@pxref{Format of GnuTLS Cryptography Inputs}). | ||
| 4621 | |||
| 4622 | This function returns @code{nil} on error, and signals a Lisp error if | ||
| 4623 | the @var{hash-method} or @var{key} or @var{input} are invalid. | ||
| 4624 | |||
| 4625 | On success, it returns a list of a binary string (the output) and the | ||
| 4626 | IV used. | ||
| 4627 | @end defun | ||
| 4628 | |||
| 4629 | @defun gnutls-ciphers | ||
| 4630 | This function returns the alist of the GnuTLS ciphers. | ||
| 4631 | |||
| 4632 | Each entry has a key which represents the cipher, followed by a plist | ||
| 4633 | with internal details about the algorithm. The plist will have | ||
| 4634 | @code{:type gnutls-symmetric-cipher} and also will have the keys | ||
| 4635 | @code{:cipher-aead-capable} set to @code{nil} or @code{t} to indicate | ||
| 4636 | AEAD capability; and @code{:cipher-tagsize} @code{:cipher-blocksize} | ||
| 4637 | @code{:cipher-keysize} @code{:cipher-ivsize} to indicate the size, in | ||
| 4638 | bytes, of the tag, block size of the resulting data, the key, and the | ||
| 4639 | IV respectively. | ||
| 4640 | @end defun | ||
| 4641 | |||
| 4642 | @defun gnutls-symmetric-encrypt cipher key iv input &optional aead_auth | ||
| 4643 | The @var{cipher} can be the whole plist from | ||
| 4644 | @code{gnutls-ciphers}, or just the symbol key, or a string with the | ||
| 4645 | name of that symbol. | ||
| 4646 | |||
| 4647 | The @var{key} can be specified as a buffer or string or in other ways | ||
| 4648 | (@pxref{Format of GnuTLS Cryptography Inputs}). The @var{key} will be | ||
| 4649 | wiped after use if it's a string. | ||
| 4650 | |||
| 4651 | The @var{iv} and @var{input} and the optional @var{aead_auth} can be | ||
| 4652 | specified as a buffer or string or in other ways (@pxref{Format of | ||
| 4653 | GnuTLS Cryptography Inputs}). | ||
| 4654 | |||
| 4655 | @var{aead_auth} is only checked with AEAD ciphers, that is, ciphers whose | ||
| 4656 | plist has @code{:cipher-aead-capable t}. Otherwise it's ignored. | ||
| 4657 | |||
| 4658 | This function returns @code{nil} on error, and signals a Lisp error if | ||
| 4659 | the @var{cipher} or @var{key}, @var{iv}, or @var{input} are invalid, | ||
| 4660 | or if @var{aead_auth} was specified with an AEAD cipher and was | ||
| 4661 | invalid. | ||
| 4662 | |||
| 4663 | On success, it returns a list of a binary string (the output) and the | ||
| 4664 | IV used. | ||
| 4665 | @end defun | ||
| 4666 | |||
| 4667 | @defun gnutls-symmetric-decrypt cipher key iv input &optional aead_auth | ||
| 4668 | The @var{cipher} can be the whole plist from | ||
| 4669 | @code{gnutls-ciphers}, or just the symbol key, or a string with the | ||
| 4670 | name of that symbol. | ||
| 4671 | |||
| 4672 | The @var{key} can be specified as a buffer or string or in other ways | ||
| 4673 | (@pxref{Format of GnuTLS Cryptography Inputs}). The @var{key} will be | ||
| 4674 | wiped after use if it's a string. | ||
| 4675 | |||
| 4676 | The @var{iv} and @var{input} and the optional @var{aead_auth} can be | ||
| 4677 | specified as a buffer or string or in other ways (@pxref{Format of | ||
| 4678 | GnuTLS Cryptography Inputs}). | ||
| 4679 | |||
| 4680 | @var{aead_auth} is only checked with AEAD ciphers, that is, ciphers whose | ||
| 4681 | plist has @code{:cipher-aead-capable t}. Otherwise it's ignored. | ||
| 4682 | |||
| 4683 | This function returns @code{nil} on decryption error, and signals a | ||
| 4684 | Lisp error if the @var{cipher} or @var{key}, @var{iv}, or @var{input} | ||
| 4685 | are invalid, or if @var{aead_auth} was specified with an AEAD cipher | ||
| 4686 | and was invalid. | ||
| 4687 | |||
| 4688 | On success, it returns a list of a binary string (the output) and the | ||
| 4689 | IV used. | ||
| 4690 | @end defun | ||
| 4691 | |||
| 4497 | @node Parsing HTML/XML | 4692 | @node Parsing HTML/XML |
| 4498 | @section Parsing HTML and XML | 4693 | @section Parsing HTML and XML |
| 4499 | @cindex parsing html | 4694 | @cindex parsing html |