summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/cipher.c
diff options
context:
space:
mode:
authormarkus <markus@openbsd.org>2012-12-11 22:31:18 +0000
committermarkus <markus@openbsd.org>2012-12-11 22:31:18 +0000
commitc2ea1f0ae6238b8053302c71a1857e7d8cd648e9 (patch)
tree7fe97b78b08b3d6e6d3d1979877c151c948285a4 /usr.bin/ssh/cipher.c
parentdrain the log messages after receiving the keystate from the unpriv (diff)
downloadwireguard-openbsd-c2ea1f0ae6238b8053302c71a1857e7d8cd648e9.tar.xz
wireguard-openbsd-c2ea1f0ae6238b8053302c71a1857e7d8cd648e9.zip
add encrypt-then-mac (EtM) modes to openssh by defining new mac algorithms
that change the packet format and compute the MAC over the encrypted message (including the packet size) instead of the plaintext data; these EtM modes are considered more secure and used by default. feedback and ok djm@
Diffstat (limited to 'usr.bin/ssh/cipher.c')
-rw-r--r--usr.bin/ssh/cipher.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/usr.bin/ssh/cipher.c b/usr.bin/ssh/cipher.c
index 3acc4182976..c7fb2628947 100644
--- a/usr.bin/ssh/cipher.c
+++ b/usr.bin/ssh/cipher.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cipher.c,v 1.82 2009/01/26 09:58:15 markus Exp $ */
+/* $OpenBSD: cipher.c,v 1.83 2012/12/11 22:31:18 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -253,13 +253,25 @@ cipher_init(CipherContext *cc, Cipher *cipher,
}
}
+/*
+ * cipher_crypt() operates as following:
+ * Copy 'aadlen' bytes (without en/decryption) from 'src' to 'dest'.
+ * Theses bytes are treated as additional authenticated data for
+ * authenticated encryption modes.
+ * En/Decrypt 'len' bytes at offset 'aadlen' from 'src' to 'dest'.
+ * Both 'aadlen' and 'authlen' can be set to 0.
+ */
void
-cipher_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
+cipher_crypt(CipherContext *cc, u_char *dest, const u_char *src,
+ u_int len, u_int aadlen)
{
+ if (aadlen)
+ memcpy(dest, src, aadlen);
if (len % cc->cipher->block_size)
- fatal("cipher_encrypt: bad plaintext length %d", len);
- if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0)
- fatal("evp_crypt: EVP_Cipher failed");
+ fatal("%s: bad plaintext length %d", __func__, len);
+ if (EVP_Cipher(&cc->evp, dest + aadlen, (u_char *)src + aadlen,
+ len) < 0)
+ fatal("%s: EVP_Cipher failed", __func__);
}
void