On Sat, 2012-02-18 at 20:42 +0100, Arturo Filastò wrote: > On Feb 18, 2012, at 8:16 PM, [email protected] wrote: > > > Hello Fabio, > > > > Clipperz's implementation does not use typed array, as they are too > > new and too little supported for our target. > > > > But Clipperz is wrapping all the binary data manipulation into an > > abstract BinaryArray class [1]. This abstract class had a few > > different implementations, one using untyped arrays, another using > > regular strings and a third one using hex strings. The hex string > > implementation performed very badly, and also the string one was not > > working great, so at the moment only the array based implementation is > > left. > > > > Yeah a custom BinaryArray class i generally the way to do it. Also sjcl the > stanford crypto library does that. > > https://github.com/bitwiseshiftleft/sjcl/blob/master/core/bitArray.js
Beware because if you use typed arrays wrapped in another object and access through an accessor (.byteAtIndex(...)) you could lose the advantages. I'm not completely sure, but if you don't see a performance gain this could be the reason. I've tried to use typed array with SJCL but it's harder than what you think, as they store the length in bit of partial word after the 32nd bit. And if you use a typed array all the information after that bit gets lost. Here's their perverse way of storing the length of a partial word: https://github.com/bitwiseshiftleft/sjcl/blob/master/core/bitArray.js#L114 It took me half day to understand what they were trying to do. I tried to put up an alternative solution compatible with typed arrays. Basically I was boxing the partial word in a Number object and adding a property .bitLength, however there are some problems and currently I'm very busy. > > But it would be trivial to add another implementation based on typed > > arrays; and it would also be possible to have both implementations > > available, and selecting the right one based on the browser where the > > code is going to be executed. > > > > It may be a good idea to have a default that goes for typed arrays and fails > over to a generally compliant version. > > I would consider the fact for Clipperz to use already existing open source > javascript > libraries for handling the crypto. It's bad to reinvent the wheel. > > SJCL is very widely used and academically studies it might be a good idea to > switch to that. I definitely agree. From my performance test they always win over other libraries. I'll share my results with you as soon as I've some spare time. Bye! venom00 _______________________________________________ http://openpgpjs.org

