| 1 |
/* Imported from OpenSSH-8.5p1, TeraTerm Project */ |
| 2 |
|
| 3 |
/* $OpenBSD: cipher.h,v 1.44 2014/01/25 10:12:50 dtucker Exp $ */ |
| 4 |
|
| 5 |
/* |
| 6 |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 7 |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 8 |
* All rights reserved |
| 9 |
* |
| 10 |
* As far as I am concerned, the code I have written for this software |
| 11 |
* can be used freely for any purpose. Any derived versions of this |
| 12 |
* software must be clearly marked as such, and if the derived work is |
| 13 |
* incompatible with the protocol description in the RFC file, it must be |
| 14 |
* called by a name other than "ssh" or "Secure Shell". |
| 15 |
* |
| 16 |
* Copyright (c) 2000 Markus Friedl. All rights reserved. |
| 17 |
* |
| 18 |
* Redistribution and use in source and binary forms, with or without |
| 19 |
* modification, are permitted provided that the following conditions |
| 20 |
* are met: |
| 21 |
* 1. Redistributions of source code must retain the above copyright |
| 22 |
* notice, this list of conditions and the following disclaimer. |
| 23 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 24 |
* notice, this list of conditions and the following disclaimer in the |
| 25 |
* documentation and/or other materials provided with the distribution. |
| 26 |
* |
| 27 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 28 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 29 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 30 |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 31 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 32 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 36 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 |
*/ |
| 38 |
|
| 39 |
#ifndef CIPHER_H |
| 40 |
#define CIPHER_H |
| 41 |
|
| 42 |
typedef unsigned int u_int; |
| 43 |
typedef unsigned char u_char; |
| 44 |
|
| 45 |
#include <openssl/evp.h> |
| 46 |
#include "cipher-chachapoly.h" |
| 47 |
|
| 48 |
/* |
| 49 |
* Cipher types for SSH-1. New types can be added, but old types should not |
| 50 |
* be removed for compatibility. The maximum allowed value is 31. |
| 51 |
*/ |
| 52 |
#define SSH_CIPHER_SSH2 -3 |
| 53 |
#define SSH_CIPHER_ILLEGAL -2 /* No valid cipher selected. */ |
| 54 |
#define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */ |
| 55 |
//#define SSH_CIPHER_NONE 0 /* no encryption */ |
| 56 |
//#define SSH_CIPHER_IDEA 1 /* IDEA CFB */ |
| 57 |
//#define SSH_CIPHER_DES 2 /* DES CBC */ |
| 58 |
//#define SSH_CIPHER_3DES 3 /* 3DES CBC */ |
| 59 |
//#define SSH_CIPHER_BROKEN_TSS 4 /* TRI's Simple Stream encryption CBC */ |
| 60 |
//#define SSH_CIPHER_BROKEN_RC4 5 /* Alleged RC4 */ |
| 61 |
//#define SSH_CIPHER_BLOWFISH 6 |
| 62 |
//#define SSH_CIPHER_RESERVED 7 |
| 63 |
|
| 64 |
#define CIPHER_ENCRYPT 1 |
| 65 |
#define CIPHER_DECRYPT 0 |
| 66 |
|
| 67 |
|
| 68 |
typedef enum { |
| 69 |
// SSH1 |
| 70 |
SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES, |
| 71 |
SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH, |
| 72 |
// SSH2 |
| 73 |
SSH2_CIPHER_3DES_CBC, SSH2_CIPHER_AES128_CBC, |
| 74 |
SSH2_CIPHER_AES192_CBC, SSH2_CIPHER_AES256_CBC, |
| 75 |
SSH2_CIPHER_BLOWFISH_CBC, SSH2_CIPHER_AES128_CTR, |
| 76 |
SSH2_CIPHER_AES192_CTR, SSH2_CIPHER_AES256_CTR, |
| 77 |
SSH2_CIPHER_ARCFOUR, SSH2_CIPHER_ARCFOUR128, SSH2_CIPHER_ARCFOUR256, |
| 78 |
SSH2_CIPHER_CAST128_CBC, |
| 79 |
SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR, |
| 80 |
SSH2_CIPHER_CAMELLIA128_CBC, SSH2_CIPHER_CAMELLIA192_CBC, SSH2_CIPHER_CAMELLIA256_CBC, |
| 81 |
SSH2_CIPHER_CAMELLIA128_CTR, SSH2_CIPHER_CAMELLIA192_CTR, SSH2_CIPHER_CAMELLIA256_CTR, |
| 82 |
SSH2_CIPHER_AES128_GCM, SSH2_CIPHER_AES256_GCM, SSH2_CIPHER_CHACHAPOLY, |
| 83 |
SSH_CIPHER_MAX = SSH2_CIPHER_CHACHAPOLY, |
| 84 |
} SSHCipherId; |
| 85 |
|
| 86 |
struct ssh2cipher { |
| 87 |
SSHCipherId id; |
| 88 |
char *name; |
| 89 |
u_int block_size; |
| 90 |
u_int key_len; |
| 91 |
u_int discard_len; |
| 92 |
u_int iv_len; |
| 93 |
u_int auth_len; |
| 94 |
const EVP_CIPHER *(*func)(void); |
| 95 |
}; |
| 96 |
|
| 97 |
struct sshcipher_ctx { |
| 98 |
// TTSSH ���� SSH_CIPHER_NONE �������������Aplaintext ���g�p�������� |
| 99 |
// int plaintext; |
| 100 |
|
| 101 |
// TTSSH ���� CRYPT_encrypt_aead(), CRYPT_decrypt_aead() ������������ encrypt �������������������g�p�������� |
| 102 |
// int encrypt; |
| 103 |
|
| 104 |
EVP_CIPHER_CTX *evp; |
| 105 |
struct chachapoly_ctx *cp_ctx; |
| 106 |
|
| 107 |
// OpenSSH �� ifndef WITH_OPENSSL �������g�p�����������������Aac_ctx ���g�p�������� |
| 108 |
// aesctr_ctx ac_ctx; /* XXX union with evp? */ |
| 109 |
|
| 110 |
// OpenSSH ���� const struct sshcipher *cipher; |
| 111 |
const struct ssh2cipher *cipher; |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
int get_cipher_id(const struct ssh2cipher *cipher); |
| 116 |
u_int get_cipher_block_size(const struct ssh2cipher *cipher); |
| 117 |
u_int get_cipher_key_len(const struct ssh2cipher *cipher); |
| 118 |
u_int get_cipher_discard_len(const struct ssh2cipher *cipher); |
| 119 |
u_int get_cipher_iv_len(const struct ssh2cipher *cipher); |
| 120 |
u_int get_cipher_auth_len(const struct ssh2cipher *cipher); |
| 121 |
const EVP_CIPHER *get_cipher_EVP_CIPHER(const struct ssh2cipher *cipher); |
| 122 |
char *get_cipher_string(const struct ssh2cipher *cipher); |
| 123 |
const struct ssh2cipher* get_cipher_by_name(char *name); |
| 124 |
char *get_cipher_name(int cipher_id); |
| 125 |
char *get_listbox_cipher_name(int cipher_id, PTInstVar pvar); |
| 126 |
|
| 127 |
void normalize_cipher_order(char *buf); |
| 128 |
const struct ssh2cipher *choose_SSH2_cipher_algorithm(char *server_proposal, char *my_proposal); |
| 129 |
void SSH2_update_cipher_myproposal(PTInstVar pvar); |
| 130 |
|
| 131 |
int cipher_init_SSH2( |
| 132 |
struct sshcipher_ctx **ccp, const struct ssh2cipher *cipher, |
| 133 |
const u_char *key, u_int keylen, |
| 134 |
const u_char *iv, u_int ivlen, |
| 135 |
int do_encrypt, |
| 136 |
PTInstVar pvar |
| 137 |
); |
| 138 |
void cipher_free_SSH2(struct sshcipher_ctx *cc); |
| 139 |
|
| 140 |
#endif /* CIPHER_H */ |