Learning to Protect Communications with Adversarial Neural Cryptography
Martín Abadi, David G. Andersen
Google Brain
cs.CR, cs.LG
2016-10-22
Alice and Bob learn 16-bit shared-key encryption against Eve: Bob can fall under 0.05 bits wrong, a retrained Eve misses only 6.1 bits versus 8 at random, and 10 of 20 runs pass.
Ciphers are usually designed by hand, then argued to resist a class of attackers. The simplest neural nets cannot compute XOR, and XOR is a building block of many ciphers. In 2016, Martín Abadi and David Andersen at Google Brain left the algorithm unspecified. Alice and Bob share a key and must stop a third network, Eve, from reading their messages.
Eve is passive. She receives the ciphertext and cannot modify it or start sessions. The goal is confidentiality only. The key is given as an input. The networks learn how to use it, not how to agree on it.
Alice, Bob, and Eve are ordinary networks on floating-point values. Bits are written as -1 and 1, and a final tanh keeps outputs in (-1, 1).
The layout is called mix & transform. A fully connected layer as wide as its input can mix every plaintext bit with every key bit. Four 1-D convolutions follow, given as window, input depth, output depth: [4, 1, 2], [2, 2, 4], [1, 4, 4], [1, 4, 1], with strides 1, 2, 1, 1. Every layer but the last uses a sigmoid. The last uses tanh. Image nets convolve first because they assume locality. Here which bits belong together is learned, so the designers do not pre-pair plaintext bits with key bits into an XOR. Alice and Bob use the same layout and untied weights, so encryption and decryption can differ. Eve has no key, and her first layer is N by 2N.
The loss does not try to make Eve maximally wrong. If every output bit is flipped, she can flip them all back and be exactly right. For shared-key encryption the useful target is a guess that looks like chance, about half of N bits wrong. Eve minimizes L1 distance to the plaintext. Alice and Bob minimize Bob's L1 plus (N/2 minus Eve's L1) squared, divided by (N/2) squared. That extra term is smallest when Eve is wrong on half the bits. Being wrong on every bit is penalized like being right on every bit, which blocks the global flip. A linear penalty on Eve's error never trained well.
Optimization is Adam at learning rate 0.0008, with no decay, so each party can keep reacting. Alice and Bob take one minibatch and Eve takes two: a small compute edge for the eavesdropper that still stops her from memorizing their current weights. The main runs use batches of 4096. Plaintexts and keys are uniform, N is 16, 32, or 64, and each plaintext gets a fresh key that can still collide at random. After training, Eve is reset and trained from scratch five times, up to 250,000 steps each. Missing the threshold within 150,000 steps counts as a failed run.
At N=16 the ideal point is Bob at 0 bits of error and Eve wrong on 8. In one successful run, Alice and Bob start pushing Eve back near step 10,000, and the training goals are largely met near step 15,000. The curve swings. It does not fall smoothly the way a normal training curve does.
Six of 20 initial runs failed. Bob never got under 0.05 bits, or Eve's error never rose above 7.3 bits out of 16. On the other 14, retrained Eves landed between 4.67 and 6.97 bits wrong, mean 6.1, compared with 8 for a random guess. The success line they draw is Bob at or below 0.05 bits and Eve wrong on at least 6 bits on average. Ten of 20 runs clear it. At batch size 512 the success rate falls to about one third. N=32 and N=64 look similar, and N=64 succeeds somewhat more often.
| Setup | Metric | Result |
| N=16, batch 4096 | Runs clearing the bar | 10/20 |
| Same | Initial failures | 6/20 |
| 14 retrained Eves | Bits wrong, mean (range) | 6.1 (4.67 to 6.97); chance is 8 |
| Batch 512 | Success rate | about 1/3 |
| One successful run | Steps to the training goals | about 15000 |
The learned map depends on the key and on the plaintext, and outputs are often values other than 0 and 1. Flipping one key bit usually moves 3 to 6 of the 16 ciphertext entries by a large amount. It is not bitwise XOR.
Selective protection uses correlated normal variables A, B, C, and D, produced with the Cholesky factor of a correlation matrix. Alice sees A, B, C and an 8-bit key, and emits a public estimate D-public plus a ciphertext. Bob uses the key to estimate D. Eve tries to recover C. Alice and Bob minimize the squared error of both D estimates plus the absolute covariance between Eve's guess of C and the true C. Blind Eve, who knows only the distribution of C, is the control. Early on, Eve's error is 0.1 to 0.2 below Blind Eve. That gap later returns to 0, so the public outputs add nothing about C beyond the prior. D-public remains slightly worse than Bob, and Bob reaches the best prediction of D available from A, B, and C.
The asymmetric setup in the appendix is usually unstable. After a reset, Eve often decrypts about as well as Bob. One run survived five resets, then broke once Alice and Bob trained further. The architecture cannot represent modular arithmetic. That run reads as parameters that happened to be hard to invert.
This does not replace a cipher library. The adversary is the networks in the training loop, not every attacker in a complexity class, so the guarantee is weaker than semantic security. Classical cryptographic functions are mostly not differentiable and do not fit SGD. Knowing how to encrypt still does not let training decide what to hide.
An adversarial loss can learn what to hide and how to hide it in one loop. Fair representations can strip a sensitive variable. Here the party with the key can also decrypt, so a value can bypass a component that should not see it and be recovered later. A submodule that must not depend on a privacy-related or discrimination-related input, and that cannot be inspected, can be treated as Eve. The run shows the objective is learnable. It is not a system to ship.
The quadratic loss trains, and the finished Eve is still a bit better than chance. The best loss is left open. The success line is drawn after the numbers are in. Eve wrong on 6.1 bits counts as a pass, which means she still recovers about 10 of 16 bits. N=16 is small on a cryptographic scale. N=32 and N=64 get no separate error table, only the remark that they look similar and that N=64 succeeds more often. The map is not fully taken apart. It diffuses bits, and it is not bitwise XOR.
The four-tuple data are synthetic correlated Gaussians, not operational data, and the correlation matrix is not reported as a main result. Eve's advantage falling to zero applies to this neural eavesdropper. The public-key runs are few, and a few more steps of training break the one that looked stable. A hard-to-invert matrix is not separated from real public-key behavior. The attacker cannot modify messages. Integrity, key generation, and probabilistic encryption are explicitly left out.