Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/comp.c

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-csrc
File size: 3881 byte(s)
ファイルを分割・コードを移動・関数名を整理・新しい OpenSSH からインポート

- OpenSSH からインポート
  cipher-3des1.c from OpenSSH-7.5p1
  ssherr.c from OpenSSH-8.5p1
  ssherr.h from OpenSSH-8.5p1
1 /*
2 * (C) 2021- TeraTerm Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "ttxssh.h"
30 #include "comp.h"
31 #include "kex.h"
32
33
34 struct ssh2_comp_t {
35 compression_type type;
36 char *name;
37 };
38
39 static const struct ssh2_comp_t ssh2_comps[] = {
40 {COMP_NOCOMP, "none"}, // RFC4253
41 {COMP_ZLIB, "zlib"}, // RFC4253
42 {COMP_DELAYED, "zlib@openssh.com"},
43 {COMP_NONE, NULL},
44 };
45
46
47 char* get_ssh2_comp_name(compression_type type)
48 {
49 const struct ssh2_comp_t *ptr = ssh2_comps;
50
51 while (ptr->name != NULL) {
52 if (type == ptr->type) {
53 return ptr->name;
54 }
55 ptr++;
56 }
57
58 // not found.
59 return "unknown";
60 }
61
62 void normalize_comp_order(char *buf)
63 {
64 static char default_strings[] = {
65 COMP_DELAYED,
66 COMP_ZLIB,
67 COMP_NOCOMP,
68 COMP_NONE,
69 };
70
71 normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
72 }
73
74 compression_type choose_SSH2_compression_algorithm(char *server_proposal, char *my_proposal)
75 {
76 compression_type type = COMP_UNKNOWN;
77 char str_comp[20];
78 const struct ssh2_comp_t *ptr = ssh2_comps;
79
80 choose_SSH2_proposal(server_proposal, my_proposal, str_comp, sizeof(str_comp));
81
82 while (ptr->name != NULL) {
83 if (strcmp(ptr->name, str_comp) == 0) {
84 type = ptr->type;
85 break;
86 }
87 ptr++;
88 }
89
90 return (type);
91 }
92
93 void SSH2_update_compression_myproposal(PTInstVar pvar)
94 {
95 static char buf[128]; // TODO: malloc()��������
96 int index;
97 int len, i;
98
99 // ���M�������������������������A�O�������B(2006.6.26 maya)
100 if (pvar->socket != INVALID_SOCKET) {
101 return;
102 }
103
104 // ���k���x�����������Amyproposal[]�������������B(2005.7.9 yutaka)
105 buf[0] = '\0';
106 for (i = 0 ; pvar->settings.CompOrder[i] != 0 ; i++) {
107 index = pvar->settings.CompOrder[i] - '0';
108 if (index == COMP_NONE) // disabled line
109 break;
110 strncat_s(buf, sizeof(buf), get_ssh2_comp_name(index), _TRUNCATE);
111 strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
112 }
113 len = strlen(buf);
114 if (len > 0)
115 buf[len - 1] = '\0'; // get rid of comma
116
117 // ���k�w���������������A���k���x�������������[���������B
118 if (buf[0] == '\0') {
119 pvar->settings.CompressionLevel = 0;
120 }
121
122 if (pvar->settings.CompressionLevel == 0) {
123 _snprintf_s(buf, sizeof(buf), _TRUNCATE, get_ssh2_comp_name(COMP_NOCOMP));
124 }
125 if (buf[0] != '\0') {
126 myproposal[PROPOSAL_COMP_ALGS_CTOS] = buf; // Client To Server
127 myproposal[PROPOSAL_COMP_ALGS_STOC] = buf; // Server To Client
128 }
129 }

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