commit 512a72e918c38f2d47279b70c9f458a9b8c9b809
parent 01b8aaa3c137a017962af0436c7ada432583cbc8
Author: Sebastian <sebastian@sebsite.pw>
Date: Mon, 6 Nov 2023 23:27:28 -0500
crypto: use test::skip
Implements: https://todo.sr.ht/~sircmpwn/hare/898
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
4 files changed, 91 insertions(+), 56 deletions(-)
diff --git a/crypto/aes/+test/ni_test+x86_64.ha b/crypto/aes/+test/ni_test+x86_64.ha
@@ -3,6 +3,7 @@
use bytes;
use crypto::cipher;
+use test;
const zero_rk: [EXPKEYLEN256]u8 = [0...];
@@ -14,7 +15,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// taken from fips-197.pdf Section A.1
@test fn ni_enc_key_expand_128() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: [16]u8 = [
@@ -60,7 +61,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// taken from fips-197.pdf Section A.2
@test fn ni_enc_key_expand_192() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: [24]u8 = [
@@ -109,7 +110,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// taken from fips-197.pdf Section A.3
@test fn ni_enc_key_expand_256() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: [32]u8 = [
@@ -161,7 +162,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
@test fn ni_test_encrypt_128() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
let key: [_]u8 = [
@@ -190,7 +191,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
@test fn ni_test_decrypt_128() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: [_]u8 = [
@@ -219,7 +220,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// fips-197.pdf Appendix C.1
@test fn ni_test_example_vector1() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: []u8 = [
@@ -252,7 +253,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// fips-197.pdf Appendix C.2
@test fn ni_test_example_vector2() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: []u8 = [
@@ -286,7 +287,7 @@ const zero_rk: [EXPKEYLEN256]u8 = [0...];
// fips-197.pdf Appendix C.3
@test fn ni_test_example_vector3() void = {
if (!x86ni_available()) {
- return;
+ test::skip("Native x86 AES interface isn't available");
};
const key: []u8 = [
diff --git a/crypto/argon2/+test.ha b/crypto/argon2/+test.ha
@@ -3,7 +3,9 @@
use bytes;
use encoding::hex;
+use os;
use strings;
+use test;
@test fn mode_d_one_pass() void = {
let pass: [32]u8 = [1...];
@@ -142,17 +144,6 @@ type tcase = struct {
const salt = strings::toutf8("abcdefgh");
const tests: [_]tcase = [
- // XXX disabled for now because it's slow
- // tcase {
- // c = low_mem_conf,
- // m = mode::ID,
- // h = "8974537c53677aae532b319af700bb4232a0d74eee7d57296b2a3f8303a6bafe",
- // },
- // tcase {
- // c = default_conf,
- // m = mode::ID,
- // h = "3b282cbf435b0e022f7041549583ddc802e519109f1da8f12d2054910913d660",
- // },
tcase {
c = conf {
passes = 1,
@@ -244,3 +235,35 @@ type tcase = struct {
};
};
+@test fn samples_slow() void = {
+ if (os::tryenv("STDLIB_SLOW_TESTS", "") == "") {
+ test::skip("Enable with STDLIB_SLOW_TESTS=1");
+ };
+
+ const pass = strings::toutf8("trustno1");
+ const salt = strings::toutf8("abcdefgh");
+
+ const tests: [_]tcase = [
+ tcase {
+ c = low_mem_conf,
+ m = mode::ID,
+ h = "8974537c53677aae532b319af700bb4232a0d74eee7d57296b2a3f8303a6bafe",
+ },
+ tcase {
+ c = default_conf,
+ m = mode::ID,
+ h = "3b282cbf435b0e022f7041549583ddc802e519109f1da8f12d2054910913d660",
+ },
+ ];
+
+ for (let i = 0z; i < len(tests); i += 1) {
+ const t = tests[i];
+ const expected = hex::decodestr(t.h)!;
+ defer free(expected);
+ let dest: []u8 = alloc([0...], len(expected));
+ defer free(dest);
+
+ argon2(dest, pass, salt, &t.c, t.m)!;
+ assert(bytes::equal(expected, dest));
+ };
+};
diff --git a/crypto/sha1/+test.ha b/crypto/sha1/+test.ha
@@ -4,7 +4,9 @@
use encoding::hex;
use fmt;
use hash;
+use os;
use strings;
+use test;
@test fn sha1() void = {
let sha = sha1();
@@ -40,24 +42,26 @@ use strings;
};
};
-// Uncomment this test to run the 1GB vector - takes a while to run, so it's
-// left disabled.
-//@test fn sha1_1gb() void = {
-// const input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno";
-// const expected = "7789f0c9ef7bfc40d93311143dfbe69e2017f592";
-//
-// let sha = sha1();
-//
-// for (let i = 0z; i < 16777216; i += 1)
-// hash::write(&sha, strings::toutf8(input));
-//
-// let sum: [SZ]u8 = [0...];
-// hash::sum(&sha, sum);
-//
-// let shahex = hex::encodestr(sum);
-//
-// if (shahex != expected) {
-// fmt::errorfln("1GB vector: {} != {}", shahex, expected)!;
-// abort();
-// };
-//};
+@test fn sha1_1gb() void = {
+ if (os::tryenv("STDLIB_SLOW_TESTS", "") == "") {
+ test::skip("Enable with STDLIB_SLOW_TESTS=1");
+ };
+
+ const input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno";
+ const expected = "7789f0c9ef7bfc40d93311143dfbe69e2017f592";
+
+ let sha = sha1();
+
+ for (let i = 0z; i < 16777216; i += 1)
+ hash::write(&sha, strings::toutf8(input));
+
+ let sum: [SZ]u8 = [0...];
+ hash::sum(&sha, sum);
+
+ let shahex = hex::encodestr(sum);
+
+ if (shahex != expected) {
+ fmt::errorfln("1GB vector: {} != {}", shahex, expected)!;
+ abort();
+ };
+};
diff --git a/crypto/sha256/+test.ha b/crypto/sha256/+test.ha
@@ -4,7 +4,9 @@
use encoding::hex;
use fmt;
use hash;
+use os;
use strings;
+use test;
@test fn sha256() void = {
let sha = sha256();
@@ -35,21 +37,26 @@ use strings;
abort();
};
};
+};
+
+@test fn sha256_1gb() void = {
+ if (os::tryenv("STDLIB_SLOW_TESTS", "") == "") {
+ test::skip("Enable with STDLIB_SLOW_TESTS=1");
+ };
- // Uncomment this to run the 1G test vector (I promise it works):
-
- //const input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno";
- //const expected = "50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e";
- //hash::reset(&sha);
- //for (let i = 0z; i < 16777216; i += 1) {
- // hash::write(&sha, strings::toutf8(input));
- //};
- //let sum: [SZ]u8 = [0...];
- //hash::sum(&sha, sum);
-
- //let shahex = hex::encodestr(sum);
- //if (shahex != expected) {
- // fmt::errorfln("Biggo vector: {} != {}", shahex, expected)!;
- // abort();
- //};
+ let sha = sha256();
+ const input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno";
+ const expected = "50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e";
+ hash::reset(&sha);
+ for (let i = 0z; i < 16777216; i += 1) {
+ hash::write(&sha, strings::toutf8(input));
+ };
+ let sum: [SZ]u8 = [0...];
+ hash::sum(&sha, sum);
+
+ let shahex = hex::encodestr(sum);
+ if (shahex != expected) {
+ fmt::errorfln("Biggo vector: {} != {}", shahex, expected)!;
+ abort();
+ };
};