| 1 |
/* Copyright (C) 2018 [email protected] |
| 2 |
* Copyright (C) 2018 Björn Esser [email protected] |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted. |
| 6 |
* |
| 7 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 8 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 9 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 10 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 11 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 12 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 13 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 14 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 15 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 16 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 17 |
* SUCH DAMAGE. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "crypt-port.h" |
| 21 |
|
| 22 |
#if INCLUDE_gost_yescrypt |
| 23 |
|
| 24 |
#include "alg-gost3411-2012-hmac.h" |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
static void |
| 29 |
dumphex(const void *ptr, size_t size) |
| 30 |
{ |
| 31 |
size_t i; |
| 32 |
|
| 33 |
for (i = 0; i < size; i++) |
| 34 |
printf("%02x", ((const unsigned char *)ptr)[i]); |
| 35 |
printf("\n"); |
| 36 |
} |
| 37 |
|
| 38 |
static int |
| 39 |
test_gost2012_hmac(const char *subject, const char *k, size_t ksize, |
| 40 |
const char *t, size_t tlen, const char *match) |
| 41 |
{ |
| 42 |
uint8_t digest[32]; |
| 43 |
gost_hmac_256_t gostbuf; |
| 44 |
|
| 45 |
gost_hmac256((const uint8_t *)k, ksize, |
| 46 |
(const uint8_t *)t, tlen, digest, &gostbuf); |
| 47 |
|
| 48 |
if (memcmp(digest, match, sizeof(digest))) |
| 49 |
{ |
| 50 |
fprintf(stderr, "ERROR: %s\n", subject); |
| 51 |
printf(" key: "); |
| 52 |
dumphex(k, ksize); |
| 53 |
printf(" t: "); |
| 54 |
dumphex(t, tlen); |
| 55 |
printf(" hmac="); |
| 56 |
dumphex(digest, sizeof(digest)); |
| 57 |
return 1; |
| 58 |
} |
| 59 |
else |
| 60 |
fprintf(stderr, " ok: %s\n", subject); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
int |
| 66 |
main (void) |
| 67 |
{ |
| 68 |
int result = 0; |
| 69 |
|
| 70 |
result |= test_gost2012_hmac( |
| 71 |
"HMAC_GOSTR3411_2012_256 test vector from P 50.1.113-2016", |
| 72 |
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" |
| 73 |
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32, |
| 74 |
"\x01\x26\xbd\xb8\x78\x00\xaf\x21\x43\x41\x45\x65\x63\x78\x01\x00", 16, |
| 75 |
"\xa1\xaa\x5f\x7d\xe4\x02\xd7\xb3\xd3\x23\xf2\x99\x1c\x8d\x45\x34" |
| 76 |
"\x01\x31\x37\x01\x0a\x83\x75\x4f\xd0\xaf\x6d\x7c\xd4\x92\x2e\xd9" |
| 77 |
); |
| 78 |
|
| 79 |
return result; |
| 80 |
} |
| 81 |
|
| 82 |
#else |
| 83 |
|
| 84 |
int |
| 85 |
main (void) |
| 86 |
{ |
| 87 |
return 77; /* UNSUPPORTED */ |
| 88 |
} |
| 89 |
|
| 90 |
#endif /* INCLUDE_gost_yescrypt */ |