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

Integer endianness #157

Closed
BasileiosKal opened this issue May 26, 2022 · 8 comments · Fixed by #241
Closed

Integer endianness #157

BasileiosKal opened this issue May 26, 2022 · 8 comments · Fixed by #241
Labels
core Associated to the core spec ready-for-pr
Milestone

Comments

@BasileiosKal
Copy link
Contributor

As noted by @mikelodder7, in the document we don't yet discuss the integers (i.e., scalars mod r) serialization. More specifically, since we have a description for the byte length of those integers (octet_scalar_length), what is missing is the byte order.

In general i thing little-endian is preferred (it is mostly used in bls libs like the rust crate and blst) but an issue is that I2OSP uses big-endian if im not mistaken.

There are 3 options i can think of;

  1. We describe them as 32 bytes (or octet_scalar_length in general) in little-endian, with a note for I2OSP.
  2. We describe them in a way similar to some libs (i.e., four 64 bit parts in little-endian order), but i don't think something like that is suitable.
  3. We leave it up for implementers with some notes for guidance.

At the moment I'm leaning more towards option 3. Implementations may elect to use any kind of optimization and this will allow for that.

Also for what i know of, other specs like ecdsa and eddsa elect to define the integer's endianness but specs like bls-sigs and h2c adopt option 3, so it does not seem to be any "absolutely correct" way to do that.

@BasileiosKal BasileiosKal changed the title Integer serialization Integer endianness May 26, 2022
@tplooker tplooker added the core Associated to the core spec label May 27, 2022
@BasileiosKal
Copy link
Contributor Author

BasileiosKal commented Jun 28, 2022

Discussed in the WG call on 2022-06-27. The direction decided is to check available implementations and either ad a note in the definition of OS2IP and I2OSP, describing that they operate in big-endian order (like H2C) or define a scalar_to_octets operation, that on input a scalar will return an octet string in litle-endian order (just a definition possible with no explicit procedure).

@tplooker
Copy link
Member

tplooker commented Aug 8, 2022

Discussed on WG call 8th of august, there is currently ambiguity around the endianness of scalar_to_octets that needs to be resolved.

@tmarkovski
Copy link
Member

I ran into this issue as I was going through spec implementation and validating against the provided fixtures. Has there been a decision made? I think at minimum, the fixtures should specify the byte order of the scalar.

@mikelodder7
Copy link
Contributor

In practice, not a decision here, whenever hexits or base64 are given it represents big endian.

@mikelodder7
Copy link
Contributor

If we give the actual bytes then little endian is preferable

@tmarkovski
Copy link
Member

If we give the actual bytes then little endian is preferable

The SignatureToOctets does give the actual bytes and for scalars it refers to i2osp which specifies them as big-endian. Do you propose that we use little-endian instead for the signature and proof composition?

@mikelodder7
Copy link
Contributor

Let me clarify, in a spec if they give the actual byte sequence it’s almost always little endian, but when encoded like hex or base64, it’s big endian. Since we rarely give the actual byte sequence, I’d propose to use big endian hexits

@tplooker
Copy link
Member

Related to updates in #221

@tplooker tplooker added this to the draft-02 milestone Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Associated to the core spec ready-for-pr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants