
Does anyone have experience with the crypto-api package? It seems to define a nice common API for block ciphers, hash functions and prng's. However, I get very low performance using it. I ran its benchmark on a NOP block cipher, where encryptBlock k = id, and it's still very slow. After expanded the included block cipher benchmark (which uses ECB) to include CBC and CTR I got the following: ECB: 30 MB/s -- somewhat slow CBC: 12 MB/s -- very slow CTR: 4 MB/s -- why is adding a counter so bad? Have anyone else benchmarked this and if so with what results? Are there any other high level crypto API? Here's my benchmark code for CTR (easily modified to use ECB/CBC): https://gist.github.com/954093 And here's my patched Benchmark/Crypto.hs: https://gist.github.com/954099 Package in question: http://hackage.haskell.org/package/crypto-api -- Johan Brinch, Dept. of Computer Science, University of Copenhagen

On Tuesday 03 May 2011 22:05:17, Johan Brinch wrote:
Does anyone have experience with the crypto-api package?
It seems to define a nice common API for block ciphers, hash functions and prng's. However, I get very low performance using it.
I ran its benchmark on a NOP block cipher, where encryptBlock k = id, and it's still very slow.
After expanded the included block cipher benchmark (which uses ECB) to include CBC and CTR I got the following: ECB: 30 MB/s -- somewhat slow CBC: 12 MB/s -- very slow CTR: 4 MB/s -- why is adding a counter so bad?
Have anyone else benchmarked this and if so with what results?
Neither benchmarked nor used it, but just to make sure: did you notice that the comment says 128KB strings for ps and lps, but they are in fact 1MB strings: -- 128KB strings ps = B.replicate (2^20) 0 lps = L.replicate (2^20) 0 ? If not, the throughput would look much better, wouldn't it?

On Tue, May 3, 2011 at 23:14, Daniel Fischer
did you notice that the comment says 128KB strings for ps and lps, but they are in fact 1MB strings:
-- 128KB strings ps = B.replicate (2^20) 0 lps = L.replicate (2^20) 0
? If not, the throughput would look much better, wouldn't it?
Ah, I failed to mention this in my previous mail. I changed the test values from 128KB to 1MB to see if it would help the throughput (by lowering overhead in the framework). So I've already compensated for this in the MB/s calculations. Nice catch, though :-) -- Johan Brinch

Also, it appears that crypto-api needs vast amounts of memory when compiled with optimization enabled. The latest version 0.6.1 is effectively unbuildable on my EeePC, which has only 1GB RAM. That property is fairly undesirable for a library package. Take care, Peter

While I haven't investigated myself, from seeing haskell build processes in the past this is almost certainly not crypto-api's fault and is in fact your linker's fault. If you are not using it already, try switching to gold over ld, it may help. --Matthew Maurer On 05/04/2011 04:27 AM, Peter Simons wrote:
Also, it appears that crypto-api needs vast amounts of memory when compiled with optimization enabled. The latest version 0.6.1 is effectively unbuildable on my EeePC, which has only 1GB RAM. That property is fairly undesirable for a library package.
Take care, Peter
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Matthew,
While I haven't investigated myself, from seeing haskell build processes in the past this is almost certainly not crypto-api's fault and is in fact your linker's fault. If you are not using it already, try switching to gold over ld, it may help.
well, memory consumption sky-rockets while compiling "Crypto.CPoly". That behavior is probably not related to the linker. Take care, Peter

On Thu, May 05, 2011 at 11:56:42AM +0200, Peter Simons wrote:
Hi Matthew,
While I haven't investigated myself, from seeing haskell build processes in the past this is almost certainly not crypto-api's fault and is in fact your linker's fault. If you are not using it already, try switching to gold over ld, it may help.
well, memory consumption sky-rockets while compiling "Crypto.CPoly". That behavior is probably not related to the linker.
That's more than likely linked to the huge dispatch table related to cpoly. It would probably helps to build a vector with the data instead of this. -- Vincent

On Tue, May 3, 2011 at 22:05, Johan Brinch
Does anyone have experience with the crypto-api package?
It seems to define a nice common API for block ciphers, hash functions and prng's. However, I get very low performance using it.
I ran its benchmark on a NOP block cipher, where encryptBlock k = id, and it's still very slow.
After expanded the included block cipher benchmark (which uses ECB) to include CBC and CTR I got the following: ECB: 30 MB/s -- somewhat slow CBC: 12 MB/s -- very slow CTR: 4 MB/s -- why is adding a counter so bad?
Have anyone else benchmarked this and if so with what results? Are there any other high level crypto API?
Here's my benchmark code for CTR (easily modified to use ECB/CBC): https://gist.github.com/954093
And here's my patched Benchmark/Crypto.hs: https://gist.github.com/954099
Package in question: http://hackage.haskell.org/package/crypto-api
Would there be anything wrong / really ugly in simply pushing those small bottlenecks into C code? Stuff like xor'ing two bytestrings or generating a block of incremental IV's (for CTR mode)? -- Johan Brinch

On Tue, May 10, 2011 at 09:47, Johan Brinch
Stuff like xor'ing two bytestrings or generating a block of incremental IV's (for CTR mode)?
I don't particularly like the notion of XOR on a bytestring. The bytestring is not a number and it does not make much sense to bitwise xor such a string. I'd rather have a type specifically tailored for doing crypto-style computations and then use it. Such that the underlying implementation can be repa, bytestring, supermegavectorizationistic, or something completely different. -- J.

On Tue, May 10, 2011 at 11:14, Jesper Louis Andersen
On Tue, May 10, 2011 at 09:47, Johan Brinch
wrote: Stuff like xor'ing two bytestrings or generating a block of incremental IV's (for CTR mode)?
I don't particularly like the notion of XOR on a bytestring. The bytestring is not a number and it does not make much sense to bitwise xor such a string. I'd rather have a type specifically tailored for doing crypto-style computations and then use it. Such that the underlying implementation can be repa, bytestring, supermegavectorizationistic, or something completely different.
Well, the need for extracting the underlying char pointer to call the c function does limit possible abstraction of the data structure somewhat. Of course, one could make a type class providing unpack/pack functions for extracting the pointer and rebuilting the Haskell value. Of course, this was never meant as part as anything, but a low level crypto lib for high level crypto libs to use. It's not meant for regular usage. -- Johan Brinch
participants (6)
-
Daniel Fischer
-
Jesper Louis Andersen
-
Johan Brinch
-
Matthew Ryan Maurer
-
Peter Simons
-
Vincent Hanquez