Lines Matching refs:k
54 Key *k; in key_new() local
57 k = xmalloc(sizeof(*k)); in key_new()
58 k->type = type; in key_new()
59 k->flags = 0; in key_new()
60 k->dsa = NULL; in key_new()
61 k->rsa = NULL; in key_new()
62 switch (k->type) { in key_new()
71 k->rsa = rsa; in key_new()
84 k->dsa = dsa; in key_new()
89 fatal("key_new: bad key type %d", k->type); in key_new()
92 return k; in key_new()
98 Key *k = key_new(type); in key_new_private() local
99 switch (k->type) { in key_new_private()
102 if ((k->rsa->d = BN_new()) == NULL) in key_new_private()
104 if ((k->rsa->iqmp = BN_new()) == NULL) in key_new_private()
106 if ((k->rsa->q = BN_new()) == NULL) in key_new_private()
108 if ((k->rsa->p = BN_new()) == NULL) in key_new_private()
110 if ((k->rsa->dmq1 = BN_new()) == NULL) in key_new_private()
112 if ((k->rsa->dmp1 = BN_new()) == NULL) in key_new_private()
116 if ((k->dsa->priv_key = BN_new()) == NULL) in key_new_private()
124 return k; in key_new_private()
128 key_free(Key *k) in key_free() argument
130 switch (k->type) { in key_free()
133 if (k->rsa != NULL) in key_free()
134 RSA_free(k->rsa); in key_free()
135 k->rsa = NULL; in key_free()
138 if (k->dsa != NULL) in key_free()
139 DSA_free(k->dsa); in key_free()
140 k->dsa = NULL; in key_free()
145 fatal("key_free: bad key type %d", k->type); in key_free()
148 xfree(k); in key_free()
177 key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length) in key_fingerprint_raw() argument
199 switch (k->type) { in key_fingerprint_raw()
201 nlen = BN_num_bytes(k->rsa->n); in key_fingerprint_raw()
202 elen = BN_num_bytes(k->rsa->e); in key_fingerprint_raw()
205 BN_bn2bin(k->rsa->n, blob); in key_fingerprint_raw()
206 BN_bn2bin(k->rsa->e, blob + nlen); in key_fingerprint_raw()
210 key_to_blob(k, &blob, &len); in key_fingerprint_raw()
216 fatal("key_fingerprint_raw: bad key type %d", k->type); in key_fingerprint_raw()
297 key_fingerprint(Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep) in key_fingerprint() argument
303 dgst_raw = key_fingerprint_raw(k, dgst_type, &dgst_raw_len); in key_fingerprint()
384 Key *k; in key_read() local
445 k = key_from_blob(blob, n); in key_read()
447 if (k == NULL) { in key_read()
451 if (k->type != type) { in key_read()
453 key_free(k); in key_read()
460 ret->rsa = k->rsa; in key_read()
461 k->rsa = NULL; in key_read()
469 ret->dsa = k->dsa; in key_read()
470 k->dsa = NULL; in key_read()
477 key_free(k); in key_read()
528 key_type(Key *k) in key_type() argument
530 switch (k->type) { in key_type()
545 key_ssh_name(const Key *k) in key_ssh_name() argument
547 switch (k->type) { in key_ssh_name()
559 key_size(Key *k) in key_size() argument
561 switch (k->type) { in key_size()
564 return BN_num_bits(k->rsa->n); in key_size()
567 return BN_num_bits(k->dsa->p); in key_size()
599 Key *k = key_new(KEY_UNSPEC); in key_generate() local
602 k->dsa = dsa_generate_private_key(bits); in key_generate()
606 k->rsa = rsa_generate_private_key(bits); in key_generate()
611 k->type = type; in key_generate()
612 return k; in key_generate()
616 key_from_private(Key *k) in key_from_private() argument
619 switch (k->type) { in key_from_private()
621 n = key_new(k->type); in key_from_private()
622 BN_copy(n->dsa->p, k->dsa->p); in key_from_private()
623 BN_copy(n->dsa->q, k->dsa->q); in key_from_private()
624 BN_copy(n->dsa->g, k->dsa->g); in key_from_private()
625 BN_copy(n->dsa->pub_key, k->dsa->pub_key); in key_from_private()
629 n = key_new(k->type); in key_from_private()
630 BN_copy(n->rsa->n, k->rsa->n); in key_from_private()
631 BN_copy(n->rsa->e, k->rsa->e); in key_from_private()
634 fatal("key_from_private: unknown type %d", k->type); in key_from_private()
838 key_demote(Key *k) in key_demote() argument
843 pk->type = k->type; in key_demote()
844 pk->flags = k->flags; in key_demote()
848 switch (k->type) { in key_demote()
853 if ((pk->rsa->e = BN_dup(k->rsa->e)) == NULL) in key_demote()
855 if ((pk->rsa->n = BN_dup(k->rsa->n)) == NULL) in key_demote()
861 if ((pk->dsa->p = BN_dup(k->dsa->p)) == NULL) in key_demote()
863 if ((pk->dsa->q = BN_dup(k->dsa->q)) == NULL) in key_demote()
865 if ((pk->dsa->g = BN_dup(k->dsa->g)) == NULL) in key_demote()
867 if ((pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL) in key_demote()
871 fatal("key_free: bad key type %d", k->type); in key_demote()