diff options
author | Pauli <paul.dale@oracle.com> | 2017-06-12 10:01:17 +1000 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-06-16 16:15:31 -0400 |
commit | 3791646202bb4da21992b0aecae253d394507a9e (patch) | |
tree | cc1f33ab05144ec2442df45366fac1175fcaca16 /test/srptest.c | |
parent | 5511101ad86fdd5bc3ad4f27143e93ae14737bfe (diff) | |
download | openssl-new-3791646202bb4da21992b0aecae253d394507a9e.tar.gz |
Add output routines to allow consistent formatting of memory, strings
and bignums. These have been refactored into their own file, along with
their error displays. The formatting follows the output format used
on error, except that bignums of sixty four bits or less are displayed
in a more compact one line form.
Added a TEST_note function for producing output without file and line
information.
Update the three tests that call BN_print so they use the new test
infrastructure instead.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3655)
Diffstat (limited to 'test/srptest.c')
-rw-r--r-- | test/srptest.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/test/srptest.c b/test/srptest.c index 3e3b589926..ed5bf611a6 100644 --- a/test/srptest.c +++ b/test/srptest.c @@ -18,22 +18,6 @@ # include <openssl/rand.h> # include <openssl/err.h> -static void showbn(const char *name, const BIGNUM *bn) -{ - BIO *b; - const char *text; - - if (!TEST_ptr(b = BIO_new(BIO_s_mem()))) - return; - BIO_write(b, name, strlen(name)); - BIO_write(b, " = ", 3); - BN_print(b, bn); - BIO_write(b, "\0", 1); - BIO_get_mem_data(b, &text); - TEST_info("%s", text); - BIO_free(b); -} - # define RANDOM_SIZE 32 /* use 256 bits on each side */ static int run_srp(const char *username, const char *client_pass, @@ -62,21 +46,21 @@ static int run_srp(const char *username, const char *client_pass, &s, &v, GN->N, GN->g))) goto end; - showbn("N", GN->N); - showbn("g", GN->g); - showbn("Salt", s); - showbn("Verifier", v); + test_output_bignum("N", GN->N); + test_output_bignum("g", GN->g); + test_output_bignum("Salt", s); + test_output_bignum("Verifier", v); /* Server random */ RAND_bytes(rand_tmp, sizeof(rand_tmp)); b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); if (!TEST_BN_ne_zero(b)) goto end; - showbn("b", b); + test_output_bignum("b", b); /* Server's first message */ Bpub = SRP_Calc_B(b, GN->N, GN->g, v); - showbn("B", Bpub); + test_output_bignum("B", Bpub); if (!TEST_true(SRP_Verify_B_mod_N(Bpub, GN->N))) goto end; @@ -86,11 +70,11 @@ static int run_srp(const char *username, const char *client_pass, a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); if (!TEST_BN_ne_zero(a)) goto end; - showbn("a", a); + test_output_bignum("a", a); /* Client's response */ Apub = SRP_Calc_A(a, GN->N, GN->g); - showbn("A", Apub); + test_output_bignum("A", Apub); if (!TEST_true(SRP_Verify_A_mod_N(Apub, GN->N))) goto end; @@ -101,11 +85,11 @@ static int run_srp(const char *username, const char *client_pass, /* Client's key */ x = SRP_Calc_x(s, username, client_pass); Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u); - showbn("Client's key", Kclient); + test_output_bignum("Client's key", Kclient); /* Server's key */ Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N); - showbn("Server's key", Kserver); + test_output_bignum("Server's key", Kserver); if (!TEST_BN_eq(Kclient, Kserver)) goto end; @@ -164,9 +148,10 @@ static int run_srp_kat(void) BN_hex2bn(&s, "BEB25379D1A8581EB5A727673A2441EE"); /* Set up server's password entry */ if (!TEST_true(SRP_create_verifier_BN("alice", "password123", &s, &v, GN->N, - GN->g))) + GN->g))) goto err; + TEST_info("checking v"); if (!TEST_true(check_bn("v", v, "7E273DE8696FFC4F4E337D05B4B375BEB0DDE1569E8FA00A9886D812" "9BADA1F1822223CA1A605B530E379BA4729FDC59F105B4787E5186F5" @@ -174,6 +159,7 @@ static int run_srp_kat(void) "EA53D15C1AFF87B2B9DA6E04E058AD51CC72BFC9033B564E26480D78" "E955A5E29E7AB245DB2BE315E2099AFB"))) goto err; + TEST_note(" okay"); /* Server random */ BN_hex2bn(&b, "E487CB59D31AC550471E81F00F6928E01DDA08E974A004F49E61F5D1" @@ -184,6 +170,7 @@ static int run_srp_kat(void) if (!TEST_true(SRP_Verify_B_mod_N(Bpub, GN->N))) goto err; + TEST_info("checking B"); if (!TEST_true(check_bn("B", Bpub, "BD0C61512C692C0CB6D041FA01BB152D4916A1E77AF46AE105393011" "BAF38964DC46A0670DD125B95A981652236F99D9B681CBF87837EC99" @@ -191,6 +178,7 @@ static int run_srp_kat(void) "37089E6F9C6059F388838E7A00030B331EB76840910440B1B27AAEAE" "EB4012B7D7665238A8E3FB004B117B58"))) goto err; + TEST_note(" okay"); /* Client random */ BN_hex2bn(&a, "60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DD" @@ -201,6 +189,7 @@ static int run_srp_kat(void) if (!TEST_true(SRP_Verify_A_mod_N(Apub, GN->N))) goto err; + TEST_info("checking A"); if (!TEST_true(check_bn("A", Apub, "61D5E490F6F1B79547B0704C436F523DD0E560F0C64115BB72557EC4" "4352E8903211C04692272D8B2D1A5358A2CF1B6E0BFCF99F921530EC" @@ -208,6 +197,7 @@ static int run_srp_kat(void) "BE087EF06530E69F66615261EEF54073CA11CF5858F0EDFDFE15EFEA" "B349EF5D76988A3672FAC47B0769447B"))) goto err; + TEST_note(" okay"); /* Both sides calculate u */ u = SRP_Calc_u(Apub, Bpub, GN->N); @@ -219,6 +209,7 @@ static int run_srp_kat(void) /* Client's key */ x = SRP_Calc_x(s, "alice", "password123"); Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u); + TEST_info("checking client's key"); if (!TEST_true(check_bn("Client's key", Kclient, "B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D" "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C" @@ -226,9 +217,11 @@ static int run_srp_kat(void) "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D" "C346D7E474B29EDE8A469FFECA686E5A"))) goto err; + TEST_note(" okay"); /* Server's key */ Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N); + TEST_info("checking server's key"); if (!TEST_true(check_bn("Server's key", Kserver, "B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D" "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C" @@ -236,6 +229,7 @@ static int run_srp_kat(void) "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D" "C346D7E474B29EDE8A469FFECA686E5A"))) goto err; + TEST_note(" okay"); ret = 1; @@ -257,10 +251,12 @@ err: static int run_srp_tests(void) { /* "Negative" test, expect a mismatch */ + TEST_info("run_srp: expecting a mismatch"); if (!TEST_false(run_srp("alice", "password1", "password2"))) return 0; /* "Positive" test, should pass */ + TEST_info("run_srp: expecting a match"); if (!TEST_true(run_srp("alice", "password", "password"))) return 0; |