Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6410708
crypto: no local name in a header hides a program's global on MSVC
Nov 23, 2026
834390f
crypto: user_globals states where MSVC's C4459 bites and checks the O…
Nov 23, 2026
ed7f76e
crypto: every factory is named by its input, and make is gone
Nov 23, 2026
21ebc02
crypto: async_from_secret's refusal is tested, and no name of the fac…
Nov 23, 2026
51eb029
crypto: crypto_box and sealed boxes are public_key_encryption's, cryp…
Nov 23, 2026
3d33474
crypto: crypto_kx's header and the curves chapter point at the key_ex…
Nov 23, 2026
019b41a
crypto: the constant-time page escapes the bars of its cells, and kx.…
Nov 23, 2026
c966ef2
crypto: crypto::erase_secret zeroes any buffer the program owns, with…
Nov 23, 2026
e4eddb5
crypto: equal is constant_time_equal, a name that says what it guaran…
Nov 23, 2026
0568c9a
crypto: the timing test checks that erase_secret enters no guard
Nov 23, 2026
d21602c
crypto: the constant-time lane's renamed comments keep the Jamfile's …
Nov 23, 2026
70b5cec
crypto: erase_secret's refusal names its fix for a const view and for…
Nov 23, 2026
0a6d672
crypto: no inline code in a doc comment is cut across lines, so the r…
Nov 23, 2026
24622b7
crypto: Ed25519's asynchronous sign and verify are defined with the p…
Nov 23, 2026
ecb120c
crypto: a signature type per curve and scheme, made from bytes of its…
Nov 23, 2026
d903bf2
crypto: the constant-time paths make crypto_kx's key pairs with deriv…
Nov 23, 2026
16beeb9
crypto: every sign returns its curve's signature type and every verif…
Nov 23, 2026
b24ffb9
crypto: check_signature names every pair of signature type and verifi…
Nov 23, 2026
b03cccc
crypto: async_verify_named_backend passes a typed signature, so the c…
Nov 23, 2026
5ea5ec0
crypto: the constant-time builds mark each verdict public by the name…
Nov 23, 2026
613a5d5
crypto: secp256k1 signs and recovers Ethereum's recoverable ECDSA ove…
Nov 23, 2026
2e1c62f
crypto: every lane compiles the constant-time marks against a stand-i…
Nov 23, 2026
c9c7104
crypto: signature_types checks Ethereum's scheme, and secp256k1's hea…
Nov 23, 2026
1826fe5
crypto: Ed25519ph is the scheme eddsa_prehashed, and its streaming si…
Nov 23, 2026
999d864
crypto: the Jam comments of secp256k1_ethereum and make_removed keep …
Nov 23, 2026
50db823
crypto: Ed25519ph's WebCrypto refusal is written once and every eddsa…
Nov 23, 2026
a2ad4d1
crypto: X25519 has a typed public key and a key pair, made, drawn and…
Nov 23, 2026
600654e
crypto: an X25519 key pair's from_secret, generate and agree on a bac…
Nov 23, 2026
394db48
crypto: x25519_access says whether a key pair holds a key, so that it…
Nov 23, 2026
d043e34
crypto: async_post refuses a moved-from X25519 key pair's async_agree…
Nov 23, 2026
7823c37
crypto: public parameters are spelled out: nonce, associated data, au…
Nov 23, 2026
ca1188a
crypto: a nonce's size and its error say nonce, and the associated da…
Nov 23, 2026
b44dde7
crypto: random_device's row names each secret once, and the renamed p…
Nov 23, 2026
12fd789
crypto: aead_checks' list of wrong nonce sizes ends with a trailing c…
Nov 23, 2026
26fe947
crypto: crypto_kx, crypto_box and the sealed box take X25519's typed …
Nov 23, 2026
b3d82cf
crypto: the curves page's Schnorr paragraph keeps 80 columns after th…
Nov 23, 2026
d8b6752
crypto: crypto_kx, the box and the sealed box refuse a backend withou…
Nov 23, 2026
ee2e030
crypto: Ed25519's key pair and public key convert to X25519's typed keys
Nov 23, 2026
ad52ba7
crypto: the conversion test says its non-canonical key is of small or…
Nov 23, 2026
2143807
crypto: crypto_kx's engine counts as defined by the capability table,…
Nov 23, 2026
f9b83c3
crypto: key pairs are checked by what they do: keypair, signing_keypa…
Nov 23, 2026
494c0ca
crypto: async_agree refuses a peer of another type as agree does, and…
Nov 23, 2026
6f4f43c
crypto: AEADs and boxes are checked by concepts in secret_key_encrypt…
Nov 23, 2026
3b5629b
crypto: the timing seam reads GCC's spelling of a function with a tra…
Nov 23, 2026
e53e787
crypto: erase_secret's and the WebCrypto oracle's tests pass the Linu…
Nov 23, 2026
d27e8f8
crypto: the timing seam compares every component a check names, and r…
Nov 23, 2026
fdcd5c8
crypto: the timing seam reads a label that starts with :: as one with…
Nov 23, 2026
0fe095d
crypto: every AEAD and box seals and opens asynchronously on a native…
Nov 23, 2026
2733f24
crypto: a construction WebCrypto lacks names a native backend from it…
Nov 23, 2026
83c8a58
crypto: async_aead's stand-in backend has internal linkage, as the Li…
Nov 23, 2026
138ab3c
crypto: a throwing getRandomValues gives entropy_unavailable in the b…
Nov 23, 2026
0197c8c
crypto: the browser draw's status maps to an error without a nested c…
Nov 23, 2026
19d6128
crypto: the browser draw catches a throw from any of its steps and fa…
Nov 24, 2026
166d23b
crypto: libsodium draws through crypto's entropy in the browser, and …
Nov 24, 2026
5a04d96
crypto: libsodium's browser generator keeps its watch state behind a …
Nov 24, 2026
d5bda21
crypto: libsodium stays uninitialised until crypto's entropy answers …
Nov 24, 2026
bc3fd50
crypto: libsodium's backend doc names no entropy source the Linux lin…
Nov 24, 2026
756d265
crypto: a construction WebCrypto lacks says that no form of it runs o…
Nov 24, 2026
27dd2da
crypto: the one-shot ChaCha20-Poly1305 template is ciphers::basic_cha…
Nov 24, 2026
378a5a3
crypto: secp256k1's tweaks, MuSig2's nonce and silent payments' summa…
Nov 24, 2026
d196e9c
crypto: X5's comments fit the lint's widths, as the Linux lint asks
Nov 24, 2026
e2ae583
crypto: the messages page lists every message a test pins, the first …
Nov 24, 2026
5664a84
crypto: heavy_without_threads' row shows the refusal, and its comment…
Nov 24, 2026
540f36f
crypto: the Ed25519ph refusal is made dependent on the backend at eve…
Nov 24, 2026
63b7f66
crypto: the page shows typed signatures, typed X25519, the concepts a…
Nov 24, 2026
e7dc82e
crypto: the page lists X25519 among the curves with four forms and an…
Nov 24, 2026
26f2a13
crypto: no test names a global after a public parameter, so MSVC's C4…
Nov 24, 2026
e5d8f9c
crypto: the browser draw zeroes its JavaScript array after the copy a…
Nov 24, 2026
59c973e
crypto: libsodium's draws through crypto's entropy leave no copy on t…
Nov 24, 2026
ce71562
crypto: tests pin that X25519's free functions over bytes, x25519_sec…
Nov 24, 2026
b380241
crypto: the changelog names ecdsa_keccak256_recoverable, Ethereum's r…
Nov 24, 2026
7106c75
crypto: keypair.hpp and secret.hpp are inside the backend-free includ…
Nov 24, 2026
3e3ed26
crypto: the overview's namespaces name webcpp::crypto::pem and suppor…
Nov 24, 2026
e07d44a
crypto: the constant-time lane checks erase_secret, X25519's key pair…
Nov 24, 2026
7b0822f
crypto: sodium_entropy_wipe's positive control shows the scan reaches…
Nov 24, 2026
07b3409
crypto: x25519_free_functions_removed's fix says its public_key half …
Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ specific to crypto.

## Cautions

- An algorithm type does every guard; a backend's header supplies only the six traits of
- An algorithm type does every guard; a backend's header supplies only the eight traits of
`detail/engines.hpp` (`block_state`, `block_engine`, `gcm_state`, `gcm_engine`, `aead_state`,
`aead_engine`), the two of `detail/p_curves.hpp` per P-curve (`p_curve_state`,
`p_curve_engine`) and, for the other curves and `hybrid`, the functions of its own header.
`aead_engine`, `secretbox_state`, `secretbox_engine`), the two of `detail/p_curves.hpp` per
P-curve (`p_curve_state`, `p_curve_engine`) and, for the other curves, `public_key_encryption`
and `key_exchange`, the functions of its own header.
- A new public function that calls a backend holds `detail::timing_guard` as its
first statement (it sets arm64's DIT for the call, `detail/timing.hpp`) and joins the coverage
test of its backend, `test/timing_coverage_<backend>_test.cpp`, which checks through the seam
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ target [webcpp](https://github.com/webcpporg/webcpp) has: native (Linux, macOS,
MSVC), wasip2, wasip3 and Emscripten.

- `webcpp::crypto`: a `random_device` that reads the operating system's or the browser's
generator, a constant-time `equal` for tags and MACs, and `error`, every failure's value.
generator, `constant_time_equal` for tags and MACs, `erase_secret`, which zeroes a buffer of
the program's with stores the optimiser keeps, and `error`, every failure's value.
- `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`), the ChaCha20-Poly1305 AEADs, and
NaCl's and libsodium's secret boxes (`secretbox`, `secretbox_xchacha20poly1305`).
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 strict verification, the
X25519 secret key of a key pair, and Ed25519ph over SHA-512 for a message given in pieces.
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, `curves::ed25519::to_x25519_public` for a peer known by its Ed25519 key, and
`kx_keypair`, libsodium's `crypto_kx`, a session key for each direction of a client and a server.
secret, with a peer known by its Ed25519 key once its `to_x25519()` converts it.
- Ed25519's and X25519's keys in RFC 8410's SPKI and PKCS#8, as OpenSSL and WebCrypto write them,
and `webcpp::crypto::pem` for their PEM text, each decoded strictly.
- `webcpp::crypto::hybrid`: NaCl's and libsodium's boxes between two key pairs (`box`,
`box_xchacha20poly1305`), refusing a peer key of small order, and sealed boxes (`sealed_box`),
anonymous encryption to a public key.
- `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, and sealed boxes
(`sealed_box`), anonymous encryption to a public key.
- `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
Expand Down
145 changes: 77 additions & 68 deletions bench/operations.hpp

Large diffs are not rendered by default.

109 changes: 65 additions & 44 deletions doc/aead.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Encryption alone does not: with counter mode alone, flipping a bit of a
ciphertext flips the same bit of the plaintext, and the receiver cannot tell; a
forged "amount" field in an encrypted cookie goes through. *AES-GCM*
(Galois/Counter Mode) encrypts with AES in counter mode and computes a 16-byte
*tag* over the ciphertext and over *additional data* that travels in clear
*tag* over the ciphertext and over *associated data* that travels in clear
(link:https://en.wikipedia.org/wiki/Galois/Counter_Mode[Wikipedia];
link:https://csrc.nist.gov/pubs/sp/800/38/d/final[NIST SP 800-38D]). Opening
recomputes the tag and returns the plaintext only if it matches; on a mismatch
Expand All @@ -27,51 +27,72 @@ size of `Cipher`, on the backend of `Cipher`, which must export GCM over its own
AES: BearSSL or OpenSSL. `aes128_gcm` and `aes256_gcm`, in
`<webcpp/crypto/ciphers/aes256_gcm.hpp>`, name it on the default backend,
OpenSSL natively and BearSSL on WebAssembly. It is
made with `make(key_bytes)`, and works in place:
made with `from_key(key_bytes)`, and works in place:

* `seal(iv_bytes, additional_data_bytes, data_bytes)` encrypts `data_bytes`
* `seal(nonce_bytes, associated_data_bytes, data_bytes)` encrypts `data_bytes`
in place and returns its 16-byte tag, a `boost::hash2::digest<16>`;
* `open(iv_bytes, additional_data_bytes, data_bytes, tag_bytes)` checks the
* `open(nonce_bytes, associated_data_bytes, data_bytes, tag_bytes)` checks the
tag and decrypts `data_bytes` in place;
* `begin_seal(iv_bytes, additional_data_bytes)`, `update(data_bytes)` and
* `begin_seal(nonce_bytes, associated_data_bytes)`, `update(data_bytes)` and
`result()` seal a message in pieces;
* `begin_open`, `authenticate`, `verify`, `decrypt` and `end_open` open a
message in pieces, in two passes (<<crypto-gcm-incremental-open>>).

`make`, `seal` and `open` have four forms each, the member and its free form,
synchronous and asynchronous, with the same work, errors and refusals
(<<crypto-curves-four-forms>>); the pieces' functions are members alone. An
asynchronous form needs `<webcpp/crypto/async.hpp>` and
`<library>/webcpp/asio//asio` in the Jamfile (<<crypto-async>>):
`from_key`, `seal` and `open` have four forms each, the member and its free
form, synchronous and asynchronous, with the same work, errors and refusals
(<<crypto-curves-four-forms>>); the pieces' functions are members alone.
AES-GCM is a `secret_key_encryption::aead::streaming_cipher`, whose free `seal`
and `open` its header brings (<<crypto-aead-contract>>). An asynchronous form
needs `<webcpp/crypto/async.hpp>` and `<library>/webcpp/asio//asio` in the
Jamfile (<<crypto-async>>):

.AES-GCM's operations in their four forms
[cols="1,3,3",options="header"]
|===
| Operation | Synchronous: the member; its free form | Asynchronous: the member; its free form

| Make
| `aes256_gcm::make(key_bytes)` +
`crypto::make<aes256_gcm>(key_bytes)`
| `aes256_gcm::async_make(executor, key_bytes, token)` +
`crypto::async_make<aes256_gcm>(executor, key_bytes, token)`
| `aes256_gcm::from_key(key_bytes)` +
`crypto::from_key<aes256_gcm>(key_bytes)`
| `aes256_gcm::async_from_key(executor, key_bytes, token)` +
`crypto::async_from_key<aes256_gcm>(executor, key_bytes, token)`

| Seal
| `aead.seal(iv, additional_data, data)` +
`crypto::seal(aead, iv, additional_data, data)`
| `aead.async_seal(executor, iv, additional_data, data, token)` +
`crypto::async_seal(executor, aead, iv, additional_data, data, token)`
| `aead.seal(nonce, associated_data, data)` +
`secret_key_encryption::aead::seal(aead, nonce, associated_data, data)`
| `aead.async_seal(executor, nonce, associated_data, data, token)` +
`secret_key_encryption::aead::async_seal(executor, aead, nonce, associated_data, data, token)`

| Open
| `aead.open(iv, additional_data, data, tag)` +
`crypto::open(aead, iv, additional_data, data, tag)`
| `aead.async_open(executor, iv, additional_data, data, tag, token)` +
`crypto::async_open(executor, aead, iv, additional_data, data, tag, token)`
| `aead.open(nonce, associated_data, data, tag)` +
`secret_key_encryption::aead::open(aead, nonce, associated_data, data, tag)`
| `aead.async_open(executor, nonce, associated_data, data, tag, token)` +
`secret_key_encryption::aead::async_open(executor, aead, nonce, associated_data, data, tag, token)`
|===

*On the web and natively.* AES-GCM is the one AEAD browsers' WebCrypto has.
On a native backend, and on every backend of this version, its four forms all
run, the asynchronous ones completing through the event loop. On the browser's
backend, once it is built (<<crypto-async-webcrypto>>), its seal and open are
asynchronous alone, and each synchronous form stops the build naming its
`async_` form. The other AEADs of `ciphers` and the boxes have their
asynchronous forms too, on a native backend, so that a program that seals in
an event loop writes one shape for every AEAD; on the browser's backend no form
of them runs, synchronous or asynchronous, and each stops the build with one
text:

[listing]
----
webcpp::crypto: WebCrypto has no ChaCha20-Poly1305, XChaCha20-Poly1305, secret
box or crypto_box: no form of them, synchronous or asynchronous, runs on the
browser's backend; name a native backend for them. On the browser's backend
only AES-GCM seals and opens.
----

include::generated/backends-gcm.adoc[]

*Example.* A program stores users' API tokens in a database. Each token is
sealed under a storage key with the user's id as additional data, so that the
sealed under a storage key with the user's id as associated data, so that the
row opens only for that user: a row copied onto another user's record does not
open.

Expand Down Expand Up @@ -111,18 +132,18 @@ include::{examples}/aes256_gcm_bearssl.expected[]

Each rule is how crypto behaves, and what it asks of the program.

* *Never reuse an IV under one key.* Two messages under one key and one IV
* *Never reuse a nonce under one key.* Two messages under one key and one nonce
reveal the XOR of their plaintexts, and let an attacker recover the
authentication key and forge tags for every later message
(link:https://csrc.nist.gov/csrc/media/projects/block-cipher-techniques/documents/bcm/comments/800-38-series-drafts/gcm/joux_comments.pdf[Joux, 2006];
link:https://eprint.iacr.org/2016/475[Boeck et al., 2016];
link:https://cwe.mitre.org/data/definitions/323.html[CWE-323]). AES-GCM does
not resist this misuse: the program must prevent it.
* *The usage limit.* With random IVs, or IVs other than 12 bytes, at most 2^32^
messages are sealed under one key (NIST SP 800-38D, section 8.3). A counter IV
(message 0, 1, 2 ...) is safe until the counter repeats, which it must never
do, a restart included. Rotate the key before either limit.
* *IVs of 1 to 128 bytes; 12 recommended.* An IV of another size than 12
* *The usage limit.* With random nonces, or nonces other than 12 bytes, at
most 2^32^ messages are sealed under one key (NIST SP 800-38D, section 8.3). A
counter nonce (message 0, 1, 2 ...) is safe until the counter repeats, which it
must never do, a restart included. Rotate the key before either limit.
* *Nonces of 1 to 128 bytes; 12 recommended.* A nonce of another size than 12
bytes is hashed into the first counter block, as every backend does; the cap
of 128 bytes is OpenSSL's, applied on every backend so that a call succeeds or
fails the same way everywhere.
Expand All @@ -138,7 +159,7 @@ tag in one pass; when the tag does not match, crypto zeroes the whole of
`update` that fails in the backend zeroes its data too, so that no message
without a tag can be sent. A caller who
needs the ciphertext after a failure keeps a copy. A guard's refusal
(`invalid_state`, `invalid_iv_size`, `invalid_tag_size`, `message_too_long`)
(`invalid_state`, `invalid_nonce_size`, `invalid_tag_size`, `message_too_long`)
comes before any work and leaves `data_bytes` untouched. Whether the tag
matched is the one value derived from the key that crypto treats as public
(<<crypto-backends-constant-time>>).
Expand Down Expand Up @@ -169,21 +190,21 @@ itself, which come after the guards:
|===
|Condition |Error

|`make`: a key of another size than `key_size` |`invalid_key_size`
|`from_key`: a key of another size than `key_size` |`invalid_key_size`
|any other function: the object was moved from |`invalid_state`
|`begin_seal` or `begin_open` while a message is in progress; `update` or
`result` outside a seal; `authenticate` or `verify` outside the open's first
pass; `decrypt` or `end_open` before `verify` matched |`invalid_state`
|an empty IV, or one longer than `max_iv_size`, 128 bytes |`invalid_iv_size`
|an empty nonce, or one longer than `max_nonce_size`, 128 bytes |`invalid_nonce_size`
|`open` or `verify`: a tag of another size than 16 |`invalid_tag_size`
|a message longer than `max_message_size`, 2^36^ - 32 bytes, in one call or
summed over `update` or `authenticate`, or additional data longer than 2^61^ -
summed over `update` or `authenticate`, or associated data longer than 2^61^ -
1 bytes (NIST SP 800-38D, section 5.2.1.1) |`message_too_long`
|`decrypt`: more bytes than `authenticate` read; `end_open`: fewer
|`invalid_input_size`
|`open` or `verify`: the tag does not match |`authentication_failed`
|the backend fails where it should not |`backend_failure`
|`make`: OpenSSL cannot allocate its context |`errc::not_enough_memory`
|`from_key`: OpenSSL cannot allocate its context |`errc::not_enough_memory`
|===

[#crypto-gcm-arm]
Expand All @@ -204,8 +225,8 @@ machine. A server on ARM keeps the default and links `/webcpp/crypto//openssl`
==== Encrypting what does not fit in memory

A 2 GB video before an upload, or a log as it is written, cannot be held whole.
`begin_seal` takes the IV and the additional data, `update` encrypts each piece
in place as it arrives, and `result` returns the tag at the end. The object
`begin_seal` takes the nonce and the associated data, `update` encrypts each
piece in place as it arrives, and `result` returns the tag at the end. The object
refuses another message while one is in progress, and any error abandons the
message: its pieces have no tag and are not to be sent.

Expand All @@ -217,24 +238,24 @@ include::{examples}/sealed_records.cpp[tag=incremental,indent=0]
What is sealed in pieces is opened whole, or, when the receiver can read the
ciphertext twice, in two passes (<<crypto-gcm-incremental-open>>). To open a
stream piece by piece as it arrives, split it into *records*, each sealed alone
with its own IV, and with two things
in its additional data: its number, so that a record cannot be reordered or
with its own nonce, and with two things
in its associated data: its number, so that a record cannot be reordered or
replayed at another position, and a flag that is 1 for the last record and 0
for every other, so that a stream cut after any record does not open: the
receiver opens the last record it got as the last, and a record that was not
sealed as the last fails. The STREAM construction binds the same two
(link:https://eprint.iacr.org/2015/189[Hoang, Reyhanitabar, Rogaway and Vizár,
2015]).

The record's number is its IV, so *each stream has a key of its own*. Every
The record's number is its nonce, so *each stream has a key of its own*. Every
stream numbers its records from 0: two files sealed under one key would both
seal record 0 with the same IV, which reveals the XOR of the two records and
seal record 0 with the same nonce, which reveals the XOR of the two records and
lets an attacker forge tags under that key (<<crypto-gcm-rules>>), and a
record of one file could be spliced into the other at the same position. The
example draws a fresh random key per stream. A program that keeps one
long-lived storage key derives the stream's key from it, for example with HKDF
of the storage key and a random salt of 32 bytes stored in the file's header
(link:https://www.rfc-editor.org/rfc/rfc5869[RFC 5869]); or it makes the IV's
(link:https://www.rfc-editor.org/rfc/rfc5869[RFC 5869]); or it makes the nonce's
first 8 bytes a random identifier drawn for the stream and its last 4 the
record number, and counts every record against the key's usage limit of 2^32^
messages, since the identifiers are random.
Expand All @@ -258,7 +279,7 @@ Never send the pieces of an abandoned message.

A message sealed whole, too large to hold in memory, is opened in two passes
when its ciphertext lies where the program can read it twice: a file on the
program's own disk. `begin_open` takes the IV and the additional data;
program's own disk. `begin_open` takes the nonce and the associated data;
`authenticate` reads each piece of the ciphertext and writes none of it;
`verify` checks the tag. Only once the tag matched does `decrypt` turn the same
pieces into plaintext, in place, and `end_open` ends the message. No byte of
Expand All @@ -282,8 +303,8 @@ backends compute GCM's hash only while they decrypt. An open in two passes
costs about two one-shot opens.

*The second pass reads the bytes the first read.* GCM's keystream is the key's
and the IV's alone: a byte changed between the passes is decrypted without ever
being authenticated, and whoever changes it chooses the change in the
and the nonce's alone: a byte changed between the passes is decrypted without
ever being authenticated, and whoever changes it chooses the change in the
plaintext, bit for bit. Only the program can keep the bytes the same: it reads
a file that no other process writes during the open, never a file another
party can reach. The object checks only the length: `decrypt` refuses more
Expand Down
Loading
Loading