From a879845434181f8bb8bcd1182e0be38740d471f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Thu, 18 May 2017 20:34:38 +0200 Subject: [PATCH] Add note about the optional all-zero test This is actually a lie: the condition is tested in both curve implementations but not returned by the Haskell API. Will be a reminder to add this in the future. A function 'allocRetAndFreeze' could be useful. --- Crypto/PubKey/Curve25519.hs | 5 ++++- Crypto/PubKey/Curve448.hs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Crypto/PubKey/Curve25519.hs b/Crypto/PubKey/Curve25519.hs index d8463eb..e3416c8 100644 --- a/Crypto/PubKey/Curve25519.hs +++ b/Crypto/PubKey/Curve25519.hs @@ -92,7 +92,10 @@ dhSecret bs | B.length bs == 32 = CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ()) | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid --- | Compute the Diffie Hellman secret from a public key and a secret key +-- | Compute the Diffie Hellman secret from a public key and a secret key. +-- +-- This implementation may return an all-zero value as it does not check for +-- the condition. dh :: PublicKey -> SecretKey -> DhSecret dh (PublicKey pub) (SecretKey sec) = DhSecret <$> B.allocAndFreeze 32 $ \result -> diff --git a/Crypto/PubKey/Curve448.hs b/Crypto/PubKey/Curve448.hs index 68e1256..95feaf3 100644 --- a/Crypto/PubKey/Curve448.hs +++ b/Crypto/PubKey/Curve448.hs @@ -79,7 +79,10 @@ dhSecret bs | B.length bs == x448_bytes = CryptoPassed $ DhSecret $ B.copyAndFreeze bs (\_ -> return ()) | otherwise = CryptoFailed CryptoError_SharedSecretSizeInvalid --- | Compute the Diffie Hellman secret from a public key and a secret key +-- | Compute the Diffie Hellman secret from a public key and a secret key. +-- +-- This implementation may return an all-zero value as it does not check for +-- the condition. dh :: PublicKey -> SecretKey -> DhSecret dh (PublicKey pub) (SecretKey sec) = DhSecret <$> B.allocAndFreeze x448_bytes $ \result ->