djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 1 | /* $OpenBSD: cipher.c,v 1.102 2016/08/03 05:41:57 djm Exp $ */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 2 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 5 | * All rights reserved |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 6 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 7 | * As far as I am concerned, the code I have written for this software |
| 8 | * can be used freely for any purpose. Any derived versions of this |
| 9 | * software must be clearly marked as such, and if the derived work is |
| 10 | * incompatible with the protocol description in the RFC file, it must be |
| 11 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 12 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 13 | * |
| 14 | * Copyright (c) 1999 Niels Provos. All rights reserved. |
Ben Lindstrom | 4469723 | 2001-07-04 03:32:30 +0000 | [diff] [blame] | 15 | * Copyright (c) 1999, 2000 Markus Friedl. All rights reserved. |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 16 | * |
| 17 | * Redistribution and use in source and binary forms, with or without |
| 18 | * modification, are permitted provided that the following conditions |
| 19 | * are met: |
| 20 | * 1. Redistributions of source code must retain the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer. |
| 22 | * 2. Redistributions in binary form must reproduce the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer in the |
| 24 | * documentation and/or other materials provided with the distribution. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 27 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 28 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 29 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 30 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 31 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 35 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 36 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 37 | |
| 38 | #include "includes.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 39 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 40 | #include <sys/types.h> |
| 41 | |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 42 | #include <string.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 43 | #include <stdarg.h> |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 44 | #include <stdio.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 45 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 46 | #include "cipher.h" |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 47 | #include "misc.h" |
| 48 | #include "sshbuf.h" |
| 49 | #include "ssherr.h" |
Damien Miller | 4a1c7aa | 2014-02-04 11:03:36 +1100 | [diff] [blame] | 50 | #include "digest.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 51 | |
Darren Tucker | 5573171 | 2014-07-21 02:24:59 +1000 | [diff] [blame] | 52 | #include "openbsd-compat/openssl-compat.h" |
| 53 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 54 | #ifdef WITH_SSH1 |
Damien Miller | 3a3261f | 2003-05-15 13:37:19 +1000 | [diff] [blame] | 55 | extern const EVP_CIPHER *evp_ssh1_bf(void); |
| 56 | extern const EVP_CIPHER *evp_ssh1_3des(void); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 57 | extern int ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 58 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 59 | |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 60 | struct sshcipher_ctx { |
| 61 | int plaintext; |
| 62 | int encrypt; |
| 63 | EVP_CIPHER_CTX *evp; |
| 64 | struct chachapoly_ctx cp_ctx; /* XXX union with evp? */ |
| 65 | struct aesctr_ctx ac_ctx; /* XXX union with evp? */ |
| 66 | const struct sshcipher *cipher; |
| 67 | }; |
| 68 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 69 | struct sshcipher { |
Damien Miller | 963f6b2 | 2002-02-19 15:21:23 +1100 | [diff] [blame] | 70 | char *name; |
| 71 | int number; /* for ssh1 only */ |
| 72 | u_int block_size; |
| 73 | u_int key_len; |
Damien Miller | d522c68 | 2013-01-09 16:42:47 +1100 | [diff] [blame] | 74 | u_int iv_len; /* defaults to block_size */ |
| 75 | u_int auth_len; |
Damien Miller | 3710f27 | 2005-05-26 12:19:17 +1000 | [diff] [blame] | 76 | u_int discard_len; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 77 | u_int flags; |
| 78 | #define CFLAG_CBC (1<<0) |
| 79 | #define CFLAG_CHACHAPOLY (1<<1) |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 80 | #define CFLAG_AESCTR (1<<2) |
| 81 | #define CFLAG_NONE (1<<3) |
| 82 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 6a24641 | 2002-06-06 19:48:16 +0000 | [diff] [blame] | 83 | const EVP_CIPHER *(*evptype)(void); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 84 | #else |
| 85 | void *ignored; |
| 86 | #endif |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 87 | }; |
| 88 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 89 | static const struct sshcipher ciphers[] = { |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 90 | #ifdef WITH_SSH1 |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 91 | { "des", SSH_CIPHER_DES, 8, 8, 0, 0, 0, 1, EVP_des_cbc }, |
| 92 | { "3des", SSH_CIPHER_3DES, 8, 16, 0, 0, 0, 1, evp_ssh1_3des }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 93 | # ifndef OPENSSL_NO_BF |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 94 | { "blowfish", SSH_CIPHER_BLOWFISH, 8, 32, 0, 0, 0, 1, evp_ssh1_bf }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 95 | # endif /* OPENSSL_NO_BF */ |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 96 | #endif /* WITH_SSH1 */ |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 97 | #ifdef WITH_OPENSSL |
| 98 | { "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, 0, EVP_enc_null }, |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 99 | { "3des-cbc", SSH_CIPHER_SSH2, 8, 24, 0, 0, 0, 1, EVP_des_ede3_cbc }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 100 | # ifndef OPENSSL_NO_BF |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 101 | { "blowfish-cbc", |
| 102 | SSH_CIPHER_SSH2, 8, 16, 0, 0, 0, 1, EVP_bf_cbc }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 103 | # endif /* OPENSSL_NO_BF */ |
| 104 | # ifndef OPENSSL_NO_CAST |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 105 | { "cast128-cbc", |
| 106 | SSH_CIPHER_SSH2, 8, 16, 0, 0, 0, 1, EVP_cast5_cbc }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 107 | # endif /* OPENSSL_NO_CAST */ |
| 108 | # ifndef OPENSSL_NO_RC4 |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 109 | { "arcfour", SSH_CIPHER_SSH2, 8, 16, 0, 0, 0, 0, EVP_rc4 }, |
| 110 | { "arcfour128", SSH_CIPHER_SSH2, 8, 16, 0, 0, 1536, 0, EVP_rc4 }, |
| 111 | { "arcfour256", SSH_CIPHER_SSH2, 8, 32, 0, 0, 1536, 0, EVP_rc4 }, |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 112 | # endif /* OPENSSL_NO_RC4 */ |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 113 | { "aes128-cbc", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 1, EVP_aes_128_cbc }, |
| 114 | { "aes192-cbc", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 1, EVP_aes_192_cbc }, |
| 115 | { "aes256-cbc", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc }, |
| 116 | { "rijndael-cbc@lysator.liu.se", |
| 117 | SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc }, |
| 118 | { "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 0, EVP_aes_128_ctr }, |
| 119 | { "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 0, EVP_aes_192_ctr }, |
| 120 | { "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 0, EVP_aes_256_ctr }, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 121 | # ifdef OPENSSL_HAVE_EVPGCM |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 122 | { "aes128-gcm@openssh.com", |
| 123 | SSH_CIPHER_SSH2, 16, 16, 12, 16, 0, 0, EVP_aes_128_gcm }, |
| 124 | { "aes256-gcm@openssh.com", |
| 125 | SSH_CIPHER_SSH2, 16, 32, 12, 16, 0, 0, EVP_aes_256_gcm }, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 126 | # endif /* OPENSSL_HAVE_EVPGCM */ |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 127 | #else /* WITH_OPENSSL */ |
| 128 | { "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, CFLAG_AESCTR, NULL }, |
| 129 | { "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, CFLAG_AESCTR, NULL }, |
| 130 | { "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, CFLAG_AESCTR, NULL }, |
| 131 | { "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, CFLAG_NONE, NULL }, |
| 132 | #endif /* WITH_OPENSSL */ |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 133 | { "chacha20-poly1305@openssh.com", |
| 134 | SSH_CIPHER_SSH2, 8, 64, 0, 16, 0, CFLAG_CHACHAPOLY, NULL }, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 135 | |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 136 | { NULL, SSH_CIPHER_INVALID, 0, 0, 0, 0, 0, 0, NULL } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 137 | }; |
| 138 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 139 | /*--*/ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 140 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 141 | /* Returns a comma-separated list of supported ciphers. */ |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 142 | char * |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 143 | cipher_alg_list(char sep, int auth_only) |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 144 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 145 | char *tmp, *ret = NULL; |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 146 | size_t nlen, rlen = 0; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 147 | const struct sshcipher *c; |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 148 | |
| 149 | for (c = ciphers; c->name != NULL; c++) { |
| 150 | if (c->number != SSH_CIPHER_SSH2) |
| 151 | continue; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 152 | if (auth_only && c->auth_len == 0) |
| 153 | continue; |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 154 | if (ret != NULL) |
Damien Miller | 690d989 | 2013-11-08 12:16:49 +1100 | [diff] [blame] | 155 | ret[rlen++] = sep; |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 156 | nlen = strlen(c->name); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 157 | if ((tmp = realloc(ret, rlen + nlen + 2)) == NULL) { |
| 158 | free(ret); |
| 159 | return NULL; |
| 160 | } |
| 161 | ret = tmp; |
Damien Miller | ea11119 | 2013-04-23 19:24:32 +1000 | [diff] [blame] | 162 | memcpy(ret + rlen, c->name, nlen + 1); |
| 163 | rlen += nlen; |
| 164 | } |
| 165 | return ret; |
| 166 | } |
| 167 | |
Ben Lindstrom | 6328ab3 | 2002-03-22 02:54:23 +0000 | [diff] [blame] | 168 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 169 | cipher_blocksize(const struct sshcipher *c) |
Damien Miller | 963f6b2 | 2002-02-19 15:21:23 +1100 | [diff] [blame] | 170 | { |
| 171 | return (c->block_size); |
| 172 | } |
Ben Lindstrom | 836f0e9 | 2002-06-23 21:21:30 +0000 | [diff] [blame] | 173 | |
Ben Lindstrom | 6328ab3 | 2002-03-22 02:54:23 +0000 | [diff] [blame] | 174 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 175 | cipher_keylen(const struct sshcipher *c) |
Damien Miller | 963f6b2 | 2002-02-19 15:21:23 +1100 | [diff] [blame] | 176 | { |
| 177 | return (c->key_len); |
| 178 | } |
Ben Lindstrom | 836f0e9 | 2002-06-23 21:21:30 +0000 | [diff] [blame] | 179 | |
Ben Lindstrom | 6328ab3 | 2002-03-22 02:54:23 +0000 | [diff] [blame] | 180 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 181 | cipher_seclen(const struct sshcipher *c) |
Damien Miller | 76eea4a | 2014-01-26 09:37:25 +1100 | [diff] [blame] | 182 | { |
| 183 | if (strcmp("3des-cbc", c->name) == 0) |
| 184 | return 14; |
| 185 | return cipher_keylen(c); |
| 186 | } |
| 187 | |
| 188 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 189 | cipher_authlen(const struct sshcipher *c) |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 190 | { |
| 191 | return (c->auth_len); |
| 192 | } |
| 193 | |
| 194 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 195 | cipher_ivlen(const struct sshcipher *c) |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 196 | { |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 197 | /* |
| 198 | * Default is cipher block size, except for chacha20+poly1305 that |
| 199 | * needs no IV. XXX make iv_len == -1 default? |
| 200 | */ |
| 201 | return (c->iv_len != 0 || (c->flags & CFLAG_CHACHAPOLY) != 0) ? |
| 202 | c->iv_len : c->block_size; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 206 | cipher_get_number(const struct sshcipher *c) |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 207 | { |
| 208 | return (c->number); |
| 209 | } |
Damien Miller | 963f6b2 | 2002-02-19 15:21:23 +1100 | [diff] [blame] | 210 | |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 211 | u_int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 212 | cipher_is_cbc(const struct sshcipher *c) |
Damien Miller | 13ae44c | 2009-01-28 16:38:41 +1100 | [diff] [blame] | 213 | { |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 214 | return (c->flags & CFLAG_CBC) != 0; |
Damien Miller | 13ae44c | 2009-01-28 16:38:41 +1100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | u_int |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 218 | cipher_ctx_is_plaintext(struct sshcipher_ctx *cc) |
| 219 | { |
| 220 | return cc->plaintext; |
| 221 | } |
| 222 | |
| 223 | u_int |
| 224 | cipher_ctx_get_number(struct sshcipher_ctx *cc) |
| 225 | { |
| 226 | return cc->cipher->number; |
| 227 | } |
| 228 | |
| 229 | u_int |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 230 | cipher_mask_ssh1(int client) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 231 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 232 | u_int mask = 0; |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 233 | mask |= 1 << SSH_CIPHER_3DES; /* Mandatory */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 234 | mask |= 1 << SSH_CIPHER_BLOWFISH; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 235 | if (client) { |
| 236 | mask |= 1 << SSH_CIPHER_DES; |
| 237 | } |
Damien Miller | 1383bd8 | 2000-04-06 12:32:37 +1000 | [diff] [blame] | 238 | return mask; |
| 239 | } |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 240 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 241 | const struct sshcipher * |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 242 | cipher_by_name(const char *name) |
Damien Miller | 1383bd8 | 2000-04-06 12:32:37 +1000 | [diff] [blame] | 243 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 244 | const struct sshcipher *c; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 245 | for (c = ciphers; c->name != NULL; c++) |
Darren Tucker | 660db78 | 2005-01-24 21:57:11 +1100 | [diff] [blame] | 246 | if (strcmp(c->name, name) == 0) |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 247 | return c; |
| 248 | return NULL; |
Damien Miller | 1383bd8 | 2000-04-06 12:32:37 +1000 | [diff] [blame] | 249 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 250 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 251 | const struct sshcipher * |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 252 | cipher_by_number(int id) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 253 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 254 | const struct sshcipher *c; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 255 | for (c = ciphers; c->name != NULL; c++) |
| 256 | if (c->number == id) |
| 257 | return c; |
| 258 | return NULL; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 259 | } |
| 260 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 261 | #define CIPHER_SEP "," |
| 262 | int |
| 263 | ciphers_valid(const char *names) |
| 264 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 265 | const struct sshcipher *c; |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 266 | char *cipher_list, *cp; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 267 | char *p; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 268 | |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 269 | if (names == NULL || strcmp(names, "") == 0) |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 270 | return 0; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 271 | if ((cipher_list = cp = strdup(names)) == NULL) |
| 272 | return 0; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 273 | for ((p = strsep(&cp, CIPHER_SEP)); p && *p != '\0'; |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 274 | (p = strsep(&cp, CIPHER_SEP))) { |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 275 | c = cipher_by_name(p); |
| 276 | if (c == NULL || c->number != SSH_CIPHER_SSH2) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 277 | free(cipher_list); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | } |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 281 | free(cipher_list); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 282 | return 1; |
| 283 | } |
| 284 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 285 | /* |
| 286 | * Parses the name of the cipher. Returns the number of the corresponding |
| 287 | * cipher, or -1 on error. |
| 288 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 289 | |
| 290 | int |
| 291 | cipher_number(const char *name) |
| 292 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 293 | const struct sshcipher *c; |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 294 | if (name == NULL) |
| 295 | return -1; |
Darren Tucker | 660db78 | 2005-01-24 21:57:11 +1100 | [diff] [blame] | 296 | for (c = ciphers; c->name != NULL; c++) |
| 297 | if (strcasecmp(c->name, name) == 0) |
| 298 | return c->number; |
| 299 | return -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | char * |
| 303 | cipher_name(int id) |
| 304 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 305 | const struct sshcipher *c = cipher_by_number(id); |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 306 | return (c==NULL) ? "<unknown>" : c->name; |
| 307 | } |
| 308 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 309 | const char * |
| 310 | cipher_warning_message(const struct sshcipher_ctx *cc) |
| 311 | { |
| 312 | if (cc == NULL || cc->cipher == NULL) |
| 313 | return NULL; |
| 314 | if (cc->cipher->number == SSH_CIPHER_DES) |
| 315 | return "use of DES is strongly discouraged due to " |
| 316 | "cryptographic weaknesses"; |
| 317 | return NULL; |
| 318 | } |
| 319 | |
| 320 | int |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 321 | cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher, |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 322 | const u_char *key, u_int keylen, const u_char *iv, u_int ivlen, |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 323 | int do_encrypt) |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 324 | { |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 325 | struct sshcipher_ctx *cc = NULL; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 326 | int ret = SSH_ERR_INTERNAL_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 327 | #ifdef WITH_OPENSSL |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 328 | const EVP_CIPHER *type; |
| 329 | int klen; |
Damien Miller | 3710f27 | 2005-05-26 12:19:17 +1000 | [diff] [blame] | 330 | u_char *junk, *discard; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 331 | #endif |
| 332 | |
| 333 | *ccp = NULL; |
| 334 | if ((cc = calloc(sizeof(*cc), 1)) == NULL) |
| 335 | return SSH_ERR_ALLOC_FAIL; |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 336 | |
| 337 | if (cipher->number == SSH_CIPHER_DES) { |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 338 | if (keylen > 8) |
| 339 | keylen = 8; |
| 340 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 341 | |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 342 | cc->plaintext = (cipher->number == SSH_CIPHER_NONE); |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 343 | cc->encrypt = do_encrypt; |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 344 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 345 | if (keylen < cipher->key_len || |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 346 | (iv != NULL && ivlen < cipher_ivlen(cipher))) { |
| 347 | ret = SSH_ERR_INVALID_ARGUMENT; |
| 348 | goto out; |
| 349 | } |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 350 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 351 | cc->cipher = cipher; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 352 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) { |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 353 | ret = chachapoly_init(&cc->cp_ctx, key, keylen); |
| 354 | goto out; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 355 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 356 | #ifndef WITH_OPENSSL |
| 357 | if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { |
| 358 | aesctr_keysetup(&cc->ac_ctx, key, 8 * keylen, 8 * ivlen); |
| 359 | aesctr_ivsetup(&cc->ac_ctx, iv); |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 360 | ret = 0; |
| 361 | goto out; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 362 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 363 | if ((cc->cipher->flags & CFLAG_NONE) != 0) { |
| 364 | ret = 0; |
| 365 | goto out; |
| 366 | } |
| 367 | ret = SSH_ERR_INVALID_ARGUMENT; |
| 368 | goto out; |
| 369 | #else /* WITH_OPENSSL */ |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 370 | type = (*cipher->evptype)(); |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 371 | if ((cc->evp = EVP_CIPHER_CTX_new()) == NULL) { |
| 372 | ret = SSH_ERR_ALLOC_FAIL; |
| 373 | goto out; |
| 374 | } |
| 375 | if (EVP_CipherInit(cc->evp, type, NULL, (u_char *)iv, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 376 | (do_encrypt == CIPHER_ENCRYPT)) == 0) { |
| 377 | ret = SSH_ERR_LIBCRYPTO_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 378 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 379 | } |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 380 | if (cipher_authlen(cipher) && |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 381 | !EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_SET_IV_FIXED, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 382 | -1, (u_char *)iv)) { |
| 383 | ret = SSH_ERR_LIBCRYPTO_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 384 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 385 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 386 | klen = EVP_CIPHER_CTX_key_length(cc->evp); |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 387 | if (klen > 0 && keylen != (u_int)klen) { |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 388 | if (EVP_CIPHER_CTX_set_key_length(cc->evp, keylen) == 0) { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 389 | ret = SSH_ERR_LIBCRYPTO_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 390 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 391 | } |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 392 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 393 | if (EVP_CipherInit(cc->evp, NULL, (u_char *)key, NULL, -1) == 0) { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 394 | ret = SSH_ERR_LIBCRYPTO_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 395 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 396 | } |
Damien Miller | 3710f27 | 2005-05-26 12:19:17 +1000 | [diff] [blame] | 397 | |
Damien Miller | 46d38de | 2005-07-17 17:02:09 +1000 | [diff] [blame] | 398 | if (cipher->discard_len > 0) { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 399 | if ((junk = malloc(cipher->discard_len)) == NULL || |
| 400 | (discard = malloc(cipher->discard_len)) == NULL) { |
mmcc@openbsd.org | d59ce08 | 2015-12-10 17:08:40 +0000 | [diff] [blame] | 401 | free(junk); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 402 | ret = SSH_ERR_ALLOC_FAIL; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 403 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 404 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 405 | ret = EVP_Cipher(cc->evp, discard, junk, cipher->discard_len); |
Damien Miller | a5103f4 | 2014-02-04 11:20:14 +1100 | [diff] [blame] | 406 | explicit_bzero(discard, cipher->discard_len); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 407 | free(junk); |
| 408 | free(discard); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 409 | if (ret != 1) { |
| 410 | ret = SSH_ERR_LIBCRYPTO_ERROR; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 411 | goto out; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 412 | } |
Damien Miller | 3710f27 | 2005-05-26 12:19:17 +1000 | [diff] [blame] | 413 | } |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 414 | ret = 0; |
| 415 | #endif /* WITH_OPENSSL */ |
| 416 | out: |
| 417 | if (ret == 0) { |
| 418 | /* success */ |
| 419 | *ccp = cc; |
| 420 | } else { |
| 421 | if (cc != NULL) { |
| 422 | #ifdef WITH_OPENSSL |
| 423 | if (cc->evp != NULL) |
| 424 | EVP_CIPHER_CTX_free(cc->evp); |
| 425 | #endif /* WITH_OPENSSL */ |
| 426 | explicit_bzero(cc, sizeof(*cc)); |
| 427 | free(cc); |
| 428 | } |
| 429 | } |
| 430 | return ret; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 431 | } |
| 432 | |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 433 | /* |
| 434 | * cipher_crypt() operates as following: |
| 435 | * Copy 'aadlen' bytes (without en/decryption) from 'src' to 'dest'. |
| 436 | * Theses bytes are treated as additional authenticated data for |
| 437 | * authenticated encryption modes. |
| 438 | * En/Decrypt 'len' bytes at offset 'aadlen' from 'src' to 'dest'. |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 439 | * Use 'authlen' bytes at offset 'len'+'aadlen' as the authentication tag. |
| 440 | * This tag is written on encryption and verified on decryption. |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 441 | * Both 'aadlen' and 'authlen' can be set to 0. |
| 442 | */ |
Damien Miller | bcd00ab | 2013-12-07 10:41:55 +1100 | [diff] [blame] | 443 | int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 444 | cipher_crypt(struct sshcipher_ctx *cc, u_int seqnr, u_char *dest, |
| 445 | const u_char *src, u_int len, u_int aadlen, u_int authlen) |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 446 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 447 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) { |
| 448 | return chachapoly_crypt(&cc->cp_ctx, seqnr, dest, src, |
| 449 | len, aadlen, authlen, cc->encrypt); |
| 450 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 451 | #ifndef WITH_OPENSSL |
| 452 | if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { |
| 453 | if (aadlen) |
| 454 | memcpy(dest, src, aadlen); |
| 455 | aesctr_encrypt_bytes(&cc->ac_ctx, src + aadlen, |
| 456 | dest + aadlen, len); |
| 457 | return 0; |
| 458 | } |
| 459 | if ((cc->cipher->flags & CFLAG_NONE) != 0) { |
| 460 | memcpy(dest, src, aadlen + len); |
| 461 | return 0; |
| 462 | } |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 463 | return SSH_ERR_INVALID_ARGUMENT; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 464 | #else |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 465 | if (authlen) { |
| 466 | u_char lastiv[1]; |
| 467 | |
| 468 | if (authlen != cipher_authlen(cc->cipher)) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 469 | return SSH_ERR_INVALID_ARGUMENT; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 470 | /* increment IV */ |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 471 | if (!EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_IV_GEN, |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 472 | 1, lastiv)) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 473 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 474 | /* set tag on decyption */ |
| 475 | if (!cc->encrypt && |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 476 | !EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_SET_TAG, |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 477 | authlen, (u_char *)src + aadlen + len)) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 478 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 479 | } |
| 480 | if (aadlen) { |
| 481 | if (authlen && |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 482 | EVP_Cipher(cc->evp, NULL, (u_char *)src, aadlen) < 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 483 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 484 | memcpy(dest, src, aadlen); |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 485 | } |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 486 | if (len % cc->cipher->block_size) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 487 | return SSH_ERR_INVALID_ARGUMENT; |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 488 | if (EVP_Cipher(cc->evp, dest + aadlen, (u_char *)src + aadlen, |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 489 | len) < 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 490 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 491 | if (authlen) { |
| 492 | /* compute tag (on encrypt) or verify tag (on decrypt) */ |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 493 | if (EVP_Cipher(cc->evp, NULL, NULL, 0) < 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 494 | return cc->encrypt ? |
| 495 | SSH_ERR_LIBCRYPTO_ERROR : SSH_ERR_MAC_INVALID; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 496 | if (cc->encrypt && |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 497 | !EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_GET_TAG, |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 498 | authlen, dest + aadlen + len)) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 499 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 500 | } |
Damien Miller | bcd00ab | 2013-12-07 10:41:55 +1100 | [diff] [blame] | 501 | return 0; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 502 | #endif |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 503 | } |
| 504 | |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 505 | /* Extract the packet length, including any decryption necessary beforehand */ |
| 506 | int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 507 | cipher_get_length(struct sshcipher_ctx *cc, u_int *plenp, u_int seqnr, |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 508 | const u_char *cp, u_int len) |
| 509 | { |
| 510 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) |
| 511 | return chachapoly_get_length(&cc->cp_ctx, plenp, seqnr, |
| 512 | cp, len); |
| 513 | if (len < 4) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 514 | return SSH_ERR_MESSAGE_INCOMPLETE; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 515 | *plenp = get_u32(cp); |
| 516 | return 0; |
| 517 | } |
| 518 | |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 519 | void |
| 520 | cipher_free(struct sshcipher_ctx *cc) |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 521 | { |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 522 | if (cc == NULL) |
| 523 | return; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 524 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) |
Damien Miller | a5103f4 | 2014-02-04 11:20:14 +1100 | [diff] [blame] | 525 | explicit_bzero(&cc->cp_ctx, sizeof(cc->cp_ctx)); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 526 | else if ((cc->cipher->flags & CFLAG_AESCTR) != 0) |
| 527 | explicit_bzero(&cc->ac_ctx, sizeof(cc->ac_ctx)); |
| 528 | #ifdef WITH_OPENSSL |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 529 | if (cc->evp != NULL) { |
| 530 | EVP_CIPHER_CTX_free(cc->evp); |
| 531 | cc->evp = NULL; |
| 532 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 533 | #endif |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 534 | explicit_bzero(cc, sizeof(*cc)); |
| 535 | free(cc); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 536 | } |
| 537 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 538 | /* |
| 539 | * Selects the cipher, and keys if by computing the MD5 checksum of the |
| 540 | * passphrase and using the resulting 16 bytes as the key. |
| 541 | */ |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 542 | int |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 543 | cipher_set_key_string(struct sshcipher_ctx **ccp, |
| 544 | const struct sshcipher *cipher, const char *passphrase, int do_encrypt) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 545 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 546 | u_char digest[16]; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 547 | int r = SSH_ERR_INTERNAL_ERROR; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 548 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 549 | if ((r = ssh_digest_memory(SSH_DIGEST_MD5, |
| 550 | passphrase, strlen(passphrase), |
| 551 | digest, sizeof(digest))) != 0) |
| 552 | goto out; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 553 | |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 554 | r = cipher_init(ccp, cipher, digest, 16, NULL, 0, do_encrypt); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 555 | out: |
Damien Miller | a5103f4 | 2014-02-04 11:20:14 +1100 | [diff] [blame] | 556 | explicit_bzero(digest, sizeof(digest)); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 557 | return r; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 558 | } |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 559 | |
Ben Lindstrom | 6328ab3 | 2002-03-22 02:54:23 +0000 | [diff] [blame] | 560 | /* |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 561 | * Exports an IV from the sshcipher_ctx required to export the key |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 562 | * state back from the unprivileged child to the privileged parent |
| 563 | * process. |
| 564 | */ |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 565 | int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 566 | cipher_get_keyiv_len(const struct sshcipher_ctx *cc) |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 567 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 568 | const struct sshcipher *c = cc->cipher; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 569 | int ivlen = 0; |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 570 | |
| 571 | if (c->number == SSH_CIPHER_3DES) |
| 572 | ivlen = 24; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 573 | else if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) |
| 574 | ivlen = 0; |
djm@openbsd.org | 540e891 | 2015-01-14 10:29:45 +0000 | [diff] [blame] | 575 | else if ((cc->cipher->flags & CFLAG_AESCTR) != 0) |
| 576 | ivlen = sizeof(cc->ac_ctx.ctr); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 577 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 578 | else |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 579 | ivlen = EVP_CIPHER_CTX_iv_length(cc->evp); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 580 | #endif /* WITH_OPENSSL */ |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 581 | return (ivlen); |
| 582 | } |
| 583 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 584 | int |
| 585 | cipher_get_keyiv(struct sshcipher_ctx *cc, u_char *iv, u_int len) |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 586 | { |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 587 | const struct sshcipher *c = cc->cipher; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 588 | #ifdef WITH_OPENSSL |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 589 | int evplen; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 590 | #endif |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 591 | |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 592 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) { |
| 593 | if (len != 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 594 | return SSH_ERR_INVALID_ARGUMENT; |
| 595 | return 0; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 596 | } |
djm@openbsd.org | 540e891 | 2015-01-14 10:29:45 +0000 | [diff] [blame] | 597 | if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { |
| 598 | if (len != sizeof(cc->ac_ctx.ctr)) |
| 599 | return SSH_ERR_INVALID_ARGUMENT; |
| 600 | memcpy(iv, cc->ac_ctx.ctr, len); |
| 601 | return 0; |
| 602 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 603 | if ((cc->cipher->flags & CFLAG_NONE) != 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 604 | return 0; |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame] | 605 | |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 606 | switch (c->number) { |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 607 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 608 | case SSH_CIPHER_SSH2: |
| 609 | case SSH_CIPHER_DES: |
| 610 | case SSH_CIPHER_BLOWFISH: |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 611 | evplen = EVP_CIPHER_CTX_iv_length(cc->evp); |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 612 | if (evplen == 0) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 613 | return 0; |
| 614 | else if (evplen < 0) |
| 615 | return SSH_ERR_LIBCRYPTO_ERROR; |
| 616 | if ((u_int)evplen != len) |
| 617 | return SSH_ERR_INVALID_ARGUMENT; |
Darren Tucker | 5573171 | 2014-07-21 02:24:59 +1000 | [diff] [blame] | 618 | #ifndef OPENSSL_HAVE_EVPCTR |
| 619 | if (c->evptype == evp_aes_128_ctr) |
Damien Miller | 315d2a4 | 2016-10-28 14:34:07 +1100 | [diff] [blame] | 620 | ssh_aes_ctr_iv(cc->evp, 0, iv, len); |
Darren Tucker | 5573171 | 2014-07-21 02:24:59 +1000 | [diff] [blame] | 621 | else |
| 622 | #endif |
Damien Miller | eae8874 | 2014-05-27 14:27:02 +1000 | [diff] [blame] | 623 | if (cipher_authlen(c)) { |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 624 | if (!EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_IV_GEN, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 625 | len, iv)) |
| 626 | return SSH_ERR_LIBCRYPTO_ERROR; |
| 627 | } else |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 628 | memcpy(iv, cc->evp->iv, len); |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 629 | break; |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 630 | #endif |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 631 | #ifdef WITH_SSH1 |
Damien Miller | a201bb3 | 2003-05-14 13:41:23 +1000 | [diff] [blame] | 632 | case SSH_CIPHER_3DES: |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 633 | return ssh1_3des_iv(cc->evp, 0, iv, 24); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 634 | #endif |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 635 | default: |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 636 | return SSH_ERR_INVALID_ARGUMENT; |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 637 | } |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 638 | return 0; |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 641 | int |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 642 | cipher_set_keyiv(struct sshcipher_ctx *cc, const u_char *iv) |
| 643 | { |
| 644 | const struct sshcipher *c = cc->cipher; |
| 645 | #ifdef WITH_OPENSSL |
| 646 | int evplen = 0; |
| 647 | #endif |
| 648 | |
| 649 | if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) |
| 650 | return 0; |
| 651 | if ((cc->cipher->flags & CFLAG_NONE) != 0) |
| 652 | return 0; |
| 653 | |
| 654 | switch (c->number) { |
| 655 | #ifdef WITH_OPENSSL |
| 656 | case SSH_CIPHER_SSH2: |
| 657 | case SSH_CIPHER_DES: |
| 658 | case SSH_CIPHER_BLOWFISH: |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 659 | evplen = EVP_CIPHER_CTX_iv_length(cc->evp); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 660 | if (evplen <= 0) |
| 661 | return SSH_ERR_LIBCRYPTO_ERROR; |
Damien Miller | 315d2a4 | 2016-10-28 14:34:07 +1100 | [diff] [blame] | 662 | #ifndef OPENSSL_HAVE_EVPCTR |
| 663 | /* XXX iv arg is const, but ssh_aes_ctr_iv isn't */ |
| 664 | if (c->evptype == evp_aes_128_ctr) |
| 665 | ssh_aes_ctr_iv(cc->evp, 1, (u_char *)iv, evplen); |
| 666 | else |
| 667 | #endif |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 668 | if (cipher_authlen(c)) { |
| 669 | /* XXX iv arg is const, but EVP_CIPHER_CTX_ctrl isn't */ |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 670 | if (!EVP_CIPHER_CTX_ctrl(cc->evp, |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 671 | EVP_CTRL_GCM_SET_IV_FIXED, -1, (void *)iv)) |
| 672 | return SSH_ERR_LIBCRYPTO_ERROR; |
| 673 | } else |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 674 | memcpy(cc->evp->iv, iv, evplen); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 675 | break; |
| 676 | #endif |
| 677 | #ifdef WITH_SSH1 |
| 678 | case SSH_CIPHER_3DES: |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 679 | return ssh1_3des_iv(cc->evp, 1, (u_char *)iv, 24); |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 680 | #endif |
| 681 | default: |
| 682 | return SSH_ERR_INVALID_ARGUMENT; |
| 683 | } |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | #ifdef WITH_OPENSSL |
djm@openbsd.org | 4706c1d | 2016-08-03 05:41:57 +0000 | [diff] [blame] | 688 | #define EVP_X_STATE(evp) (evp)->cipher_data |
| 689 | #define EVP_X_STATE_LEN(evp) (evp)->cipher->ctx_size |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 690 | #endif |
| 691 | |
| 692 | int |
| 693 | cipher_get_keycontext(const struct sshcipher_ctx *cc, u_char *dat) |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 694 | { |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 695 | #if defined(WITH_OPENSSL) && !defined(OPENSSL_NO_RC4) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 696 | const struct sshcipher *c = cc->cipher; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 697 | int plen = 0; |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 698 | |
Damien Miller | f0a8ded | 2013-02-12 11:00:34 +1100 | [diff] [blame] | 699 | if (c->evptype == EVP_rc4) { |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 700 | plen = EVP_X_STATE_LEN(cc->evp); |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 701 | if (dat == NULL) |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 702 | return (plen); |
| 703 | memcpy(dat, EVP_X_STATE(cc->evp), plen); |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 704 | } |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 705 | return (plen); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 706 | #else |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 707 | return 0; |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 708 | #endif |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 712 | cipher_set_keycontext(struct sshcipher_ctx *cc, const u_char *dat) |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 713 | { |
Damien Miller | 832b744 | 2016-07-15 14:45:34 +1000 | [diff] [blame] | 714 | #if defined(WITH_OPENSSL) && !defined(OPENSSL_NO_RC4) |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 715 | const struct sshcipher *c = cc->cipher; |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 716 | int plen; |
| 717 | |
Damien Miller | f0a8ded | 2013-02-12 11:00:34 +1100 | [diff] [blame] | 718 | if (c->evptype == EVP_rc4) { |
Ben Lindstrom | 212faca | 2002-03-22 01:39:44 +0000 | [diff] [blame] | 719 | plen = EVP_X_STATE_LEN(cc->evp); |
| 720 | memcpy(EVP_X_STATE(cc->evp), dat, plen); |
| 721 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 722 | #endif |
Damien Miller | 21cf4e0 | 2002-02-19 15:26:42 +1100 | [diff] [blame] | 723 | } |