X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost89.c;h=593bc237257cd568594a4a5a03a69bce3d2382e2;hb=bd1b2c234ea8ef2bdfe8f303f6002525d6d69bc7;hp=670dfb55f5da84e9fe683edbda09e5a625e5b179;hpb=12be7c21781eba9f7a37762e7e307571225c6c47;p=openssl-gost%2Fengine.git diff --git a/gost89.c b/gost89.c index 670dfb5..593bc23 100644 --- a/gost89.c +++ b/gost89.c @@ -250,7 +250,7 @@ const byte ACPKM_D_const[] = { }; /* Initialization of gost_ctx subst blocks*/ -static void kboxinit(gost_ctx * c, const gost_subst_block * b) +void kboxinit(gost_ctx * c, const gost_subst_block * b) { int i; @@ -621,15 +621,18 @@ int gost_mac_iv(gost_ctx * ctx, int mac_len, const unsigned char *iv, /* Implements key meshing algorithm by modifing ctx and IV in place */ void cryptopro_key_meshing(gost_ctx * ctx, unsigned char *iv) { - unsigned char newkey[32], newiv[8]; + unsigned char newkey[32]; /* Set static keymeshing key */ /* "Decrypt" key with keymeshing key */ gost_dec(ctx, CryptoProKeyMeshingKey, newkey, 4); /* set new key */ gost_key(ctx, newkey); /* Encrypt iv with new key */ - gostcrypt(ctx, iv, newiv); - memcpy(iv, newiv, 8); + if (iv != NULL ) { + unsigned char newiv[8]; + gostcrypt(ctx, iv, newiv); + memcpy(iv, newiv, 8); + } } void acpkm_magma_key_meshing(gost_ctx * ctx) @@ -649,65 +652,3 @@ void acpkm_magma_key_meshing(gost_ctx * ctx) /* set new key */ gost_key(ctx, newkey); } - -#ifdef ENABLE_UNIT_TESTS -# include -# include - -static void hexdump(FILE *f, const char *title, const unsigned char *s, int l) -{ - int n = 0; - - fprintf(f, "%s", title); - for (; n < l; ++n) { - if ((n % 16) == 0) - fprintf(f, "\n%04x", n); - fprintf(f, " %02x", s[n]); - } - fprintf(f, "\n"); -} - -int main(void) -{ - const unsigned char initial_key[] = { - 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF - }; - - const unsigned char meshed_key[] = { - 0x86, 0x3E, 0xA0, 0x17, 0x84, 0x2C, 0x3D, 0x37, - 0x2B, 0x18, 0xA8, 0x5A, 0x28, 0xE2, 0x31, 0x7D, - 0x74, 0xBE, 0xFC, 0x10, 0x77, 0x20, 0xDE, 0x0C, - 0x9E, 0x8A, 0xB9, 0x74, 0xAB, 0xD0, 0x0C, 0xA0, - }; - - unsigned char buf[32]; - - gost_ctx ctx; - kboxinit(&ctx, &Gost28147_TC26ParamSetZ); - magma_key(&ctx, initial_key); - magma_get_key(&ctx, buf); - - hexdump(stdout, "Initial key", buf, 32); - - acpkm_magma_key_meshing(&ctx); - magma_get_key(&ctx, buf); - hexdump(stdout, "Meshed key - K2", buf, 32); - - if (memcmp(meshed_key, buf, 32)) { - fprintf(stderr, "Magma meshing failed"); - } - - acpkm_magma_key_meshing(&ctx); - magma_get_key(&ctx, buf); - hexdump(stdout, "Meshed key - K3", buf, 32); - - acpkm_magma_key_meshing(&ctx); - magma_get_key(&ctx, buf); - hexdump(stdout, "Meshed key - K4", buf, 32); - -} - -#endif