hashes.go 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  // This file provides functions for creating instances of the SHA-3
   8  // and SHAKE hash functions, as well as utility functions for hashing
   9  // bytes.
  10  
  11  // New224 creates a new SHA3-224 hash.
  12  // Its generic security strength is 224 bits against preimage attacks,
  13  // and 112 bits against collision attacks.
  14  func New224() State {
  15  	return State{rate: 144, outputLen: 28, dsbyte: 0x06}
  16  }
  17  
  18  // New256 creates a new SHA3-256 hash.
  19  // Its generic security strength is 256 bits against preimage attacks,
  20  // and 128 bits against collision attacks.
  21  func New256() State {
  22  	return State{rate: 136, outputLen: 32, dsbyte: 0x06}
  23  }
  24  
  25  // New384 creates a new SHA3-384 hash.
  26  // Its generic security strength is 384 bits against preimage attacks,
  27  // and 192 bits against collision attacks.
  28  func New384() State {
  29  	return State{rate: 104, outputLen: 48, dsbyte: 0x06}
  30  }
  31  
  32  // New512 creates a new SHA3-512 hash.
  33  // Its generic security strength is 512 bits against preimage attacks,
  34  // and 256 bits against collision attacks.
  35  func New512() State {
  36  	return State{rate: 72, outputLen: 64, dsbyte: 0x06}
  37  }
  38  
  39  // Sum224 returns the SHA3-224 digest of the data.
  40  func Sum224(data []byte) (digest [28]byte) {
  41  	h := New224()
  42  	_, _ = h.Write(data)
  43  	h.Sum(digest[:0])
  44  	return
  45  }
  46  
  47  // Sum256 returns the SHA3-256 digest of the data.
  48  func Sum256(data []byte) (digest [32]byte) {
  49  	h := New256()
  50  	_, _ = h.Write(data)
  51  	h.Sum(digest[:0])
  52  	return
  53  }
  54  
  55  // Sum384 returns the SHA3-384 digest of the data.
  56  func Sum384(data []byte) (digest [48]byte) {
  57  	h := New384()
  58  	_, _ = h.Write(data)
  59  	h.Sum(digest[:0])
  60  	return
  61  }
  62  
  63  // Sum512 returns the SHA3-512 digest of the data.
  64  func Sum512(data []byte) (digest [64]byte) {
  65  	h := New512()
  66  	_, _ = h.Write(data)
  67  	h.Sum(digest[:0])
  68  	return
  69  }
  70