vincenthz / hs-cipher-aes

DEPRECATED - use cryptonite - a comprehensive fast AES implementation for haskell that supports aesni and advanced cryptographic modes.
Other
21 stars 15 forks source link

Provide means of serializing keys #10

Closed snoyberg closed 11 years ago

snoyberg commented 11 years ago

In trying to upgrade clientsession to work with cryptocipher 0.4.0, I ran up against the fact that there is no Serialize instance available, and seemingly no way to make one. What I'm really trying to do is just recreate the previous AES256 datatype. You can see my initial work here:

https://github.com/yesodweb/clientsession/commit/21038d04b31bb3e1573c33bcd29558bf628b401a

Do you have any recommendations for how to proceed?

Pinging @meteficha as well in case he has some ideas.

meteficha commented 11 years ago

It's easy to add serialization support for the keys. Actually, using GeneralizedNewtypeDeriving I guess we may just deriving (Serialize).

However, I don't really like not having support for crypto-api anymore on crypto-cipher, it seems as a step backwards. I understand that the performance may be worse, but this should be a reason to document the performance characteristics of each interface, not to remove one of them.

meteficha commented 11 years ago

@snoyberg, on the clientsession side we may directly use cipher-aes's interface as well instead of using it via crypto-api. This won't solve the serialization problem but will avoid needing to define the relevant instances ourselves and possibly be faster. At a glance, it seems that we'll just need to use encryptCTR.

vincenthz commented 11 years ago

quick reply during lunch break, sorry can't elaborate much:

edit: just corrected a typo "2.16ns" is actually "2.16us" in aes128 1024 bytes.

TomMD commented 11 years ago

WRT crypto-api. I will be adding the modes as overridable methods of the BlockCipher class, thus answering the performance concern. This isn't to suggest there is anything wrong with just using the interface specific to the algorithm you know you want.

vincenthz commented 11 years ago

@TomMD good news !

vincenthz commented 11 years ago

@meteficha @snoyberg there's now a (weirdly called) keyOfCtx which take a Key and return the original key used. For the name, Key is going to be renamed to Ctx eventually when i get around to it.

snoyberg commented 11 years ago

Thanks!

TomMD commented 11 years ago

Following up: I have released a new version of crypto-api that includes the modes of operation as methods of the BlockCipher class. I had wanted to keep the code inside of Cipher.Modes, but found some corner cases with GHC and mutually recursive modules so had to do more significant refactoring.