-
Notifications
You must be signed in to change notification settings - Fork 139
Conversation
* Use TypeFamilies; need to see what to do for older GHC versions * Start implementing some API related to ECIES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's the right thing to do. if you really need the PRK in binary format, you should make it part of ByteArrayAccess / ByteArray class
encodePoint :: Point curve -> ByteString | ||
decodePoint :: ByteString -> Point curve | ||
|
||
instance {-# OVERLAPPABLE #-} Show (Point a) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like the ugly conclusion of having the associated type as newtype instead of types; really shouldn't be here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea on how to make Point
an instance of ByteArrayAccess
.
Would you show me code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment for instance
rather than encodePoint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point
and Scalar
should be instance of Eq
and Show
because upper layer data structures in tls
require so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea on how to make Point
and Scalar
instances of Eq
and Show
except this approach.
decodeECPoint :: ByteString -> (Integer,Integer) | ||
decodeECPoint mxy = (x,y) | ||
where | ||
xy = B.drop 1 mxy -- dropping 4 (uncompressed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it really really shouldn't be a drop 1. at the very least it should be a case that check for 4, and put a note for the 2,3 format. Also this shouldn't use ByteString
but should do things through the ByteArray / ByteArrayClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
-- | Pseudo Random Key | ||
data PRK a = PRK (HMAC a) | PRK_NoExpand ScrubbedBytes | ||
deriving (Eq) | ||
|
||
instance Show (PRK a) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should have a Show instance for security reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
show (PRK hm) = show (hmacGetDigest hm) | ||
show (PRK_NoExpand sb) = show sb | ||
|
||
toByteString :: PRK a -> BS.ByteString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ByteArray / ByteArrayAccess not direct use of ByteString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -110,3 +119,22 @@ foreign import ccall "cryptonite_curve25519_donna" | |||
-> Ptr Word8 -- ^ secret | |||
-> Ptr Word8 -- ^ basepoint | |||
-> IO () | |||
|
|||
generateSecretKey :: MonadRandom m => m SecretKey | |||
generateSecretKey = return $ unsafeDoIO $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you really don't want to put things into a bytestring and then moved it to a Scrubbed bytes. it does defeat the purpose. getRandomBytes should gives you Scrubbed Bytes too if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Now |
All issues except one, which I cannot solve, are fixed. |
Note that those patches are tested with the |
now tracked by #114 |
This patches extend the rebased
ecc
branch to support ECDH, P384 and X25521.I confirmed that this can be use in the
tls
library.This also extends PRK which is necessary to implement TLS1.3.
Please give me comments.