Added the BLAKE2 algorithm.

main
Tylan Tyson 1 year ago
parent e8e3bda3ec
commit 4b51809ce9

@ -11,7 +11,9 @@ GCL is a Go library designed to offer a robust collection of cryptographic algor
## Features
Coming soon.
GCL offers support for a diverse range of cryptographic algorithms, ensuring that your cryptographic requirements are comprehensively addressed. Our library includes:
- [X] BLAKE2
## Installation

@ -0,0 +1,27 @@
package blake2
import (
// Standard
"crypto/subtle"
// Standard Extended
"golang.org/x/crypto/blake2b"
)
// Check Hash
func (algorithm Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) {
// Hasher
hasher, err := blake2b.New(algorithm.size, nil)
// Handle Error
if err != nil {
return false, err
}
// Write To Hasher
_, err = hasher.Write(data)
// Handle Error
if err != nil {
return false, err
}
// Return Match
return subtle.ConstantTimeCompare(hasher.Sum(nil), hashToCheck) == 1, err
}

@ -0,0 +1,24 @@
package blake2
import (
// Standard Extended
"golang.org/x/crypto/blake2b"
)
// Hash
func (algorithm Algorithm) Hash(data []byte) ([]byte, error) {
// Hasher
hasher, err := blake2b.New(algorithm.size, nil)
// Handle Error
if err != nil {
return []byte(""), err
}
// Write To Hasher
_, err = hasher.Write(data)
// Handle Error
if err != nil {
return []byte(""), err
}
// Return Hash
return hasher.Sum(nil), err
}

@ -0,0 +1,14 @@
package blake2
// Algorithm
type Algorithm struct {
size int
}
// New
func New(size int) Algorithm {
// Return Algorithm
return Algorithm{
size: size,
}
}

@ -1,3 +1,8 @@
module gcl
go 1.20
require (
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
)

@ -0,0 +1,4 @@
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Loading…
Cancel
Save