LCOV - code coverage report
Current view: top level - src/tests - siphash.c (source / functions) Hit Total Coverage
Test: passgen-test.info Lines: 18 18 100.0 %
Date: 2024-05-03 06:05:14 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "passgen/util/siphash.h"
       2             : #include "tests.h"
       3             : 
       4           1 : test_result test_siphash64(void) {
       5             :     // test siphash64 (8 byte output)
       6           1 :     const char *key = "zppyfssftiwghlcy";
       7             :     struct {
       8             :         const char *input;
       9             :         uint8_t output[8];
      10           1 :     } testcases[] = {
      11             :         {.input = "input",
      12             :          .output = {0x6c, 0xef, 0x54, 0xb9, 0xcb, 0x8a, 0xe9, 0x43}},
      13             :         {.input = "test",
      14             :          .output = {0xf0, 0x32, 0x3b, 0x4f, 0x2d, 0x61, 0x5d, 0x99}},
      15             :         {.input = "passgen",
      16             :          .output = {0x45, 0x10, 0x48, 0x0e, 0x04, 0x58, 0xc0, 0xee}},
      17             :         {.input = "pattern",
      18             :          .output = {0x83, 0x99, 0xf6, 0xc6, 0x57, 0x7e, 0xdb, 0x7e}},
      19             :         {.input = "hash",
      20             :          .output = {0xbf, 0x27, 0xf4, 0x7b, 0xf8, 0xb4, 0xef, 0xbe}},
      21             :         {.input = "asam",
      22             :          .output = {0x9c, 0x7d, 0xae, 0x86, 0xdd, 0x97, 0x94, 0xe6}},
      23             :         {.input = "bsam",
      24             :          .output = {0xce, 0x87, 0x56, 0x58, 0xbb, 0x3c, 0x80, 0xe1}},
      25             :         {.input = "longjohn",
      26             :          .output = {0xbc, 0xfd, 0x5a, 0xf7, 0x43, 0xaf, 0x4a, 0x55}},
      27             :         {NULL}};
      28             : 
      29           9 :     for(size_t i = 0; testcases[i].input; i++) {
      30             :         uint8_t output[8];
      31           8 :         const char *input = testcases[i].input;
      32           8 :         assert_eq(
      33             :             0,
      34             :             passgen_siphash(input, strlen(input), key, output, sizeof(output)));
      35          72 :         for(size_t b = 0; b < sizeof(output); b++) {
      36          64 :             assert_eq(output[b], testcases[i].output[b]);
      37             :         }
      38             :     }
      39             : 
      40           1 :     return test_ok;
      41             : }
      42             : 
      43           1 : test_result test_siphash128(void) {
      44             :     // test siphash128 (16 byte output)
      45           1 :     const char *key = "zppyfssftiwghlcy";
      46             :     struct {
      47             :         const char *input;
      48             :         uint8_t output[16];
      49           1 :     } testcases[] = {
      50             :         {.input = "input",
      51             :          .output =
      52             :              {0xaa,
      53             :               0x06,
      54             :               0xb4,
      55             :               0x1b,
      56             :               0x1e,
      57             :               0x00,
      58             :               0xaa,
      59             :               0x80,
      60             :               0x07,
      61             :               0xdc,
      62             :               0xd5,
      63             :               0x7b,
      64             :               0x82,
      65             :               0x33,
      66             :               0x79,
      67             :               0x1a}},
      68             :         {.input = "test",
      69             :          .output =
      70             :              {0x9c,
      71             :               0x04,
      72             :               0x7e,
      73             :               0x22,
      74             :               0x1c,
      75             :               0x46,
      76             :               0x69,
      77             :               0xd6,
      78             :               0xd7,
      79             :               0xe1,
      80             :               0x73,
      81             :               0xa8,
      82             :               0x66,
      83             :               0xeb,
      84             :               0x93,
      85             :               0x2b}},
      86             :         {.input = "passgen",
      87             :          .output =
      88             :              {0xbf,
      89             :               0x62,
      90             :               0x3a,
      91             :               0xac,
      92             :               0x34,
      93             :               0x5a,
      94             :               0xd7,
      95             :               0x74,
      96             :               0xab,
      97             :               0x83,
      98             :               0xac,
      99             :               0xad,
     100             :               0x04,
     101             :               0xd4,
     102             :               0xa0,
     103             :               0xed}},
     104             :         {.input = "pattern",
     105             :          .output =
     106             :              {0x26,
     107             :               0xe5,
     108             :               0x55,
     109             :               0xd0,
     110             :               0xd1,
     111             :               0x90,
     112             :               0xbc,
     113             :               0x9e,
     114             :               0x8c,
     115             :               0x34,
     116             :               0x7f,
     117             :               0xe0,
     118             :               0x87,
     119             :               0xd6,
     120             :               0x87,
     121             :               0xdc}},
     122             :         {.input = "hash",
     123             :          .output =
     124             :              {0x34,
     125             :               0x70,
     126             :               0x1f,
     127             :               0x51,
     128             :               0xac,
     129             :               0xce,
     130             :               0x41,
     131             :               0x65,
     132             :               0x19,
     133             :               0x0f,
     134             :               0x1c,
     135             :               0x72,
     136             :               0x1b,
     137             :               0x84,
     138             :               0x45,
     139             :               0xd8}},
     140             :         {.input = "asam",
     141             :          .output =
     142             :              {0xd6,
     143             :               0x19,
     144             :               0x0d,
     145             :               0xfa,
     146             :               0xdc,
     147             :               0xfc,
     148             :               0xd2,
     149             :               0x5a,
     150             :               0xbf,
     151             :               0xa8,
     152             :               0xdc,
     153             :               0x78,
     154             :               0x41,
     155             :               0xb4,
     156             :               0xa9,
     157             :               0xd0}},
     158             :         {.input = "bsam",
     159             :          .output =
     160             :              {0xe3,
     161             :               0x70,
     162             :               0x02,
     163             :               0x94,
     164             :               0x4b,
     165             :               0xc4,
     166             :               0xeb,
     167             :               0xec,
     168             :               0x92,
     169             :               0x3e,
     170             :               0xee,
     171             :               0xa2,
     172             :               0xfb,
     173             :               0x18,
     174             :               0x5d,
     175             :               0xef}},
     176             :         {.input = "longjohn",
     177             :          .output =
     178             :              {0xdf,
     179             :               0xa7,
     180             :               0x8a,
     181             :               0x97,
     182             :               0xf0,
     183             :               0xdf,
     184             :               0x0e,
     185             :               0x62,
     186             :               0xc5,
     187             :               0x1b,
     188             :               0x8b,
     189             :               0x6b,
     190             :               0x79,
     191             :               0xda,
     192             :               0x3f,
     193             :               0xde}},
     194             :         {NULL}};
     195             : 
     196           9 :     for(size_t i = 0; testcases[i].input; i++) {
     197             :         uint8_t output[16];
     198           8 :         const char *input = testcases[i].input;
     199           8 :         assert_eq(
     200             :             0,
     201             :             passgen_siphash(input, strlen(input), key, output, sizeof(output)));
     202         136 :         for(size_t b = 0; b < sizeof(output); b++) {
     203         128 :             assert_eq(output[b], testcases[i].output[b]);
     204             :         }
     205             :     }
     206             : 
     207           1 :     return test_ok;
     208             : }

Generated by: LCOV version 1.14