diff --git a/engines/ccgost/e_gost_err.c b/engines/ccgost/e_gost_err.c
index 9a79a37..5e003c9 100644
--- a/engines/ccgost/e_gost_err.c
+++ b/engines/ccgost/e_gost_err.c
@@ -1,6 +1,6 @@
 /* e_gost_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2009 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2010 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -133,6 +133,7 @@ static ERR_STRING_DATA GOST_str_reasons[]=
 {ERR_REASON(GOST_R_INVALID_IV_LENGTH)    ,"invalid iv length"},
 {ERR_REASON(GOST_R_INVALID_MAC_KEY_LENGTH),"invalid mac key length"},
 {ERR_REASON(GOST_R_INVALID_PARAMSET)     ,"invalid paramset"},
+{ERR_REASON(GOST_R_INVALID_SHARED_UKM)   ,"invalid shared ukm"},
 {ERR_REASON(GOST_R_KEY_IS_NOT_INITALIZED),"key is not initalized"},
 {ERR_REASON(GOST_R_KEY_IS_NOT_INITIALIZED),"key is not initialized"},
 {ERR_REASON(GOST_R_KEY_PARAMETERS_MISSING),"key parameters missing"},
diff --git a/engines/ccgost/e_gost_err.h b/engines/ccgost/e_gost_err.h
index 6dc5000..9ec49d1 100644
--- a/engines/ccgost/e_gost_err.h
+++ b/engines/ccgost/e_gost_err.h
@@ -131,6 +131,7 @@ void ERR_GOST_error(int function, int reason, char *file, int line);
 #define GOST_R_INVALID_IV_LENGTH			 110
 #define GOST_R_INVALID_MAC_KEY_LENGTH			 111
 #define GOST_R_INVALID_PARAMSET				 112
+#define GOST_R_INVALID_SHARED_UKM			 133
 #define GOST_R_KEY_IS_NOT_INITALIZED			 113
 #define GOST_R_KEY_IS_NOT_INITIALIZED			 114
 #define GOST_R_KEY_PARAMETERS_MISSING			 115
diff --git a/engines/ccgost/gost2001_keyx.c b/engines/ccgost/gost2001_keyx.c
index 3c34c32..ba24ccb 100644
--- a/engines/ccgost/gost2001_keyx.c
+++ b/engines/ccgost/gost2001_keyx.c
@@ -235,13 +235,15 @@ int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t * key_l
 	const unsigned char *p = in;
 	EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx);
 	GOST_KEY_TRANSPORT *gkt = NULL;
-	int ret=0;	
+	int ret=0;
+	int ukm_error=0;
 	unsigned char wrappedKey[44];
 	unsigned char sharedKey[32];
 	gost_ctx ctx;
 	const struct gost_cipher_info *param=NULL;
 	EVP_PKEY *eph_key=NULL, *peerkey=NULL;
-
+	struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
+	
 	if (!key)
 		{
 		*key_len = 32;
@@ -296,6 +298,13 @@ int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t * key_l
 	memcpy(wrappedKey+8,gkt->key_info->encrypted_key->data,32);
 	OPENSSL_assert(gkt->key_info->imit->length==4);
 	memcpy(wrappedKey+40,gkt->key_info->imit->data,4);	
+	
+    if(!data || !data->shared_ukm || memcmp(wrappedKey, data->shared_ukm, 8)){
+        ukm_error = 1; /* To prevent timing attacks, do not interrupt for the moment... */
+        GOSTerr(GOST_F_PKEY_GOST01CP_DECRYPT,
+			GOST_R_INVALID_SHARED_UKM);
+    }
+		
 	VKO_compute_key(sharedKey,32,EC_KEY_get0_public_key(EVP_PKEY_get0(peerkey)),
 		EVP_PKEY_get0(priv),wrappedKey);
 	if (!keyUnwrapCryptoPro(&ctx,sharedKey,wrappedKey,key))
@@ -304,8 +313,8 @@ int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t * key_l
 			GOST_R_ERROR_COMPUTING_SHARED_KEY);
 		goto err;
 		}	
-				
-	ret=1;
+	if(!ukm_error)			
+		ret=1;
 err:	
 	if (eph_key) EVP_PKEY_free(eph_key);
 	if (gkt) GOST_KEY_TRANSPORT_free(gkt);
diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c
index 19f4b27..f256fa7 100644
--- a/ssl/s3_srvr.c
+++ b/ssl/s3_srvr.c
@@ -2589,6 +2589,9 @@ int ssl3_get_client_key_exchange(SSL *s)
 			unsigned char premaster_secret[32], *start;
 			size_t outlen=32, inlen;
 			unsigned long alg_a;
+			unsigned char shared_ukm[32];
+			EVP_MD_CTX *ukm_hash;
+			unsigned int md_len;
 
 			/* Get our certificate private key*/
 			alg_a = s->s3->tmp.new_cipher->algorithm_auth;
@@ -2630,6 +2633,20 @@ int ssl3_get_client_key_exchange(SSL *s)
 				SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DECRYPTION_FAILED);
 				goto gerr;
 				}
+				
+			ukm_hash = EVP_MD_CTX_create();
+			EVP_DigestInit(ukm_hash,EVP_get_digestbynid(NID_id_GostR3411_94));
+			EVP_DigestUpdate(ukm_hash,s->s3->client_random,SSL3_RANDOM_SIZE);
+			EVP_DigestUpdate(ukm_hash,s->s3->server_random,SSL3_RANDOM_SIZE);
+			EVP_DigestFinal_ex(ukm_hash, shared_ukm, &md_len);
+			EVP_MD_CTX_destroy(ukm_hash);
+			if (EVP_PKEY_CTX_ctrl(pkey_ctx,-1,EVP_PKEY_OP_DECRYPT, EVP_PKEY_CTRL_SET_IV,
+				8,shared_ukm)<0) {
+					SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+						SSL_R_LIBRARY_BUG);
+					goto gerr;
+				}
+			
 			if (EVP_PKEY_decrypt(pkey_ctx,premaster_secret,&outlen,start,inlen) <=0)
 
 				{
