]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
test_grasshopper: Tests for CBC and CFB
authorVitaly Chikunov <vt@altlinux.org>
Mon, 23 Jul 2018 01:15:25 +0000 (04:15 +0300)
committerVitaly Chikunov <vt@altlinux.org>
Mon, 23 Jul 2018 01:15:25 +0000 (04:15 +0300)
These tests are with generated test vectors from canonical TC26
implementation with truncated IVs.

test_grasshopper.c

index 434586fc1a34cb7a940167e51341091ad3d733a7..351194ac261c54b6ba2c5be922a27bc5d0b71e7b 100644 (file)
@@ -35,6 +35,8 @@ enum e_mode {
     E_CTR,
     E_CTR_IV2,
     E_OFB,
+    E_CBC,
+    E_CFB,
 };
 
 /* Test key from both GOST R 34.12-2015 and GOST R 34.13-2015. */
@@ -51,7 +53,7 @@ static const unsigned char P[] = {
     0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xee,0xff,0x0a,0x00,
     0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xee,0xff,0x0a,0x00,0x11,
 };
-static const unsigned char E[4][sizeof(P)] = {
+static const unsigned char E[6][sizeof(P)] = {
     { /* ECB test vectors from GOST R 34.13-2015  A.1.1 */
        /* first 16 bytes is vector (b) from GOST R 34.12-2015 A.1 */
        0x7f,0x67,0x9d,0x90,0xbe,0xbc,0x24,0x30,0x5a,0x46,0x8d,0x42,0xb9,0xd4,0xed,0xcd,
@@ -76,14 +78,33 @@ static const unsigned char E[4][sizeof(P)] = {
        0x77,0x91,0x46,0xdb,0x2d,0x93,0xa9,0x4e,0xd9,0x3c,0xf6,0x8b,0x32,0x39,0x7f,0x19,
        0xe9,0x3c,0x9e,0x57,0x44,0x1d,0x87,0x05,0x45,0xf2,0x40,0x36,0xa5,0x8c,0xee,0xa3,
        0xcf,0x3f,0x00,0x61,0xd5,0x64,0x23,0x54,0x5b,0x96,0x0d,0x86,0x4c,0xc8,0x68,0xda,
-    }
+    },
+    { /* CBC test vector generated from canonical implementation */
+       0x68,0x99,0x72,0xd4,0xa0,0x85,0xfa,0x4d,0x90,0xe5,0x2e,0x3d,0x6d,0x7d,0xcc,0x27,
+       0xab,0xf1,0x70,0xb2,0xb2,0x26,0xc3,0x01,0x0c,0xcf,0xa1,0x36,0xd6,0x59,0xcd,0xaa,
+       0xca,0x71,0x92,0x72,0xab,0x1d,0x43,0x8e,0x15,0x50,0x7d,0x52,0x1e,0xcd,0x55,0x22,
+       0xe0,0x11,0x08,0xff,0x8d,0x9d,0x3a,0x6d,0x8c,0xa2,0xa5,0x33,0xfa,0x61,0x4e,0x71,
+    },
+    { /* CFB test vector generated from canonical implementation */
+       0x81,0x80,0x0a,0x59,0xb1,0x84,0x2b,0x24,0xff,0x1f,0x79,0x5e,0x89,0x7a,0xbd,0x95,
+       0x68,0xc1,0xb9,0x9c,0x4d,0xf5,0x9c,0xc7,0x95,0x1e,0x37,0x39,0xb5,0xb3,0xcd,0xbf,
+       0x07,0x3f,0x4d,0xd2,0xd6,0xde,0xb3,0xcf,0xb0,0x26,0x54,0x5f,0x7a,0xf1,0xd8,0xe8,
+       0xe1,0xc8,0x52,0xe9,0xa8,0x56,0x71,0x62,0xdb,0xb5,0xda,0x7f,0x66,0xde,0xa9,0x26,
+    },
 };
 static const unsigned char iv_ctr[]    = { 0x12,0x34,0x56,0x78,0x90,0xab,0xce,0xf0 };
 /* right [8] part of IV should be ignored by ctr */
 static const unsigned char iv_ctr_iv2[]        = { 0x12,0x34,0x56,0x78,0x90,0xab,0xce,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
 /* truncated to 128-bits IV */
-static const unsigned char iv_ofb_t[]  = { 0x12,0x34,0x56,0x78,0x90,0xab,0xce,0xf0,0xa1,0xb2,0xc3,0xd4,0xe5,0xf0,0x01,0x12 };
-static const unsigned char *iv[4] = { NULL, iv_ctr, iv_ctr_iv2, iv_ofb_t };
+static const unsigned char iv_128bit[] = { 0x12,0x34,0x56,0x78,0x90,0xab,0xce,0xf0,0xa1,0xb2,0xc3,0xd4,0xe5,0xf0,0x01,0x12 };
+static const unsigned char *iv[6] = {
+    NULL,      /* ecb */
+    iv_ctr,
+    iv_ctr_iv2,
+    iv_128bit, /* ofb */
+    iv_128bit, /* cbc*/
+    iv_128bit, /* cfb */
+};
 
 static void hexdump(const void *ptr, size_t len)
 {
@@ -235,6 +256,8 @@ int main(int argc, char **argv)
      */
     ret |= test_block(cipher_gost_grasshopper_ofb(), "ofb", E_OFB);
     ret |= test_stream(cipher_gost_grasshopper_ctr(), "ofb", E_CTR);
+    ret |= test_block(cipher_gost_grasshopper_cbc(), "cbc", E_CBC);
+    ret |= test_block(cipher_gost_grasshopper_cfb(), "cfb", E_CFB);
 
     ret |= test_omac();