Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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