Giter Club home page Giter Club logo

rust-hpke's Introduction

rust-hpke

Version Docs CI Coverage

This is an implementation of the HPKE hybrid encryption standard (RFC 9180).

Warning

This crate has not been formally audited. Cloudflare did a security review of version 0.8, though:

The HPKE implementation we decided on comes with the caveat of not yet being formally audited, so we performed our own internal security review. We analyzed the cryptography primitives being used and the corresponding libraries. Between the composition of said primitives and secure programming practices like correctly zeroing memory and safe usage of random number generators, we found no security issues.

What it implements

This implementation complies with the HPKE standard (RFC 9180).

Here are all the primitives listed in the spec. The primitives with checked boxes are the ones that are implemented.

  • KEMs
    • DHKEM(Curve25519, HKDF-SHA256)
    • DHKEM(Curve448, HKDF-SHA512)
    • DHKEM(P-256, HKDF-SHA256)
    • DHKEM(P-384, HKDF-SHA384)
    • DHKEM(P-521, HKDF-SHA512)
  • KDFs
    • HKDF-SHA256
    • HKDF-SHA384
    • HKDF-SHA512
  • AEADs
    • AES-GCM-128
    • AES-GCM-256
    • ChaCha20Poly1305

Crate Features

Default features flags: x25519, p256.

Feature flag list:

  • x25519 - Enables X25519-based KEMs
  • p256 - Enables NIST P-256-based KEMs
  • serde_impls - Includes implementations of serde::Serialize and serde::Deserialize for all hpke::Serializable and hpke::Deserializable types
  • std - Includes an implementation of std::error::Error for HpkeError

For info on how to omit or include feature flags, see the cargo docs on features.

Tests

To run all tests, execute cargo test --all-features. This includes known-answer tests, which test against test-vector-COMMIT_ID.json,where COMMIT_ID is the short commit of the version of the spec that the test vectors came from. The finalized spec uses commit 5f503c5. See the reference implementation for information on how to generate a test vector.

Benchmarks

To run all benchmarks, execute cargo bench --all-features. If you set your own feature flags, the benchmarks will still work, and run the subset of benches that it is able to. The results of a benchmark can be read as a neat webpage at target/criterion/report/index.html.

Ciphersuites benchmarked:

  • NIST Ciphersuite with 128-bit security: AES-GCM-128, HKDF-SHA256, ECDH-P256
  • Non-NIST Ciphersuite with 128-bit security: ChaCha20-Poly1305, HKDF-SHA256, X25519

Functions benchmarked in each ciphersuite:

  • Kem::gen_keypair
  • setup_sender with OpModes of Base, Auth, Psk, and AuthPsk
  • setup_receiver with OpModes of Base, Auth, Psk, and AuthPsk
  • AeadCtxS::seal with plaintext length 64 and AAD length 64
  • AeadCtxR::open with ciphertext length 64 and AAD length 64

Usage Examples

See the client-server example for an idea of how to use HPKE.

Agility

A definition: crypto agility refers to the ability of a cryptosystem or protocol to vary its underlying primitives. For example, TLS has "crypto agility" in that you can run the protocol with many different ciphersuites.

This crate does not support crypto agility out of the box. This is because the cryptographic primitives are encoded as types satisfying certain constraints, and types need to be determined at compile time (broadly speaking). That said, there is nothing preventing you from implementing agility yourself. There is a sample implementation in the examples folder. The sample implementation is messy because agility is messy.

What's next

  • Add support for more KEMs
  • More examples

License

Licensed under either of

at your option.

rust-hpke's People

Contributors

rozbb avatar tgeoghegan avatar tomtau avatar marmeladema avatar xofyarg avatar daxpedda avatar

Forkers

siyengar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.