コード例 #1
0
ファイル: rmd128.c プロジェクト: scenkov/vrbrain_nuttx
/**
  Self-test the hash
  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
*/
int rmd128_test(void)
{
#ifndef LTC_TEST
    return CRYPT_NOP;
#else
    static const struct {
        char *msg;
        unsigned char md[16];
    } tests[] = {
        {   "",
            {   0xcd, 0xf2, 0x62, 0x13, 0xa1, 0x50, 0xdc, 0x3e,
                0xcb, 0x61, 0x0f, 0x18, 0xf6, 0xb3, 0x8b, 0x46
            }
        },
        {   "a",
            {   0x86, 0xbe, 0x7a, 0xfa, 0x33, 0x9d, 0x0f, 0xc7,
                0xcf, 0xc7, 0x85, 0xe7, 0x2f, 0x57, 0x8d, 0x33
            }
        },
        {   "abc",
            {   0xc1, 0x4a, 0x12, 0x19, 0x9c, 0x66, 0xe4, 0xba,
                0x84, 0x63, 0x6b, 0x0f, 0x69, 0x14, 0x4c, 0x77
            }
        },
        {   "message digest",
            {   0x9e, 0x32, 0x7b, 0x3d, 0x6e, 0x52, 0x30, 0x62,
                0xaf, 0xc1, 0x13, 0x2d, 0x7d, 0xf9, 0xd1, 0xb8
            }
        },
        {   "abcdefghijklmnopqrstuvwxyz",
            {   0xfd, 0x2a, 0xa6, 0x07, 0xf7, 0x1d, 0xc8, 0xf5,
                0x10, 0x71, 0x49, 0x22, 0xb3, 0x71, 0x83, 0x4e
            }
        },
        {   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
            {   0xd1, 0xe9, 0x59, 0xeb, 0x17, 0x9c, 0x91, 0x1f,
                0xae, 0xa4, 0x62, 0x4c, 0x60, 0xc5, 0xc7, 0x02
            }
        }
    };
    int x;
    unsigned char buf[16];
    hash_state md;

    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
        rmd128_init(&md);
        rmd128_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
        rmd128_done(&md, buf);
        if (XMEMCMP(buf, tests[x].md, 16) != 0) {
#if 0
            printf("Failed test %d\n", x);
#endif
            return CRYPT_FAIL_TESTVECTOR;
        }
    }
    return CRYPT_OK;
#endif
}
コード例 #2
0
ファイル: rmd128.c プロジェクト: dyemanov/firebird
/**
  Self-test the hash
  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
*/
int rmd128_test(void)
{
#ifndef LTC_TEST
   return CRYPT_NOP;
#else
   static const struct {
        const char *msg;
        unsigned char hash[16];
   } tests[] = {
   { "",
     { 0xcd, 0xf2, 0x62, 0x13, 0xa1, 0x50, 0xdc, 0x3e,
       0xcb, 0x61, 0x0f, 0x18, 0xf6, 0xb3, 0x8b, 0x46 }
   },
   { "a",
     { 0x86, 0xbe, 0x7a, 0xfa, 0x33, 0x9d, 0x0f, 0xc7,
       0xcf, 0xc7, 0x85, 0xe7, 0x2f, 0x57, 0x8d, 0x33 }
   },
   { "abc",
     { 0xc1, 0x4a, 0x12, 0x19, 0x9c, 0x66, 0xe4, 0xba,
       0x84, 0x63, 0x6b, 0x0f, 0x69, 0x14, 0x4c, 0x77 }
   },
   { "message digest",
     { 0x9e, 0x32, 0x7b, 0x3d, 0x6e, 0x52, 0x30, 0x62,
       0xaf, 0xc1, 0x13, 0x2d, 0x7d, 0xf9, 0xd1, 0xb8 }
   },
   { "abcdefghijklmnopqrstuvwxyz",
     { 0xfd, 0x2a, 0xa6, 0x07, 0xf7, 0x1d, 0xc8, 0xf5,
       0x10, 0x71, 0x49, 0x22, 0xb3, 0x71, 0x83, 0x4e }
   },
   { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
     { 0xd1, 0xe9, 0x59, 0xeb, 0x17, 0x9c, 0x91, 0x1f,
       0xae, 0xa4, 0x62, 0x4c, 0x60, 0xc5, 0xc7, 0x02 }
   }
   };

   int i;
   unsigned char tmp[16];
   hash_state md;

   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
       rmd128_init(&md);
       rmd128_process(&md, (unsigned char *)tests[i].msg, strlen(tests[i].msg));
       rmd128_done(&md, tmp);
       if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "RIPEMD128", i)) {
          return CRYPT_FAIL_TESTVECTOR;
       }
   }
   return CRYPT_OK;
#endif
}