Skip to content

Fix byte ordering#11

Open
thorsten-e wants to merge 1 commit into
lovesh:masterfrom
thorsten-e:master
Open

Fix byte ordering#11
thorsten-e wants to merge 1 commit into
lovesh:masterfrom
thorsten-e:master

Conversation

@thorsten-e

Copy link
Copy Markdown

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