drand / tlock-js

Timelock Encryption made practical. A Typescript library for encrypting for the future.
Other
94 stars 8 forks source link

avoid nonce reuse for large payloads #11

Closed CluEleSsUK closed 1 year ago

CluEleSsUK commented 1 year ago

due to using a counter size of 32bits in the stream cipher, only up to 256TB may be encrypted before a nonce reuse would occur. This solution checks if the counter has reached the limit on every increment. This may add overhead or may be free on some engines and I haven't benchmarked it

CluEleSsUK commented 1 year ago

Converting to a draft so nobody merges it until I'll I've done some perf testing

CluEleSsUK commented 1 year ago

So I've successfully tested this with a payload of 2^28 chars. Theoretically V8 should be able to handle 2^29 - 24 chars, but when I try with this I get the error Error: Cannot create a string longer than 0x1fffffe8 characters... which equates to 2^29 -24 haha. Tried a few lower just in case it's a funky bounds check, but to no avail.

Either way, I think this is a reasonable limitation for now.

If people have a use case for encrypting massive payloads they may have to resort to the go lib or do some fiddling themselves.