Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto_generichash_blake2b_salt_personal has another result on x86 emulator #29

Open
samosudov opened this issue Sep 26, 2019 · 6 comments
Assignees
Labels
bug You've found something that definitely should not happen, e.g a crash in a critical part of the lib

Comments

@samosudov
Copy link

Hey!

Device: Android emulator Pixel 2 API 27 (x86)

I built a test app to demonstrate working the function.
https://github.com/samosudov/test-libsodium
I've got K variable after doing crypto_generichash_blake2b_salt_personal function. Results from a real device and from emulator are different.
Device:
K=[30, 124, 96, -39, 26, 25, -21, -24, -11, 38, -119, -118, -9, -119, 89, -7, 111, 66, -6, 41, 62, -78, -68, -60, -118, 33, -117, -58, 85, -110, 65, 102]
Emulator:
K=[2, 2, -20, -102, 39, 111, -117, 61, 29, -12, -19, 86, -106, -14, -127, -33, 41, -39, -65, 4, 110, -4, -34, 113, -86, -124, 32, 36, -50, 51, 83, 116]

dependencies:

implementation "com.goterl.lazycode:lazysodium-android:4.1.0@aar"
implementation "net.java.dev.jna:jna:5.4.0@aar"
@gurpreet- gurpreet- self-assigned this Sep 26, 2019
@gurpreet- gurpreet- added the bug You've found something that definitely should not happen, e.g a crash in a critical part of the lib label Sep 26, 2019
@gurpreet-
Copy link
Contributor

Does the real device have an architecture of x86 just like the emulator?

@samosudov
Copy link
Author

Can't check it. Have no real device

@gurpreet-
Copy link
Contributor

gurpreet- commented Nov 24, 2019

Hi just tested this on my device and emulator:

Real device: Samsung Galaxy S10, API 28 (64 bit)
K=[30, 124, 96, -39, 26, 25, -21, -24, -11, 38, -119, -118, -9, -119, 89, -7, 111, 66, -6, 41, 62, -78, -68, -60, -118, 33, -117, -58, 85, -110, 65, 102]
Emulator - Pixel 2, API 25 (32 bit)
K=[30, 124, 96, -39, 26, 25, -21, -24, -11, 38, -119, -118, -9, -119, 89, -7, 111, 66, -6, 41, 62, -78, -68, -60, -118, 33, -117, -58, 85, -110, 65, 102]

Seems to work for me!

Also why aren't you passing a masterKey parameter? As far as I'm aware, the Blake2b function is a key derivation function that puts the derived subkey into the subKey array that you provide.

@samosudov
Copy link
Author

samosudov commented Dec 2, 2019

I've checked on Emulator - Pixel 2, API 25 x86 (Android Studio emulator), but the result is the same as in my first message.
I implemented this functionality (https://github.com/str4d/librustzcash/blob/note-spending-v5/zcash_primitives/src/note_encryption.rs#L175). As I know there is no master key or it's empty.
I don't need to use masterkey, but I need to use a personal field.

What kind of emulator do you use, Genymotion?

@samosudov
Copy link
Author

@gurpreet-
Hi! I found an old device with Android Kitkat (4.4.2), which has the same result as my emulator.
It's BQS-4009 (with parameters Build.CPU_ABI = armeabi-v7a and Build.CPU_ABI2 = armeabi).
The result of the same code on the device is:

01-22 13:43:02.351 23299-23299/work.samosudov.testlibsodium D/tag: KDFSapling - K=[2, 2, -20, -102, 39, 111, -117, 61, 29, -12, -19, 86, -106, -14, -127, -33, 41, -39, -65, 4, 110, -4, -34, 113, -86, -124, 32, 36, -50, 51, 83, 116]

@gurpreet-
Copy link
Contributor

Hold on, crypto_generichash_blake2b_salt_personal says that if all the parameters are the same then it should have the same resulting K array. More info can be found here https://libsodium.gitbook.io/doc/key_derivation#key-derivation-with-libsodium-less-than-1-0-12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug You've found something that definitely should not happen, e.g a crash in a critical part of the lib
Projects
None yet
Development

No branches or pull requests

2 participants