IntersectMBO / IntersectMBO/cardano-crypto
Odd behaviour (including SIGSEGV) from encryptedCreateDirectWithTweak
- Dominant language
- C
- Stars
- 68
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
### Setup
```
stack ghci --test cardano-crypto:cardano-crypto-test
```
```haskell
import Cardano.Crypto.Wallet.Encrypted
:set -XOverloadedStrings
import qualified Data.ByteString as BS
bytes = "(\134\242|I\141L\EM\NUL\128\173\252q\191\172\167>f \218\222\167.\136\DC4\216\191\253r8cD8&I\STX;\185&\177\172E\241\185\241\157\226\r\163+\EM\GS\232-\188\250[E^N\129J\158\STX\134\188!\241\DLEzt\222\199\247U\143\ETB\128,\226Q\"\230\234\"\191\177\250\230\167\n\214X\244z\\" :: BS.ByteString
pwd = "" :: BS.ByteString
```
### Oddness 1
`BS.take 1` on input does not affect output:
```haskell
λ> k1 = unEncryptedKey $ encryptedCreateDirectWithTweak bytes pwd
λ> k2 = unEncryptedKey $ encryptedCreateDirectWithTweak (BS.take 1 bytes) pwd
λ> k1 == k2
True -- 🧐
```
### Oddness 2
`BS.take 0` on input causes SIGSEGV.
```haskell
λ> unEncryptedKey $ encryptedCreateDirectWithTweak (BS.take 0 bytes) pwd
"fish: 'stack ghci --test cardano-crypt…' terminated by signal SIGSEGV (Address boundary error)
```
### Comment
It is mentioned in the doc-comment that the input must be 96 bytes long. Are these findings as expected?
https://github.com/input-output-hk/cardano-crypto/blob/3c5db489c71a4d70ee43f5f9b979fcde3c797f2a/src/Cardano/Crypto/Wallet/Encrypted.hs#L95-L96
Contributor guide
Assessment
This issue has not been assessed yet.