]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: Use dcrypt_key_id_private when applicable
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 13 Jun 2016 09:44:09 +0000 (12:44 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 14 Jun 2016 09:26:43 +0000 (12:26 +0300)
src/lib-dcrypt/istream-decrypt.c

index d8c6329aaa915b4f9eb9660e78672985e140cd1a..77c68c33819e3fad2cd6df7c1e2bbce51bb52ea0 100644 (file)
@@ -138,25 +138,16 @@ ssize_t i_stream_decrypt_read_header_v1(struct decrypt_istream *stream,
        }
 
        buffer_t *check = buffer_create_dynamic(pool_datastack_create(), 32);
-       struct dcrypt_public_key *pubkey = NULL;
 
-       /* do we have correct private key? */
-       if (!dcrypt_key_convert_private_to_public(stream->priv_key, &pubkey, &error)) {
-               io_stream_set_error(&stream->istream.iostream, "Cannot convert private key to public: %s", error);
-               return -1;
-       }
-       ec = 0;
-       if (!dcrypt_key_id_public_old(pubkey, check, &error)) {
+       if (!dcrypt_key_id_private_old(stream->priv_key, check, &error)) {
                io_stream_set_error(&stream->istream.iostream, "Cannot get public key hash: %s", error);
-               ec = -1;
+               return -1;
        } else {
                if (memcmp(digest_pos, check->data, I_MIN(digest_len,check->used)) != 0) {
                        io_stream_set_error(&stream->istream.iostream, "Private key not available");
-                       ec = -1;
+                       return -1;
                }
        }
-       dcrypt_key_free_public(&pubkey);
-       if (ec != 0) return ec;
 
        /* derive shared secret */
        if (!dcrypt_ecdh_derive_secret_local(stream->priv_key, &ephemeral_key, secret, &error)) {
@@ -296,10 +287,7 @@ ssize_t i_stream_decrypt_key(struct decrypt_istream *stream, const char *malg, u
                        return -1;
                }
                buffer_create_from_data(&buf, dgst, sizeof(dgst));
-               struct dcrypt_public_key *pub = NULL;
-               dcrypt_key_convert_private_to_public(stream->priv_key, &pub, NULL);
-               dcrypt_key_id_public(pub, "sha256", &buf, NULL);
-               dcrypt_key_free_public(&pub);
+               dcrypt_key_id_private(stream->priv_key, "sha256", &buf, NULL);
        }
 
        /* for each key */