Skip to content

Commit ca84020

Browse files
authored
Merge pull request #525 from locallycompact/hydra/sha3_512
Add SHA512 and SHA3_512 algorithms.
2 parents 808bd86 + 90f28f4 commit ca84020

File tree

8 files changed

+59
-6
lines changed

8 files changed

+59
-6
lines changed

cardano-crypto-class/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Changelog for `cardano-crypto-class`
22

3-
## 2.2.1.1
3+
## 2.2.2.0
44

5-
*
5+
* Add `SHA512` and `SHA3_512` algorithms.
66

77
## 2.2.1.0
88

cardano-crypto-class/cardano-crypto-class.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: cardano-crypto-class
3-
version: 2.2.1.0
3+
version: 2.2.2.0
44
synopsis:
55
Type classes abstracting over cryptography primitives for Cardano
66

@@ -64,6 +64,8 @@ library
6464
Cardano.Crypto.Hash.RIPEMD160
6565
Cardano.Crypto.Hash.SHA256
6666
Cardano.Crypto.Hash.SHA3_256
67+
Cardano.Crypto.Hash.SHA3_512
68+
Cardano.Crypto.Hash.SHA512
6769
Cardano.Crypto.Hash.Short
6870
Cardano.Crypto.Init
6971
Cardano.Crypto.KES

cardano-crypto-class/src/Cardano/Crypto/Hash.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ import Cardano.Crypto.Hash.Keccak256 as X
1010
import Cardano.Crypto.Hash.NeverUsed as X
1111
import Cardano.Crypto.Hash.SHA256 as X
1212
import Cardano.Crypto.Hash.SHA3_256 as X
13+
import Cardano.Crypto.Hash.SHA3_512 as X
14+
import Cardano.Crypto.Hash.SHA512 as X
1315
import Cardano.Crypto.Hash.Short as X
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE PackageImports #-}
3+
{-# LANGUAGE TypeFamilies #-}
4+
5+
-- | Implementation of the SHA3_512 hashing algorithm.
6+
module Cardano.Crypto.Hash.SHA3_512 (
7+
SHA3_512,
8+
)
9+
where
10+
11+
import Cardano.Crypto.Hash.Class
12+
import qualified Data.ByteArray as BA
13+
import qualified "crypton" Crypto.Hash as H
14+
15+
data SHA3_512
16+
17+
instance HashAlgorithm SHA3_512 where
18+
type SizeHash SHA3_512 = 64
19+
hashAlgorithmName _ = "sha3-512"
20+
digest _ = convert . H.hash
21+
22+
convert :: H.Digest H.SHA3_512 -> ByteString
23+
convert = BA.convert
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE PackageImports #-}
3+
{-# LANGUAGE TypeFamilies #-}
4+
5+
-- | Implementation of the SHA512 hashing algorithm.
6+
module Cardano.Crypto.Hash.SHA512 (
7+
SHA512,
8+
)
9+
where
10+
11+
import Cardano.Crypto.Hash.Class
12+
import qualified Data.ByteArray as BA
13+
import qualified "crypton" Crypto.Hash as H
14+
15+
data SHA512
16+
17+
instance HashAlgorithm SHA512 where
18+
type SizeHash SHA512 = 64
19+
hashAlgorithmName _ = "sha512"
20+
digest _ = convert . H.hash
21+
22+
convert :: H.Digest H.SHA512 -> ByteString
23+
convert = BA.convert

cardano-crypto-tests/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog for `cardano-crypto-tests`
22

3-
## 2.2.0.1
3+
## 2.2.1.0
44

5+
* Add test for `SHA512` and `SHA3_512` algorithms.
56
* Add tests using standard test vectors and generated ones for Praos and PraosBatchCompat
67

78
## 2.2.0.0

cardano-crypto-tests/cardano-crypto-tests.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: cardano-crypto-tests
3-
version: 2.2.0.0
3+
version: 2.2.1.0
44
synopsis: Tests for cardano-crypto-class and -praos
55
description: Tests for cardano-crypto-class and -praos
66
license: Apache-2.0
@@ -89,7 +89,7 @@ library
8989
base16-bytestring,
9090
bytestring >=0.10.12.0,
9191
cardano-binary,
92-
cardano-crypto-class ^>=2.2,
92+
cardano-crypto-class ^>=2.2.2,
9393
cardano-crypto-praos,
9494
cborg,
9595
containers,

cardano-crypto-tests/src/Test/Crypto/Hash.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ tests lock =
4242
, testHashAlgorithm (Proxy :: Proxy Keccak256)
4343
, testSodiumHashAlgorithm lock (Proxy :: Proxy SHA256)
4444
, testSodiumHashAlgorithm lock (Proxy :: Proxy Blake2b_256)
45+
, testHashAlgorithm (Proxy :: Proxy SHA512)
46+
, testHashAlgorithm (Proxy :: Proxy SHA3_512)
4547
, testPackedBytes
4648
]
4749

0 commit comments

Comments
 (0)