aboutsummaryrefslogtreecommitdiff
path: root/gost_ec_keyx.c
diff options
context:
space:
mode:
authorDmitry Belyavskiy <beldmit@gmail.com>2018-09-04 17:02:57 +0300
committerDmitry Belyavskiy <beldmit@gmail.com>2018-09-04 17:02:57 +0300
commit06eb03a547f646080830d2cd5572844e19909b97 (patch)
tree8f31f70f3200201f835d372235b8d617b9512255 /gost_ec_keyx.c
parentf72fe5c4cfaa5130d0afb5174eb272bac01a912a (diff)
downloadgost-engine-06eb03a547f646080830d2cd5572844e19909b97.zip
gost-engine-06eb03a547f646080830d2cd5572844e19909b97.tar.gz
gost-engine-06eb03a547f646080830d2cd5572844e19909b97.tar.bz2
Let's wrap old and new key enncryption together
Diffstat (limited to 'gost_ec_keyx.c')
-rw-r--r--gost_ec_keyx.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/gost_ec_keyx.c b/gost_ec_keyx.c
index 1e17f83..409d8e1 100644
--- a/gost_ec_keyx.c
+++ b/gost_ec_keyx.c
@@ -229,7 +229,7 @@ int pkey_gost_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
* Implementation of GOST2001/12 key transport, cryptopro variation
*/
-int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+static int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
size_t *out_len, const unsigned char *key,
size_t key_len)
{
@@ -346,7 +346,7 @@ int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
* EVP_PKEY_METHOD callback decrypt
* Implementation of GOST2018 key transport
*/
-int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+static int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
size_t *out_len, const unsigned char *key,
size_t key_len)
{
@@ -435,11 +435,25 @@ int pkey_gost2018_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
return ret;
}
+int pkey_gost_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
+ size_t *out_len, const unsigned char *key, size_t key_len)
+{
+ struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+ if (data->shared_ukm == NULL || data->shared_ukm_size == 8)
+ return pkey_GOST_ECcp_encrypt(pctx, out, out_len, key, key_len);
+ else if (data->shared_ukm_size == 32)
+ return pkey_gost2018_encrypt(pctx, out, out_len, key, key_len);
+ else {
+ GOSTerr(GOST_F_PKEY_GOST_ENCRYPT, ERR_R_INTERNAL_ERROR);
+ return -1;
+ }
+}
+
/*
* EVP_PKEY_METHOD callback decrypt
* Implementation of GOST2001/12 key transport, cryptopro variation
*/
-int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+static int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
size_t *key_len, const unsigned char *in,
size_t in_len)
{
@@ -528,7 +542,7 @@ int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
* EVP_PKEY_METHOD callback decrypt
* Implementation of GOST2018 key transport
*/
-int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+static int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
size_t *key_len, const unsigned char *in,
size_t in_len)
{
@@ -593,3 +607,17 @@ int pkey_gost2018_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
PSKeyTransport_gost_free(pst);
return ret;
}
+
+int pkey_gost_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
+ size_t *key_len, const unsigned char *in, size_t in_len)
+{
+ struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+ if (data->shared_ukm == NULL || data->shared_ukm_size == 8)
+ return pkey_GOST_ECcp_decrypt(pctx, key, key_len, in, in_len);
+ else if (data->shared_ukm_size == 32)
+ return pkey_gost2018_decrypt(pctx, key, key_len, in, in_len);
+ else {
+ GOSTerr(GOST_F_PKEY_GOST_DECRYPT, ERR_R_INTERNAL_ERROR);
+ return -1;
+ }
+}