Adding a `constEq` (or similar) function for security use cases
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by reviewing the issue's proposed constEq signature and example, then inspect the bytestring API to determine the appropriate integration point and required security guarantees. Done means agreeing on the API and behavior for byte comparisons, implementing it safely, and adding verification for the intended constant-time use case.
Written by the indexing model from the issue text.
Description
To prevent timing attacks, sometimes you'd want to compare bytes (like hashes) in constant time, since this can give the attacker information on how far they have matched the bytes.
This is a semi-quick example of what it might/would look like (did not compile, might have errors)
(based it off of constEq from the memory package)
constEq :: ByteString -> ByteString -> Bool
constEq (BS fptr1 len1) (BS fptr2 len2)
| len1 /= len2 = False
| otherwise = accursedUnutterablePerformIO $ do
withForeignPtr fptr1 $ \ptr1 ->
withForeignPtr fptr2 $ \ptr2 ->
let loop i !acc
| i == len1 = pure $! acc == 0
| otherwise = do
mZero <- xor <$> peekByteOff i ptr1 <*> (peekByteOff i ptr2 :: IO Word8)
loop (i + 1) (acc .|. mZero)
in loop 0 0
- Dominant language
- Haskell
- Stars
- 302
- Forks
- 146
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from haskell/bytestring
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/bytestring#730 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
haskell/bytestring#723 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
haskell/bytestring#689 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
haskell/bytestring#684 · 3 comments ·
-
Fixed Point RoundingOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
haskell/bytestring#679 · 2 comments ·
All issues in haskell/bytestring
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
seal-harness/seal-harness#399 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
fmidue/codeworld-tasks#124 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
reflex-frp/reflex#563 ·
-
The codecov job never gets a runner on macos-26 and is cancelledPossibly taken @yegor256 claimed this 1 day ago. Openbug
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
objectionary/phino#2524 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cardano-api#1434 ·
Maintainers usually reply within 2 days