Re: [Haskell-cafe] Re: Crypto-API is stabilizing

On Sat, Sep 4, 2010 at 3:23 AM, Heinrich Apfelmus
A better reason is the data structure has no way to implement generateKeyPair.
That's a non-problem: each algorithm (RSA, DSA, ...) implements a function with the same type as generateKeyPair . Compare
rsa :: RangomGen g => BitLength -> g -> ((Key,Key), g)
vs
((k1 :: RSA, k2), g') = generateKeyPair g
You always have to write down the name of the algorithm ("RSA") when using generateKeyPair , so you may as well drop it entirely.
That simply isn't true. What if you have a key exchange in which the ephemeral key is of the same type as your signing key? Slightly contrived example: buildAgreementMessage :: (Monad m, CryptoRandomGen g, ASymetricCipher k) => g -> k -> m (B.ByteString,g) buildAgreementMessages g k = do (e,g') <- liftM eitherToFail (buildAsymKey g `asTypeOf` k) let eBS = encode e msg = runPut (putByteString agreementHeader >> putWord16be (B.length eBS) >> putByteString eBS) return msg

Sorry, the example was all messed up, even if it did communicate what
I wanted its just so broken I must fix.
Slightly contrived example:
buildAgreementMessage :: (Monad m, CryptoRandomGen g,
ASymetricCipher k) => g -> k -> m (B.ByteString, (k,k), g)
buildAgreementMessages g k = do
((p,q),g') <- eitherToFail (buildKeyPair g)
let pBS = encode p
msg = runPut $ do
putByteString agreementHeader
putWord16be (B.length pBS)
putByteString pBS
return $ (sign msg k, (p,q), g')
Again, this is simply trying to re-enforce the fact that buildKeyPair
(formerly 'generateKeyPair') does have a place.
Cheers,
Thomas
On Sat, Sep 4, 2010 at 7:45 AM, Thomas DuBuisson
Slightly contrived example:
buildAgreementMessage :: (Monad m, CryptoRandomGen g, ASymetricCipher k) => g -> k -> m (B.ByteString,g) buildAgreementMessages g k = do (e,g') <- liftM eitherToFail (buildAsymKey g `asTypeOf` k) let eBS = encode e msg = runPut (putByteString agreementHeader >> putWord16be (B.length eBS) >> putByteString eBS) return msg

Thomas DuBuisson wrote:
Sorry, the example was all messed up, even if it did communicate what I wanted its just so broken I must fix.
Slightly contrived example:
buildAgreementMessage :: (Monad m, CryptoRandomGen g, ASymetricCipher k) => g -> k -> m (B.ByteString, (k,k), g) buildAgreementMessages g k = do ((p,q),g') <- eitherToFail (buildKeyPair g) let pBS = encode p msg = runPut $ do putByteString agreementHeader putWord16be (B.length pBS) putByteString pBS return $ (sign msg k, (p,q), g')
Again, this is simply trying to re-enforce the fact that buildKeyPair (formerly 'generateKeyPair') does have a place.
Granted. However, the key feature of your example is that a new key is derived from an old key, i.e. the function used is type BuildKeyPair g k = CryptoRandomGen g => g -> ((k,k),g) buildKeyPair' :: k -> BuildKeyPair g k Thanks to the additional argument, this can be added to the Key record data Key = Key { cipher :: BuildKeyPair g k , ... } In other words, the Key can also store a method to generate new keys with the same cipher algorithm. All examples that use buildKeyPair and type classes can be reformulated in terms of Key with this additional field. That's because buildKeyPair actually expects a type argument; the cipher filed merely shifts that argument to the value level. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com
participants (2)
-
Heinrich Apfelmus
-
Thomas DuBuisson