~ubuntu-branches/debian/lenny/dropbear/lenny

« back to all changes in this revision

Viewing changes to dss.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2005-05-25 22:38:17 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050525223817-fdl653extybmz1zb
Tags: 0.45-3
* debian/dropbear.init: init script prints human readable message in case
  it's disabled (closes: #309099).
* debian/dropbear.postinst: configure: restart service through init script
  instead of start.
* debian/dropbear.prerm: set -u -> set -e.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
46
46
int buf_get_dss_pub_key(buffer* buf, dss_key *key) {
47
47
 
 
48
        TRACE(("enter buf_get_dss_pub_key"))
48
49
        assert(key != NULL);
49
50
        key->p = m_malloc(sizeof(mp_int));
50
51
        key->q = m_malloc(sizeof(mp_int));
58
59
         || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
59
60
         || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
60
61
         || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
 
62
                TRACE(("leave buf_get_dss_pub_key: failed reading mpints"))
61
63
                return DROPBEAR_FAILURE;
62
64
        }
63
65
 
64
66
        if (mp_count_bits(key->p) < MIN_DSS_KEYLEN) {
65
67
                dropbear_log(LOG_WARNING, "DSS key too short");
 
68
                TRACE(("leave buf_get_dss_pub_key: short key"))
66
69
                return DROPBEAR_FAILURE;
67
70
        }
68
71
 
 
72
        TRACE(("leave buf_get_dss_pub_key: success"))
69
73
        return DROPBEAR_SUCCESS;
70
74
}
71
75
 
94
98
/* Clear and free the memory used by a public or private key */
95
99
void dss_key_free(dss_key *key) {
96
100
 
97
 
        TRACE(("enter dsa_key_free"));
 
101
        TRACE(("enter dsa_key_free"))
98
102
        if (key == NULL) {
99
 
                TRACE(("enter dsa_key_free: key == NULL"));
 
103
                TRACE(("enter dsa_key_free: key == NULL"))
100
104
                return;
101
105
        }
102
106
        if (key->p) {
120
124
                m_free(key->x);
121
125
        }
122
126
        m_free(key);
123
 
        TRACE(("leave dsa_key_free"));
 
127
        TRACE(("leave dsa_key_free"))
124
128
}
125
129
 
126
130
/* put the dss public key into the buffer in the required format:
160
164
        unsigned char msghash[SHA1_HASH_SIZE];
161
165
        hash_state hs;
162
166
        int ret = DROPBEAR_FAILURE;
163
 
        mp_int val1, val2, val3, val4;
 
167
        DEF_MP_INT(val1);
 
168
        DEF_MP_INT(val2);
 
169
        DEF_MP_INT(val3);
 
170
        DEF_MP_INT(val4);
164
171
        char * string = NULL;
165
172
        int stringlen;
166
173
 
167
 
        TRACE(("enter buf_dss_verify"));
 
174
        TRACE(("enter buf_dss_verify"))
168
175
        assert(key != NULL);
169
176
 
170
177
        m_mp_init_multi(&val1, &val2, &val3, &val4, NULL);
188
195
                goto out;
189
196
        }
190
197
        if (mp_cmp(&val1, key->q) != MP_LT) {
191
 
                TRACE(("verify failed, s' >= q"));
 
198
                TRACE(("verify failed, s' >= q"))
192
199
                goto out;
193
200
        }
194
201
        /* let val2 = w = (s')^-1 mod q*/
213
220
                goto out;
214
221
        }
215
222
        if (mp_cmp(&val1, key->q) != MP_LT) {
216
 
                TRACE(("verify failed, r' >= q"));
 
223
                TRACE(("verify failed, r' >= q"))
217
224
                goto out;
218
225
        }
219
226
        /* let val4 = u2 = ((r')w) mod q */
254
261
}
255
262
#endif /* DROPBEAR_SIGNKEY_VERIFY */
256
263
 
 
264
/* convert an unsigned mp into an array of bytes, malloced.
 
265
 * This array must be freed after use, len contains the length of the array,
 
266
 * if len != NULL */
 
267
static unsigned char* mptobytes(mp_int *mp, int *len) {
 
268
        
 
269
        unsigned char* ret;
 
270
        int size;
 
271
 
 
272
        size = mp_unsigned_bin_size(mp);
 
273
        ret = m_malloc(size);
 
274
        if (mp_to_unsigned_bin(mp, ret) != MP_OKAY) {
 
275
                dropbear_exit("mem alloc error");
 
276
        }
 
277
        if (len != NULL) {
 
278
                *len = size;
 
279
        }
 
280
        return ret;
 
281
}
 
282
 
257
283
/* Sign the data presented with key, writing the signature contents
258
284
 * to the buffer
259
285
 *
277
303
        unsigned char privkeyhash[SHA512_HASH_SIZE];
278
304
        unsigned char *privkeytmp;
279
305
        unsigned char proto_k[SHA512_HASH_SIZE];
280
 
        mp_int dss_protok;
 
306
        DEF_MP_INT(dss_protok);
281
307
#else
282
308
        unsigned char kbuf[SHA1_HASH_SIZE];
283
309
#endif
284
 
        mp_int dss_k, dss_m;
285
 
        mp_int dss_temp1, dss_temp2;
286
 
        mp_int dss_r, dss_s;
 
310
        DEF_MP_INT(dss_k);
 
311
        DEF_MP_INT(dss_m);
 
312
        DEF_MP_INT(dss_temp1);
 
313
        DEF_MP_INT(dss_temp2);
 
314
        DEF_MP_INT(dss_r);
 
315
        DEF_MP_INT(dss_s);
287
316
        hash_state hs;
288
317
        
289
 
        TRACE(("enter buf_put_dss_sign"));
 
318
        TRACE(("enter buf_put_dss_sign"))
290
319
        assert(key != NULL);
291
320
        
292
321
        /* hash the data */
393
422
        
394
423
        /* create the signature to return */
395
424
 
396
 
        TRACE(("leave buf_put_dss_sign"));
 
425
        TRACE(("leave buf_put_dss_sign"))
397
426
}
398
427
 
399
428
#endif /* DROPBEAR_DSS */