aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorTed Zlatanov2017-07-14 11:04:19 -0400
committerTed Zlatanov2017-07-14 11:06:16 -0400
commit583995c62dd424775dda33d5134ce04bee2ae685 (patch)
tree732251c7c468b20a70d20578b778946cf49f77fe /doc
parent0f3cc0b8245dfd7a9f6fcc95ec148be03fde8931 (diff)
downloademacs-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.texi195
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
4436security-related applications you should use the other hash types, 4437security-related applications you should use the other hash types,
4437such as SHA-2. 4438such as SHA-2.
4438 4439
4440@defun secure-hash-algorithms
4441This 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
4440This function returns a hash for @var{object}. The argument 4446This 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
4514If compiled with GnuTLS, Emacs offers built-in cryptographic support.
4515Following the GnuTLS API terminology, the available tools are digests,
4516MACs, symmetric ciphers, and AEAD ciphers.
4517
4518The terms used herein, such as IV (Initialization Vector), require
4519some familiarity with cryptography and will not be defined in detail.
4520Please consult @uref{https://www.gnutls.org/} for specific
4521documentation which may help you understand the terminology and
4522structure 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
4529The inputs to GnuTLS cryptographic functions can be specified in
4530several ways, both as primitive Emacs Lisp types or as lists.
4531
4532The list form is currently similar to how @code{md5} and
4533@code{secure-hash} operate.
4534
4535@table @code
4536@item @var{buffer}
4537Simply passing a buffer as input means the whole buffer should be used.
4538
4539@item @var{string}
4540A string as input will be used directly. It may be modified by the
4541function (unlike most other Emacs Lisp functions) to reduce the chance
4542of 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})
4545This specifies a buffer or a string as described above, but an
4546optional range can be specified with @var{start} and @var{end}.
4547
4548In addition an optional @var{coding-system} can be specified if needed.
4549
4550The last optional item, @var{noerror}, overrides the normal error when
4551the text can't be encoded using the specified or chosen coding system.
4552When @var{noerror} is non-@code{nil}, this function silently uses
4553@code{raw-text} coding instead.
4554
4555@item (@code{iv-auto} @var{length})
4556This will generate an IV (Initialization Vector) of the specified
4557length using the GnuTLS @code{GNUTLS_RND_NONCE} generator and pass it
4558to the function. This ensures that the IV is unpredictable and
4559unlikely to be reused in the same session. The actual value of the IV
4560is 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
4569This function returns the alist of the GnuTLS digest algorithms.
4570
4571Each entry has a key which represents the algorithm, followed by a
4572plist 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
4575the resulting digest.
4576
4577There is a name parallel between GnuTLS MAC and digest algorithms but
4578they are separate things internally and should not be mixed.
4579@end defun
4580
4581@defun gnutls-hash-digest digest-method input
4582The @var{digest-method} can be the whole plist from
4583@code{gnutls-digests}, or just the symbol key, or a string with the
4584name of that symbol.
4585
4586The @var{input} can be specified as a buffer or string or in other
4587ways (@pxref{Format of GnuTLS Cryptography Inputs}).
4588
4589This function returns @code{nil} on error, and signals a Lisp error if
4590the @var{digest-method} or @var{input} are invalid. On success, it
4591returns a list of a binary string (the output) and the IV used.
4592@end defun
4593
4594@defun gnutls-macs
4595This function returns the alist of the GnuTLS MAC algorithms.
4596
4597Each entry has a key which represents the algorithm, followed by a
4598plist 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
4602resulting hash, the key, and the nonce respectively.
4603
4604The nonce is currently unused and only some MACs support it.
4605
4606There is a name parallel between GnuTLS MAC and digest algorithms but
4607they are separate things internally and should not be mixed.
4608@end defun
4609
4610@defun gnutls-hash-mac hash-method key input
4611The @var{hash-method} can be the whole plist from
4612@code{gnutls-macs}, or just the symbol key, or a string with the
4613name of that symbol.
4614
4615The @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
4617wiped after use if it's a string.
4618
4619The @var{input} can be specified as a buffer or string or in other
4620ways (@pxref{Format of GnuTLS Cryptography Inputs}).
4621
4622This function returns @code{nil} on error, and signals a Lisp error if
4623the @var{hash-method} or @var{key} or @var{input} are invalid.
4624
4625On success, it returns a list of a binary string (the output) and the
4626IV used.
4627@end defun
4628
4629@defun gnutls-ciphers
4630This function returns the alist of the GnuTLS ciphers.
4631
4632Each entry has a key which represents the cipher, followed by a plist
4633with 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
4636AEAD capability; and @code{:cipher-tagsize} @code{:cipher-blocksize}
4637@code{:cipher-keysize} @code{:cipher-ivsize} to indicate the size, in
4638bytes, of the tag, block size of the resulting data, the key, and the
4639IV respectively.
4640@end defun
4641
4642@defun gnutls-symmetric-encrypt cipher key iv input &optional aead_auth
4643The @var{cipher} can be the whole plist from
4644@code{gnutls-ciphers}, or just the symbol key, or a string with the
4645name of that symbol.
4646
4647The @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
4649wiped after use if it's a string.
4650
4651The @var{iv} and @var{input} and the optional @var{aead_auth} can be
4652specified as a buffer or string or in other ways (@pxref{Format of
4653GnuTLS Cryptography Inputs}).
4654
4655@var{aead_auth} is only checked with AEAD ciphers, that is, ciphers whose
4656plist has @code{:cipher-aead-capable t}. Otherwise it's ignored.
4657
4658This function returns @code{nil} on error, and signals a Lisp error if
4659the @var{cipher} or @var{key}, @var{iv}, or @var{input} are invalid,
4660or if @var{aead_auth} was specified with an AEAD cipher and was
4661invalid.
4662
4663On success, it returns a list of a binary string (the output) and the
4664IV used.
4665@end defun
4666
4667@defun gnutls-symmetric-decrypt cipher key iv input &optional aead_auth
4668The @var{cipher} can be the whole plist from
4669@code{gnutls-ciphers}, or just the symbol key, or a string with the
4670name of that symbol.
4671
4672The @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
4674wiped after use if it's a string.
4675
4676The @var{iv} and @var{input} and the optional @var{aead_auth} can be
4677specified as a buffer or string or in other ways (@pxref{Format of
4678GnuTLS Cryptography Inputs}).
4679
4680@var{aead_auth} is only checked with AEAD ciphers, that is, ciphers whose
4681plist has @code{:cipher-aead-capable t}. Otherwise it's ignored.
4682
4683This function returns @code{nil} on decryption error, and signals a
4684Lisp error if the @var{cipher} or @var{key}, @var{iv}, or @var{input}
4685are invalid, or if @var{aead_auth} was specified with an AEAD cipher
4686and was invalid.
4687
4688On success, it returns a list of a binary string (the output) and the
4689IV 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