cryptocoinjs / keccak

Keccak sponge function family
MIT License
87 stars 24 forks source link

Allow Uint8Array inputs #2

Closed jacogr closed 5 years ago

jacogr commented 6 years ago

Allow Uint8Array as input values as well, these can be iterated in the same way inside absorb (or update) as the Buffer.

dcousens commented 6 years ago

What situation are you in where Buffer is not equal to Uint8Array? Node?

fanatid commented 6 years ago

@jacogr are you want fix all libraries which you are using? https://github.com/ethereumjs/rlp/pull/16 Why not convert Uint8Array to Buffer before pass it?

fanatid commented 6 years ago

From other side, Hash#update allow not only string/Buffer. Maybe we should change crypto-browserify libraries... @dcousens ?

jacogr commented 6 years ago

The conversion between Uint8Array -> Buffer is a simple one, i.e. Buffer.from(u8a). However by skipping this (underlying inside the library the iteration of the data stays the same), it minimises the unneeded allocations that does happen when your are dealing mostly with Uint8Array (my specific case), i.e. no keccack(Buffer.from(data)) where I'm calling.

So yes, Buffer === Uint8Array (mostly), however Uint8Array !== Buffer (when passed in, needs a conversion).

Additionally, you are correct though, if we are attempting to strictly match Hash#update, the API is a bit wider than currently implemented. (And my PR falls short of expanding that completely)