1
1

pki: Add support to generate ecdsa keys.

Этот коммит содержится в:
Andreas Schneider 2011-12-30 11:02:06 +01:00
родитель 91372e298d
Коммит b309dd8fb7
3 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -40,6 +40,7 @@ int pki_key_ecdsa_nid_from_name(const char *name);
ssh_key pki_key_dup(const ssh_key key, int demote); ssh_key pki_key_dup(const ssh_key key, int demote);
int pki_key_generate_rsa(ssh_key key, int parameter); int pki_key_generate_rsa(ssh_key key, int parameter);
int pki_key_generate_dss(ssh_key key, int parameter); int pki_key_generate_dss(ssh_key key, int parameter);
int pki_key_generate_ecdsa(ssh_key key, int parameter);
int pki_key_compare(const ssh_key k1, int pki_key_compare(const ssh_key k1,
const ssh_key k2, const ssh_key k2,
enum ssh_keycmp_e what); enum ssh_keycmp_e what);

Просмотреть файл

@ -870,7 +870,7 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
* @param[in] parameter Parameter to the creation of key: * @param[in] parameter Parameter to the creation of key:
* rsa : length of the key in bits (e.g. 1024, 2048, 4096) * rsa : length of the key in bits (e.g. 1024, 2048, 4096)
* dsa : length of the key in bits (e.g. 1024, 2048, 3072) * dsa : length of the key in bits (e.g. 1024, 2048, 3072)
* ecdsa : not implemented * ecdsa : bits of the key (e.g. 256, 384, 512)
* @param[out] pkey A pointer to store the private key. You need to free the * @param[out] pkey A pointer to store the private key. You need to free the
* memory. * memory.
* @return SSH_OK on success, SSH_ERROR on error. * @return SSH_OK on success, SSH_ERROR on error.
@ -881,6 +881,11 @@ int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
ssh_key *pkey){ ssh_key *pkey){
int rc; int rc;
ssh_key key = ssh_key_new(); ssh_key key = ssh_key_new();
key->type = type;
key->type_c = ssh_key_type_to_char(type);
key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
switch(type){ switch(type){
case SSH_KEYTYPE_RSA: case SSH_KEYTYPE_RSA:
case SSH_KEYTYPE_RSA1: case SSH_KEYTYPE_RSA1:
@ -894,12 +899,16 @@ int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
goto error; goto error;
break; break;
case SSH_KEYTYPE_ECDSA: case SSH_KEYTYPE_ECDSA:
#ifdef HAVE_ECC
rc = pki_key_generate_ecdsa(key, parameter);
if(rc == SSH_ERROR)
goto error;
break;
#endif
case SSH_KEYTYPE_UNKNOWN: case SSH_KEYTYPE_UNKNOWN:
goto error; goto error;
} }
key->type = type;
key->type_c = ssh_key_type_to_char(type);
key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
*pkey = key; *pkey = key;
return SSH_OK; return SSH_OK;
error: error:

Просмотреть файл

@ -403,6 +403,40 @@ int pki_key_generate_dss(ssh_key key, int parameter){
return SSH_OK; return SSH_OK;
} }
int pki_key_generate_ecdsa(ssh_key key, int parameter) {
int nid;
int ok;
switch (parameter) {
case 384:
nid = NID_secp384r1;
case 512:
nid = NID_secp521r1;
case 256:
default:
nid = NID_X9_62_prime256v1;
}
key->ecdsa_nid = nid;
key->type = SSH_KEYTYPE_ECDSA;
key->type_c = pki_key_ecdsa_nid_to_name(nid);
key->ecdsa = EC_KEY_new_by_curve_name(nid);
if (key->ecdsa == NULL) {
return SSH_ERROR;
}
ok = EC_KEY_generate_key(key->ecdsa);
if (!ok) {
EC_KEY_free(key->ecdsa);
return SSH_ERROR;
}
EC_KEY_set_asn1_flag(key->ecdsa, OPENSSL_EC_NAMED_CURVE);
return SSH_OK;
}
int pki_key_compare(const ssh_key k1, int pki_key_compare(const ssh_key k1,
const ssh_key k2, const ssh_key k2,
enum ssh_keycmp_e what) enum ssh_keycmp_e what)