Skip to content
webcpporgPublic

About

Authenticated encryption, randomness and secp256k1 for C++20 on every target, over BearSSL, OpenSSL, ctaes and libsecp256k1.

Resources

Stars

0 stars

Watchers

0 watching

Forks

crypto

crypto gives a C++20 program the cryptographic primitives that Boost does not provide, on every target webcpp has: native (Linux, macOS, Windows with MSVC), wasip2, wasip3 and Emscripten.

  • webcpp::crypto: a random_device that reads the operating system's or the browser's generator, and error, every failure's value. The constant-time comparison (constant_time_equal), the erasure of a buffer (erase_secret) and the self-wiping secret<N> crypto returns are webcpp::secure's, which crypto depends on.
  • webcpp::crypto::ciphers: AES-GCM (gcm, aes128_gcm, aes256_gcm) with keys of 16, 24 and 32 bytes, the AES block cipher (aes128, aes192, aes256) and the ChaCha20-Poly1305 AEADs.
  • webcpp::crypto::secret_key_encryption: NaCl's and libsodium's secret boxes (secretbox, secretbox_xchacha20poly1305), and the AEAD contract, aead::cipher and the free aead::seal and aead::open of every AEAD.
  • webcpp::crypto::curves::secp256k1: BIP 340 Schnorr and ECDSA signatures, their verification, ECDH, ECDSA's strict DER and low-S forms, and the x-only tweak.
  • webcpp::crypto::curves::ed25519: Ed25519 signatures (RFC 8032) with canonical verification, the conversion of a key pair and of a public key to X25519's typed keys, to_x25519(), and Ed25519ph over SHA-512 for a message given in pieces.
  • webcpp::crypto::curves::x25519: X25519 key agreement (RFC 7748), refusing an all-zero shared secret, with a peer known by its Ed25519 key once its to_x25519() converts it.
  • webcpp::crypto::curves::p256: P-256's ECDSA signatures over SHA-256, low S or any S as the verification policy says, and its ECDH, on BearSSL natively and on WebCrypto in a browser.
  • webcpp::crypto::formats: every curve's keys and signatures in their formats, as OpenSSL, WebCrypto and node write them, through codecs::encode and codecs::decode (crypto has no verbs of its own; its types are declared to codecs): a key's raw bytes with its point forms, RFC 5480's and RFC 8410's SPKI, PKCS#8, an ECDSA signature's strict DER, and the PEM of the SPKI and PKCS#8, formats::pem, codecs' armor over the DER with its label in its type, each decoded strictly, and an input past a format's bound refused as codecs::error::input_too_long.
  • webcpp::crypto::public_key_encryption: NaCl's and libsodium's boxes between two key pairs (box, box_xchacha20poly1305), refusing a peer key of small order, sealed boxes (sealed_box), anonymous encryption to a public key, and RFC 9180's HPKE (hpke::suite), composed from X25519 or P-256, webcpp::hash's HKDF and AES-GCM or ChaCha20-Poly1305, in its four modes, as MLS and Marmot use it.
  • webcpp::crypto::key_exchange: kx_keypair, libsodium's crypto_kx, a session key for each direction of a client and a server.

The algorithms are those of widely used, reviewed C libraries, each a backend that a program names in its own Jamfile and that webcpp builds from its sources: BearSSL (/third_party//bearssl), OpenSSL 3.5.9 (/webcpp/crypto//openssl, never the system's, refused on Emscripten), ctaes (/third_party//ctaes), libsecp256k1 (/third_party//secp256k1) and libsodium (/third_party//sodium). Which operation runs on which backend and target is the page's generated table, from the tests that run each. Hashing and HMAC stay with Boost.Hash2. Protocols built on these primitives (Bitcoin, Ethereum, Nostr) belong to domain libraries.

Building and testing

crypto lives in the superproject's libs/crypto. From the root of a webcpp checkout, each lane builds from scratch:

b2 -a --build-dir=bin/lane-native libs/crypto/test libs/crypto/example
b2 -a --build-dir=bin/lane-wasip2 toolset=clang-wasip2 testing.launcher=tools/boost/asio-wasip2/run.sh libs/crypto/test libs/crypto/example
b2 -a --build-dir=bin/lane-wasip3 toolset=clang-wasip3 testing.launcher=tools/boost/asio-wasip3/run.sh libs/crypto/test libs/crypto/example
b2 -a --build-dir=bin/lane-emscripten toolset=emscripten libs/crypto/test libs/crypto/example

A program names /webcpp/crypto//crypto and the library of each backend it uses.

Documentation

The page is published at https://webcpporg.github.io/libs/crypto/, with llms.txt, an index for language models, beside it. It opens with a table that answers "what do I use for ...", teaches each namespace and three families of applications (wallets, peer-to-peer, everyday), and shows every Jamfile a user writes and every message with its fix. Every program it shows is an example of example/, built and run on every target. Its tables are generated by doc/tables/generate.py from doc/tables/crypto.json and the tests; b2 libs/crypto/doc checks them.

Licence

crypto is under the Boost Software License, Version 1.0 (LICENSE_1_0.txt). The backends keep their own: BearSSL is MIT (LICENSE-BEARSSL.txt), ctaes is MIT (LICENSE-CTAES.txt), libsecp256k1 is MIT (LICENSE-SECP256K1.txt), libsodium is ISC (LICENSE-LIBSODIUM.txt) and OpenSSL is Apache-2.0. The documentation's sections on libsodium's families adapt parts of libsodium's documentation (jedisct1/libsodium-doc), which is ISC (LICENSE-LIBSODIUM-DOC.txt).

About

Authenticated encryption, randomness and secp256k1 for C++20 on every target, over BearSSL, OpenSSL, ctaes and libsecp256k1.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages