Make improvements

- Document redbean's argon2 module
- Fix regressions in cthreads library
- Make testlib work better with threads
- Give the cthreads library lots of love
- Remove some of the stdio assembly code
- Implement getloadavg() across platforms
- Code size optimizations for errnos, etc.
- Only check for signals in main thread on Windows
- Make errnos for dup2 / dup3 consistent with posix

This change also fixes a bug in the argon2 module, where the NUL
terminator was being included in the hash encoded ascii string. This
shouldn't require any database migrations to folks who found this module
and productionized it, since the argon2 library treats it as a c string.
This commit is contained in:
Justine Tunney 2022-05-27 13:25:46 -07:00
parent cb67223051
commit de5de19004
234 changed files with 1728 additions and 1993 deletions

View file

@ -16,12 +16,39 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "net/https/https.h"
#include "third_party/argon2/argon2.h"
TEST(argon2, test) {
TEST(argon2, testArgon2ReadmeExample) {
uint8_t hash[24];
uint8_t salt[8] = {'s', 'o', 'm', 'e', 's', 'a', 'l', 't'};
uint8_t pass[8] = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
uint32_t parallelism = 4;
uint32_t memorycost = 1 << 16;
uint32_t iterations = 2;
argon2i_hash_raw(iterations, memorycost, parallelism, pass, sizeof(pass),
salt, sizeof(salt), hash, sizeof(hash));
ASSERT_BINEQ("45d7ac72e76f242b20b77b9bf9bf9d5915894e669a24e6c6", hash);
}
TEST(argon2, testArgon2ReadmeExampleEncoded) {
char hash[128];
uint8_t salt[8] = {'s', 'o', 'm', 'e', 's', 'a', 'l', 't'};
uint8_t pass[8] = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
uint32_t parallelism = 4;
uint32_t memorycost = 1 << 16;
uint32_t iterations = 2;
argon2i_hash_encoded(iterations, memorycost, parallelism, pass, sizeof(pass),
salt, sizeof(salt), 24, hash, sizeof(hash));
ASSERT_STREQ("$argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+"
"dWRWJTmaaJObG",
hash);
}
TEST(argon2i, testOnlineGeneratorExample) {
/* consistent with https://argon2.online/ */
uint8_t hash[32];
uint8_t salt[8] = {'s', 'a', 'l', 't', 's', 'a', 'l', 't'};
@ -35,17 +62,31 @@ TEST(argon2, test) {
"b5d0818d1c0c05684e68aef02de8b4ed14bfe6c60800e0aa36a5c18f846a297b", hash);
}
void specimen(void) {
TEST(argon2id, testOnlineGeneratorExample) {
/* consistent with https://argon2.online/ */
uint8_t hash[32];
uint8_t salt[8] = {'s', 'a', 'l', 't', 's', 'a', 'l', 't'};
uint8_t pass[8] = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
uint32_t parallelism = 1;
uint32_t memorycost = 65536 / 4;
uint32_t memorycost = 65536;
uint32_t iterations = 2;
argon2id_hash_raw(iterations, memorycost, parallelism, pass, sizeof(pass),
salt, sizeof(salt), hash, sizeof(hash));
ASSERT_BINEQ(
"360da2d90fd9d6f52923f293d142131a13909b780698daf09e6756422ebd1045", hash);
}
void BenchmarkArgon2(void) {
uint8_t hash[24];
uint8_t salt[8] = {'s', 'o', 'm', 'e', 's', 'a', 'l', 't'};
uint8_t pass[8] = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
uint32_t parallelism = 4;
uint32_t memorycost = (1 << 16) / 8;
uint32_t iterations = 2;
argon2i_hash_raw(iterations, memorycost, parallelism, pass, sizeof(pass),
salt, sizeof(salt), hash, sizeof(hash));
}
BENCH(argon2, bench) {
EZBENCH2("argon2", donothing, specimen());
EZBENCH2("argon2", donothing, BenchmarkArgon2());
}