--- openssl-SNAP-20121220.orig/engines/ccgost/gost_crypt.c	2012-12-21 01:33:45.000000000 +0400
+++ openssl-SNAP-20121220.check/engines/ccgost/gost_crypt.c	2012-12-21 11:04:41.000000000 +0400
@@ -6,6 +6,12 @@
  *       OpenSSL interface to GOST 28147-89 cipher functions          *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+#if !defined(CCGOST_DEBUG) && !defined(DEBUG)
+# ifndef NDEBUG
+#  define NDEBUG
+# endif
+#endif
+#include <assert.h>
 #include <string.h>
 #include "gost89.h"
 #include <openssl/rand.h>
@@ -206,6 +212,7 @@
 static void gost_crypt_mesh (void *ctx,unsigned char *iv,unsigned char *buf)
 	{
 	struct ossl_gost_cipher_ctx *c = ctx;
+	assert(0 == c->count%8 && 1024 >= c->count);
 	if (c->key_meshing && c->count==1024)
 		{
 		cryptopro_key_meshing(&(c->cctx),iv);
@@ -219,6 +226,7 @@
 	struct ossl_gost_cipher_ctx *c = ctx;
 	word32 g,go;
 	unsigned char buf1[8];
+	assert(0 == c->count%8 && 1024 >= c->count);
 	if (c->key_meshing && c->count==1024)
 		{
 		cryptopro_key_meshing(&(c->cctx),iv);
@@ -511,6 +519,7 @@
 	 * interpret internal state of MAC algorithm as iv during keymeshing
 	 * (but does initialize internal state from iv in key transport
 	 */
+	assert(0 == c->count%8 && 1024 >= c->count);
 	if (c->key_meshing && c->count==1024)
 		{
 		cryptopro_key_meshing(&(c->cctx),buffer);
