aws-lc-rs

repository·main·Indexed 20 days ago

https://github.com/aws/aws-lc-rs

AWS Libcrypto for Rust provides high-performance, FIPS-compliant cryptographic operations by wrapping the AWS-LC library. It is designed as a drop-in, API-compatible replacement for the ring (v0.16) crate, intended for developers needing to meet US and Canadian government cryptographic requirements. The project includes aws-lc-fips-sys for low-level FIPS bindings and aws-lc-sys for linking against AWS-LC installations.

Tokens
25.1K
Snippets
94
Records
141
Agent score
68%

What's inside aws-lc-rs

  1. Overview of aws-lc-rs

    main

    What is aws-lc-rs?

    aws-lc-rs is a cryptographic library for Rust that uses AWS Libcrypto (AWS-LC) for its cryptographic operations.

    Key Features

    • API Compatibility: It is designed to be API-compatible with the ring library (specifically v0.16), allowing it to serve as a drop-in replacement.
    • FIPS Support: It is intended for developers who need to meet US and Canadian government cryptographic requirements (FIPS) while maintaining idiomatic and performant Rust code.
    • FFI Bindings: The library uses auto-generated Foreign Function Interface (FFI) crates—either aws-lc-sys or aws-lc-fips-sys—to bind to the underlying AWS-LC implementations.

    When to use it

    Use aws-lc-rs if you are currently using ring but need to deploy applications into AWS Regions that require FIPS-validated cryptography.

  2. Overview of AWS Libcrypto for Rust

    main

    AWS Libcrypto for Rust is a cryptographic library that uses AWS-LC for its cryptographic operations. It is designed to be an API-compatible, drop-in replacement for the ring (v0.16) library, specifically aimed at providing FIPS-validated cryptography for Rust developers who need to meet US and Canadian government requirements.

    It achieves this by using either the aws-lc-sys or aws-lc-fips-sys FFI crates to invoke the underlying AWS-LC implementation.

  3. Overview of aws-lc-fips-sys

    main

    The aws-lc-fips-sys crate provides autogenerated low-level AWS-LC FIPS bindings for the Rust programming language. It is designed to link against the AWS-LC-FIPS module that has completed FIPS validation testing and has been submitted to NIST for certification.

    Warning: This crate provides low-level bindings. Direct reliance on these bindings is not recommended for most users; instead, use higher-level crates like aws-lc-rs.

  4. Distribution requirements for FIPS builds on macOS

    main
    When building with the fips feature on macOS, the build process creates shared libraries (e.g., libaws_lc_fips_0_xx_yy_crypto.dylib and libaws_lc_fips_0_xx_yy_rust_wrapper.dylib). These shared libraries must be distributed alongside any executable that depends on aws-lc-rs.
  5. Configure automatic detection of system AWS-LC

    main

    When AWS_LC_SYS_SYSTEM_DIR is unset, the build script attempts to discover a usable AWS-LC using the following precedence:

    1. AWS_LC_SYS_SYSTEM_DIR: Explicit install prefix.
    2. OPENSSL_DIR: Install prefix.
    3. OPENSSL_INCLUDE_DIR and OPENSSL_LIB_DIR: Independent header and library directories.
    4. pkg-config (Unix only): Probes openssl, aws-lc, libcrypto, then libcrypto-awslc.

    Each OPENSSL_* variable also supports a target-suffixed form (e.g., OPENSSL_DIR_x86_64_unknown_linux_gnu).

    Requirements for a discovered install:

    • Must contain include/openssl/base.h (used to verify the OPENSSL_IS_AWSLC marker and version).
    • Must contain lib/ or lib64/ containing libcrypto (and libssl if the ssl feature is enabled).
    • Must satisfy the minimum version requirement (defined by MINIMUM_AWS_LC_VERSION).
    • Must provide usable bindings.
  6. Understand aws-lc-rs ring-compatibility differences

    main

    While aws-lc-rs aims for full compatibility with ring (v0.16.x), there are key differences to note:

    • Standard Library Requirement: aws-lc-rs requires the std library and does not support #[no_std] builds.
    • Platform Support: It supports platforms compatible with aws-lc-sys and AWS-LC.
    • PKCS#8 Parsing: Ed25519KeyPair::from_pkcs8 and Ed25519KeyPair::from_pkcs8_maybe_unchecked support both v1 and v2 PKCS#8 documents. For v2 documents, the public key component (if present) is verified against the derived private key.
  7. Manage AWS-LC FIPS version compatibility

    main

    The crate requires a minimum AWS-LC FIPS module version (an integer identifying a validation submission). Currently, the minimum supported version is 3.

    To ensure you are using the correct version of the FIPS module, refer to the following compatibility mapping:

    AWS-LC-FIPS moduleaws-lc-rs
    2.0.x<1.12.0
    3.0.xlatest

    If you need to remain on a specific version of the AWS-LC-FIPS module for compliance, you should pin your aws-lc-rs dependency to a compatible version in your Cargo.toml.

    To bypass the version check (not recommended), set the environment variable AWS_LC_FIPS_SYS_SYSTEM_SKIP_VERSION_CHECK=1.

  8. Understanding Bindgen requirements for aws-lc-rs

    main

    Whether you need bindgen installed depends on which crate you are using and whether pre-generated bindings are available for your platform.

    • For aws-lc-rs users (Non-FIPS): You do not need bindgen. aws-lc-rs uses pre-generated "universal" bindings that work across all supported platforms.
    • For aws-lc-sys direct users: If you depend on aws-lc-sys directly rather than through aws-lc-rs, it defaults to target-specific bindings, which may require bindgen.
    • For FIPS (aws-lc-fips-sys) users: bindgen is required for most targets. It is only unnecessary if your specific target platform is included in the limited set of targets with pre-generated FIPS bindings.
  9. Compare aws-lc-rs and ring

    main
    While aws-lc-rs aims for API compatibility with ring v0.16, there are implementation differences. Users migrating from or using ring should consult the ring-compatibility section in the aws-lc-rs API reference guide to identify these differences.
  10. Understanding the AWS Libcrypto crates

    main

    The project is composed of several crates with different levels of abstraction:

    • aws-lc-rs: The primary high-level crate. It is a ring-compatible crypto library that uses AWS-LC. This is the crate most end-users should use.
    • aws-lc-sys: Low-level, autogenerated FFI bindings for AWS-LC. Direct use is not recommended.
    • aws-lc-fips-sys: Low-level, autogenerated FFI bindings providing FIPS support (specifically AWS-LC-FIPS 3.x). This crate is used for FIPS-compliant requirements. Direct use is not recommended.
  11. Understand the motivation for aws-lc-rs

    main
    The aws-lc-rs library is designed as a drop-in replacement for the ring (v0.16) library. Its primary goal is to provide FIPS-validated cryptography in an idiomatic and performant Rust interface. It is specifically intended for developers who need to meet US and Canadian government cryptographic requirements while maintaining compatibility with the ring API.