Пример #1
0
void testrun_nessie2(void){
	uint16_t i;
	uint8_t j;
	uint8_t data[128], hash[64];
	whirlpool_ctx_t ctx;
	char str[8];
	memset(data, 0, 128);
	cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
	for(i=0; i<1024; ++i){
		cli_putstr_P(PSTR("\r\n    L = "));
		itoa(i, str, 10);
		j=4;
		j-= strlen(str);
		if(j>3){
			j=0;
		}
		while(j--){
			cli_putc(' ');
		}
		cli_putstr(str);
		cli_putstr_P(PSTR(": "));
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, data, i);
		whirlpool_ctx2hash(hash, &ctx);
		cli_hexdump(hash, 64);
	}
	cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
	for(i=0; i<512; ++i){
		cli_putstr_P(PSTR("\r\n    S = "));
		data[i/8] = 0x80>>(i&7);
		cli_hexdump(data, 64);
		cli_putstr_P(PSTR(": "));
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, data, 512);
		whirlpool_ctx2hash(hash, &ctx);
		data[i/8] = 0x00;
		cli_hexdump(hash, 64);
	}
	cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
	uint32_t c;
	memset(hash, 0, 64);
	for(c=0; c<1000000; ++c){
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, hash, 512);
		whirlpool_ctx2hash(hash, &ctx);
	}
	cli_hexdump(hash, 64);
	cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
}
Пример #2
0
void testrun_whirlpool(void){
	whirlpool_ctx_t ctx;
	uint8_t hash[64];
	uint8_t data[64];
	memset(data, 0, 64);
	data[0] = 'a';
	data[1] = 'b';
	data[2] = 'c';
	whirlpool_init(&ctx);
	whirlpool_lastBlock(&ctx, data, 3*8);
	whirlpool_ctx2hash(hash, &ctx);
	cli_putstr_P(PSTR("\r\nEmpty message hash:"));
	cli_hexdump_block(hash, 64, 4, 16);
}
Пример #3
0
char *whirlpool_digest(const char *str)
{
	whirlpool_t ctx;
	stralloc_t sa;
	char *buf;
	uint8_t digest[DIGESTBYTES];
	int i;

	whirlpool_init(&ctx);
	whirlpool_add(&ctx, (const unsigned char * const) str, str_len(str)*8);
	whirlpool_finalize(&ctx, digest);

	stralloc_init(&sa);

	for (i = 0; i < DIGESTBYTES; i++)
		stralloc_catf(&sa, "%02X", digest[i]);

	buf = stralloc_finalize(&sa);

	stralloc_free(&sa);

	return buf;
}
Пример #4
0
/**
  Self-test the hash
  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
*/  
int  whirlpool_test(void)
{
#ifndef LTC_TEST
    return CRYPT_NOP;
#else    
  static const struct {
      int len;
      unsigned char msg[128], hash[64];
  } tests[] = {
  
  /* NULL Message */
{
  0, 
  { 0x00 },
  { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, 0x9B, 0x44, 0xE3, 0x9C, 0x1D, 0x2E, 0x17, 0x26,
    0xC5, 0x30, 0x23, 0x21, 0x30, 0xD4, 0x07, 0xF8, 0x9A, 0xFE, 0xE0, 0x96, 0x49, 0x97, 0xF7, 0xA7,
    0x3E, 0x83, 0xBE, 0x69, 0x8B, 0x28, 0x8F, 0xEB, 0xCF, 0x88, 0xE3, 0xE0, 0x3C, 0x4F, 0x07, 0x57,
    0xEA, 0x89, 0x64, 0xE5, 0x9B, 0x63, 0xD9, 0x37, 0x08, 0xB1, 0x38, 0xCC, 0x42, 0xA6, 0x6E, 0xB3 }
},


   /* 448-bits of 0 bits */
{

  56,
  { 0x00 },
  { 0x0B, 0x3F, 0x53, 0x78, 0xEB, 0xED, 0x2B, 0xF4, 0xD7, 0xBE, 0x3C, 0xFD, 0x81, 0x8C, 0x1B, 0x03,
    0xB6, 0xBB, 0x03, 0xD3, 0x46, 0x94, 0x8B, 0x04, 0xF4, 0xF4, 0x0C, 0x72, 0x6F, 0x07, 0x58, 0x70,
    0x2A, 0x0F, 0x1E, 0x22, 0x58, 0x80, 0xE3, 0x8D, 0xD5, 0xF6, 0xED, 0x6D, 0xE9, 0xB1, 0xE9, 0x61,
    0xE4, 0x9F, 0xC1, 0x31, 0x8D, 0x7C, 0xB7, 0x48, 0x22, 0xF3, 0xD0, 0xE2, 0xE9, 0xA7, 0xE7, 0xB0 }
},

   /* 520-bits of 0 bits */
{
  65,
  { 0x00 },
  { 0x85, 0xE1, 0x24, 0xC4, 0x41, 0x5B, 0xCF, 0x43, 0x19, 0x54, 0x3E, 0x3A, 0x63, 0xFF, 0x57, 0x1D,
    0x09, 0x35, 0x4C, 0xEE, 0xBE, 0xE1, 0xE3, 0x25, 0x30, 0x8C, 0x90, 0x69, 0xF4, 0x3E, 0x2A, 0xE4,
    0xD0, 0xE5, 0x1D, 0x4E, 0xB1, 0xE8, 0x64, 0x28, 0x70, 0x19, 0x4E, 0x95, 0x30, 0xD8, 0xD8, 0xAF,
    0x65, 0x89, 0xD1, 0xBF, 0x69, 0x49, 0xDD, 0xF9, 0x0A, 0x7F, 0x12, 0x08, 0x62, 0x37, 0x95, 0xB9 }
},

   /* 512-bits, leading set */
{
  64,
  { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  { 0x10, 0x3E, 0x00, 0x55, 0xA9, 0xB0, 0x90, 0xE1, 0x1C, 0x8F, 0xDD, 0xEB, 0xBA, 0x06, 0xC0, 0x5A,
    0xCE, 0x8B, 0x64, 0xB8, 0x96, 0x12, 0x8F, 0x6E, 0xED, 0x30, 0x71, 0xFC, 0xF3, 0xDC, 0x16, 0x94,
    0x67, 0x78, 0xE0, 0x72, 0x23, 0x23, 0x3F, 0xD1, 0x80, 0xFC, 0x40, 0xCC, 0xDB, 0x84, 0x30, 0xA6,
    0x40, 0xE3, 0x76, 0x34, 0x27, 0x1E, 0x65, 0x5C, 0xA1, 0x67, 0x4E, 0xBF, 0xF5, 0x07, 0xF8, 0xCB }
},

   /* 512-bits, leading set of second byte */
{
  64,
  { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  { 0x35, 0x7B, 0x42, 0xEA, 0x79, 0xBC, 0x97, 0x86, 0x97, 0x5A, 0x3C, 0x44, 0x70, 0xAA, 0xB2, 0x3E,
    0x62, 0x29, 0x79, 0x7B, 0xAD, 0xBD, 0x54, 0x36, 0x5B, 0x54, 0x96, 0xE5, 0x5D, 0x9D, 0xD7, 0x9F,
    0xE9, 0x62, 0x4F, 0xB4, 0x22, 0x66, 0x93, 0x0A, 0x62, 0x8E, 0xD4, 0xDB, 0x08, 0xF9, 0xDD, 0x35,
    0xEF, 0x1B, 0xE1, 0x04, 0x53, 0xFC, 0x18, 0xF4, 0x2C, 0x7F, 0x5E, 0x1F, 0x9B, 0xAE, 0x55, 0xE0 }
},

   /* 512-bits, leading set of last byte */
{
  64,
  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 },
  { 0x8B, 0x39, 0x04, 0xDD, 0x19, 0x81, 0x41, 0x26, 0xFD, 0x02, 0x74, 0xAB, 0x49, 0xC5, 0x97, 0xF6,
    0xD7, 0x75, 0x33, 0x52, 0xA2, 0xDD, 0x91, 0xFD, 0x8F, 0x9F, 0x54, 0x05, 0x4C, 0x54, 0xBF, 0x0F,
    0x06, 0xDB, 0x4F, 0xF7, 0x08, 0xA3, 0xA2, 0x8B, 0xC3, 0x7A, 0x92, 0x1E, 0xEE, 0x11, 0xED, 0x7B,
    0x6A, 0x53, 0x79, 0x32, 0xCC, 0x5E, 0x94, 0xEE, 0x1E, 0xA6, 0x57, 0x60, 0x7E, 0x36, 0xC9, 0xF7 }
},
   
};

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

  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
      whirlpool_init(&md);
      whirlpool_process(&md, (unsigned char *)tests[i].msg, tests[i].len);
      whirlpool_done(&md, tmp);
      if (memcmp(tmp, tests[i].hash, 64) != 0) {
#if 0      
         printf("\nFailed test %d\n", i);
         for (i = 0; i < 64; ) {
            printf("%02x ", tmp[i]);
            if (!(++i & 15)) printf("\n");
         }
#endif         
         return CRYPT_FAIL_TESTVECTOR;
      }
  }
  return CRYPT_OK;
#endif
}