Commit ec06417d authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Updated GOST MAC support.

Submitted by: vitus@cryptocom.ru
parent a4346646
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -238,19 +238,21 @@ gost_params.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
gost_params.o: ../../include/openssl/symhacks.h gost_params.c gost_params.h
gost_pmeth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
gost_pmeth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
gost_pmeth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
gost_pmeth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
gost_pmeth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
gost_pmeth.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
gost_pmeth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
gost_pmeth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
gost_pmeth.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
gost_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
gost_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
gost_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
gost_pmeth.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
gost_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
gost_pmeth.o: ../../include/openssl/objects.h
gost_pmeth.o: ../../include/openssl/opensslconf.h
gost_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
gost_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
gost_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
gost_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
gost_pmeth.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h gost_lcl.h
gost_pmeth.o: gost_params.h gost_pmeth.c gosthash.h
gost_pmeth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
gost_pmeth.o: e_gost_err.h gost89.h gost_lcl.h gost_params.h gost_pmeth.c
gost_pmeth.o: gosthash.h
gost_sign.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
gost_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
gost_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+2 −1
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ static ERR_STRING_DATA GOST_str_functs[]=
{ERR_FUNC(GOST_F_GOST_COMPUTE_PUBLIC),	"GOST_COMPUTE_PUBLIC"},
{ERR_FUNC(GOST_F_GOST_DO_SIGN),	"GOST_DO_SIGN"},
{ERR_FUNC(GOST_F_GOST_DO_VERIFY),	"GOST_DO_VERIFY"},
{ERR_FUNC(GOST_F_GOST_IMIT_CTRL),	"GOST_IMIT_CTRL"},
{ERR_FUNC(GOST_F_GOST_IMIT_UPDATE),	"GOST_IMIT_UPDATE"},
{ERR_FUNC(GOST_F_MAKE_RFC4490_KEYTRANSPORT_2001),	"MAKE_RFC4490_KEYTRANSPORT_2001"},
{ERR_FUNC(GOST_F_PARAM_COPY_GOST01),	"PARAM_COPY_GOST01"},
{ERR_FUNC(GOST_F_PARAM_COPY_GOST94),	"PARAM_COPY_GOST94"},
@@ -122,7 +124,6 @@ static ERR_STRING_DATA GOST_str_reasons[]=
{ERR_REASON(GOST_R_BAD_PKEY_PARAMETERS_FORMAT),"bad pkey parameters format"},
{ERR_REASON(GOST_R_CANNOT_PACK_EPHEMERAL_KEY),"cannot pack ephemeral key"},
{ERR_REASON(GOST_R_CTX_NOT_INITIALIZED_FOR_ENCRYPT),"ctx not initialized for encrypt"},
{ERR_REASON(GOST_R_DECODE_ERROR)         ,"decode error"},
{ERR_REASON(GOST_R_ERROR_COMPUTING_MAC)  ,"error computing mac"},
{ERR_REASON(GOST_R_ERROR_COMPUTING_SHARED_KEY),"error computing shared key"},
{ERR_REASON(GOST_R_ERROR_PACKING_KEY_TRANSPORT_INFO),"error packing key transport info"},
+8 −7
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
#define GOST_F_GOST_COMPUTE_PUBLIC			 109
#define GOST_F_GOST_DO_SIGN				 110
#define GOST_F_GOST_DO_VERIFY				 111
#define GOST_F_GOST_IMIT_CTRL				 138
#define GOST_F_GOST_IMIT_UPDATE				 139
#define GOST_F_MAKE_RFC4490_KEYTRANSPORT_2001		 127
#define GOST_F_PARAM_COPY_GOST01			 132
#define GOST_F_PARAM_COPY_GOST94			 133
@@ -100,11 +102,11 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
#define GOST_F_PKEY_GOST_CTRL				 114
#define GOST_F_PKEY_GOST_CTRL01_STR			 115
#define GOST_F_PKEY_GOST_CTRL94_STR			 116
#define GOST_F_PKEY_GOST_MAC_CTRL			 138
#define GOST_F_PKEY_GOST_MAC_CTRL_STR			 139
#define GOST_F_PKEY_GOST_MAC_KEYGEN			 140
#define GOST_F_PKEY_GOST_MAC_CTRL			 140
#define GOST_F_PKEY_GOST_MAC_CTRL_STR			 141
#define GOST_F_PKEY_GOST_MAC_KEYGEN			 142
#define GOST_F_PRIV_DECODE_GOST_94			 117
#define GOST_F_PRIV_DECODE_MAC				 141
#define GOST_F_PRIV_DECODE_MAC				 143
#define GOST_F_PUB_DECODE_GOST01			 136
#define GOST_F_PUB_DECODE_GOST94			 134
#define GOST_F_PUB_ENCODE_GOST01			 135
@@ -116,7 +118,6 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
#define GOST_R_BAD_PKEY_PARAMETERS_FORMAT		 129
#define GOST_R_CANNOT_PACK_EPHEMERAL_KEY		 114
#define GOST_R_CTX_NOT_INITIALIZED_FOR_ENCRYPT		 115
#define GOST_R_DECODE_ERROR				 134
#define GOST_R_ERROR_COMPUTING_MAC			 116
#define GOST_R_ERROR_COMPUTING_SHARED_KEY		 117
#define GOST_R_ERROR_PACKING_KEY_TRANSPORT_INFO		 118
@@ -131,12 +132,12 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
#define GOST_R_INVALID_ENCRYPTED_KEY_SIZE		 123
#define GOST_R_INVALID_GOST94_PARMSET			 127
#define GOST_R_INVALID_IV_LENGTH			 102
#define GOST_R_INVALID_MAC_KEY_LENGTH			 135
#define GOST_R_INVALID_MAC_KEY_LENGTH			 134
#define GOST_R_INVALID_PARAMSET				 103
#define GOST_R_KEY_IS_NOT_INITALIZED			 104
#define GOST_R_KEY_IS_NOT_INITIALIZED			 105
#define GOST_R_KEY_PARAMETERS_MISSING			 131
#define GOST_R_MAC_KEY_NOT_SET				 136
#define GOST_R_MAC_KEY_NOT_SET				 135
#define GOST_R_MALLOC_FAILURE				 124
#define GOST_R_NOT_ENOUGH_SPACE_FOR_KEY			 125
#define GOST_R_NO_MEMORY				 106
+7 −3
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ int pkey_GOST01cc_encrypt (EVP_PKEY_CTX *pctx,unsigned char *out,
	struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);	
	GOST_KEY_TRANSPORT *gkt = NULL;
	int ret=0;
	const struct gost_cipher_info *cipher_info;
	gost_ctx ctx;
	EC_KEY *ephemeral=NULL;
	const EC_POINT *pub_key_point=NULL;
@@ -84,7 +85,8 @@ int pkey_GOST01cc_encrypt (EVP_PKEY_CTX *pctx,unsigned char *out,
		goto err;
		}	
	/* encrypt session key */
	gost_init(&ctx, &GostR3411_94_CryptoProParamSet);
	cipher_info = get_encryption_params(NULL);
	gost_init(&ctx, cipher_info->sblock);
	gost_key(&ctx,shared_key);
	encrypt_cryptocom_key(key,key_len,encrypted_key,&ctx);
	/* compute hmac of session key */
@@ -122,7 +124,7 @@ int pkey_GOST01cc_encrypt (EVP_PKEY_CTX *pctx,unsigned char *out,
		goto err;
		}	
	ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
	gkt->key_agreement_info->cipher = OBJ_nid2obj(NID_id_Gost28147_89_cc);
	gkt->key_agreement_info->cipher = OBJ_nid2obj(cipher_info->nid);
	if ((*out_len = i2d_GOST_KEY_TRANSPORT(gkt,&out))>0) ret = 1;
	;
	err:
@@ -143,6 +145,7 @@ int pkey_GOST01cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_l
	unsigned char hmac[4],hmac_comp[4];
	unsigned char iv[8];
	int i;
	const struct gost_cipher_info *cipher_info;
	gost_ctx ctx;
	const EC_POINT *pub_key_point;
	EVP_PKEY *eph_key;
@@ -178,7 +181,8 @@ int pkey_GOST01cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_l
		return 0;
		}
	/* Decrypt session key */
	gost_init(&ctx, &GostR3411_94_CryptoProParamSet);
	cipher_info = get_encryption_params(gkt->key_agreement_info->cipher);
	gost_init(&ctx, cipher_info->sblock);
	gost_key(&ctx,shared_key);
	
	if (!decrypt_cryptocom_key(key,*key_len,gkt->key_info->encrypted_key->data, 
+7 −3
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ int pkey_GOST94cc_encrypt (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen
	/* create DH structure filling parameters from passed pub_key */
	DH *dh = NULL;
	GOST_KEY_TRANSPORT *gkt = NULL;
	const struct gost_cipher_info *cipher_info;
	gost_ctx cctx;
	EVP_PKEY *newkey=NULL;
	unsigned char shared_key[32],encrypted_key[32],hmac[4],
@@ -254,7 +255,8 @@ int pkey_GOST94cc_encrypt (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen
		goto err;
		}	
	/* encrypt session key */
	gost_init(&cctx, &GostR3411_94_CryptoProParamSet);
	cipher_info = get_encryption_params(NULL);
	gost_init(&cctx, cipher_info->sblock);
	gost_key(&cctx,shared_key);
	encrypt_cryptocom_key(key,key_len,encrypted_key,&cctx);
	/* compute hmac of session key */
@@ -293,7 +295,7 @@ int pkey_GOST94cc_encrypt (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen
		goto err;
		}	
	ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
	gkt->key_agreement_info->cipher = OBJ_nid2obj(NID_id_Gost28147_89_cc);
	gkt->key_agreement_info->cipher = OBJ_nid2obj(cipher_info->nid);
	*outlen = i2d_GOST_KEY_TRANSPORT(gkt,&out);
	err:
	if (gkt) GOST_KEY_TRANSPORT_free(gkt);
@@ -374,6 +376,7 @@ int pkey_GOST94cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_l
	unsigned char hmac[4],hmac_comp[4];
	unsigned char iv[8];
	int i;
	const struct gost_cipher_info *cipher_info;
	gost_ctx ctx;
	DH *dh = DH_new();
	EVP_PKEY *eph_key;
@@ -415,7 +418,8 @@ int pkey_GOST94cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_l
		return 0;
		}
	/* Decrypt session key */
	gost_init(&ctx, &GostR3411_94_CryptoProParamSet);
	cipher_info = get_encryption_params(gkt->key_agreement_info->cipher);
	gost_init(&ctx, cipher_info->sblock);
	gost_key(&ctx,shared_key);
	
	if (!decrypt_cryptocom_key(key,*key_len,gkt->key_info->encrypted_key->data, 
Loading