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.

@@ -102,7 +102,6 @@

SHA-3
 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"

-

Hash to integer +

Hash to integer / SHAKE256 XOF

-sha3("秘密の基地の中", bits = 384, convert = NA)
-#>  [1]  1421990570   338241144  1760362273 -1213241427  1313032644 -1154474231
-#>  [7]  1041052480   697347630 -1488396834  -917712316  1835427495  2044829552
-
-sha3("秘密の基地の中", bits = 32, convert = NA)
+shake256("秘密の基地の中", bits = 32, convert = NA)
 #> [1] 2000208511

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]

-

SHA-256 +

Keccak

+keccak("secret base", bits = 384)
+#> [1] "c82bae24175676028e44aa08b9e2424311847adb0b071c68c7ea47edf049b0e935ddd2fc7c499333bccc08c7eb7b1203"
+
+
+

SHA-256 +

+
 sha256("secret base")
 #> [1] "1951c1ca3d50e95e6ede2b1c26fefd0f0e8eba1e51a837f8ccefb583a2b686fe"
  • For a SHA-256 HMAC, pass a character string or raw vector to ‘key’
-
+
 sha256("secret base", key = "秘密の基地の中")
 #> [1] "ec58099ab21325e792bef8f1aafc0a70e1a7227463cfc410931112705d753392"
@@ -177,7 +179,7 @@

SipHashSipHash-1-3 is optimized for performance
  • Pass a character string or raw vector to ‘key’ - up to 16 bytes (128 bits) of the key data is used
  • -
    +
     siphash13("secret base", key = charToRaw("秘密の基地の中"))
     #> [1] "a1f0a751892cc7dd"
    diff --git a/news/index.html b/news/index.html index b15257a..3e8872a 100644 --- a/news/index.html +++ b/news/index.html @@ -56,6 +56,8 @@

    Changelog

    • Adds Keccak cryptographic hash algorithm.
    • +
    • Adds shake256() to delineate from sha3().
    • +
    • Use of sha3() supplying ‘bit’ argument other than 224, 256, 384 or 512 is deprecated.
    diff --git a/pkgdown.yml b/pkgdown.yml index 15bd266..ae6fddd 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 3.1.11 pkgdown: 2.0.9 pkgdown_sha: ~ articles: {} -last_built: 2024-04-24T15:02Z +last_built: 2024-04-24T15:33Z urls: reference: https://shikokuchuo.net/secretbase/reference article: https://shikokuchuo.net/secretbase/articles diff --git a/reference/index.html b/reference/index.html index f6f9e0e..2e7f3b5 100644 --- a/reference/index.html +++ b/reference/index.html @@ -67,7 +67,11 @@

    Reference

    sha3()

    -

    SHA-3 Cryptographic Hash Algorithms and SHAKE256 XOF

    +

    SHA-3 Cryptographic Hash Algorithms

    + +

    shake256()

    + +

    SHAKE256 Extensible Output Function (XOF)

    siphash13()

    diff --git a/reference/sha3.html b/reference/sha3.html index 647dfc1..e101263 100644 --- a/reference/sha3.html +++ b/reference/sha3.html @@ -1,5 +1,5 @@ -SHA-3 Cryptographic Hash Algorithms and SHAKE256 XOF — sha3 • secretbaseSHA-3 Cryptographic Hash Algorithms — sha3 • secretbase @@ -49,13 +49,13 @@
    -

    Returns a SHA-3 or SHAKE256 hash of the supplied object or file.

    +

    Returns a SHA-3 hash of the supplied object or file.

    @@ -74,10 +74,9 @@

    Arguments

    bits
    -

    [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.

    convert
    @@ -99,11 +98,8 @@

    Value

    Details

    -

    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 @@

    Examples

    sha3("secret base", bits = 512) #> [1] "31076b4690961320a761be0951eeaa9efd0c75c37137a2a50877cbebb8afcc6d7927c41a120ae8fa73fdce8fff726fcbc51d448d020240bc7455963a16e639b1" -# SHAKE256 hash to integer: -sha3("secret base", bits = 32L, convert = NA) -#> [1] -1044750695 - # SHA3-256 hash a file: file <- tempfile(); cat("secret base", file = file) sha3(file = file) diff --git a/reference/shake256.html b/reference/shake256.html new file mode 100644 index 0000000..ae8d973 --- /dev/null +++ b/reference/shake256.html @@ -0,0 +1,154 @@ + +SHAKE256 Extensible Output Function (XOF) — shake256 • secretbase + + +
    +
    + + + +
    +
    + + +
    +

    Returns a SHAKE256 hash of the supplied object or file.

    +
    + +
    +
    shake256(x, bits = 256L, convert = TRUE, file)
    +
    + +
    +

    Arguments

    +
    x
    +

    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).

    + + +
    bits
    +

    [default 256L] output size of the returned hash. Must be between +8 and 2^24 and coercible to integer.

    + + +
    convert
    +

    [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.

    + + +
    file
    +

    character file name / path. If specified, 'x' is ignored. The +file is stream hashed, thus capable of handling files larger than memory.

    + +
    +
    +

    Value

    + + +

    A character string, raw or integer vector depending on 'convert'.

    +
    +
    +

    Details

    +

    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.

    +
    + +
    +

    Examples

    +
    # 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)
    +
    +
    +
    +
    + +
    + + +
    + +
    +

    Site built with pkgdown 2.0.9.

    +
    + +
    + + + + + + + + diff --git a/sitemap.xml b/sitemap.xml index fac3b11..7a4a259 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -33,6 +33,9 @@ https://shikokuchuo.net/secretbase/reference/sha3.html + + https://shikokuchuo.net/secretbase/reference/shake256.html + https://shikokuchuo.net/secretbase/reference/siphash13.html