Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/cipher.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9210 - (show annotations) (download) (as text)
Sat Apr 17 08:36:59 2021 UTC (2 years, 10 months ago) by nmaya
File MIME type: text/x-chdr
File size: 5556 byte(s)
ファイルを分割・コードを移動・関数名を整理・新しい OpenSSH からインポート

- OpenSSH からインポート
  cipher-3des1.c from OpenSSH-7.5p1
  ssherr.c from OpenSSH-8.5p1
  ssherr.h from OpenSSH-8.5p1
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 /*
47 * Cipher types for SSH-1. New types can be added, but old types should not
48 * be removed for compatibility. The maximum allowed value is 31.
49 */
50 #define SSH_CIPHER_SSH2 -3
51 #define SSH_CIPHER_ILLEGAL -2 /* No valid cipher selected. */
52 #define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */
53 //#define SSH_CIPHER_NONE 0 /* no encryption */
54 //#define SSH_CIPHER_IDEA 1 /* IDEA CFB */
55 //#define SSH_CIPHER_DES 2 /* DES CBC */
56 //#define SSH_CIPHER_3DES 3 /* 3DES CBC */
57 //#define SSH_CIPHER_BROKEN_TSS 4 /* TRI's Simple Stream encryption CBC */
58 //#define SSH_CIPHER_BROKEN_RC4 5 /* Alleged RC4 */
59 //#define SSH_CIPHER_BLOWFISH 6
60 //#define SSH_CIPHER_RESERVED 7
61
62 #define CIPHER_ENCRYPT 1
63 #define CIPHER_DECRYPT 0
64
65
66 typedef enum {
67 // SSH1
68 SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES,
69 SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH,
70 // SSH2
71 SSH2_CIPHER_3DES_CBC, SSH2_CIPHER_AES128_CBC,
72 SSH2_CIPHER_AES192_CBC, SSH2_CIPHER_AES256_CBC,
73 SSH2_CIPHER_BLOWFISH_CBC, SSH2_CIPHER_AES128_CTR,
74 SSH2_CIPHER_AES192_CTR, SSH2_CIPHER_AES256_CTR,
75 SSH2_CIPHER_ARCFOUR, SSH2_CIPHER_ARCFOUR128, SSH2_CIPHER_ARCFOUR256,
76 SSH2_CIPHER_CAST128_CBC,
77 SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR,
78 SSH2_CIPHER_CAMELLIA128_CBC, SSH2_CIPHER_CAMELLIA192_CBC, SSH2_CIPHER_CAMELLIA256_CBC,
79 SSH2_CIPHER_CAMELLIA128_CTR, SSH2_CIPHER_CAMELLIA192_CTR, SSH2_CIPHER_CAMELLIA256_CTR,
80 SSH2_CIPHER_AES128_GCM, SSH2_CIPHER_AES256_GCM, SSH2_CIPHER_CHACHAPOLY,
81 SSH_CIPHER_MAX = SSH2_CIPHER_CHACHAPOLY,
82 } SSHCipherId;
83
84 struct ssh2cipher {
85 SSHCipherId id;
86 char *name;
87 u_int block_size;
88 u_int key_len;
89 u_int discard_len;
90 u_int iv_len;
91 u_int auth_len;
92 const EVP_CIPHER *(*func)(void);
93 };
94
95 struct sshcipher_ctx {
96 // TTSSH ���� SSH_CIPHER_NONE �������������Aplaintext ���g�p��������
97 // int plaintext;
98 // TTSSH ���� CRYPT_encrypt_aead(), CRYPT_decrypt_aead() ������������ encrypt �������������������g�p��������
99 // int encrypt;
100 EVP_CIPHER_CTX *evp;
101 // struct chachapoly_ctx *cp_ctx;
102 // OpenSSH �� ifndef WITH_OPENSSL �������g�p�����������������Aac_ctx ���g�p��������
103 // aesctr_ctx ac_ctx; /* XXX union with evp? */
104 // OpenSSH ���� const struct sshcipher *cipher;
105 const struct ssh2cipher *cipher;
106 };
107
108
109 int get_cipher_id(const struct ssh2cipher *cipher);
110 u_int get_cipher_block_size(const struct ssh2cipher *cipher);
111 u_int get_cipher_key_len(const struct ssh2cipher *cipher);
112 u_int get_cipher_discard_len(const struct ssh2cipher *cipher);
113 u_int get_cipher_iv_len(const struct ssh2cipher *cipher);
114 u_int get_cipher_auth_len(const struct ssh2cipher *cipher);
115 const EVP_CIPHER *get_cipher_EVP_CIPHER(const struct ssh2cipher *cipher);
116 char *get_cipher_string(const struct ssh2cipher *cipher);
117 const struct ssh2cipher* get_cipher_by_name(char *name);
118 char *get_cipher_name(int cipher_id);
119 char *get_listbox_cipher_name(int cipher_id, PTInstVar pvar);
120
121 void normalize_cipher_order(char *buf);
122 const struct ssh2cipher *choose_SSH2_cipher_algorithm(char *server_proposal, char *my_proposal);
123 void SSH2_update_cipher_myproposal(PTInstVar pvar);
124
125 void cipher_init_SSH2(
126 EVP_CIPHER_CTX *evp,
127 const u_char *key, u_int keylen,
128 const u_char *iv, u_int ivlen,
129 int encrypt,
130 const EVP_CIPHER *type,
131 int discard_len,
132 unsigned int authlen,
133 PTInstVar pvar
134 );
135 void cipher_free_SSH2(EVP_CIPHER_CTX *evp);
136
137 #endif /* CIPHER_H */

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26