engines/ccgost/gost94_keyx.c:391: error: NULL_DEREFERENCE
  pointer `dh` last assigned on line 381 could be null and is dereferenced at line 391, column 2.
Showing all 81 steps of the trace


engines/ccgost/gost94_keyx.c:370:1: start of procedure pkey_GOST94cc_decrypt()
368.    */
369.   
370. > int pkey_GOST94cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_len, const unsigned char *in, size_t in_len)
371.   	{
372.   	/* Form DH params from compute shared key */

engines/ccgost/gost94_keyx.c:373:2: 
371.   	{
372.   	/* Form DH params from compute shared key */
373. > 	GOST_KEY_TRANSPORT *gkt = NULL;
374.   	const unsigned char *p=in;
375.   	unsigned char shared_key[32];

engines/ccgost/gost94_keyx.c:374:2: 
372.   	/* Form DH params from compute shared key */
373.   	GOST_KEY_TRANSPORT *gkt = NULL;
374. > 	const unsigned char *p=in;
375.   	unsigned char shared_key[32];
376.   	unsigned char hmac[4],hmac_comp[4];

engines/ccgost/gost94_keyx.c:381:2: 
379.   	const struct gost_cipher_info *cipher_info;
380.   	gost_ctx ctx;
381. > 	DH *dh = DH_new();
382.   	EVP_PKEY *eph_key;
383.   	EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);

crypto/dh/dh_lib.c:102:1: start of procedure DH_new()
  100.   	}
  101.   
  102. > DH *DH_new(void)
  103.   	{
  104.   	return DH_new_method(NULL);

crypto/dh/dh_lib.c:104:2: 
  102.   DH *DH_new(void)
  103.   	{
  104. > 	return DH_new_method(NULL);
  105.   	}
  106.   

crypto/dh/dh_lib.c:107:1: start of procedure DH_new_method()
    105.   	}
    106.   
    107. > DH *DH_new_method(ENGINE *engine)
    108.   	{
    109.   	DH *ret;

crypto/dh/dh_lib.c:111:2: 
    109.   	DH *ret;
    110.   
    111. > 	ret=(DH *)OPENSSL_malloc(sizeof(DH));
    112.   	if (ret == NULL)
    113.   		{

crypto/mem.c:294:1: start of procedure CRYPTO_malloc()
      292.   	}
      293.   
      294. > void *CRYPTO_malloc(int num, const char *file, int line)
      295.   	{
      296.   	void *ret = NULL;

crypto/mem.c:296:2: 
      294.   void *CRYPTO_malloc(int num, const char *file, int line)
      295.   	{
      296. > 	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;

crypto/mem.c:298:6: Taking false branch
      296.   	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;
                  ^
      299.   
      300.   	allow_customize = 0;

crypto/mem.c:300:2: 
      298.   	if (num <= 0) return NULL;
      299.   
      300. > 	allow_customize = 0;
      301.   	if (malloc_debug_func != NULL)
      302.   		{

crypto/mem.c:301:6: Taking true branch
      299.   
      300.   	allow_customize = 0;
      301.   	if (malloc_debug_func != NULL)
                  ^
      302.   		{
      303.   		allow_customize_debug = 0;

crypto/mem.c:303:3: 
      301.   	if (malloc_debug_func != NULL)
      302.   		{
      303. > 		allow_customize_debug = 0;
      304.   		malloc_debug_func(NULL, num, file, line, 0);
      305.   		}

crypto/mem.c:304:3: Skipping __function_pointer__(): unresolved function pointer
      302.   		{
      303.   		allow_customize_debug = 0;
      304.   		malloc_debug_func(NULL, num, file, line, 0);
               ^
      305.   		}
      306.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:306:2: Skipping __function_pointer__(): unresolved function pointer
      304.   		malloc_debug_func(NULL, num, file, line, 0);
      305.   		}
      306.   	ret = malloc_ex_func(num,file,line);
              ^
      307.   #ifdef LEVITTE_DEBUG_MEM
      308.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:310:6: Taking true branch
      308.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
      309.   #endif
      310.   	if (malloc_debug_func != NULL)
                  ^
      311.   		malloc_debug_func(ret, num, file, line, 1);
      312.   

crypto/mem.c:311:3: Skipping __function_pointer__(): unresolved function pointer
      309.   #endif
      310.   	if (malloc_debug_func != NULL)
      311.   		malloc_debug_func(ret, num, file, line, 1);
               ^
      312.   
      313.   #ifndef OPENSSL_CPUID_OBJ

crypto/mem.c:317:12: Taking false branch
      315.            * sanitisation function can't be optimised out. NB: We only do
      316.            * this for >2Kb so the overhead doesn't bother us. */
      317.           if(ret && (num > 2048))
                        ^
      318.   	{	extern unsigned char cleanse_ctr;
      319.                   ((unsigned char *)ret)[0] = cleanse_ctr;

crypto/mem.c:323:2: 
      321.   #endif
      322.   
      323. > 	return ret;
      324.   	}
      325.   

crypto/mem.c:324:2: return from a call to CRYPTO_malloc
      322.   
      323.   	return ret;
      324.   	}
              ^
      325.   
      326.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/dh/dh_lib.c:112:6: Taking true branch
    110.   
    111.   	ret=(DH *)OPENSSL_malloc(sizeof(DH));
    112.   	if (ret == NULL)
                ^
    113.   		{
    114.   		DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);

crypto/dh/dh_lib.c:114:3: 
    112.   	if (ret == NULL)
    113.   		{
    114. > 		DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
    115.   		return(NULL);
    116.   		}

crypto/err/err.c:680:1: start of procedure ERR_put_error()
      678.   /********************************************************/
      679.   
      680. > void ERR_put_error(int lib, int func, int reason, const char *file,
      681.   	     int line)
      682.   	{

crypto/err/err.c:704:2: Skipping ERR_get_state(): empty list of specs
      702.   	}
      703.   #endif
      704.   	es=ERR_get_state();
              ^
      705.   
      706.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:706:2: 
      704.   	es=ERR_get_state();
      705.   
      706. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
      707.   	if (es->top == es->bottom)
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:707:6: Taking false branch
      705.   
      706.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
      707.   	if (es->top == es->bottom)
                  ^
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709.   	es->err_flags[es->top]=0;

crypto/err/err.c:709:2: 
      707.   	if (es->top == es->bottom)
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709. > 	es->err_flags[es->top]=0;
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;

crypto/err/err.c:710:2: 
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709.   	es->err_flags[es->top]=0;
      710. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;

crypto/err/err.c:711:2: 
      709.   	es->err_flags[es->top]=0;
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711. > 	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);

crypto/err/err.c:712:2: 
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;
      712. > 	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
      714.   	}

crypto/err/err.c:713:2: Taking true branch
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:713:2: Taking false branch
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:713:2: Loop condition is false. Leaving loop
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:714:2: return from a call to ERR_put_error
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
      714.   	}
              ^
      715.   
      716.   void ERR_clear_error(void)

crypto/dh/dh_lib.c:115:3: 
    113.   		{
    114.   		DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
    115. > 		return(NULL);
    116.   		}
    117.   

crypto/dh/dh_lib.c:172:2: return from a call to DH_new_method
    170.   		}
    171.   	return(ret);
    172.   	}
            ^
    173.   
    174.   void DH_free(DH *r)

crypto/dh/dh_lib.c:105:2: return from a call to DH_new
  103.   	{
  104.   	return DH_new_method(NULL);
  105.   	}
          ^
  106.   
  107.   DH *DH_new_method(ENGINE *engine)

engines/ccgost/gost94_keyx.c:383:2: 
381.   	DH *dh = DH_new();
382.   	EVP_PKEY *eph_key;
383. > 	EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);
384.   	
385.   	if (!key)

crypto/evp/pmeth_lib.c:388:1: start of procedure EVP_PKEY_CTX_get0_pkey()
  386.   	}
  387.   
  388. > EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
  389.   	{
  390.   	return ctx->pkey;

crypto/evp/pmeth_lib.c:390:2: 
  388.   EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
  389.   	{
  390. > 	return ctx->pkey;
  391.   	}
  392.   

crypto/evp/pmeth_lib.c:391:2: return from a call to EVP_PKEY_CTX_get0_pkey
  389.   	{
  390.   	return ctx->pkey;
  391.   	}
          ^
  392.   
  393.   void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)

engines/ccgost/gost94_keyx.c:385:7: Taking false branch
383.   	EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);
384.   	
385.   	if (!key)
             ^
386.   		{
387.   		*key_len = 32;

engines/ccgost/gost94_keyx.c:391:2: 
389.   		}
390.   	/* Construct DH structure from the our GOST private key */
391. > 	dh->g = BN_dup(priv->pkey.dsa->g);
392.   	dh->p = BN_dup(priv->pkey.dsa->p);
393.   	dh->priv_key = BN_dup(priv->pkey.dsa->priv_key);

crypto/bn/bn_lib.c:479:1: start of procedure BN_dup()
  477.   	}
  478.   
  479. > BIGNUM *BN_dup(const BIGNUM *a)
  480.   	{
  481.   	BIGNUM *t;

crypto/bn/bn_lib.c:483:6: Taking false branch
  481.   	BIGNUM *t;
  482.   
  483.   	if (a == NULL) return NULL;
              ^
  484.   	bn_check_top(a);
  485.   

crypto/bn/bn_lib.c:486:2: 
  484.   	bn_check_top(a);
  485.   
  486. > 	t = BN_new();
  487.   	if (t == NULL) return NULL;
  488.   	if(!BN_copy(t, a))

crypto/bn/bn_lib.c:298:1: start of procedure BN_new()
    296.   	}
    297.   
    298. > BIGNUM *BN_new(void)
    299.   	{
    300.   	BIGNUM *ret;

crypto/bn/bn_lib.c:302:6: 
    300.   	BIGNUM *ret;
    301.   
    302. > 	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
    303.   		{
    304.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);

crypto/mem.c:294:1: start of procedure CRYPTO_malloc()
      292.   	}
      293.   
      294. > void *CRYPTO_malloc(int num, const char *file, int line)
      295.   	{
      296.   	void *ret = NULL;

crypto/mem.c:296:2: 
      294.   void *CRYPTO_malloc(int num, const char *file, int line)
      295.   	{
      296. > 	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;

crypto/mem.c:298:6: Taking false branch
      296.   	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;
                  ^
      299.   
      300.   	allow_customize = 0;

crypto/mem.c:300:2: 
      298.   	if (num <= 0) return NULL;
      299.   
      300. > 	allow_customize = 0;
      301.   	if (malloc_debug_func != NULL)
      302.   		{

crypto/mem.c:301:6: Taking true branch
      299.   
      300.   	allow_customize = 0;
      301.   	if (malloc_debug_func != NULL)
                  ^
      302.   		{
      303.   		allow_customize_debug = 0;

crypto/mem.c:303:3: 
      301.   	if (malloc_debug_func != NULL)
      302.   		{
      303. > 		allow_customize_debug = 0;
      304.   		malloc_debug_func(NULL, num, file, line, 0);
      305.   		}

crypto/mem.c:304:3: Skipping __function_pointer__(): unresolved function pointer
      302.   		{
      303.   		allow_customize_debug = 0;
      304.   		malloc_debug_func(NULL, num, file, line, 0);
               ^
      305.   		}
      306.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:306:2: Skipping __function_pointer__(): unresolved function pointer
      304.   		malloc_debug_func(NULL, num, file, line, 0);
      305.   		}
      306.   	ret = malloc_ex_func(num,file,line);
              ^
      307.   #ifdef LEVITTE_DEBUG_MEM
      308.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:310:6: Taking true branch
      308.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
      309.   #endif
      310.   	if (malloc_debug_func != NULL)
                  ^
      311.   		malloc_debug_func(ret, num, file, line, 1);
      312.   

crypto/mem.c:311:3: Skipping __function_pointer__(): unresolved function pointer
      309.   #endif
      310.   	if (malloc_debug_func != NULL)
      311.   		malloc_debug_func(ret, num, file, line, 1);
               ^
      312.   
      313.   #ifndef OPENSSL_CPUID_OBJ

crypto/mem.c:317:12: Taking false branch
      315.            * sanitisation function can't be optimised out. NB: We only do
      316.            * this for >2Kb so the overhead doesn't bother us. */
      317.           if(ret && (num > 2048))
                        ^
      318.   	{	extern unsigned char cleanse_ctr;
      319.                   ((unsigned char *)ret)[0] = cleanse_ctr;

crypto/mem.c:323:2: 
      321.   #endif
      322.   
      323. > 	return ret;
      324.   	}
      325.   

crypto/mem.c:324:2: return from a call to CRYPTO_malloc
      322.   
      323.   	return ret;
      324.   	}
              ^
      325.   
      326.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/bn/bn_lib.c:302:6: Taking true branch
    300.   	BIGNUM *ret;
    301.   
    302.   	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
                ^
    303.   		{
    304.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:304:3: 
    302.   	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
    303.   		{
    304. > 		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
    305.   		return(NULL);
    306.   		}

crypto/err/err.c:680:1: start of procedure ERR_put_error()
      678.   /********************************************************/
      679.   
      680. > void ERR_put_error(int lib, int func, int reason, const char *file,
      681.   	     int line)
      682.   	{

crypto/err/err.c:704:2: Skipping ERR_get_state(): empty list of specs
      702.   	}
      703.   #endif
      704.   	es=ERR_get_state();
              ^
      705.   
      706.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:706:2: 
      704.   	es=ERR_get_state();
      705.   
      706. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
      707.   	if (es->top == es->bottom)
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:707:6: Taking false branch
      705.   
      706.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
      707.   	if (es->top == es->bottom)
                  ^
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709.   	es->err_flags[es->top]=0;

crypto/err/err.c:709:2: 
      707.   	if (es->top == es->bottom)
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709. > 	es->err_flags[es->top]=0;
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;

crypto/err/err.c:710:2: 
      708.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
      709.   	es->err_flags[es->top]=0;
      710. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;

crypto/err/err.c:711:2: 
      709.   	es->err_flags[es->top]=0;
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711. > 	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);

crypto/err/err.c:712:2: 
      710.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
      711.   	es->err_file[es->top]=file;
      712. > 	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
      714.   	}

crypto/err/err.c:713:2: Taking true branch
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:713:2: Taking false branch
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:713:2: Loop condition is false. Leaving loop
      711.   	es->err_file[es->top]=file;
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
              ^
      714.   	}
      715.   

crypto/err/err.c:714:2: return from a call to ERR_put_error
      712.   	es->err_line[es->top]=line;
      713.   	err_clear_data(es,es->top);
      714.   	}
              ^
      715.   
      716.   void ERR_clear_error(void)

crypto/bn/bn_lib.c:305:3: 
    303.   		{
    304.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
    305. > 		return(NULL);
    306.   		}
    307.   	ret->flags=BN_FLG_MALLOCED;

crypto/bn/bn_lib.c:314:2: return from a call to BN_new
    312.   	bn_check_top(ret);
    313.   	return(ret);
    314.   	}
            ^
    315.   
    316.   /* This is used both by bn_expand2() and bn_dup_expand() */

crypto/bn/bn_lib.c:487:6: Taking true branch
  485.   
  486.   	t = BN_new();
  487.   	if (t == NULL) return NULL;
              ^
  488.   	if(!BN_copy(t, a))
  489.   		{

crypto/bn/bn_lib.c:487:17: 
  485.   
  486.   	t = BN_new();
  487. > 	if (t == NULL) return NULL;
  488.   	if(!BN_copy(t, a))
  489.   		{

crypto/bn/bn_lib.c:495:2: return from a call to BN_dup
  493.   	bn_check_top(t);
  494.   	return t;
  495.   	}
          ^
  496.   
  497.   BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)

int pkey_GOST94cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_len, const unsigned char *in, size_t in_len)
	{
	GOST_KEY_TRANSPORT *gkt = NULL;
	const unsigned char *p=in;
	unsigned char shared_key[32];
	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;
	EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);
	if (!key)
		{
		*key_len = 32;
		return 1;
		}
	dh->g = BN_dup(priv->pkey.dsa->g);
	dh->p = BN_dup(priv->pkey.dsa->p);
	dh->priv_key = BN_dup(priv->pkey.dsa->priv_key);
	gkt = d2i_GOST_KEY_TRANSPORT(NULL,(const unsigned char **)&p,
		in_len);
	if (!gkt)
		{
		GOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
		DH_free(dh);
		return 0;
		}
	eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);
	OPENSSL_assert(gkt->key_agreement_info->eph_iv->length==8);
	memcpy(iv,gkt->key_agreement_info->eph_iv->data,8);
	OPENSSL_assert(gkt->key_info->imit->length==4);
	memcpy(hmac,gkt->key_info->imit->data,4);
	i=make_gost_shared_key(dh,eph_key,shared_key);
	EVP_PKEY_free(eph_key);
	DH_free(dh);
	if (!i)
		{
		GOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_COMPUTING_SHARED_KEY);
		GOST_KEY_TRANSPORT_free(gkt);
		return 0;
		}
	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,
			gkt->key_info->encrypted_key->length, &ctx))
		{
		GOST_KEY_TRANSPORT_free(gkt);
		return 0;
		}
	GOST_KEY_TRANSPORT_free(gkt);
	if (!gost_mac(&ctx,32,key,32,hmac_comp))
		{
		GOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_COMPUTING_MAC);
		return 0;
		}
    if (memcmp(hmac,hmac_comp,4)!=0)
		{
		GOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_SESSION_KEY_MAC_DOES_NOT_MATCH);
		return 0;
		}
	return 1;
	}
['int pkey_GOST94cc_decrypt (EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_len, const unsigned char *in, size_t in_len)\n\t{\n\tGOST_KEY_TRANSPORT *gkt = NULL;\n\tconst unsigned char *p=in;\n\tunsigned char shared_key[32];\n\tunsigned char hmac[4],hmac_comp[4];\n\tunsigned char iv[8];\n\tint i;\n\tconst struct gost_cipher_info *cipher_info;\n\tgost_ctx ctx;\n\tDH *dh = DH_new();\n\tEVP_PKEY *eph_key;\n\tEVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);\n\tif (!key)\n\t\t{\n\t\t*key_len = 32;\n\t\treturn 1;\n\t\t}\n\tdh->g = BN_dup(priv->pkey.dsa->g);\n\tdh->p = BN_dup(priv->pkey.dsa->p);\n\tdh->priv_key = BN_dup(priv->pkey.dsa->priv_key);\n\tgkt = d2i_GOST_KEY_TRANSPORT(NULL,(const unsigned char **)&p,\n\t\tin_len);\n\tif (!gkt)\n\t\t{\n\t\tGOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);\n\t\tDH_free(dh);\n\t\treturn 0;\n\t\t}\n\teph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);\n\tOPENSSL_assert(gkt->key_agreement_info->eph_iv->length==8);\n\tmemcpy(iv,gkt->key_agreement_info->eph_iv->data,8);\n\tOPENSSL_assert(gkt->key_info->imit->length==4);\n\tmemcpy(hmac,gkt->key_info->imit->data,4);\n\ti=make_gost_shared_key(dh,eph_key,shared_key);\n\tEVP_PKEY_free(eph_key);\n\tDH_free(dh);\n\tif (!i)\n\t\t{\n\t\tGOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_COMPUTING_SHARED_KEY);\n\t\tGOST_KEY_TRANSPORT_free(gkt);\n\t\treturn 0;\n\t\t}\n\tcipher_info = get_encryption_params(gkt->key_agreement_info->cipher);\n\tgost_init(&ctx, cipher_info->sblock);\n\tgost_key(&ctx,shared_key);\n\tif (!decrypt_cryptocom_key(key,*key_len,gkt->key_info->encrypted_key->data,\n\t\t\tgkt->key_info->encrypted_key->length, &ctx))\n\t\t{\n\t\tGOST_KEY_TRANSPORT_free(gkt);\n\t\treturn 0;\n\t\t}\n\tGOST_KEY_TRANSPORT_free(gkt);\n\tif (!gost_mac(&ctx,32,key,32,hmac_comp))\n\t\t{\n\t\tGOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_ERROR_COMPUTING_MAC);\n\t\treturn 0;\n\t\t}\n    if (memcmp(hmac,hmac_comp,4)!=0)\n\t\t{\n\t\tGOSTerr(GOST_F_PKEY_GOST94CC_DECRYPT,GOST_R_SESSION_KEY_MAC_DOES_NOT_MATCH);\n\t\treturn 0;\n\t\t}\n\treturn 1;\n\t}', 'DH *DH_new(void)\n\t{\n\treturn DH_new_method(NULL);\n\t}', 'DH *DH_new_method(ENGINE *engine)\n\t{\n\tDH *ret;\n\tret=(DH *)OPENSSL_malloc(sizeof(DH));\n\tif (ret == NULL)\n\t\t{\n\t\tDHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->meth = DH_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tDHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_DH();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_DH(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tDHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n#endif\n\tret->pad=0;\n\tret->version=0;\n\tret->p=NULL;\n\tret->g=NULL;\n\tret->length=0;\n\tret->pub_key=NULL;\n\tret->priv_key=NULL;\n\tret->q=NULL;\n\tret->j=NULL;\n\tret->seed = NULL;\n\tret->seedlen = 0;\n\tret->counter = NULL;\n\tret->method_mont_p=NULL;\n\tret->references = 1;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n#ifndef OPENSSL_NO_ENGINE\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n#endif\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n        if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t     int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)\n\t{\n\treturn ctx->pkey;\n\t}', 'BIGNUM *BN_dup(const BIGNUM *a)\n\t{\n\tBIGNUM *t;\n\tif (a == NULL) return NULL;\n\tbn_check_top(a);\n\tt = BN_new();\n\tif (t == NULL) return NULL;\n\tif(!BN_copy(t, a))\n\t\t{\n\t\tBN_free(t);\n\t\treturn NULL;\n\t\t}\n\tbn_check_top(t);\n\treturn t;\n\t}', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->dmax=0;\n\tret->d=NULL;\n\tbn_check_top(ret);\n\treturn(ret);\n\t}']