gcm-nonceless
Decrypts GCM encrypted data without access to the nonce.
Similar to situations in the following Stack Exchange question (note as of today the accepted answer is incorrect, you do not need any prior knowledge of the plaintext to decrypt the data with a lost nonce):
⚠️ Security Warning: Hazmat!
This is super sketchy cryptanalysis and should not be used in production but security research, forensics and data salvage applications.
All integrity and authenticity guarantees of AES-GCM are lost.
Theory of Operation
Firstly, reconstruct the GHASH key $H$.
$$ H = E_{K}(0^{128}) $$
Given the relationship:
$$ T = \mathtt{GHASH}{H}(A, C) \oplus E{K}(Y_0) $$
Rearrange. This part is done in recover_counter.
$$ E_{K}(Y_0) = \mathtt{GHASH}{H}(A, C) \oplus T \ Y_0 = E{K}^{-1}(\mathtt{GHASH}_{H}(A, C) \oplus T) $$
For practical purposes using standard 12 byte nonces, initialization vector $\mathtt{IV}$ is simply the first 12 bytes of $Y_0$ by construction. This is done in extract_nonce.
$$ Y_0 = \mathtt{IV} || 0^{31}1 $$
For other nonce lengths, the initialization vector cannot be deterministically deduced, but the exact original nonce is not required for any further decryption. The following decryption always holds:
$$ P = \mathtt{CTR}{32}(E{K}, \mathtt{INCR}_{32}(Y_0), C) $$
Usage
Here's a piece of data encrypted using the first 12 bytes of SHA-512 initial hash value as the nonce:
| |
Library usage:
use ;
use ;
let mut ct = *b"\xba\x0c\x7b\x18\xf7\xa4\x4a\xde\x46\x7a\xac\xa6\x8e\xa8\x71\xf5\xa7\xcc\xee\x25\xee\x55\xd8\x16\x7f\x06\x2e\x92\x55\x5e";
let tag =
from;
let aad = *b"\xAE\xAD\xAE\xAD";
let key = from;
let cipher = new;
let y0 = recover_counter;
let recovered_nonce = .unwrap;
assert_eq!;
let mut recovered_keystream = instantiate_keystream;
recovered_keystream.apply_keystream;
assert_eq!;