github.com/braveheart12/insolar-09-08-19@v0.8.7/platformpolicy/internal/hash/provider.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  package hash
    18  
    19  import (
    20  	"github.com/insolar/insolar/core"
    21  	"golang.org/x/crypto/sha3"
    22  )
    23  
    24  type sha3Provider struct{}
    25  
    26  func NewSHA3Provider() AlgorithmProvider {
    27  	return &sha3Provider{}
    28  }
    29  
    30  func (*sha3Provider) Hash224bits() core.Hasher {
    31  	return &hashWrapper{
    32  		hash: sha3.New224(),
    33  		sumFunc: func(b []byte) []byte {
    34  			s := sha3.Sum224(b)
    35  			return s[:]
    36  		},
    37  	}
    38  }
    39  
    40  func (*sha3Provider) Hash256bits() core.Hasher {
    41  	return &hashWrapper{
    42  		hash: sha3.New256(),
    43  		sumFunc: func(b []byte) []byte {
    44  			s := sha3.Sum256(b)
    45  			return s[:]
    46  		},
    47  	}
    48  }
    49  
    50  func (*sha3Provider) Hash512bits() core.Hasher {
    51  	return &hashWrapper{
    52  		hash: sha3.New512(),
    53  		sumFunc: func(b []byte) []byte {
    54  			s := sha3.Sum512(b)
    55  			return s[:]
    56  		},
    57  	}
    58  }