Skip to content

Replace repeated integer literals with constants #830

@tarcieri

Description

@tarcieri

I think it would be good to add some more constants in places where integer literals are frequently repeated, and ideally establish a naming pattern that can be reused across types/backends (and also shared by ed448-goldilocks, ideally). Some examples:

  • 32 is used all over the place (along with [u8; 32]) as the serialized size in bytes of a compressed coordinate, either an Edwards y-coordinate or a Montgomery-x/u coordinate.
  • The number of limbs and number of bits-per-limb in the unsaturated representations of field elements, e.g. 5 and 51-bits for the 64-bit field implementations, with up to a 54-bit capacity (cc @kayabaNerve)

In particular I'd like to see [u8; CONSTANT1], [u32; CONSTANT2], [u64; CONSTANT3] in places where there are currently [u8; 32], [u32; 10], and [u64; 5], and e.g. loops bounded on constants instead of integer literals. Perhaps we could come up for type aliases for e.g. [u8; 32] that's frequently found in the external API.

For ed25519-dalek perhaps we could migrate some of the freestanding constants like PUBLIC_KEY_LENGTH and SECRET_KEY_LENGTH to inherent constants like SigningKey::LENGTH or SigningKey::SIZE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions