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

write_bigint_bytes: strip leading 0s (and also sometimes leading 255s) #69

Merged
merged 1 commit into from Apr 6, 2023

Conversation

est31
Copy link
Collaborator

@est31 est31 commented Apr 6, 2023

This stripping is required, some parsers don't like these leading numbers.

This stripping is required, some parsers don't like these leading numbers.
@est31
Copy link
Collaborator Author

est31 commented Apr 6, 2023

Quoting X.690 here, section 8.3.2:

If the contents octets of an integer value encoding consist of more than one octet, then the bits of the first octet
and bit 8 of the second octet:

  • a) shall not all be ones; and
  • b) shall not all be zero

For the check to remove leading 0 bytes, we don't look at the highest bit of the next octet because otherwise, if that bit is one, we'd not remove the leading 0 and confuse the entire value with a 0 further below. There is no problem in not checking the highest bit because even if it is 1, and the removal was "illegal", the code below re-adds a leading 0.

For the check to remove leading 255 bytes, we only do it if the positive flag is unset; otherwise we'd get into trouble in situations where we have removed any leading 0 but were going to add it back in code below: [0, 255, 255] is supposed to be a fixpoint as that encodes 65535. We do the highest bit checking there because otherwise we might remove a leading 255 when we shouldn't.

@est31 est31 merged commit f2d48e6 into qnighy:master Apr 6, 2023
4 checks passed
@est31 est31 mentioned this pull request Apr 6, 2023
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.

None yet

1 participant