~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to common-algo.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
/* Mappings for ciphers, parameters are
33
33
   {&cipher_desc, keysize, blocksize} */
34
34
 
 
35
#ifdef DROPBEAR_AES256_CBC
 
36
static const struct dropbear_cipher dropbear_aes256 = 
 
37
        {&aes_desc, 32, 16};
 
38
#endif
35
39
#ifdef DROPBEAR_AES128_CBC
36
 
const struct dropbear_cipher dropbear_aes128 = 
 
40
static const struct dropbear_cipher dropbear_aes128 = 
37
41
        {&aes_desc, 16, 16};
38
42
#endif
39
43
#ifdef DROPBEAR_BLOWFISH_CBC
40
 
const struct dropbear_cipher dropbear_blowfish = 
 
44
static const struct dropbear_cipher dropbear_blowfish = 
41
45
        {&blowfish_desc, 16, 8};
42
46
#endif
 
47
#ifdef DROPBEAR_TWOFISH256_CBC
 
48
static const struct dropbear_cipher dropbear_twofish256 = 
 
49
        {&twofish_desc, 32, 16};
 
50
#endif
43
51
#ifdef DROPBEAR_TWOFISH128_CBC
44
 
const struct dropbear_cipher dropbear_twofish128 = 
 
52
static const struct dropbear_cipher dropbear_twofish128 = 
45
53
        {&twofish_desc, 16, 16};
46
54
#endif
47
55
#ifdef DROPBEAR_3DES_CBC
48
 
const struct dropbear_cipher dropbear_3des = 
 
56
static const struct dropbear_cipher dropbear_3des = 
49
57
        {&des3_desc, 24, 8};
50
58
#endif
51
59
 
57
65
   {&hash_desc, keysize, hashsize} */
58
66
 
59
67
#ifdef DROPBEAR_SHA1_HMAC
60
 
const struct dropbear_hash dropbear_sha1 = 
 
68
static const struct dropbear_hash dropbear_sha1 = 
61
69
        {&sha1_desc, 20, 20};
62
70
#endif
 
71
#ifdef DROPBEAR_SHA1_96_HMAC
 
72
static const struct dropbear_hash dropbear_sha1_96 = 
 
73
        {&sha1_desc, 20, 12};
 
74
#endif
63
75
#ifdef DROPBEAR_MD5_HMAC
64
 
const struct dropbear_hash dropbear_md5 = 
 
76
static const struct dropbear_hash dropbear_md5 = 
65
77
        {&md5_desc, 16, 16};
66
78
#endif
67
79
 
75
87
#ifdef DROPBEAR_AES128_CBC
76
88
        {"aes128-cbc", 0, (void*)&dropbear_aes128, 1},
77
89
#endif
 
90
#ifdef DROPBEAR_3DES_CBC
 
91
        {"3des-cbc", 0, (void*)&dropbear_3des, 1},
 
92
#endif
 
93
#ifdef DROPBEAR_AES256_CBC
 
94
        {"aes256-cbc", 0, (void*)&dropbear_aes256, 1},
 
95
#endif
 
96
#ifdef DROPBEAR_TWOFISH256_CBC
 
97
        {"twofish256-cbc", 0, (void*)&dropbear_twofish256, 1},
 
98
        {"twofish-cbc", 0, (void*)&dropbear_twofish256, 1},
 
99
#endif
 
100
#ifdef DROPBEAR_TWOFISH128_CBC
 
101
        {"twofish128-cbc", 0, (void*)&dropbear_twofish128, 1},
 
102
#endif
78
103
#ifdef DROPBEAR_BLOWFISH_CBC
79
104
        {"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1},
80
105
#endif
81
 
#ifdef DROPBEAR_TWOFISH128_CBC
82
 
        {"twofish-cbc", 0, (void*)&dropbear_twofish128, 1},
83
 
#endif
84
 
#ifdef DROPBEAR_3DES_CBC
85
 
        {"3des-cbc", 0, (void*)&dropbear_3des, 1},
86
 
#endif
87
106
        {NULL, 0, NULL, 0}
88
107
};
89
108
 
90
109
algo_type sshhashes[] = {
 
110
#ifdef DROPBEAR_SHA1_96_HMAC
 
111
        {"hmac-sha1-96", 0, (void*)&dropbear_sha1_96, 1},
 
112
#endif
91
113
#ifdef DROPBEAR_SHA1_HMAC
92
114
        {"hmac-sha1", 0, (void*)&dropbear_sha1, 1},
93
115
#endif
98
120
};
99
121
 
100
122
algo_type sshcompress[] = {
101
 
        {"none", DROPBEAR_COMP_NONE, NULL, 1},
102
123
#ifndef DISABLE_ZLIB
103
124
        {"zlib", DROPBEAR_COMP_ZLIB, NULL, 1},
104
125
#endif
 
126
        {"none", DROPBEAR_COMP_NONE, NULL, 1},
105
127
        {NULL, 0, NULL, 0}
106
128
};
107
129
 
125
147
 * This should be run before using any of the ciphers/hashes */
126
148
void crypto_init() {
127
149
 
128
 
        const struct _cipher_descriptor *regciphers[] = {
129
 
#ifdef DROPBEAR_AES128_CBC
 
150
        const struct ltc_cipher_descriptor *regciphers[] = {
 
151
#ifdef DROPBEAR_AES_CBC
130
152
                &aes_desc,
131
153
#endif
132
154
#ifdef DROPBEAR_BLOWFISH_CBC
133
155
                &blowfish_desc,
134
156
#endif
135
 
#ifdef DROPBEAR_TWOFISH128_CBC
 
157
#ifdef DROPBEAR_TWOFISH_CBC
136
158
                &twofish_desc,
137
159
#endif
138
160
#ifdef DROPBEAR_3DES_CBC
141
163
                NULL
142
164
        };
143
165
 
144
 
        const struct _hash_descriptor *reghashes[] = {
 
166
        const struct ltc_hash_descriptor *reghashes[] = {
145
167
                /* we need sha1 for hostkey stuff regardless */
146
168
                &sha1_desc,
147
169
#ifdef DROPBEAR_MD5_HMAC
187
209
/* Output a comma separated list of algorithms to a buffer */
188
210
void buf_put_algolist(buffer * buf, algo_type localalgos[]) {
189
211
 
190
 
        unsigned int pos = 0, i, len;
191
 
        char str[50]; /* enough for local algo storage */
 
212
        unsigned int i, len;
 
213
        unsigned int donefirst = 0;
 
214
        buffer *algolist = NULL;
192
215
 
 
216
        algolist = buf_new(100);
193
217
        for (i = 0; localalgos[i].name != NULL; i++) {
194
218
                if (localalgos[i].usable) {
195
 
                        /* Avoid generating a trailing comma */
196
 
                        if (pos)
197
 
                            str[pos++] = ',';
 
219
                        if (donefirst)
 
220
                                buf_putbyte(algolist, ',');
 
221
                        donefirst = 1;
198
222
                        len = strlen(localalgos[i].name);
199
 
                        memcpy(&str[pos], localalgos[i].name, len);
200
 
                        pos += len;
 
223
                        buf_putbytes(algolist, localalgos[i].name, len);
201
224
                }
202
225
        }
203
 
        str[pos]=0;
204
 
        /* Debug this */
205
 
        TRACE(("buf_put_algolist: %s", str))
206
 
        buf_putstring(buf, str, pos);
 
226
        buf_putstring(buf, algolist->data, algolist->len);
 
227
        buf_free(algolist);
207
228
}