diff options
| author | tb <> | 2023-07-28 13:05:59 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-28 13:05:59 +0000 |
| commit | 9f0716d2dac49cad446d297eeba594aff1b6c2a9 (patch) | |
| tree | 56042034f6cedd22a66342e1344c174289b9a4bb /src | |
| parent | eb0ba672767b5f9dde96e6a410c32a569046382d (diff) | |
| download | openbsd-9f0716d2dac49cad446d297eeba594aff1b6c2a9.tar.gz openbsd-9f0716d2dac49cad446d297eeba594aff1b6c2a9.tar.bz2 openbsd-9f0716d2dac49cad446d297eeba594aff1b6c2a9.zip | |
dhtest: simplify printing and make the output slightly less ugly
CID 463174
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/dh/dhtest.c | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/src/regress/lib/libcrypto/dh/dhtest.c b/src/regress/lib/libcrypto/dh/dhtest.c index ee06259dce..7ddd118124 100644 --- a/src/regress/lib/libcrypto/dh/dhtest.c +++ b/src/regress/lib/libcrypto/dh/dhtest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dhtest.c,v 1.7 2022/01/12 08:58:12 tb Exp $ */ | 1 | /* $OpenBSD: dhtest.c,v 1.8 2023/07/28 13:05:59 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -87,8 +87,8 @@ cb(int p, int n, BN_GENCB *arg) | |||
| 87 | c = '*'; | 87 | c = '*'; |
| 88 | if (p == 3) | 88 | if (p == 3) |
| 89 | c = '\n'; | 89 | c = '\n'; |
| 90 | BIO_write(BN_GENCB_get_arg(arg), &c, 1); | 90 | printf("%c", c); |
| 91 | (void)BIO_flush(BN_GENCB_get_arg(arg)); | 91 | fflush(stdout); |
| 92 | return 1; | 92 | return 1; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| @@ -96,21 +96,15 @@ int | |||
| 96 | main(int argc, char *argv[]) | 96 | main(int argc, char *argv[]) |
| 97 | { | 97 | { |
| 98 | BN_GENCB *_cb; | 98 | BN_GENCB *_cb; |
| 99 | DH *a; | 99 | DH *a = NULL; |
| 100 | char buf[12]; | 100 | unsigned char *abuf = NULL; |
| 101 | unsigned char *abuf=NULL; | ||
| 102 | int i, alen, aout; | 101 | int i, alen, aout; |
| 103 | BIO *out; | ||
| 104 | int ret = 1; | 102 | int ret = 1; |
| 105 | 103 | ||
| 106 | if ((out = BIO_new(BIO_s_file())) == NULL) | ||
| 107 | err(1, "BIO_new"); | ||
| 108 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | ||
| 109 | |||
| 110 | if ((_cb = BN_GENCB_new()) == NULL) | 104 | if ((_cb = BN_GENCB_new()) == NULL) |
| 111 | err(1, "BN_GENCB_new"); | 105 | err(1, "BN_GENCB_new"); |
| 112 | 106 | ||
| 113 | BN_GENCB_set(_cb, &cb, out); | 107 | BN_GENCB_set(_cb, &cb, NULL); |
| 114 | if ((a = DH_new()) == NULL) | 108 | if ((a = DH_new()) == NULL) |
| 115 | goto err; | 109 | goto err; |
| 116 | 110 | ||
| @@ -120,39 +114,42 @@ main(int argc, char *argv[]) | |||
| 120 | if (!DH_check(a, &i)) | 114 | if (!DH_check(a, &i)) |
| 121 | goto err; | 115 | goto err; |
| 122 | if (i & DH_CHECK_P_NOT_PRIME) | 116 | if (i & DH_CHECK_P_NOT_PRIME) |
| 123 | BIO_puts(out, "p value is not prime\n"); | 117 | puts("p value is not prime\n"); |
| 124 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) | 118 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) |
| 125 | BIO_puts(out, "p value is not a safe prime\n"); | 119 | puts("p value is not a safe prime\n"); |
| 126 | if (i & DH_UNABLE_TO_CHECK_GENERATOR) | 120 | if (i & DH_UNABLE_TO_CHECK_GENERATOR) |
| 127 | BIO_puts(out, "unable to check the generator value\n"); | 121 | puts("unable to check the generator value\n"); |
| 128 | if (i & DH_NOT_SUITABLE_GENERATOR) | 122 | if (i & DH_NOT_SUITABLE_GENERATOR) |
| 129 | BIO_puts(out, "the g value is not a generator\n"); | 123 | puts("the g value is not a generator\n"); |
| 130 | 124 | ||
| 131 | BIO_puts(out, "\np ="); | 125 | printf("\np = "); |
| 132 | BN_print(out, DH_get0_p(a)); | 126 | if (!BN_print_fp(stdout, DH_get0_p(a))) |
| 133 | BIO_puts(out, "\ng ="); | 127 | goto err; |
| 134 | BN_print(out, DH_get0_g(a)); | 128 | printf("\ng = "); |
| 135 | BIO_puts(out, "\n"); | 129 | if (!BN_print_fp(stdout, DH_get0_g(a))) |
| 130 | goto err; | ||
| 131 | printf("\n"); | ||
| 136 | 132 | ||
| 137 | if (!DH_generate_key(a)) | 133 | if (!DH_generate_key(a)) |
| 138 | goto err; | 134 | goto err; |
| 139 | BIO_puts(out, "pri 1="); | 135 | printf("pri1 = "); |
| 140 | BN_print(out, DH_get0_priv_key(a)); | 136 | if (!BN_print_fp(stdout, DH_get0_priv_key(a))) |
| 141 | BIO_puts(out, "\npub 1="); | 137 | goto err; |
| 142 | BN_print(out, DH_get0_pub_key(a)); | 138 | printf("\npub1 = "); |
| 143 | BIO_puts(out, "\n"); | 139 | if (!BN_print_fp(stdout, DH_get0_pub_key(a))) |
| 140 | goto err; | ||
| 141 | printf("\n"); | ||
| 144 | 142 | ||
| 145 | alen = DH_size(a); | 143 | alen = DH_size(a); |
| 146 | if ((abuf = malloc(alen)) == NULL) | 144 | if ((abuf = malloc(alen)) == NULL) |
| 147 | err(1, "malloc"); | 145 | err(1, "malloc"); |
| 148 | aout = DH_compute_key(abuf, DH_get0_pub_key(a), a); | 146 | aout = DH_compute_key(abuf, DH_get0_pub_key(a), a); |
| 149 | 147 | ||
| 150 | BIO_puts(out, "key1 ="); | 148 | printf("key1 = "); |
| 151 | for (i=0; i<aout; i++) { | 149 | for (i = 0; i < aout; i++) { |
| 152 | snprintf(buf, sizeof buf, "%02X", abuf[i]); | 150 | printf("%02X", abuf[i]); |
| 153 | BIO_puts(out, buf); | ||
| 154 | } | 151 | } |
| 155 | BIO_puts(out, "\n"); | 152 | printf("\n"); |
| 156 | 153 | ||
| 157 | if (aout < 4) { | 154 | if (aout < 4) { |
| 158 | fprintf(stderr, "Error in DH routines\n"); | 155 | fprintf(stderr, "Error in DH routines\n"); |
| @@ -164,9 +161,7 @@ err: | |||
| 164 | ERR_print_errors_fp(stderr); | 161 | ERR_print_errors_fp(stderr); |
| 165 | 162 | ||
| 166 | free(abuf); | 163 | free(abuf); |
| 167 | if (a != NULL) | 164 | DH_free(a); |
| 168 | DH_free(a); | ||
| 169 | BIO_free(out); | ||
| 170 | BN_GENCB_free(_cb); | 165 | BN_GENCB_free(_cb); |
| 171 | 166 | ||
| 172 | return (ret); | 167 | return (ret); |
