mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Run all BLAKE2B256 test vectors (#1185)
This commit is contained in:
parent
0768807935
commit
787b04f752
4 changed files with 63 additions and 1 deletions
|
@ -13,6 +13,7 @@ LIBC_TESTLIB_A = o/$(MODE)/libc/testlib/testlib.a
|
|||
LIBC_TESTLIB_A_CHECKS = $(LIBC_TESTLIB_A).pkg
|
||||
|
||||
LIBC_TESTLIB_A_ASSETS = \
|
||||
libc/testlib/blake2b256_tests.txt \
|
||||
libc/testlib/blocktronics.txt \
|
||||
libc/testlib/viewables.txt \
|
||||
libc/testlib/hyperion.txt \
|
||||
|
@ -32,6 +33,7 @@ LIBC_TESTLIB_A_HDRS = \
|
|||
|
||||
LIBC_TESTLIB_A_SRCS_S = \
|
||||
libc/testlib/bench.S \
|
||||
libc/testlib/blake2b256_tests.S \
|
||||
libc/testlib/blocktronics.S \
|
||||
libc/testlib/fixture.S \
|
||||
libc/testlib/hyperion.S \
|
||||
|
@ -124,6 +126,7 @@ $(LIBC_TESTLIB_A).pkg: \
|
|||
$(LIBC_TESTLIB_A_OBJS) \
|
||||
$(foreach x,$(LIBC_TESTLIB_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/libc/testlib/blake2b256_tests.o: libc/testlib/blake2b256_tests.txt
|
||||
o/$(MODE)/libc/testlib/blocktronics.o: libc/testlib/blocktronics.txt
|
||||
o/$(MODE)/libc/testlib/viewables.o: libc/testlib/viewables.txt
|
||||
o/$(MODE)/libc/testlib/hyperion.o: libc/testlib/hyperion.txt
|
||||
|
@ -132,6 +135,8 @@ o/$(MODE)/libc/testlib/moby.o: libc/testlib/moby.txt
|
|||
# these assembly files are safe to build on aarch64
|
||||
o/$(MODE)/libc/testlib/bench.o: libc/testlib/bench.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/testlib/blake2b256_tests.o: libc/testlib/blake2b256_tests.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/testlib/blocktronics.o: libc/testlib/blocktronics.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/testlib/fixture.o: libc/testlib/fixture.S
|
||||
|
|
33
libc/testlib/blake2b256_tests.S
Normal file
33
libc/testlib/blake2b256_tests.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.rodata
|
||||
|
||||
// Blake2B256 test vectors.
|
||||
.underrun
|
||||
kBlake2b256Tests:
|
||||
0: .incbin "libc/testlib/blake2b256_tests.txt"
|
||||
1: .byte 0
|
||||
.endobj kBlake2b256Tests,globl
|
||||
.overrun
|
||||
|
||||
.balign 8
|
||||
kBlake2b256TestsSize:
|
||||
.quad 1b-0b
|
||||
.endobj kBlake2b256TestsSize,globl
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/blake2.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -26,6 +27,9 @@
|
|||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
__static_yoink("libc/testlib/blake2b256_tests.txt");
|
||||
__static_yoink("zipos");
|
||||
|
||||
uint8_t *EZBLAKE2B256(const char *s, size_t n) {
|
||||
static uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
|
||||
BLAKE2B256(s, n, digest);
|
||||
|
@ -63,7 +67,27 @@ TEST(BLAKE2B256Test, ABC) {
|
|||
EXPECT_BINEQ(
|
||||
"03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314",
|
||||
HEXBLAKE2B256("00"));
|
||||
/* TODO(jart): do rest */
|
||||
}
|
||||
|
||||
TEST(BLAKE2B256Test, vectors) {
|
||||
char *line = NULL;
|
||||
size_t cap = 0;
|
||||
ssize_t n;
|
||||
FILE *f = fopen("/zip/libc/testlib/blake2b256_tests.txt", "r");
|
||||
uint8_t *digest = 0;
|
||||
while ((n = getline(&line, &cap, f)) != -1) {
|
||||
if (n < 2 || line[0] == '#')
|
||||
continue;
|
||||
line[n - 1] = 0;
|
||||
if (!strncmp(line, "IN:", 3)) {
|
||||
digest = HEXBLAKE2B256(line + 4);
|
||||
}
|
||||
if (!strncmp(line, "HASH: ", 6)) {
|
||||
EXPECT_BINEQ(line + 6, digest);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
free(line);
|
||||
}
|
||||
|
||||
BENCH(blake2, bench) {
|
||||
|
|
Loading…
Reference in a new issue