diff --git a/index.html b/index.html index 0ffbc72..9f2c469 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@ - +
Fast and memory-efficient streaming hash functions. Performs direct hashing of strings, raw bytes, and files potentially larger than memory, as well as hashing in-memory objects through R’s serialization mechanism, without requiring allocation of the serialized object.
-Implementations include the SHA-256 and SHA-3 cryptographic hash functions, SHAKE256 extendable-output function (XOF), and ‘SipHash’ pseudo-random function.
+Implementations include the SHA-256, SHA-3 and Keccak cryptographic hash functions, SHAKE256 extendable-output function (XOF), and ‘SipHash’ pseudo-random function.
The SHA-3 Secure Hash Standard was published by the National Institute of Standards and Technology (NIST) in 2015 at doi:10.6028/NIST.FIPS.202. The SHA-256 Secure Hash Standard was published by NIST in 2002 at https://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf. The SipHash family of pseudo-random functions by Jean-Philippe Aumasson and Daniel J. Bernstein was published in 2012 at https://ia.cr/2012/351.[1]
The SHA-256 and SHA-3 implementations are based on those by the ‘Mbed TLS’ Trusted Firmware Project at https://www.trustedfirmware.org/projects/mbed-tls. The SipHash implementation is based on that of Daniele Nicolodi, David Rheinsberg and Tom Gundersen at https://github.com/c-util/c-siphash, which is in turn based on the reference implementation by Jean-Philippe Aumasson and Daniel J. Bernstein released to the public domain at https://github.com/veorq/SipHash.
224
, 256
, 384
or 512
sha3("secret base")
@@ -124,8 +123,8 @@ Hash arbitrary R objectsPortable as always uses R serialization version 3 big-endian representation, skipping headers (which contain R version and native encoding information)
-sha3(data.frame(a = 1, b = 2), bits = 160)
-#> [1] "bc5a411f87ef083296c60d6557f189b62ff9e7e6"
+sha3(data.frame(a = 1, b = 2), bits = 224)
+#> [1] "03778aad53bff7dd68caab94374bba6f07cea235fb97b3c52cf612e9"
sha3(NULL)
#> [1] "b3e37e4c5def1bfb2841b79ef8503b83d1fed46836b5b913d7c16de92966dcee"
@@ -142,31 +141,34 @@ Hash files#> [1] "a721d57570e7ce366adee2fccbe9770723c6e3622549c31c7cab9dbb4a795520"
NA
(and ‘bits’ as 32
for a single integer value)For use in parallel computing, this is a valid method for reducing to a negligible probability that RNGs in each process may overlap. This may be especially suitable when first-best alternatives such as using recursive streams are too expensive or unable to preserve reproducibility. [2]
+keccak("secret base", bits = 384)
+#> [1] "c82bae24175676028e44aa08b9e2424311847adb0b071c68c7ea47edf049b0e935ddd2fc7c499333bccc08c7eb7b1203"
sha256("secret base")
#> [1] "1951c1ca3d50e95e6ede2b1c26fefd0f0e8eba1e51a837f8ccefb583a2b686fe"
+sha256("secret base", key = "秘密の基地の中") #> [1] "ec58099ab21325e792bef8f1aafc0a70e1a7227463cfc410931112705d753392"
shake256()
to delineate from sha3()
.sha3()
supplying ‘bit’ argument other than 224, 256, 384 or 512 is deprecated.SHA-3 Cryptographic Hash Algorithms and SHAKE256 XOF
SHA-3 Cryptographic Hash Algorithms
SHAKE256 Extensible Output Function (XOF)
R/base.R
sha3.Rd
Returns a SHA-3 or SHAKE256 hash of the supplied object or file.
+Returns a SHA-3 hash of the supplied object or file.
[default 256L] output size of the returned hash. If one of 224, -256, 384 or 512, uses the respective SHA-3 cryptographic hash function. -For all other values, uses the SHAKE256 extendable-output function (XOF). -Must be between 8 and 2^24 and coercible to integer.
[default 256L] output size of the returned hash. Must be one of
+224, 256, 384 or 512. For legacy reasons (usage is deprecated), all other
+values return the value of shake256
.
To produce single integer values suitable for use as random seeds - for R's pseudo random number generators (RNGs), set 'bits' to 32 and - 'convert' to NA.
-The SHA-3 Secure Hash Standard was published by the National Institute of - Standards and Technology (NIST) in 2015 at +
The SHA-3 Secure Hash Standard was published by the National + Institute of Standards and Technology (NIST) in 2015 at doi:10.6028/NIST.FIPS.202 .
This implementation is based on one by 'The Mbed TLS Contributors' under @@ -134,10 +130,6 @@
Returns a SHAKE256 hash of the supplied object or file.
+shake256(x, bits = 256L, convert = TRUE, file)
object to hash. A character string or raw vector (without +attributes) is hashed 'as is'. All other objects are stream hashed using +R serialization, but without requiring allocation of the serialized +object. To ensure portability, serialization version 3 big-endian +represenation is always used with headers skipped (as these contain R +version and native encoding information).
[default 256L] output size of the returned hash. Must be between +8 and 2^24 and coercible to integer.
[default TRUE] if TRUE, the hash is converted to its hex +representation as a character string, if FALSE, output directly as a raw +vector, or if NA, a vector of (32-bit) integer values.
character file name / path. If specified, 'x' is ignored. The +file is stream hashed, thus capable of handling files larger than memory.
A character string, raw or integer vector depending on 'convert'.
+To produce single integer values suitable for use as random seeds + for R's pseudo random number generators (RNGs), set 'bits' to 32 and + 'convert' to NA.
+This implementation is based on one by 'The Mbed TLS Contributors' under + the 'Mbed TLS' Trusted Firmware Project at + https://www.trustedfirmware.org/projects/mbed-tls.
+# SHAKE256 hash as character string:
+shake256("secret base")
+#> [1] "995ebac18dbfeb170606cbbc0f2accce85db4db0dcf4fbe4d3efaf8ccf4e0a94"
+
+# SHAKE256 hash as raw vector:
+shake256("secret base", convert = FALSE)
+#> [1] 99 5e ba c1 8d bf eb 17 06 06 cb bc 0f 2a cc ce 85 db 4d b0 dc f4 fb e4 d3
+#> [26] ef af 8c cf 4e 0a 94
+
+# SHAKE256 hash to integer:
+sha3("secret base", bits = 32L, convert = NA)
+#> [1] -1044750695
+
+# SHAKE256 hash a file:
+file <- tempfile(); cat("secret base", file = file)
+shake256(file = file)
+#> [1] "995ebac18dbfeb170606cbbc0f2accce85db4db0dcf4fbe4d3efaf8ccf4e0a94"
+unlink(file)
+
+