When you upload an object to an S3-compatible bucket using standard Signature Version 4, you must compute the SHA-256 hash of the entire payload before sending the very first HTTP byte. That works cleanly for small files. But if you are streaming an 80 GB PostgreSQL dump directly from pg_dump, piping live video, or generating archives on the fly, buffering the whole stream into RAM or spilling it to local disk just to calculate a preliminary hash defeats the purpose of streaming.
AWS solved this by defining Content-Encoding: aws-chunked paired with the header x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD. Instead of hashing the full payload up front, you sign only the initial HTTP request headers to produce a seed signature. You then stream the data in successive chunks, where each chunk carries its own cryptographic signature over the wire. Crucially, these chunk signatures are chained together like an HMAC ratchet: each chunk's signature incorporates the signature of the previous chunk. Here is how that chain is calculated byte by byte, how it matches botocore, and what happens when chunks arrive out of order.
1. The request headers and the seed signature
A streaming chunked upload starts with four required headers that configure the signing protocol on the S3 endpoint:
x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD: Tells the storage gateway that the payload is not pre-hashed and will arrive in signed chunks.Content-Encoding: aws-chunked: Informs HTTP decoders that the body contains chunk metadata headers and framing.x-amz-decoded-content-length: The exact size in bytes of the unchunked, raw object payload (e.g.66560).Content-Length: The total wire length, which includes raw data bytes PLUS chunk size headers, signatures, and CRLF separators (e.g.66824).
Before transmitting any body bytes, the client builds a standard SigV4 canonical request over the headers. In place of the usual payload hash, line 7 contains the literal ASCII string STREAMING-AWS4-HMAC-SHA256-PAYLOAD. Using AWS's standard test credentials (AKIAIOSFODNN7EXAMPLE with secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY) for a PUT to /examplebucket/chunkObject.txt on 2013-05-24, the canonical request is:
The SHA-256 hash of this canonical request is cee3fed04b70f867d036f722359b0b1f2f0e5dc0efadbc082b76c4c60e316455. Feeding this hash into the standard SigV4 string-to-sign produces the seed signature:
Computing HMAC-SHA256 with the derived kSigning key gives the seed signature: 4f232c4386841ef735655705268965c44a0e4690baa4adea153f7db9fa80a0a9. This value is sent in the initial HTTP Authorization header and serves as the cryptographic anchor for the entire chunk stream.
2. Wire framing and protocol overhead
Every chunk transmitted in aws-chunked format adheres to a strict framing structure. Each data chunk begins with the chunk size in hexadecimal, followed by ;chunk-signature=, the 64-character lowercase hexadecimal signature, and a \r\n delimiter. The raw chunk data follows, terminated by another \r\n. Once all data chunks are transmitted, a final 0-byte terminal chunk closes the stream:
Notice why Content-Length (66,824 bytes) is larger than x-amz-decoded-content-length (66,560 bytes). For a 65 KB file uploaded in two data chunks (64 KB and 1 KB) plus the zero-byte terminal chunk, the framing adds exactly 264 bytes of overhead:
| Segment | Raw Data | Header Bytes | Trailing CRLF | Wire Bytes |
|---|---|---|---|---|
| Chunk 1 (64 KB) | 65,536 B | 88 B (10000;chunk-signature=...\r\n) | 2 B | 65,626 B |
| Chunk 2 (1 KB) | 1,024 B | 86 B (400;chunk-signature=...\r\n) | 2 B | 1,112 B |
| Chunk 3 (0 B terminal) | 0 B | 84 B (0;chunk-signature=...\r\n) | 2 B | 86 B |
| Total | 66,560 B | 258 B | 6 B | 66,824 B |
The framing adds only 264 bytes of wire data for a 65 KB object—an overhead of just 0.39%. For large multi-megabyte streams, framing overhead drops to negligible fractions of a percent.
3. Walking the 3-chunk signature chain
Every chunk's signature is calculated from a standardized 6-line StringToSign. Unlike the initial request string-to-sign which starts with AWS4-HMAC-SHA256, chunk strings-to-sign start with AWS4-HMAC-SHA256-PAYLOAD:
Here is the exact progression across all three chunks:
Chunk 1: 65,536 bytes ('a' x 65,536)
For the first data chunk, <PreviousSignature> is the Seed Signature (4f232c43...). The SHA-256 hash of 65,536 ASCII 'a' characters is bf718b6f653bebc184e1479f1935b8da974d701b893afcf49e701f3e2f9f9c5a:
Computing HMAC-SHA256 with kSigning yields Chunk 1 Signature: ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648.
Chunk 2: 1,024 bytes ('a' x 1,024)
For the second chunk, <PreviousSignature> becomes the Chunk 1 Signature (ad80c730...). The SHA-256 hash of 1,024 'a's is 2edc986847e209b4016e141a6dc8716d3207350f416969382d431539bf292e4a:
Computing HMAC-SHA256 with kSigning yields Chunk 2 Signature: 0055627c9e194cb4542bae2aa5492e3c1575bbb81b612b7d234b86a503ef5497.
Chunk 3: 0 bytes (terminal completion)
The stream terminates with a 0-byte chunk. <PreviousSignature> is the Chunk 2 Signature (0055627c...). Because the chunk has zero data bytes, both line 5 and line 6 contain the empty-string SHA-256 hash (e3b0c442...):
Computing HMAC-SHA256 with kSigning yields Chunk 3 Signature: b6c6ea8a5354eaf15b3cb7646744f4275b71ea724fed81ceb9323e279d449df9.
| Step | Input Previous Signature | Current Chunk Hash | Computed Signature |
|---|---|---|---|
| Seed (Headers) | N/A (Canonical Request) | cee3fed04b70f8... | 4f232c4386841e... |
| Chunk 1 (64 KB) | 4f232c4386841e... (Seed) | bf718b6f653beb... | ad80c730a21e5b... |
| Chunk 2 (1 KB) | ad80c730a21e5b... (C1) | 2edc986847e209... | 0055627c9e194c... |
| Chunk 3 (0 B) | 0055627c9e194c... (C2) | e3b0c44298fc1c... (empty) | b6c6ea8a5354ea... |
4. Failure modes: what happens when chunks are reordered
Suppose a network middlebox, HTTP/2 multiplexing bug, or proxy error delivers Chunk 2 before Chunk 1. How does the S3 server react?
The server maintains an internal cursor of the signature chain. When Chunk 2 arrives first over the connection, the server expects its <PreviousSignature> to equal the Seed Signature (4f232c43...). It reconstructs Chunk 2's String-to-Sign accordingly:
The server calculates HMAC-SHA256 over this string and obtains 4f9f4e93a9785ad19aaa4c6713fc20b87c8ea6da0e1aa2948b81e23256328f8f. It then compares this value to the signature sent in the wire header (0055627c9e194cb4542bae2aa5492e3c1575bbb81b612b7d234b86a503ef5497).
The signatures do not match. The server immediately closes the TCP socket and returns HTTP 403 SignatureDoesNotMatch. The upload fails before a single corrupted byte is written to storage.
Even if an attacker intentionally recalculated Chunk 2's signature against the seed signature to make it valid (4f9f4e93...), the stored file content would be completely scrambled (1 KB followed by 64 KB). The terminal chunk and object-level checksums would then fail. The hash chain guarantees both tamper-evidence and strict sequential ordering.
5. SDK realities: botocore, Go, and trailing checksums
If chunked signing is cryptographically elegant, why don't all SDKs use it for every streaming upload? The answer is CPU overhead and language runtimes:
- Python botocore defaults to UNSIGNED-PAYLOAD: In Python's
botocore/auth.py(lines 502 & 533), body signing is deliberately disabled for streaming inputs. Computing HMAC-SHA256 chunk-by-chunk in pure Python under the GIL creates substantial CPU bottlenecks on gigabit pipes. Botocore replaces the content hash withUNSIGNED-PAYLOADover TLS. - Go and Rust AWS SDKs support aws-chunked natively: Compiled languages with SIMD-accelerated SHA-256 instructions compute chunk HMACs with minimal latency, making
aws-chunkedviable for high-throughput pipes. - Trailing Checksums (Modern S3 Standard): Modern AWS SDKs increasingly favor trailing checksums (
STREAMING-UNSIGNED-PAYLOAD-TRAILERwithx-amz-trailer: x-amz-checksum-crc32c). The client streams the body without per-chunk HMAC overhead, then sends an end-of-stream CRC32C or SHA-256 trailer. S3 verifies object integrity upon stream completion without requiring upfront buffering.
| Mode | RAM Buffering | CPU Cost | Integrity Guarantee |
|---|---|---|---|
| Standard SigV4 | Full payload buffered | One full SHA-256 pass | Full payload signed in header |
| aws-chunked SigV4 | One chunk (e.g. 64 KB) | Per-chunk SHA-256 + HMAC | Cryptographic hash chain; aborts on corrupt chunk |
| UNSIGNED-PAYLOAD | Zero (direct stream) | None (TLS crypto only) | TLS transport integrity only |
| Trailing CRC32C | Zero (direct stream) | Hardware-accelerated CRC32C | End-to-end checksum verified at EOF |
6. Reproducing the chain in Python
You can verify every hash in this chain yourself with standard Python libraries. The script below computes the seed signature, builds the 3-chunk hash chain, asserts that all values match the AWS test vectors, and simulates the failure when Chunk 2 is received out of order: