hashes.mx raw

   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  
   5  package sha3
   6  
   7  // New224 returns a new Digest computing the SHA3-224 hash.
   8  func New224() *Digest {
   9  	return &Digest{rate: rateK448, outputLen: 28, dsbyte: dsbyteSHA3}
  10  }
  11  
  12  // New256 returns a new Digest computing the SHA3-256 hash.
  13  func New256() *Digest {
  14  	return &Digest{rate: rateK512, outputLen: 32, dsbyte: dsbyteSHA3}
  15  }
  16  
  17  // New384 returns a new Digest computing the SHA3-384 hash.
  18  func New384() *Digest {
  19  	return &Digest{rate: rateK768, outputLen: 48, dsbyte: dsbyteSHA3}
  20  }
  21  
  22  // New512 returns a new Digest computing the SHA3-512 hash.
  23  func New512() *Digest {
  24  	return &Digest{rate: rateK1024, outputLen: 64, dsbyte: dsbyteSHA3}
  25  }
  26  
  27  // TODO(fips): do this in the stdlib crypto/sha3 package.
  28  //
  29  //     crypto.RegisterHash(crypto.SHA3_224, New224)
  30  //     crypto.RegisterHash(crypto.SHA3_256, New256)
  31  //     crypto.RegisterHash(crypto.SHA3_384, New384)
  32  //     crypto.RegisterHash(crypto.SHA3_512, New512)
  33  
  34  const (
  35  	dsbyteSHA3   = 0b00000110
  36  	dsbyteKeccak = 0b00000001
  37  	dsbyteShake  = 0b00011111
  38  	dsbyteCShake = 0b00000100
  39  
  40  	// rateK[c] is the rate in bytes for Keccak[c] where c is the capacity in
  41  	// bits. Given the sponge size is 1600 bits, the rate is 1600 - c bits.
  42  	rateK256  = (1600 - 256) / 8
  43  	rateK448  = (1600 - 448) / 8
  44  	rateK512  = (1600 - 512) / 8
  45  	rateK768  = (1600 - 768) / 8
  46  	rateK1024 = (1600 - 1024) / 8
  47  )
  48  
  49  // NewLegacyKeccak256 returns a new Digest computing the legacy, non-standard
  50  // Keccak-256 hash.
  51  func NewLegacyKeccak256() *Digest {
  52  	return &Digest{rate: rateK512, outputLen: 32, dsbyte: dsbyteKeccak}
  53  }
  54  
  55  // NewLegacyKeccak512 returns a new Digest computing the legacy, non-standard
  56  // Keccak-512 hash.
  57  func NewLegacyKeccak512() *Digest {
  58  	return &Digest{rate: rateK1024, outputLen: 64, dsbyte: dsbyteKeccak}
  59  }
  60