cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Crypto.Emip3

Description

Password-encrypted storage using EMIP-003: PBKDF2-HMAC-SHA512 with 19162 iterations and a 32-byte key, then ChaCha20-Poly1305 with empty AAD. The encoded envelope is salt (32 bytes), nonce (12), tag (16), ciphertext. Passwords and plaintext are raw bytes with no normalization. Plaintext and passwords supplied by the caller, and exported plaintext, are not erased.

import qualified Cometa.Crypto.Emip3 as Emip3
store password bytes = Emip3.encrypt password bytes
load password envelope = Emip3.decryptBytes password envelope
Synopsis

Documentation

encrypt :: ByteString -> ByteString -> IO (Either Error ByteString) Source #

Encrypt plaintext, including empty data, using a fresh random salt and nonce. Password comes first and may be empty or contain NUL. Plaintext must contain 0..min(maxBound - 60, 274877906880) bytes, where maxBound :: Int; other lengths return InvalidEmip3PlaintextLength before encryption. Success is exactly 60 bytes longer than the plaintext. Random generation and allocation occur in IO. Other failures return NativeError; allocation exceptions propagate. Cancellation waits for the operation and cleanup.

decryptBytes :: ByteString -> ByteString -> IO (Either Error ByteString) Source #

Authenticate and explicitly export plaintext from an encoded envelope. Password comes first and may be empty or contain NUL. Envelopes must contain 60 through 274877906940 bytes; other lengths return InvalidEmip3EnvelopeLength. A 60-byte envelope authenticates empty plaintext. A wrong password or modified envelope returns NativeError with the native generic failure code and never returns plaintext. Allocation exceptions propagate. Cancellation waits for native completion and cleanup. Returned plaintext has application-managed lifetime; this function cannot erase it or subsequent copies.