Mercurial > dropbear
comparison dss.c @ 586:b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
we don't conflict with libtomcrypt.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 21 Jul 2010 12:55:25 +0000 |
parents | a124aff0cbf1 |
children | a98a2138364a |
comparison
equal
deleted
inserted
replaced
585:d194db6f9453 | 586:b50f0107e505 |
---|---|
41 | 41 |
42 /* Load a dss key from a buffer, initialising the values. | 42 /* Load a dss key from a buffer, initialising the values. |
43 * The key will have the same format as buf_put_dss_key. | 43 * The key will have the same format as buf_put_dss_key. |
44 * These should be freed with dss_key_free. | 44 * These should be freed with dss_key_free. |
45 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ | 45 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
46 int buf_get_dss_pub_key(buffer* buf, dss_key *key) { | 46 int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) { |
47 | 47 |
48 TRACE(("enter buf_get_dss_pub_key")) | 48 TRACE(("enter buf_get_dss_pub_key")) |
49 dropbear_assert(key != NULL); | 49 dropbear_assert(key != NULL); |
50 key->p = m_malloc(sizeof(mp_int)); | 50 key->p = m_malloc(sizeof(mp_int)); |
51 key->q = m_malloc(sizeof(mp_int)); | 51 key->q = m_malloc(sizeof(mp_int)); |
74 } | 74 } |
75 | 75 |
76 /* Same as buf_get_dss_pub_key, but reads a private "x" key at the end. | 76 /* Same as buf_get_dss_pub_key, but reads a private "x" key at the end. |
77 * Loads a private dss key from a buffer | 77 * Loads a private dss key from a buffer |
78 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ | 78 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
79 int buf_get_dss_priv_key(buffer* buf, dss_key *key) { | 79 int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) { |
80 | 80 |
81 int ret = DROPBEAR_FAILURE; | 81 int ret = DROPBEAR_FAILURE; |
82 | 82 |
83 dropbear_assert(key != NULL); | 83 dropbear_assert(key != NULL); |
84 | 84 |
97 return ret; | 97 return ret; |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 /* Clear and free the memory used by a public or private key */ | 101 /* Clear and free the memory used by a public or private key */ |
102 void dss_key_free(dss_key *key) { | 102 void dss_key_free(dropbear_dss_key *key) { |
103 | 103 |
104 TRACE(("enter dsa_key_free")) | 104 TRACE(("enter dsa_key_free")) |
105 if (key == NULL) { | 105 if (key == NULL) { |
106 TRACE(("enter dsa_key_free: key == NULL")) | 106 TRACE(("enter dsa_key_free: key == NULL")) |
107 return; | 107 return; |
136 * mpint p | 136 * mpint p |
137 * mpint q | 137 * mpint q |
138 * mpint g | 138 * mpint g |
139 * mpint y | 139 * mpint y |
140 */ | 140 */ |
141 void buf_put_dss_pub_key(buffer* buf, dss_key *key) { | 141 void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key) { |
142 | 142 |
143 dropbear_assert(key != NULL); | 143 dropbear_assert(key != NULL); |
144 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); | 144 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); |
145 buf_putmpint(buf, key->p); | 145 buf_putmpint(buf, key->p); |
146 buf_putmpint(buf, key->q); | 146 buf_putmpint(buf, key->q); |
148 buf_putmpint(buf, key->y); | 148 buf_putmpint(buf, key->y); |
149 | 149 |
150 } | 150 } |
151 | 151 |
152 /* Same as buf_put_dss_pub_key, but with the private "x" key appended */ | 152 /* Same as buf_put_dss_pub_key, but with the private "x" key appended */ |
153 void buf_put_dss_priv_key(buffer* buf, dss_key *key) { | 153 void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key) { |
154 | 154 |
155 dropbear_assert(key != NULL); | 155 dropbear_assert(key != NULL); |
156 buf_put_dss_pub_key(buf, key); | 156 buf_put_dss_pub_key(buf, key); |
157 buf_putmpint(buf, key->x); | 157 buf_putmpint(buf, key->x); |
158 | 158 |
159 } | 159 } |
160 | 160 |
161 #ifdef DROPBEAR_SIGNKEY_VERIFY | 161 #ifdef DROPBEAR_SIGNKEY_VERIFY |
162 /* Verify a DSS signature (in buf) made on data by the key given. | 162 /* Verify a DSS signature (in buf) made on data by the key given. |
163 * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ | 163 * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
164 int buf_dss_verify(buffer* buf, dss_key *key, const unsigned char* data, | 164 int buf_dss_verify(buffer* buf, dropbear_dss_key *key, const unsigned char* data, |
165 unsigned int len) { | 165 unsigned int len) { |
166 | 166 |
167 unsigned char msghash[SHA1_HASH_SIZE]; | 167 unsigned char msghash[SHA1_HASH_SIZE]; |
168 hash_state hs; | 168 hash_state hs; |
169 int ret = DROPBEAR_FAILURE; | 169 int ret = DROPBEAR_FAILURE; |
290 * proto_k = SHA512 ( SHA512(x) || SHA160(message) ) | 290 * proto_k = SHA512 ( SHA512(x) || SHA160(message) ) |
291 * k = proto_k mod q | 291 * k = proto_k mod q |
292 * | 292 * |
293 * Now we aren't relying on the random number generation to protect the private | 293 * Now we aren't relying on the random number generation to protect the private |
294 * key x, which is a long term secret */ | 294 * key x, which is a long term secret */ |
295 void buf_put_dss_sign(buffer* buf, dss_key *key, const unsigned char* data, | 295 void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, const unsigned char* data, |
296 unsigned int len) { | 296 unsigned int len) { |
297 | 297 |
298 unsigned char msghash[SHA1_HASH_SIZE]; | 298 unsigned char msghash[SHA1_HASH_SIZE]; |
299 unsigned int writelen; | 299 unsigned int writelen; |
300 unsigned int i; | 300 unsigned int i; |