Did you know ... | Search Documentation: |
SHA* Secure Hash Algorithms |
The library library(sha)
provides Secure Hash
Algorihms approved by FIPS (Federal Information Processing
Standard). Quoting
Wikipedia: “The
SHA (Secure Hash Algorithm) hash functions refer to five FIPS-approved
algorithms for computing a condensed digital representation (known as a
message digest) that is, to a high degree of probability, unique for a
given input data sequence (the message). These algorithms are called‘secure’because
(in the words of the standard), “for a given algorithm, it is
computationally infeasible 1) to find a message that corresponds to a
given message digest, or 2) to find two different messages that produce
the same message digest. Any change to a message will, with a very high
probability, result in a different message digest.’
The current library supports all 5 approved algorithms, both computing the hash-key from data and the hash Message Authentication Code (HMAC).
A general comprehensive hash interface is provided by library(crypto)
,
part of the
ssl package.
Input is text, represented as an atom, packed string object or code-list. Note that these functions operate on byte-sequences and therefore are not meaningful on Unicode text. The result is returned as a list of byte-values. This is the most general format that is comfortable supported by standard Prolog and can easily be transformed in other formats. Commonly used text formats are ASCII created by encoding each byte as two hexadecimal digits and ASCII created using base64 encoding. Representation as a large integer can be desirable for computational processing.
sha1
(default), sha224
, sha256
,
sha384
or sha512
utf8
,
which implies that Unicode text is encoded as UTF-8 bytes. This option
can deal with any atom. The alternative is
octet
, which implies that the text is considered as a
sequence of bytes. This is suitable for e.g., atoms that represent
binary data. An error is raised if the text contains code-points outside
the range 0..255.
Key and Data are either an atom, packed string
or list of character codes. HMAC is unified with a list of
integers representing the authentication code. Options is the
same as for
sha_hash/3,
but currently only sha1
and sha256
are
supported.
See also crypto_data_hash/3
from library(crypto)
library provided by the SSL package.
?- sha_hash('SWI-Prolog', Hash, []), hash_atom(Hash, Hex). Hash = [61, 128, 252, 38, 121, 69, 229, 85, 199|...], Hex = '3d80fc267945e555c730403bd0ab0716e2a68c68'.
The underlying SHA-2 library is an unmodified copy created by Dr Brian Gladman, Worcester, UK. It is distributed under the license conditions below.
The free distribution and use of this software in both source and binary form is allowed (with or without changes) provided that:
ALTERNATIVELY, provided that this notice is retained in full, this product may be distributed under the terms of the GNU General Public License (GPL), in which case the provisions of the GPL apply INSTEAD OF those given above.