doc.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package sha3 implements the SHA-3 fixed-output-length hash functions and
  5. // the SHAKE variable-output-length hash functions defined by FIPS-202.
  6. //
  7. // All types in this package also implement [encoding.BinaryMarshaler],
  8. // [encoding.BinaryAppender] and [encoding.BinaryUnmarshaler] to marshal and
  9. // unmarshal the internal state of the hash.
  10. //
  11. // Both types of hash function use the "sponge" construction and the Keccak
  12. // permutation. For a detailed specification see http://keccak.noekeon.org/
  13. //
  14. // # Guidance
  15. //
  16. // If you aren't sure what function you need, use SHAKE256 with at least 64
  17. // bytes of output. The SHAKE instances are faster than the SHA3 instances;
  18. // the latter have to allocate memory to conform to the hash.Hash interface.
  19. //
  20. // If you need a secret-key MAC (message authentication code), prepend the
  21. // secret key to the input, hash with SHAKE256 and read at least 32 bytes of
  22. // output.
  23. //
  24. // # Security strengths
  25. //
  26. // The SHA3-x (x equals 224, 256, 384, or 512) functions have a security
  27. // strength against preimage attacks of x bits. Since they only produce "x"
  28. // bits of output, their collision-resistance is only "x/2" bits.
  29. //
  30. // The SHAKE-256 and -128 functions have a generic security strength of 256 and
  31. // 128 bits against all attacks, provided that at least 2x bits of their output
  32. // is used. Requesting more than 64 or 32 bytes of output, respectively, does
  33. // not increase the collision-resistance of the SHAKE functions.
  34. //
  35. // # The sponge construction
  36. //
  37. // A sponge builds a pseudo-random function from a public pseudo-random
  38. // permutation, by applying the permutation to a state of "rate + capacity"
  39. // bytes, but hiding "capacity" of the bytes.
  40. //
  41. // A sponge starts out with a zero state. To hash an input using a sponge, up
  42. // to "rate" bytes of the input are XORed into the sponge's state. The sponge
  43. // is then "full" and the permutation is applied to "empty" it. This process is
  44. // repeated until all the input has been "absorbed". The input is then padded.
  45. // The digest is "squeezed" from the sponge in the same way, except that output
  46. // is copied out instead of input being XORed in.
  47. //
  48. // A sponge is parameterized by its generic security strength, which is equal
  49. // to half its capacity; capacity + rate is equal to the permutation's width.
  50. // Since the KeccakF-1600 permutation is 1600 bits (200 bytes) wide, this means
  51. // that the security strength of a sponge instance is equal to (1600 - bitrate) / 2.
  52. //
  53. // # Recommendations
  54. //
  55. // The SHAKE functions are recommended for most new uses. They can produce
  56. // output of arbitrary length. SHAKE256, with an output length of at least
  57. // 64 bytes, provides 256-bit security against all attacks. The Keccak team
  58. // recommends it for most applications upgrading from SHA2-512. (NIST chose a
  59. // much stronger, but much slower, sponge instance for SHA3-512.)
  60. //
  61. // The SHA-3 functions are "drop-in" replacements for the SHA-2 functions.
  62. // They produce output of the same length, with the same security strengths
  63. // against all attacks. This means, in particular, that SHA3-256 only has
  64. // 128-bit collision resistance, because its output length is 32 bytes.
  65. package sha3