github.com/klaytn/klaytn@v1.12.1/crypto/sha3/hashes.go (about)

     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  import (
    12  	"hash"
    13  )
    14  
    15  // NewKeccak256 creates a new Keccak-256 hash.
    16  func NewKeccak256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x01} }
    17  
    18  // NewKeccak512 creates a new Keccak-512 hash.
    19  func NewKeccak512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x01} }
    20  
    21  // New224 creates a new SHA3-224 hash.
    22  // Its generic security strength is 224 bits against preimage attacks,
    23  // and 112 bits against collision attacks.
    24  func New224() hash.Hash { return &state{rate: 144, outputLen: 28, dsbyte: 0x06} }
    25  
    26  // New256 creates a new SHA3-256 hash.
    27  // Its generic security strength is 256 bits against preimage attacks,
    28  // and 128 bits against collision attacks.
    29  func New256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x06} }
    30  
    31  // New384 creates a new SHA3-384 hash.
    32  // Its generic security strength is 384 bits against preimage attacks,
    33  // and 192 bits against collision attacks.
    34  func New384() hash.Hash { return &state{rate: 104, outputLen: 48, dsbyte: 0x06} }
    35  
    36  // New512 creates a new SHA3-512 hash.
    37  // Its generic security strength is 512 bits against preimage attacks,
    38  // and 256 bits against collision attacks.
    39  func New512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x06} }
    40  
    41  // Sum224 returns the SHA3-224 digest of the data.
    42  func Sum224(data []byte) (digest [28]byte) {
    43  	h := New224()
    44  	h.Write(data)
    45  	h.Sum(digest[:0])
    46  	return
    47  }
    48  
    49  // Sum256 returns the SHA3-256 digest of the data.
    50  func Sum256(data []byte) (digest [32]byte) {
    51  	h := New256()
    52  	h.Write(data)
    53  	h.Sum(digest[:0])
    54  	return
    55  }
    56  
    57  // Sum384 returns the SHA3-384 digest of the data.
    58  func Sum384(data []byte) (digest [48]byte) {
    59  	h := New384()
    60  	h.Write(data)
    61  	h.Sum(digest[:0])
    62  	return
    63  }
    64  
    65  // Sum512 returns the SHA3-512 digest of the data.
    66  func Sum512(data []byte) (digest [64]byte) {
    67  	h := New512()
    68  	h.Write(data)
    69  	h.Sum(digest[:0])
    70  	return
    71  }