#include "gost_lcl.h"
#include "e_gost_err.h"
+#define PK_WRAP_PARAM "LEGACY_PK_WRAP"
+
/*
* Pack bignum into byte buffer of given size, filling all leading bytes by
* zeros
{
ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
ASN1_STRING *params = encode_gost_algor_params(pk);
- unsigned char /**priv_buf = NULL,*/ *buf = NULL;
- int key_len = pkey_bits_gost(pk), /*priv_len = 0,*/ i = 0;
+ unsigned char *buf = NULL;
+ int key_len = pkey_bits_gost(pk), i = 0;
+ /* unmasked private key */
+ const char *pk_format = get_gost_engine_param(GOST_PARAM_PK_FORMAT);
- /*ASN1_STRING *octet = NULL;*/
if (!params) {
return 0;
}
buf[key_len - 1 - i] = tmp;
}
-/*
- octet = ASN1_STRING_new();
- ASN1_OCTET_STRING_set(octet, buf, key_len);
+ if(pk_format != NULL && strcmp(pk_format, PK_WRAP_PARAM) == 0) {
+ ASN1_STRING *octet = NULL;
+ int priv_len = 0;
+ unsigned char *priv_buf = NULL;
- priv_len = i2d_ASN1_OCTET_STRING(octet, &priv_buf);
- ASN1_STRING_free(octet);
- OPENSSL_free(buf);
+ octet = ASN1_STRING_new();
+ ASN1_OCTET_STRING_set(octet, buf, key_len);
+ priv_len = i2d_ASN1_OCTET_STRING(octet, &priv_buf);
+ ASN1_STRING_free(octet);
+ OPENSSL_free(buf);
+
+ return PKCS8_pkey_set0(p8, algobj, 0, V_ASN1_SEQUENCE, params,
+ priv_buf, priv_len);
+ }
return PKCS8_pkey_set0(p8, algobj, 0, V_ASN1_SEQUENCE, params,
- priv_buf, priv_len); */
- return PKCS8_pkey_set0(p8, algobj, 0, V_ASN1_SEQUENCE, params,
- buf, key_len);
+ buf, key_len);
}
/* --------- printing keys --------------------------------*/
return -2;
}
+static int mac_ctrl_magma(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+{
+ switch (op) {
+ case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+ if (arg2) {
+ *(int *)arg2 = NID_magma_mac;
+ return 2;
+ }
+ }
+ return -2;
+}
+
+static int mac_ctrl_grasshopper(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+{
+ switch (op) {
+ case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+ if (arg2) {
+ *(int *)arg2 = NID_grasshopper_mac;
+ return 2;
+ }
+ }
+ return -2;
+}
+
static int gost2001_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
{
int nid =
EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_gost_12);
break;
+ case NID_magma_mac:
+ EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
+ EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_magma);
+ break;
+ case NID_grasshopper_mac:
+ EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
+ EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_grasshopper);
+ break;
}
return 1;
}