int BN_bn2bin(const BIGNUM *a, unsigned char *to)
	{
	int n,i;
	BN_ULONG l;
	bn_check_top(a);
	n=i=BN_num_bytes(a);
	while (i--)
		{
		l=a->d[i/BN_BYTES];
		*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
		}
	return(n);
	}
['static int VKO_compute_key(unsigned char *shared_key,size_t shared_key_size,const EC_POINT *pub_key,EC_KEY *priv_key,const unsigned char *ukm)\n\t{\n\tunsigned char ukm_be[8],databuf[64],hashbuf[64];\n\tBIGNUM *UKM=NULL,*p=NULL,*order=NULL,*X=NULL,*Y=NULL;\n\tconst BIGNUM* key=EC_KEY_get0_private_key(priv_key);\n\tEC_POINT *pnt=EC_POINT_new(EC_KEY_get0_group(priv_key));\n\tint i;\n\tgost_hash_ctx hash_ctx;\n\tBN_CTX *ctx = BN_CTX_new();\n\tfor (i=0;i<8;i++)\n\t\t{\n\t\tukm_be[7-i]=ukm[i];\n\t\t}\n\tBN_CTX_start(ctx);\n\tUKM=getbnfrombuf(ukm_be,8);\n\tp=BN_CTX_get(ctx);\n\torder = BN_CTX_get(ctx);\n\tX=BN_CTX_get(ctx);\n\tY=BN_CTX_get(ctx);\n\tEC_GROUP_get_order(EC_KEY_get0_group(priv_key),order,ctx);\n\tBN_mod_mul(p,key,UKM,order,ctx);\n\tEC_POINT_mul(EC_KEY_get0_group(priv_key),pnt,NULL,pub_key,p,ctx);\n\tEC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),\n\t\tpnt,X,Y,ctx);\n\tstore_bignum(Y,databuf,32);\n\tstore_bignum(X,databuf+32,32);\n\tfor (i=0;i<64;i++)\n\t\t{\n\t\thashbuf[63-i]=databuf[i];\n\t\t}\n\tinit_gost_hash_ctx(&hash_ctx,&GostR3411_94_CryptoProParamSet);\n\tstart_hash(&hash_ctx);\n\thash_block(&hash_ctx,hashbuf,64);\n\tfinish_hash(&hash_ctx,shared_key);\n\tdone_gost_hash_ctx(&hash_ctx);\n\tBN_free(UKM);\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tEC_POINT_free(pnt);\n\treturn 32;\n\t}', 'int store_bignum(BIGNUM *bn, unsigned char *buf,int len)\n\t{\n\tint bytes = BN_num_bytes(bn);\n\tif (bytes>len) return 0;\n\tmemset(buf,0,len);\n\tBN_bn2bin(bn,buf+len-bytes);\n\treturn 1;\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}']