5 #include <common/pkcs5_pbkdf2.h>
15 gchar
*expected_output
;
18 /* Test vectors from RFC 6070 */
19 struct td td_rfc6070_1
= { "password", 8,
22 "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6" };
23 struct td td_rfc6070_2
= { "password", 8,
26 "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57" };
27 struct td td_rfc6070_3
= { "password", 8,
30 "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1" };
31 struct td td_rfc6070_4
= { "password", 8,
34 "\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84" };
35 struct td td_rfc6070_5
= { "passwordPASSWORDpassword", 24,
36 "saltSALTsaltSALTsaltSALTsaltSALTsalt", 36,
38 "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38" };
39 struct td td_rfc6070_6
= { "pass\0word", 9,
42 "\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37\xd7\xf0\x34\x25\xe0\xc3" };
44 struct td td_zero_rounds
= { "abc", 3, "abc", 3, 3, 0, -1, "" };
45 struct td td_zero_output_length
= { "abc", 3, "abc", 3, 0, 1, -1, NULL
};
46 struct td td_null_input
= { NULL
, 10, "", 10, 10, 100, -1, "" };
47 struct td td_null_salt
= { "", 10, NULL
, 10, 10, 100, -1, "" };
50 test_pkcs5_pbkdf2(gconstpointer user_data
)
52 struct td
*data
= (struct td
*)user_data
;
53 guchar
*kd
= g_malloc0(data
->length
);
56 if (data
->rounds
> 10000 && !g_test_slow()) {
57 gchar
*msg
= "Time-intensive test, rerun in slow mode to run it.";
63 if (g_test_verbose()) {
64 g_printerr("input '%s' (%ld)\nsalt '%s' (%ld)\nlength %ld\nrounds %d\nexpected_return %d\n",
65 data
->input
, data
->input_length
,
66 data
->salt
, data
->salt_length
,
69 data
->expected_return
);
81 g_assert_cmpint(ret
, ==, data
->expected_return
);
82 g_assert_cmpstr(kd
, ==, data
->expected_output
);
86 test_pkcs5_pbkdf2_null_output_buffer(void)
88 gint ret
= pkcs5_pbkdf2("abc", 3, "abc", 3, NULL
, 10, 1);
90 g_assert_cmpint(ret
, ==, -1);
94 main(int argc
, char *argv
[])
96 g_test_init(&argc
, &argv
, NULL
);
98 g_test_add_data_func("/common/pkcs5_pbkdf2/zero_rounds",
99 &td_zero_rounds
, test_pkcs5_pbkdf2
);
100 g_test_add_data_func("/common/pkcs5_pbkdf2/zero_output_length",
101 &td_zero_output_length
, test_pkcs5_pbkdf2
);
102 g_test_add_data_func("/common/pkcs5_pbkdf2/null_salt",
103 &td_null_salt
, test_pkcs5_pbkdf2
);
104 g_test_add_data_func("/common/pkcs5_pbkdf2/null_input",
105 &td_null_input
, test_pkcs5_pbkdf2
);
106 g_test_add_func("/common/pkcs5_pbkdf2/null_output_buffer",
107 test_pkcs5_pbkdf2_null_output_buffer
);
109 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_1",
110 &td_rfc6070_1
, test_pkcs5_pbkdf2
);
111 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_2",
112 &td_rfc6070_2
, test_pkcs5_pbkdf2
);
113 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_3",
114 &td_rfc6070_3
, test_pkcs5_pbkdf2
);
115 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_4",
116 &td_rfc6070_4
, test_pkcs5_pbkdf2
);
117 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_5",
118 &td_rfc6070_5
, test_pkcs5_pbkdf2
);
119 g_test_add_data_func("/common/pkcs5_pbkdf2/rfc6070_6",
120 &td_rfc6070_6
, test_pkcs5_pbkdf2
);