{ERR_PACK(0, GOST_F_PKEY_GOST2018_DECRYPT, 0), "pkey_gost2018_decrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST2018_ENCRYPT, 0), "pkey_gost2018_encrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST_CTRL, 0), "pkey_gost_ctrl"},
+ {ERR_PACK(0, GOST_F_PKEY_GOST_DECRYPT, 0), "pkey_gost_decrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST_ECCP_DECRYPT, 0), "pkey_GOST_ECcp_decrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST_ECCP_ENCRYPT, 0), "pkey_GOST_ECcp_encrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST_EC_CTRL_STR_256, 0),
{ERR_PACK(0, GOST_F_PKEY_GOST_EC_CTRL_STR_512, 0),
"pkey_gost_ec_ctrl_str_512"},
{ERR_PACK(0, GOST_F_PKEY_GOST_EC_DERIVE, 0), "pkey_gost_ec_derive"},
+ {ERR_PACK(0, GOST_F_PKEY_GOST_ENCRYPT, 0), "pkey_gost_encrypt"},
{ERR_PACK(0, GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT, 0),
"pkey_gost_grasshopper_mac_signctx_init"},
{ERR_PACK(0, GOST_F_PKEY_GOST_MAC_CTRL, 0), "pkey_gost_mac_ctrl"},
# define GOST_F_PKEY_GOST2018_DECRYPT 150
# define GOST_F_PKEY_GOST2018_ENCRYPT 151
# define GOST_F_PKEY_GOST_CTRL 122
+# define GOST_F_PKEY_GOST_DECRYPT 153
# define GOST_F_PKEY_GOST_ECCP_DECRYPT 123
# define GOST_F_PKEY_GOST_ECCP_ENCRYPT 124
# define GOST_F_PKEY_GOST_EC_CTRL_STR_256 125
# define GOST_F_PKEY_GOST_EC_CTRL_STR_512 126
# define GOST_F_PKEY_GOST_EC_DERIVE 127
+# define GOST_F_PKEY_GOST_ENCRYPT 152
# define GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT 141
# define GOST_F_PKEY_GOST_MAC_CTRL 128
# define GOST_F_PKEY_GOST_MAC_CTRL_STR 129
GOST_F_PKEY_GOST2018_DECRYPT:150:pkey_gost2018_decrypt
GOST_F_PKEY_GOST2018_ENCRYPT:151:pkey_gost2018_encrypt
GOST_F_PKEY_GOST_CTRL:122:pkey_gost_ctrl
+GOST_F_PKEY_GOST_DECRYPT:153:pkey_gost_decrypt
GOST_F_PKEY_GOST_ECCP_DECRYPT:123:pkey_GOST_ECcp_decrypt
GOST_F_PKEY_GOST_ECCP_ENCRYPT:124:pkey_GOST_ECcp_encrypt
GOST_F_PKEY_GOST_EC_CTRL_STR_256:125:pkey_gost_ec_ctrl_str_256
GOST_F_PKEY_GOST_EC_CTRL_STR_512:126:pkey_gost_ec_ctrl_str_512
GOST_F_PKEY_GOST_EC_DERIVE:127:pkey_gost_ec_derive
+GOST_F_PKEY_GOST_ENCRYPT:152:pkey_gost_encrypt
GOST_F_PKEY_GOST_GRASSHOPPER_MAC_SIGNCTX_INIT:141:\
pkey_gost_grasshopper_mac_signctx_init
GOST_F_PKEY_GOST_MAC_CTRL:128:pkey_gost_mac_ctrl
* 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)
{
* 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)
{
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)
{
* 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)
{
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;
+ }
+}
# define EVP_MD_CTRL_MAC_LEN (EVP_MD_CTRL_ALG_CTRL+5)
/* EVP_PKEY_METHOD key encryption callbacks */
/* From gost_ec_keyx.c */
-int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
+int pkey_gost_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
size_t *outlen, const unsigned char *key,
size_t key_len);
-int pkey_GOST_ECcp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
+int pkey_gost_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
size_t *outlen, const unsigned char *in,
size_t in_len);
/* derive functions */
EVP_PKEY_meth_set_encrypt(*pmeth,
pkey_gost_encrypt_init,
- pkey_GOST_ECcp_encrypt);
- EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+ pkey_gost_encrypt);
+ EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
EVP_PKEY_meth_set_derive(*pmeth,
pkey_gost_derive_init, pkey_gost_ec_derive);
EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
EVP_PKEY_meth_set_encrypt(*pmeth,
pkey_gost_encrypt_init,
- pkey_GOST_ECcp_encrypt);
- EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+ pkey_gost_encrypt);
+ EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
EVP_PKEY_meth_set_derive(*pmeth,
pkey_gost_derive_init, pkey_gost_ec_derive);
EVP_PKEY_meth_set_paramgen(*pmeth,
EVP_PKEY_meth_set_encrypt(*pmeth,
pkey_gost_encrypt_init,
- pkey_GOST_ECcp_encrypt);
- EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
+ pkey_gost_encrypt);
+ EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_gost_decrypt);
EVP_PKEY_meth_set_derive(*pmeth,
pkey_gost_derive_init, pkey_gost_ec_derive);
EVP_PKEY_meth_set_paramgen(*pmeth,