diff options
author | Martin Willi <martin@strongswan.org> | 2009-08-27 09:58:38 +0200 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2009-08-27 09:58:38 +0200 |
commit | b12c6d163d179ad238fe920eb9f1746b96f51166 (patch) | |
tree | 417f9955630d710b543ce5289e308e0bb08a8a39 /src/libstrongswan/plugins/openssl/openssl_ec_public_key.c | |
parent | 2ee8cd04bdeac33c893c9b20c82e465e03b5a769 (diff) | |
download | strongswan-b12c6d163d179ad238fe920eb9f1746b96f51166.tar.bz2 strongswan-b12c6d163d179ad238fe920eb9f1746b96f51166.tar.xz |
do openssl fingerprinting/encoding directly, openssl provides all functions
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_ec_public_key.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_ec_public_key.c | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c b/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c index 4d0af04b4..a290f3d05 100644 --- a/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c +++ b/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c @@ -194,26 +194,53 @@ static size_t get_keysize(private_openssl_ec_public_key_t *this) } /** - * Implementation of private_key_t.get_fingerprint. + * Calculate fingerprint from a EC_KEY, also used in ec private key. */ -static bool get_fingerprint(private_openssl_ec_public_key_t *this, - key_encoding_type_t type, chunk_t *fingerprint) +bool openssl_ec_fingerprint(EC_KEY *ec, key_encoding_type_t type, chunk_t *fp) { + hasher_t *hasher; chunk_t key; u_char *p; - bool success; - if (lib->encoding->get_cache(lib->encoding, type, this, fingerprint)) + if (lib->encoding->get_cache(lib->encoding, type, ec, fp)) { return TRUE; } - key = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL)); - p = key.ptr; - i2d_EC_PUBKEY(this->ec, &p); - success = lib->encoding->encode(lib->encoding, type, this, fingerprint, - KEY_PART_ECDSA_PUB_ASN1_DER, key, KEY_PART_END); - free(key.ptr); - return success; + switch (type) + { + case KEY_ID_PUBKEY_SHA1: + key = chunk_alloc(i2o_ECPublicKey(ec, NULL)); + p = key.ptr; + i2o_ECPublicKey(ec, &p); + break; + case KEY_ID_PUBKEY_INFO_SHA1: + key = chunk_alloc(i2d_EC_PUBKEY(ec, NULL)); + p = key.ptr; + i2d_EC_PUBKEY(ec, &p); + break; + default: + return FALSE; + } + hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1); + if (!hasher) + { + DBG1("SHA1 hash algorithm not supported, fingerprinting failed"); + free(key.ptr); + return FALSE; + } + hasher->allocate_hash(hasher, key, fp); + hasher->destroy(hasher); + lib->encoding->cache(lib->encoding, type, ec, *fp); + return TRUE; +} + +/** + * Implementation of private_key_t.get_fingerprint. + */ +static bool get_fingerprint(private_openssl_ec_public_key_t *this, + key_encoding_type_t type, chunk_t *fingerprint) +{ + return openssl_ec_fingerprint(this->ec, type, fingerprint); } /** @@ -222,17 +249,20 @@ static bool get_fingerprint(private_openssl_ec_public_key_t *this, static bool get_encoding(private_openssl_ec_public_key_t *this, key_encoding_type_t type, chunk_t *encoding) { - chunk_t key; u_char *p; - bool success; - key = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL)); - p = key.ptr; - i2d_EC_PUBKEY(this->ec, &p); - success = lib->encoding->encode(lib->encoding, type, NULL, encoding, - KEY_PART_ECDSA_PUB_ASN1_DER, key, KEY_PART_END); - free(key.ptr); - return success; + switch (type) + { + case KEY_PUB_SPKI_ASN1_DER: + { + *encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL)); + p = encoding->ptr; + i2d_EC_PUBKEY(this->ec, &p); + return TRUE; + } + default: + return FALSE; + } } /** @@ -253,9 +283,9 @@ static void destroy(private_openssl_ec_public_key_t *this) { if (this->ec) { + lib->encoding->clear_cache(lib->encoding, this->ec); EC_KEY_free(this->ec); } - lib->encoding->clear_cache(lib->encoding, this); free(this); } } |