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

Use BitLength for all bit-denoted lengths #350

Closed
briansmith opened this issue Nov 15, 2016 · 4 comments
Closed

Use BitLength for all bit-denoted lengths #350

briansmith opened this issue Nov 15, 2016 · 4 comments

Comments

@briansmith
Copy link
Owner

See also #345, 346, #347.

Without the compiler supporting const fns, we are limited in the contexts in which we can use BitLength. @samscott89 noted that we may be able to make BitLength a newtype struct BitLength(usize), which might be able to let us use it in more contexts before const fns are available. That sounds good to me, but we should add some TODO comments about reversing that once we have const fns.

Similarly, we have code like this for converting from bits to bytes:

                public_key_len: 1 + (2 * (($bits + 7) / 8)),
                elem_and_scalar_len: ($bits + 7) / 8,

We could define a bits_as_bytes_rounded_up! macro that would allow us to write:

                public_key_len: 1 + (2 * bits_as_bytes_rounded_up!($bits)),
                elem_and_scalar_len: bits_as_bytes_rounded_up!($bits),

Again, if we do that then we should have a TODO to remove the macro when const fns are available.

@briansmith
Copy link
Owner Author

Searching for "8 ", " 8", "+ 7", and "/ 8" is a good way to find relevant code.

@briansmith
Copy link
Owner Author

Also, it's a good idea to update STYLE.md to mention the conventions for using BitLength, assuming usize-typed lengths are in bytes, using the _len/_LEN suffix for byte-delineated lengths, and using the _bits/_BITS suffix for lengths delineated in bits.

@pietro
Copy link
Contributor

pietro commented Jan 15, 2019

Some work done on the branch mentioned on #346. If you're ok with that I'll go after the "/ 8" left in the codebase.

@briansmith
Copy link
Owner Author

In order to do this completely we'd need to handle non-usize types, especually u64 for SHA-256/SHA-384/SHA-512, and unsigned for GFp_AES_set_encrypt_key`.

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

No branches or pull requests

2 participants