From 2e8276978c44e74cdb512debb057272fc45e85d4 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Thu, 29 Aug 2019 16:52:51 +0300 Subject: [PATCH] lib-dcrypt: Add API for dcrypt_ecdh_derive_secret --- src/lib-dcrypt/dcrypt-private.h | 3 +++ src/lib-dcrypt/dcrypt.c | 14 ++++++++++++++ src/lib-dcrypt/dcrypt.h | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/src/lib-dcrypt/dcrypt-private.h b/src/lib-dcrypt/dcrypt-private.h index 96fa8d3c96..834ed7fab2 100644 --- a/src/lib-dcrypt/dcrypt-private.h +++ b/src/lib-dcrypt/dcrypt-private.h @@ -191,6 +191,9 @@ struct dcrypt_vfs { const unsigned char *signature, size_t signature_len, bool *valid_r, enum dcrypt_padding padding, const char **error_r); + bool (*ecdh_derive_secret)(struct dcrypt_private_key *priv_key, + struct dcrypt_public_key *pub_key, + buffer_t *shared_secret, const char **error_r); }; void dcrypt_set_vfs(struct dcrypt_vfs *vfs); diff --git a/src/lib-dcrypt/dcrypt.c b/src/lib-dcrypt/dcrypt.c index 6b2abc9b0c..ef55c69e4d 100644 --- a/src/lib-dcrypt/dcrypt.c +++ b/src/lib-dcrypt/dcrypt.c @@ -242,6 +242,20 @@ bool dcrypt_ctx_hmac_final(struct dcrypt_context_hmac *ctx, buffer_t *result, return dcrypt_vfs->ctx_hmac_final(ctx, result, error_r); } +bool dcrypt_ecdh_derive_secret(struct dcrypt_private_key *local_key, + struct dcrypt_public_key *pub_key, + buffer_t *shared_secret, + const char **error_r) +{ + i_assert(dcrypt_vfs != NULL); + if (dcrypt_vfs->ecdh_derive_secret == NULL) { + *error_r = "Not implemented"; + return FALSE; + } + return dcrypt_vfs->ecdh_derive_secret(local_key, pub_key, shared_secret, + error_r); +} + bool dcrypt_ecdh_derive_secret_local(struct dcrypt_private_key *local_key, buffer_t *R, buffer_t *S, const char **error_r) diff --git a/src/lib-dcrypt/dcrypt.h b/src/lib-dcrypt/dcrypt.h index ab22d9b4f3..62fa1949db 100644 --- a/src/lib-dcrypt/dcrypt.h +++ b/src/lib-dcrypt/dcrypt.h @@ -212,6 +212,12 @@ bool dcrypt_ctx_hmac_final(struct dcrypt_context_hmac *ctx, buffer_t *result, /** * Elliptic Curve based Diffie-Heffman shared secret derivation */ +bool dcrypt_ecdh_derive_secret(struct dcrypt_private_key *priv_key, + struct dcrypt_public_key *pub_key, + buffer_t *shared_secret, + const char **error_r); +/** + * Helpers for DCRYPT file format */ bool dcrypt_ecdh_derive_secret_local(struct dcrypt_private_key *local_key, buffer_t *R, buffer_t *S, const char **error_r); -- 2.47.3