Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ttssh2/ttxssh/crypt.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9048 - (show annotations) (download) (as text)
Wed Dec 16 12:24:13 2020 UTC (3 years, 2 months ago) by nmaya
File MIME type: text/x-chdr
File size: 6101 byte(s)
ソースファイルの著作権表記の "最後の発行の年" を削除

ticket #40996
1 /*
2 * Copyright (c) 1998-2001, Robert O'Callahan
3 * (C) 2004- TeraTerm Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 This code is copyright (C) 1998-1999 Robert O'Callahan.
32 See LICENSE.TXT for the license.
33 */
34
35 #ifndef __CRYPT_H
36 #define __CRYPT_H
37
38 #include <openssl/rsa.h>
39 #include <openssl/des.h>
40 #include <openssl/blowfish.h>
41
42 #define SSH_SESSION_KEY_LENGTH 32
43 #define SSH_RSA_CHALLENGE_LENGTH 32
44 #define SSH_COOKIE_LENGTH 8
45 #define SSH2_COOKIE_LENGTH 16
46
47 #define CRYPT_KEY_LENGTH 32
48 #define COOKIE_LENGTH 16
49
50 typedef struct {
51 DES_key_schedule k1;
52 DES_key_schedule k2;
53 DES_key_schedule k3;
54 DES_cblock ivec1;
55 DES_cblock ivec2;
56 DES_cblock ivec3;
57 } Cipher3DESState;
58
59 typedef struct {
60 DES_key_schedule k;
61 DES_cblock ivec;
62 } CipherDESState;
63
64 typedef struct {
65 BF_KEY k;
66 unsigned char ivec[8];
67 } CipherBlowfishState;
68
69 typedef struct {
70 uint32 *h;
71 uint32 n;
72 } CRYPTDetectAttack;
73
74 typedef struct {
75 RSA *RSA_key;
76 } CRYPTPublicKey;
77
78 typedef union {
79 Cipher3DESState c3DES;
80 CipherDESState cDES;
81 CipherBlowfishState cBlowfish;
82 } CRYPTCipherState;
83
84 typedef void (* CRYPTCryptFun)(PTInstVar pvar, unsigned char *buf, unsigned int bytes);
85
86 typedef struct {
87 CRYPTDetectAttack detect_attack_statics;
88
89 CRYPTPublicKey server_key;
90 CRYPTPublicKey host_key;
91
92 char server_cookie[COOKIE_LENGTH];
93 char client_cookie[COOKIE_LENGTH];
94
95 int supported_sender_ciphers;
96 int supported_receiver_ciphers;
97 int sender_cipher;
98 int receiver_cipher;
99 char sender_cipher_key[CRYPT_KEY_LENGTH];
100 char receiver_cipher_key[CRYPT_KEY_LENGTH];
101 CRYPTCryptFun encrypt;
102 CRYPTCryptFun decrypt;
103 CRYPTCipherState enc;
104 CRYPTCipherState dec;
105 } CRYPTState;
106
107 void CRYPT_init(PTInstVar pvar);
108 /* this function is called during 'slack time' while we wait for a response
109 from the server. Therefore we have some time available to do some
110 moderately expensive computations. */
111 void CRYPT_initialize_random_numbers(PTInstVar pvar);
112 void CRYPT_set_random_data(PTInstVar pvar, unsigned char *buf, unsigned int bytes);
113 void CRYPT_end(PTInstVar pvar);
114
115 void CRYPT_get_cipher_info(PTInstVar pvar, char *dest, int len);
116 void CRYPT_get_server_key_info(PTInstVar pvar, char *dest, int len);
117
118 void CRYPT_set_server_cookie(PTInstVar pvar, unsigned char *cookie);
119 void CRYPT_set_client_cookie(PTInstVar pvar, unsigned char *cookie);
120 #define CRYPT_get_server_cookie(pvar) ((pvar)->crypt_state.server_cookie)
121
122 void CRYPT_free_public_key(CRYPTPublicKey *key);
123
124 BOOL CRYPT_set_server_RSA_key(PTInstVar pvar,
125 int bits, unsigned char *exp, unsigned char *mod);
126 BOOL CRYPT_set_host_RSA_key(PTInstVar pvar,
127 int bits, unsigned char *exp, unsigned char *mod);
128 unsigned int CRYPT_get_encrypted_session_key_len(PTInstVar pvar);
129 int CRYPT_choose_session_key(PTInstVar pvar, unsigned char *encrypted_key_buf);
130 BOOL CRYPT_start_encryption(PTInstVar pvar, int sender_flag, int receiver_flag);
131 int CRYPT_generate_RSA_challenge_response(PTInstVar pvar, unsigned char *challenge,
132 int challenge_len, unsigned char *response);
133
134 unsigned int CRYPT_get_receiver_MAC_size(PTInstVar pvar);
135 BOOL CRYPT_verify_receiver_MAC(PTInstVar pvar, uint32 sequence_number,
136 char *data, int len, char *MAC);
137 unsigned int CRYPT_get_sender_MAC_size(PTInstVar pvar);
138
139 BOOL CRYPT_build_sender_MAC(PTInstVar pvar, uint32 sequence_number,
140 char *data, int len, char *MAC);
141
142 BOOL CRYPT_set_supported_ciphers(PTInstVar pvar, int sender_ciphers, int receiver_ciphers);
143 BOOL CRYPT_choose_ciphers(PTInstVar pvar);
144 #define CRYPT_get_sender_cipher(pvar) ((pvar)->crypt_state.sender_cipher)
145 #define CRYPT_get_receiver_cipher(pvar) ((pvar)->crypt_state.receiver_cipher)
146 unsigned int CRYPT_get_decryption_block_size(PTInstVar pvar);
147 unsigned int CRYPT_get_encryption_block_size(PTInstVar pvar);
148 #define CRYPT_encrypt(pvar, buf, bytes) \
149 ((pvar)->crypt_state.encrypt((pvar), (buf), (bytes)))
150 #define CRYPT_decrypt(pvar, buf, bytes) \
151 ((pvar)->crypt_state.decrypt((pvar), (buf), (bytes)))
152
153 BOOL CRYPT_encrypt_aead(PTInstVar pvar, unsigned char *data, unsigned int len, unsigned int aadlen, unsigned int authlen);
154 BOOL CRYPT_decrypt_aead(PTInstVar pvar, unsigned char *data, unsigned int len, unsigned int aadlen, unsigned int authlen);
155
156 BOOL CRYPT_detect_attack(PTInstVar pvar, unsigned char *buf, int bytes);
157 int CRYPT_passphrase_decrypt(int cipher, char *passphrase, char *buf, int len);
158 RSA *make_key(PTInstVar pvar,
159 int bits, unsigned char *exp,
160 unsigned char *mod);
161
162 #endif

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