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

Fix byte ordering #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix byte ordering #11

wants to merge 1 commit into from

Conversation

thrsten
Copy link

@thrsten thrsten commented Dec 31, 2022

Hi! If I'm not mistaken the Scalar struct seems to represent values internally as little endian (cf. https://docs.rs/curve25519-dalek/3.2.1/curve25519_dalek/scalar/struct.Scalar.html#). After decoding the hex string, I think the bytes need to be reversed before creating the scalar.

For example, in this snippet Scalar would represent 1 as 0x01..00 rather than 0x00..01

let one: u64 = 1;
let s_one = Scalar::from(one);

let bytes_one = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
let s_bytes_one = Scalar::from_bytes_mod_order(bytes_one);

let bytes_one_reverse = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let s_bytes_one_reverse = Scalar::from_bytes_mod_order(bytes_one_reverse);
    
assert!(s_one != s_bytes_one);
assert!(s_one == s_bytes_one_reverse);

Let me know if you have any questions (or disagree) and thanks for publishing your artifacts!!

Thorsten

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

Successfully merging this pull request may close these issues.

1 participant