Skip to content

Use BitLength for all bit-denoted lengths #350

Closed

Description

@briansmith

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.

Activity

  1. briansmith commented on Nov 15, 2016

    @briansmith
    OwnerAuthor

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

  2. briansmith commented on Nov 15, 2016

    @briansmith
    OwnerAuthor

    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.

  3. pietro commented on Jan 15, 2019

    @pietro
    Contributor

    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.

  4. briansmith commented on Mar 25, 2019

    @briansmith
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions