ucryptolib/test.c
static void testHMAC() {
  static const uint8_t KAT256[] = {
    0x5b,0xdc,0xc1,0x46,0xbf,0x60,0x75,0x4e,
    0x6a,0x04,0x24,0x26,0x08,0x95,0x75,0xc7,
    0x5a,0x00,0x3f,0x08,0x9d,0x27,0x39,0x83,
    0x9d,0xec,0x58,0xb9,0x64,0xec,0x38,0x43
  };
  static const uint8_t KAT1[] = {
    0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,0xd2,0x74,
    0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79
  };
  const unsigned char* digest;
  clHMAC_CTX hmac;

  // HMAC-SHA256
  clHMAC_SHA256_init(&hmac, "Jefe", 4);
  clHMAC_update(&hmac, "what do ya want for nothing?", 28);
  digest = clHMAC_final(&hmac);
  printHex("hmac:", digest, clHMAC_size(&hmac));
  CHECK(clEqual(digest, clHMAC_size(&hmac), KAT256, sizeof KAT256) == 0);

  // HMAC-SHA1
  clHMAC_SHA1_init(&hmac, "Jefe", 4);
  clHMAC_update(&hmac, "what do ya want for nothing?", 28);
  digest = clHMAC_final(&hmac);
  printHex("hmac:", digest, clHMAC_size(&hmac));
  CHECK(clEqual(digest, clHMAC_size(&hmac), KAT1, sizeof KAT1) == 0);
}
// Simple known answer test for HMAC-SHA256 and HMAC-SHA1.
Simple known answer test for HMAC-SHA256 and HMAC-SHA1.
Simple known answer test for HMAC - SHA256 and HMAC - SHA1 .
static void testHMAC() {
  static const uint8_t KAT256[] = {
    0x5b,0xdc,0xc1,0x46,0xbf,0x60,0x75,0x4e,
    0x6a,0x04,0x24,0x26,0x08,0x95,0x75,0xc7,
    0x5a,0x00,0x3f,0x08,0x9d,0x27,0x39,0x83,
    0x9d,0xec,0x58,0xb9,0x64,0xec,0x38,0x43
  };
  static const uint8_t KAT1[] = {
    0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,0xd2,0x74,
    0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79
  };
  const unsigned char* digest;
  clHMAC_CTX hmac;
  clHMAC_SHA256_init(&hmac, "Jefe", 4);
  clHMAC_update(&hmac, "what do ya want for nothing?", 28);
  digest = clHMAC_final(&hmac);
  printHex("hmac:", digest, clHMAC_size(&hmac));
  CHECK(clEqual(digest, clHMAC_size(&hmac), KAT256, sizeof KAT256) == 0);
  clHMAC_SHA1_init(&hmac, "Jefe", 4);
  clHMAC_update(&hmac, "what do ya want for nothing?", 28);
  digest = clHMAC_final(&hmac);
  printHex("hmac:", digest, clHMAC_size(&hmac));
  CHECK(clEqual(digest, clHMAC_size(&hmac), KAT1, sizeof KAT1) == 0);
}
static void testHMAC ( ) { static const uint8_t KAT256 [ ] = { 0x5b , 0xdc , 0xc1 , 0x46 , 0xbf , 0x60 , 0x75 , 0x4e , 0x6a , 0x04 , 0x24 , 0x26 , 0x08 , 0x95 , 0x75 , 0xc7 , 0x5a , 0x00 , 0x3f , 0x08 , 0x9d , 0x27 , 0x39 , 0x83 , 0x9d , 0xec , 0x58 , 0xb9 , 0x64 , 0xec , 0x38 , 0x43 } ; static const uint8_t KAT1 [ ] = { 0xef , 0xfc , 0xdf , 0x6a , 0xe5 , 0xeb , 0x2f , 0xa2 , 0xd2 , 0x74 , 0x16 , 0xd5 , 0xf1 , 0x84 , 0xdf , 0x9c , 0x25 , 0x9a , 0x7c , 0x79 } ; const unsigned char * digest ; clHMAC_CTX hmac ; clHMAC_SHA256_init ( & hmac , " " , 4 ) ; clHMAC_update ( & hmac , " " , 28 ) ; digest = clHMAC_final ( & hmac ) ; printHex ( " " , digest , clHMAC_size ( & hmac ) ) ; CHECK ( clEqual ( digest , clHMAC_size ( & hmac ) , KAT256 , sizeof KAT256 ) == 0 ) ; clHMAC_SHA1_init ( & hmac , " " , 4 ) ; clHMAC_update ( & hmac , " " , 28 ) ; digest = clHMAC_final ( & hmac ) ; printHex ( " " , digest , clHMAC_size ( & hmac ) ) ; CHECK ( clEqual ( digest , clHMAC_size ( & hmac ) , KAT1 , sizeof KAT1 ) == 0 ) ; }
Simple known answer test for HMAC-SHA256 and HMAC-SHA1.
Simple known answer test for HMAC - SHA256 and HMAC - SHA1 .
// HMAC-SHA256 // HMAC-SHA1