Update tests and tools

This commit is contained in:
Zhi Guan
2022-03-16 15:12:29 +08:00
parent 2c2425d230
commit ea4cc6585c
52 changed files with 3600 additions and 3216 deletions

View File

@@ -52,7 +52,7 @@
#include <stdlib.h>
#include <gmssl/hex.h>
#include <gmssl/pbkdf2.h>
#include <gmssl/error.h>
struct {
@@ -85,13 +85,15 @@ struct {
20,
"4b007901b765489abead49d926f721d065a429c1",
},
/*
{
"password",
"salt",
16777216,
16777216, // very slow
20,
"eefe3d61cd4da4e4e9945b3d6ba2158c2634e984",
},
*/
{
"passwordPASSWORDpassword",
"saltSALTsaltSALTsaltSALTsaltSALTsalt",
@@ -101,7 +103,7 @@ struct {
},
};
/*
void test(void)
{
HMAC_CTX ctx;
@@ -133,8 +135,9 @@ void test(void)
}
printf("\n");
}
*/
int main(void)
static int test_pbkdf2_genkey(void)
{
int i;
uint8_t key[64];
@@ -144,17 +147,28 @@ int main(void)
for (i = 0; i < sizeof(pbkdf2_hmac_sha1_tests)/sizeof(pbkdf2_hmac_sha1_tests[0]); i++) {
hex_to_bytes(pbkdf2_hmac_sha1_tests[i].dk, strlen(pbkdf2_hmac_sha1_tests[i].dk), buf, &len);
pbkdf2_genkey(DIGEST_sha1(),
if (pbkdf2_genkey(DIGEST_sha1(),
pbkdf2_hmac_sha1_tests[i].pass, strlen(pbkdf2_hmac_sha1_tests[i].pass),
(uint8_t *)pbkdf2_hmac_sha1_tests[i].salt, strlen(pbkdf2_hmac_sha1_tests[i].salt),
pbkdf2_hmac_sha1_tests[i].iter, pbkdf2_hmac_sha1_tests[i].dklen, key);
pbkdf2_hmac_sha1_tests[i].iter, pbkdf2_hmac_sha1_tests[i].dklen, key) != 1) {
error_print();
return -1;
}
if (memcmp(key, buf, pbkdf2_hmac_sha1_tests[i].dklen) != 0) {
printf("%d failed\n", i);
fprintf(stderr, "test_pbkdf2_genkey test %d failed\n", i);
return -1;
} else {
printf("%d ok\n", i);
fprintf(stderr, "test_pbkdf2_genkey test %d ok\n", i);
}
}
return 1;
printf("%s() ok\n", __FUNCTION__);
return 0;
}
int main(int argc, char **argv)
{
int err = 0;
err += test_pbkdf2_genkey();
return err;
}