mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
Implement AES-GCM using the @openssh.com protocol IDs.
I only recently found out that OpenSSH defined their own protocol IDs for AES-GCM, defined to work the same as the standard ones except that they fixed the semantics for how you select the linked cipher+MAC pair during key exchange. (RFC 5647 defines protocol ids for AES-GCM in both the cipher and MAC namespaces, and requires that you MUST select both or neither - but this contradicts the selection policy set out in the base SSH RFCs, and there's no discussion of how you resolve a conflict between them! OpenSSH's answer is to do it the same way ChaCha20-Poly1305 works, because that will ensure the two suites don't fight.) People do occasionally ask us for this linked cipher/MAC pair, and now I know it's actually feasible, I've implemented it, including a pair of vector implementations for x86 and Arm using their respective architecture extensions for multiplying polynomials over GF(2). Unlike ChaCha20-Poly1305, I've kept the cipher and MAC implementations in separate objects, with an arm's-length link between them that the MAC uses when it needs to encrypt single cipher blocks to use as the inputs to the MAC algorithm. That enables the cipher and the MAC to be independently selected from their hardware-accelerated versions, just in case someone runs on a system that has polynomial multiplication instructions but not AES acceleration, or vice versa. There's a fourth implementation of the GCM MAC, which is a pure software implementation of the same algorithm used in the vectorised versions. It's too slow to use live, but I've kept it in the code for future testing needs, and because it's a convenient place to dump my design comments. The vectorised implementations are fairly crude as far as optimisation goes. I'm sure serious x86 _or_ Arm optimisation engineers would look at them and laugh. But GCM is a fast MAC compared to HMAC-SHA-256 (indeed compared to HMAC-anything-at-all), so it should at least be good enough to use. And we've got a working version with some tests now, so if someone else wants to improve them, they can.
This commit is contained in:
@ -132,6 +132,12 @@ void ssh2_bpp_new_outgoing_crypto(
|
||||
s->out.etm_mode = etm_mode;
|
||||
if (mac) {
|
||||
s->out.mac = ssh2_mac_new(mac, s->out.cipher);
|
||||
/*
|
||||
* Important that mac_setkey comes after cipher_setkey,
|
||||
* because in the case where the MAC makes use of the cipher
|
||||
* (e.g. AES-GCM), it will need the cipher to be keyed
|
||||
* already.
|
||||
*/
|
||||
ssh2_mac_setkey(s->out.mac, make_ptrlen(mac_key, mac->keylen));
|
||||
|
||||
bpp_logevent("Initialised %s outbound MAC algorithm%s%s",
|
||||
@ -189,6 +195,7 @@ void ssh2_bpp_new_incoming_crypto(
|
||||
s->in.etm_mode = etm_mode;
|
||||
if (mac) {
|
||||
s->in.mac = ssh2_mac_new(mac, s->in.cipher);
|
||||
/* MAC setkey has to follow cipher, just as in outgoing_crypto above */
|
||||
ssh2_mac_setkey(s->in.mac, make_ptrlen(mac_key, mac->keylen));
|
||||
|
||||
bpp_logevent("Initialised %s inbound MAC algorithm%s%s",
|
||||
|
@ -600,6 +600,9 @@ static void ssh2_write_kexinit_lists(
|
||||
case CIPHER_CHACHA20:
|
||||
preferred_ciphers[n_preferred_ciphers++] = &ssh2_ccp;
|
||||
break;
|
||||
case CIPHER_AESGCM:
|
||||
preferred_ciphers[n_preferred_ciphers++] = &ssh2_aesgcm;
|
||||
break;
|
||||
case CIPHER_WARN:
|
||||
/* Flag for later. Don't bother if it's the last in
|
||||
* the list. */
|
||||
|
Reference in New Issue
Block a user