Home | History | Annotate | Download | only in dropbear

Lines Matching refs:key

34  * operations, such as key reading, signing, verification. Key generation
42 /* Load a dss key from a buffer, initialising the values.
43 * The key will have the same format as buf_put_dss_key.
46 int buf_get_dss_pub_key(buffer* buf, dss_key *key) {
49 dropbear_assert(key != NULL);
50 key->p = m_malloc(sizeof(mp_int));
51 key->q = m_malloc(sizeof(mp_int));
52 key->g = m_malloc(sizeof(mp_int));
53 key->y = m_malloc(sizeof(mp_int));
54 m_mp_init_multi(key->p, key->q, key->g, key->y, NULL);
55 key->x = NULL;
58 if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE
59 || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
60 || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
61 || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
66 if (mp_count_bits(key->p) < MIN_DSS_KEYLEN) {
67 dropbear_log(LOG_WARNING, "DSS key too short");
68 TRACE(("leave buf_get_dss_pub_key: short key"))
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
79 int buf_get_dss_priv_key(buffer* buf, dss_key *key) {
83 dropbear_assert(key != NULL);
85 ret = buf_get_dss_pub_key(buf, key);
90 key->x = m_malloc(sizeof(mp_int));
91 m_mp_init(key->x);
92 ret = buf_getmpint(buf, key->x);
94 m_free(key->x);
101 /* Clear and free the memory used by a public or private key */
102 void dss_key_free(dss_key *key) {
105 if (key == NULL) {
106 TRACE(("enter dsa_key_free: key == NULL"))
109 if (key->p) {
110 mp_clear(key->p);
111 m_free(key->p);
113 if (key->q) {
114 mp_clear(key->q);
115 m_free(key->q);
117 if (key->g) {
118 mp_clear(key->g);
119 m_free(key->g);
121 if (key->y) {
122 mp_clear(key->y);
123 m_free(key->y);
125 if (key->x) {
126 mp_clear(key->x);
127 m_free(key->x);
129 m_free(key);
133 /* put the dss public key into the buffer in the required format:
141 void buf_put_dss_pub_key(buffer* buf, dss_key *key) {
143 dropbear_assert(key != NULL);
145 buf_putmpint(buf, key->p);
146 buf_putmpint(buf, key->q);
147 buf_putmpint(buf, key->g);
148 buf_putmpint(buf, key->y);
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) {
155 dropbear_assert(key != NULL);
156 buf_put_dss_pub_key(buf, key);
157 buf_putmpint(buf, key->x);
162 /* Verify a DSS signature (in buf) made on data by the key given.
164 int buf_dss_verify(buffer* buf, dss_key *key, const unsigned char* data,
178 dropbear_assert(key != NULL);
198 if (mp_cmp(&val1, key->q) != MP_LT) {
203 if (mp_invmod(&val1, key->q, &val2) != MP_OKAY) {
212 if (mp_mulmod(&val1, &val2, key->q, &val3) != MP_OKAY) {
219 if (mp_cmp(&val1, key->q) != MP_LT) {
224 if (mp_mulmod(&val1, &val2, key->q, &val4) != MP_OKAY) {
230 if (mp_exptmod(key->g, &val3, key->p, &val2) != MP_OKAY) {
234 if (mp_exptmod(key->y, &val4, key->p, &val3) != MP_OKAY) {
238 if (mp_mulmod(&val2, &val3, key->p, &val4) != MP_OKAY) {
242 if (mp_mod(&val4, key->q, &val2) != MP_OKAY) {
282 /* Sign the data presented with key, writing the signature contents
294 * key x, which is a long term secret */
295 void buf_put_dss_sign(buffer* buf, dss_key *key, const unsigned char* data,
316 dropbear_assert(key != NULL);
327 privkeytmp = mptobytes(key->x, &i);
344 if (mp_mod(&dss_protok, key->q, &dss_k) != MP_OKAY) {
350 gen_random_mpint(key->q, &dss_k);
357 if (mp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != MP_OKAY) {
361 if (mp_mod(&dss_temp1, key->q, &dss_r) != MP_OKAY) {
366 if (mp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != MP_OKAY) {
370 if (mp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != MP_OKAY) {
375 if (mp_invmod(&dss_k, key->q, &dss_temp1) != MP_OKAY) {
380 if (mp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != MP_OKAY) {