1 /**********************************************************************
3 * Copyright (c) 2005-2006 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Implementation of GOST 28147-89 encryption algorithm *
7 * No OpenSSL libraries required to compile and use *
9 **********************************************************************/
11 # pragma warning(push, 3)
12 # include <openssl/applink.c>
20 static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
24 fprintf(f, "%s", title);
27 fprintf(f, "\n%04x", n);
28 fprintf(f, " %02x", s[n]);
37 const unsigned char initial_key[] = {
38 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
39 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
40 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
41 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
44 const unsigned char meshed_key[] = {
45 0x86, 0x3E, 0xA0, 0x17, 0x84, 0x2C, 0x3D, 0x37,
46 0x2B, 0x18, 0xA8, 0x5A, 0x28, 0xE2, 0x31, 0x7D,
47 0x74, 0xBE, 0xFC, 0x10, 0x77, 0x20, 0xDE, 0x0C,
48 0x9E, 0x8A, 0xB9, 0x74, 0xAB, 0xD0, 0x0C, 0xA0,
51 unsigned char buf[32];
54 kboxinit(&ctx, &Gost28147_TC26ParamSetZ);
55 magma_key(&ctx, initial_key);
56 magma_get_key(&ctx, buf);
58 hexdump(stdout, "Initial key", buf, 32);
60 acpkm_magma_key_meshing(&ctx);
61 magma_get_key(&ctx, buf);
62 hexdump(stdout, "Meshed key - K2", buf, 32);
64 if (memcmp(meshed_key, buf, 32)) {
65 fprintf(stderr, "Magma meshing failed");
69 acpkm_magma_key_meshing(&ctx);
70 magma_get_key(&ctx, buf);
71 hexdump(stdout, "Meshed key - K3", buf, 32);
73 acpkm_magma_key_meshing(&ctx);
74 magma_get_key(&ctx, buf);
75 hexdump(stdout, "Meshed key - K4", buf, 32);