Skip to content

digest::Algorithm definitions are defined as static instead of const #904

@jsparj

Description

@jsparj

Security issue notifications

If you discover a potential security issue in AWS-LC for Rust we ask that you notify AWS Security via our
vulnerability reporting page. Please do not create a
public github issue, if in doubt contact AWS security first.

Problem:

digest::Algorithm definitions are static instead of const in aws-lc-rs/src/digest/sha/*.

That makes them:

  1. The digest::Algorithm definitions are not consistent with other algorithm definitions, like definitions for aead::Algorithm which use const correctly instead of static.
  2. Impractical to use.
    • They are not directly &'static referencable
    • Cannot be used to create const combinational definitiones
      (for example the following use case, this would result to better memory locality when using &'static references for algorithm bundles)
/// **See**: [RFC 8446 - B.4. Cipher Suites](https://www.rfc-editor.org/rfc/rfc8446#appendix-B.4)
pub struct Tls13CipherSuite {
    pub aead: aead::Algorithm,
    pub hash: digest::Algorithm,
}

impl Tls13CipherSuite {
    ///**See**: [RFC 5116 - 5.1. AEAD_AES_128_GCM](https://www.rfc-editor.org/rfc/rfc5116#section-5.1)
    pub const AES_128_GCM_SHA256: Self = Self {
        aead: aead::AES_128_GCM,
        hash: digest::SHA256   // <-- not possible now
    };
    ///**See**: [RFC 5116 - 5.2. AEAD_AES_256_GCM](https://www.rfc-editor.org/rfc/rfc5116#section-5.2)
    pub const AES_256_GCM_SHA384: Self = Self {
        aead: aead::AES_256_GCM,
        hash: digest::SHA3_384   // <-- not possible now
    };
    ///**See**: [RFC 8439 - ChaCha20 and Poly1305 for IETF Protocols](https://www.rfc-editor.org/rfc/rfc8439)
    pub const CHACHA20_POLY1305_SHA256: Self = Self {
        aead: aead::CHACHA20_POLY1305,
        hash: digest::SHA256   // <-- not possible now
    };
}
  1. static instead of const will also result in less optimal machine code since complier inlining is not possible for the underlying algorithm parameters.

Solution:

A description of the possible solution in terms of AWS-LC for Rust architecture. Highlight and explain any potentially
controversial design decisions taken.

  • Does this change any public APIs?

No.

  • Which algorithm(s) will this impact?

digest::Algorithm definitions in aws-lc-rs/src/digest/sha/*.

Requirements / Acceptance Criteria:

What must a solution address in order to solve the problem? How do we know the solution is complete?

  • RFC links: Links to relevant RFC(s)

None.

  • Related Issues: Link any relevant issues

None.

  • Will the Usage Guide or other documentation need to be updated?

None needed.

  • Testing: How will this change be tested? Call out new integration tests, functional tests, or particularly
    interesting/important unit tests.

None needed.

Out of scope:

Is there anything the solution will intentionally NOT address?

No.

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