summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--Makefile.in4
-rw-r--r--cipher-ctr.c149
-rw-r--r--cipher.c13
-rw-r--r--myproposal.h5
5 files changed, 172 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e5bb37e2..ee0099624 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,11 @@
9 - itojun@cvs.openbsd.org 2003/05/17 03:25:58 9 - itojun@cvs.openbsd.org 2003/05/17 03:25:58
10 [auth-rhosts.c] 10 [auth-rhosts.c]
11 just in case, put numbers to sscanf %s arg. 11 just in case, put numbers to sscanf %s arg.
12 - markus@cvs.openbsd.org 2003/05/17 04:27:52
13 [cipher.c cipher-ctr.c myproposal.h]
14 experimental support for aes-ctr modes from
15 http://www.ietf.org/internet-drafts/draft-ietf-secsh-newmodes-00.txt
16 ok djm@
12 - (djm) Remove IPv4 by default hack now that we can specify AF in config 17 - (djm) Remove IPv4 by default hack now that we can specify AF in config
13 18
1420030517 1920030517
@@ -1565,4 +1570,4 @@
1565 save auth method before monitor_reset_key_state(); bugzilla bug #284; 1570 save auth method before monitor_reset_key_state(); bugzilla bug #284;
1566 ok provos@ 1571 ok provos@
1567 1572
1568$Id: ChangeLog,v 1.2735 2003/05/18 10:53:10 djm Exp $ 1573$Id: ChangeLog,v 1.2736 2003/05/18 10:53:59 djm Exp $
diff --git a/Makefile.in b/Makefile.in
index 004f05466..33058a828 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.236 2003/05/15 11:33:46 djm Exp $ 1# $Id: Makefile.in,v 1.237 2003/05/18 10:53:59 djm Exp $
2 2
3# uncomment if you run a non bourne compatable shell. Ie. csh 3# uncomment if you run a non bourne compatable shell. Ie. csh
4#SHELL = @SH@ 4#SHELL = @SH@
@@ -61,7 +61,7 @@ INSTALL_SSH_RAND_HELPER=@INSTALL_SSH_RAND_HELPER@
61TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} sftp-server$(EXEEXT) sftp$(EXEEXT) 61TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} sftp-server$(EXEEXT) sftp$(EXEEXT)
62 62
63LIBSSH_OBJS=authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o \ 63LIBSSH_OBJS=authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o \
64 cipher.o cipher-aes.o cipher-bf1.o cipher-3des1.o \ 64 cipher.o cipher-aes.o cipher-bf1.o cipher-ctr.o cipher-3des1.o \
65 compat.o compress.o crc32.o deattack.o fatal.o \ 65 compat.o compress.o crc32.o deattack.o fatal.o \
66 hostfile.o log.o match.o mpaux.o nchan.o packet.o radix.o \ 66 hostfile.o log.o match.o mpaux.o nchan.o packet.o radix.o \
67 readpass.o rsa.o tildexpand.o ttymodes.o xmalloc.o atomicio.o \ 67 readpass.o rsa.o tildexpand.o ttymodes.o xmalloc.o atomicio.o \
diff --git a/cipher-ctr.c b/cipher-ctr.c
new file mode 100644
index 000000000..8d548c708
--- /dev/null
+++ b/cipher-ctr.c
@@ -0,0 +1,149 @@
1/*
2 * Copyright (c) 2003 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24#include "includes.h"
25RCSID("$OpenBSD: cipher-ctr.c,v 1.1 2003/05/17 04:27:52 markus Exp $");
26
27#include <openssl/evp.h>
28
29#include "log.h"
30#include "xmalloc.h"
31
32#if OPENSSL_VERSION_NUMBER < 0x00907000L
33#include "rijndael.h"
34#define AES_KEY rijndael_ctx
35#define AES_BLOCK_SIZE 16
36#define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b)
37#define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1)
38#else
39#include <openssl/aes.h>
40#endif
41
42const EVP_CIPHER *evp_aes_128_ctr(void);
43void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
44
45struct ssh_aes_ctr_ctx
46{
47 AES_KEY aes_ctx;
48 u_char aes_counter[AES_BLOCK_SIZE];
49};
50
51/*
52 * increment counter 'ctr',
53 * the counter is of size 'len' bytes and stored in network-byte-order.
54 * (LSB at ctr[len-1], MSB at ctr[0])
55 */
56static void
57ssh_ctr_inc(u_char *ctr, u_int len)
58{
59 int i;
60
61 for (i = len - 1; i >= 0; i--)
62 if (++ctr[i]) /* continue on overflow */
63 return;
64}
65
66static int
67ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src,
68 u_int len)
69{
70 struct ssh_aes_ctr_ctx *c;
71 u_int n = 0;
72 u_char buf[AES_BLOCK_SIZE];
73
74 if (len == 0)
75 return (1);
76 if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL)
77 return (0);
78
79 while ((len--) > 0) {
80 if (n == 0) {
81 AES_encrypt(c->aes_counter, buf, &c->aes_ctx);
82 ssh_ctr_inc(c->aes_counter, AES_BLOCK_SIZE);
83 }
84 *(dest++) = *(src++) ^ buf[n];
85 n = (n + 1) % AES_BLOCK_SIZE;
86 }
87 return (1);
88}
89
90static int
91ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
92 int enc)
93{
94 struct ssh_aes_ctr_ctx *c;
95
96 if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) {
97 c = xmalloc(sizeof(*c));
98 EVP_CIPHER_CTX_set_app_data(ctx, c);
99 }
100 if (key != NULL)
101 AES_set_encrypt_key(key, ctx->key_len * 8, &c->aes_ctx);
102 if (iv != NULL)
103 memcpy(c->aes_counter, iv, AES_BLOCK_SIZE);
104 return (1);
105}
106
107static int
108ssh_aes_ctr_cleanup(EVP_CIPHER_CTX *ctx)
109{
110 struct ssh_aes_ctr_ctx *c;
111
112 if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) {
113 memset(c, 0, sizeof(*c));
114 xfree(c);
115 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
116 }
117 return (1);
118}
119
120void
121ssh_aes_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, u_int len)
122{
123 struct ssh_aes_ctr_ctx *c;
124
125 if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL)
126 fatal("ssh_aes_ctr_iv: no context");
127 if (doset)
128 memcpy(c->aes_counter, iv, len);
129 else
130 memcpy(iv, c->aes_counter, len);
131}
132
133const EVP_CIPHER *
134evp_aes_128_ctr(void)
135{
136 static EVP_CIPHER aes_ctr;
137
138 memset(&aes_ctr, 0, sizeof(EVP_CIPHER));
139 aes_ctr.nid = NID_undef;
140 aes_ctr.block_size = AES_BLOCK_SIZE;
141 aes_ctr.iv_len = AES_BLOCK_SIZE;
142 aes_ctr.key_len = 16;
143 aes_ctr.init = ssh_aes_ctr_init;
144 aes_ctr.cleanup = ssh_aes_ctr_cleanup;
145 aes_ctr.do_cipher = ssh_aes_ctr;
146 aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
147 EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
148 return (&aes_ctr);
149}
diff --git a/cipher.c b/cipher.c
index acb436c8a..e7c3c5411 100644
--- a/cipher.c
+++ b/cipher.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: cipher.c,v 1.64 2003/05/15 03:08:29 markus Exp $"); 38RCSID("$OpenBSD: cipher.c,v 1.65 2003/05/17 04:27:52 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "log.h" 41#include "log.h"
@@ -55,6 +55,8 @@ extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
55extern const EVP_CIPHER *evp_ssh1_bf(void); 55extern const EVP_CIPHER *evp_ssh1_bf(void);
56extern const EVP_CIPHER *evp_ssh1_3des(void); 56extern const EVP_CIPHER *evp_ssh1_3des(void);
57extern void ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int); 57extern void ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int);
58extern const EVP_CIPHER *evp_aes_128_ctr(void);
59extern void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
58 60
59struct Cipher { 61struct Cipher {
60 char *name; 62 char *name;
@@ -85,6 +87,9 @@ struct Cipher {
85 { "rijndael-cbc@lysator.liu.se", 87 { "rijndael-cbc@lysator.liu.se",
86 SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc }, 88 SSH_CIPHER_SSH2, 16, 32, EVP_aes_256_cbc },
87#endif 89#endif
90 { "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, evp_aes_128_ctr },
91 { "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, evp_aes_128_ctr },
92 { "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, evp_aes_128_ctr },
88 93
89 { NULL, SSH_CIPHER_ILLEGAL, 0, 0, NULL } 94 { NULL, SSH_CIPHER_ILLEGAL, 0, 0, NULL }
90}; 95};
@@ -337,6 +342,9 @@ cipher_get_keyiv(CipherContext *cc, u_char *iv, u_int len)
337 ssh_rijndael_iv(&cc->evp, 0, iv, len); 342 ssh_rijndael_iv(&cc->evp, 0, iv, len);
338 else 343 else
339#endif 344#endif
345 if (c->evptype == evp_aes_128_ctr)
346 ssh_aes_ctr_iv(&cc->evp, 0, iv, len);
347 else
340 memcpy(iv, cc->evp.iv, len); 348 memcpy(iv, cc->evp.iv, len);
341 break; 349 break;
342 case SSH_CIPHER_3DES: 350 case SSH_CIPHER_3DES:
@@ -365,6 +373,9 @@ cipher_set_keyiv(CipherContext *cc, u_char *iv)
365 ssh_rijndael_iv(&cc->evp, 1, iv, evplen); 373 ssh_rijndael_iv(&cc->evp, 1, iv, evplen);
366 else 374 else
367#endif 375#endif
376 if (c->evptype == evp_aes_128_ctr)
377 ssh_aes_ctr_iv(&cc->evp, 1, iv, evplen);
378 else
368 memcpy(cc->evp.iv, iv, evplen); 379 memcpy(cc->evp.iv, iv, evplen);
369 break; 380 break;
370 case SSH_CIPHER_3DES: 381 case SSH_CIPHER_3DES:
diff --git a/myproposal.h b/myproposal.h
index 62f5cfb65..8b431d9d2 100644
--- a/myproposal.h
+++ b/myproposal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: myproposal.h,v 1.14 2002/04/03 09:26:11 markus Exp $ */ 1/* $OpenBSD: myproposal.h,v 1.15 2003/05/17 04:27:52 markus Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -27,7 +27,8 @@
27#define KEX_DEFAULT_PK_ALG "ssh-rsa,ssh-dss" 27#define KEX_DEFAULT_PK_ALG "ssh-rsa,ssh-dss"
28#define KEX_DEFAULT_ENCRYPT \ 28#define KEX_DEFAULT_ENCRYPT \
29 "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour," \ 29 "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour," \
30 "aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se" 30 "aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
31 "aes128-ctr,aes192-ctr,aes256-ctr"
31#define KEX_DEFAULT_MAC \ 32#define KEX_DEFAULT_MAC \
32 "hmac-md5,hmac-sha1,hmac-ripemd160," \ 33 "hmac-md5,hmac-sha1,hmac-ripemd160," \
33 "hmac-ripemd160@openssh.com," \ 34 "hmac-ripemd160@openssh.com," \