Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Key derivation using XOR (^) instead of power function #69

Open
guilhermeavanci opened this issue Jan 27, 2022 · 2 comments
Open

Key derivation using XOR (^) instead of power function #69

guilhermeavanci opened this issue Jan 27, 2022 · 2 comments

Comments

@guilhermeavanci
Copy link

Hi guys!

I recently moved an app to Flutter 2.x, and with that updated the flutter_sodium to the most up-to-date version.

After the update I started getting an RangeError coming from the library. Following the functions' calls I faced what I believe to be the issue. Just to clarify, here is the step-by-step:

KeyDerivation.derive (src/key_derivation.dart) -> cryptoKdfDeriveFromKey (src/sodium.dart) -> RangeError.checkValueInInterval(subkeyId, 0, (2 ^ 64) - 1, 'subkeyId')

The code checks here if subkeyId fit in the interval between 0 and (2 ^ 64) - 1.

Something was off about this error, so I made some research and concluded it's a typo in the max value of the range, probably came from the official sodium key derivation docs or something like that. In this page we have the identical math operation: subkey_id can be any value up to (2^64)-1.

Apparently the end of the interval is erroneous represented here using the math notation instead of dart language notation, which means the ^ character is a bitwise XOR instead of the math operation power, which I suppose should be the correct thing to do here. Btw, the result of (2 ^ 64) - 1 is always 65.

Anyway, here is the issue. Can you guys confirm? I hope I'm not being blind about something and opening an issue with no need.

@guilhermeavanci
Copy link
Author

Maybe we can't just use a power function to solve that, but to get the biggest number we can use ~(1 << 63). Sadly it won't work in 32 bits systems, like Javascript probably.

@guilhermeavanci
Copy link
Author

We can also use -1 >>> 1 to get the max int value for the current system, but I don't believe that's what you guys want, right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant