RustCrypto Formats

repository·master·Indexed 43 days ago

https://github.com/rustcrypto/formats

A collection of specialized Rust crates for encoding and decoding cryptographic data formats. Includes implementations for ASN.1 DER, PEM (RFC 7468), CMS (RFC 5652), CRMF (RFC 4211), CMP (RFC 4210), and constant-time Base16, Base32, and Base64 encoding. Also provides tools for Object Identifier (OID) parsing and GSS-API security services.

Tokens
94.3K
Snippets
307
Records
425
Agent score
53%

What's inside RustCrypto Formats

  1. Overview of pem-rfc7468

    master

    The pem-rfc7468 crate is a pure Rust implementation of PEM Encoding as defined in [RFC 7468]. It is specifically designed for PKIX, PKCS, and CMS structures, providing a strict subset of the original Privacy-Enhanced Mail (PEM) encoding intended for cryptographic keys, certificates, and other messages.

    Key features include:

    • no_std support: The core implementation is no_std-friendly, requiring no heap allocations and avoiding unnecessary copies or temporary buffers.
    • Constant-time operations: Uses the base64ct crate for constant-time Base64 encoding/decoding, making it suitable for use with cryptographic private keys.
    • Security-focused parsing: The PEM parser is designed to avoid branching on potentially secret data to mitigate side-channel attacks.
    • Strict compliance: Implements the "ABNF (Strict)" subset of the grammar described in RFC 7468, focusing on interoperability by implementing MUSTs and SHOULDs while avoiding MAYs.
  2. Overview of RustCrypto Formats crates

    master
    The rustcrypto/formats repository is a collection of crates providing cryptography-related format encoders and decoders, such as PKCS and PKIX. These crates are designed to handle various data serialization and encoding standards used in cryptographic protocols.
  3. Overview of the `der` crate

    master

    The der crate provides a pure Rust, embedded-friendly implementation of the Distinguished Encoding Rules (DER) for Abstract Syntax Notation One (ASN.1), as described in ITU X.690. It is designed to be no_std/no_alloc friendly, making it suitable for environments without a heap.

    Key characteristics:

    • Canonicalization Checks: The decoder performs checks to ensure input documents are in canonical form. It will return errors if non-canonical productions are encountered; these checks cannot be disabled.
    • Heap Usage: The core implementation avoids heap usage. Convenience methods that perform allocation are gated behind the optional alloc feature.
    • Use Cases: It provides the subset of ASN.1 DER necessary for decoding/encoding various cryptography-related formats used by the RustCrypto project, such as CMS, PKCS#1, PKCS#8, X.509, and SEC1.
  4. Overview of PKCS#5 implementation

    master

    The pkcs5 crate is a pure Rust implementation of the Public-Key Cryptography Standards (PKCS) #5: Password-Based Cryptography Specification Version 2.1 ([RFC 8018]).

    It is used for deriving cryptographic keys from passwords and can be used to encrypt or decrypt data (such as PKCS#8 private keys) using those derived keys. The crate currently supports two key derivation algorithms:

    • scrypt
    • pbkdf2
  5. What is the sec1 crate used for?

    master

    The sec1 crate provides a pure Rust implementation of SEC1: Elliptic Curve Cryptography encoding formats. It is used for:

    • ASN.1 DER-serialized private keys: Encoding/decoding private keys as described in [RFC5915].
    • Elliptic Curve Point encoding: Implementing the Elliptic-Curve-Point-to-Octet-String and Octet-String-to-Elliptic-Curve-Point algorithms for converting between points and octet strings.
  6. Overview of Cryptographic Message Syntax (CMS) crate

    master

    The cms crate is a pure Rust implementation of the Cryptographic Message Syntax (CMS) as defined in [RFC 5652], [RFC 5911], and [RFC 3274].

    CMS is an IETF standard used for signing and/or encrypting data. It utilizes a certificate-based architecture to authenticate principals during the exchange of encrypted or signed messages. It is based on the syntax of PKCS #7 and is a foundational component for standards like S/MIME, PKCS#12, and the RFC 3161 digital timestamping protocol.

  7. Overview of base64ct

    master

    The base64ct crate provides a pure Rust implementation of Base64 ([RFC 4648]) designed for sidechannel resistance. It implements multiple Base64 alphabets using constant-time operations (avoiding data-dependent branches or lookup tables) to protect against leakage that could be used to extract cryptographic keys.

    Key features:

    • Constant-Time: Provides "best effort" constant-time operation for sidechannel resistance.
    • Environment Support: Supports no_std environments.
    • Memory Management: Core API avoids heap allocations, though optional alloc support is available.
    • Padding Rules: Padded variants require = padding; unpadded variants expressly reject it.
    • Whitespace: Whitespace is disallowed by default, except when using Decoder::new_wrapped or Encoder::new_wrapped for fixed-width line wrapping.
  8. Overview of base16ct

    master

    base16ct is a pure Rust implementation of Base16 (hexadecimal) encoding and decoding as defined in [RFC 4648]. It is designed for cryptographic use cases by providing portable "best effort" constant-time operations, avoiding data-dependent branches or lookup tables.

    Key features:

    • Constant-Time: Implements both lower and upper case Base16 variants without data-dependent branches or lookup tables.
    • Environment Support: Supports no_std environments.
    • Memory Management: The core API avoids heap allocations, though optional alloc support is available for convenience.