Skip to content

Commit eb6e966

Browse files
committed
Hmac and HalfHmac types
1 parent 6bfa704 commit eb6e966

File tree

1 file changed

+25
-1
lines changed
  • pub/functora/src/aes/Functora

1 file changed

+25
-1
lines changed

pub/functora/src/aes/Functora/Aes.hs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module Functora.Aes
2-
( Crypto,
2+
( Hmac,
3+
mkHmac,
4+
HalfHmac,
5+
mkHalfHmac,
6+
Crypto,
37
encryptHmac,
48
unsafeEncrypt,
59
unHmacDecrypt,
@@ -27,6 +31,26 @@ import Functora.Cfg
2731
import Functora.Prelude
2832
import Type.Reflection
2933

34+
newtype Hmac = Hmac
35+
{ unHmac :: ByteString
36+
}
37+
deriving stock (Eq, Ord, Show, Read, Data, Generic)
38+
deriving newtype (Binary)
39+
40+
mkHmac :: (From a [Word8]) => SomeAesKey -> a -> Hmac
41+
mkHmac aes =
42+
Hmac . sha256Hmac (unOkm $ someAesKeyHmacer aes)
43+
44+
newtype HalfHmac = HalfHmac
45+
{ unHalfHmac :: ByteString
46+
}
47+
deriving stock (Eq, Ord, Show, Read, Data, Generic)
48+
deriving newtype (Binary)
49+
50+
mkHalfHmac :: (From a [Word8]) => SomeAesKey -> a -> HalfHmac
51+
mkHalfHmac aes =
52+
HalfHmac . take 16 . sha256Hmac (unOkm $ someAesKeyHmacer aes)
53+
3054
data Crypto = Crypto
3155
{ cryptoValue :: ByteString,
3256
cryptoValueHmac :: ByteString

0 commit comments

Comments
 (0)