diff options
-rw-r--r-- | src/regress/lib/libcrypto/evp/evptest.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/regress/lib/libcrypto/evp/evptest.c b/src/regress/lib/libcrypto/evp/evptest.c index f652cf5a25..6c47e38a5f 100644 --- a/src/regress/lib/libcrypto/evp/evptest.c +++ b/src/regress/lib/libcrypto/evp/evptest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evptest.c,v 1.14 2024/02/29 20:04:43 tb Exp $ */ | 1 | /* $OpenBSD: evptest.c,v 1.15 2024/03/30 09:49:59 tb Exp $ */ |
2 | /* Written by Ben Laurie, 2001 */ | 2 | /* Written by Ben Laurie, 2001 */ |
3 | /* | 3 | /* |
4 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | 4 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. |
@@ -49,6 +49,7 @@ | |||
49 | */ | 49 | */ |
50 | 50 | ||
51 | #include <stdio.h> | 51 | #include <stdio.h> |
52 | #include <stdlib.h> | ||
52 | #include <string.h> | 53 | #include <string.h> |
53 | 54 | ||
54 | #include <openssl/opensslconf.h> | 55 | #include <openssl/opensslconf.h> |
@@ -129,13 +130,6 @@ ustrsep(char **p, const char *sep) | |||
129 | return (unsigned char *)sstrsep(p, sep); | 130 | return (unsigned char *)sstrsep(p, sep); |
130 | } | 131 | } |
131 | 132 | ||
132 | static int | ||
133 | test1_exit(int ec) | ||
134 | { | ||
135 | exit(ec); | ||
136 | return(0); /* To keep some compilers quiet */ | ||
137 | } | ||
138 | |||
139 | static void | 133 | static void |
140 | test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | 134 | test1(const EVP_CIPHER *c, const unsigned char *key, int kn, |
141 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | 135 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, |
@@ -159,12 +153,12 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
159 | if (kn != EVP_CIPHER_key_length(c)) { | 153 | if (kn != EVP_CIPHER_key_length(c)) { |
160 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, | 154 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, |
161 | (unsigned long)EVP_CIPHER_key_length(c)); | 155 | (unsigned long)EVP_CIPHER_key_length(c)); |
162 | test1_exit(5); | 156 | exit(5); |
163 | } | 157 | } |
164 | if ((ctx = EVP_CIPHER_CTX_new()) == NULL) { | 158 | if ((ctx = EVP_CIPHER_CTX_new()) == NULL) { |
165 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); | 159 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); |
166 | ERR_print_errors_fp(stderr); | 160 | ERR_print_errors_fp(stderr); |
167 | test1_exit(12); | 161 | exit(12); |
168 | } | 162 | } |
169 | EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); | 163 | EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); |
170 | if (encdec != 0) { | 164 | if (encdec != 0) { |
@@ -174,32 +168,32 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
174 | if (!EVP_EncryptInit_ex(ctx, c, NULL, key, eiv)) { | 168 | if (!EVP_EncryptInit_ex(ctx, c, NULL, key, eiv)) { |
175 | fprintf(stderr, "EncryptInit failed\n"); | 169 | fprintf(stderr, "EncryptInit failed\n"); |
176 | ERR_print_errors_fp(stderr); | 170 | ERR_print_errors_fp(stderr); |
177 | test1_exit(10); | 171 | exit(10); |
178 | } | 172 | } |
179 | EVP_CIPHER_CTX_set_padding(ctx, 0); | 173 | EVP_CIPHER_CTX_set_padding(ctx, 0); |
180 | 174 | ||
181 | if (!EVP_EncryptUpdate(ctx, out, &outl, plaintext, pn)) { | 175 | if (!EVP_EncryptUpdate(ctx, out, &outl, plaintext, pn)) { |
182 | fprintf(stderr, "Encrypt failed\n"); | 176 | fprintf(stderr, "Encrypt failed\n"); |
183 | ERR_print_errors_fp(stderr); | 177 | ERR_print_errors_fp(stderr); |
184 | test1_exit(6); | 178 | exit(6); |
185 | } | 179 | } |
186 | if (!EVP_EncryptFinal_ex(ctx, out + outl, &outl2)) { | 180 | if (!EVP_EncryptFinal_ex(ctx, out + outl, &outl2)) { |
187 | fprintf(stderr, "EncryptFinal failed\n"); | 181 | fprintf(stderr, "EncryptFinal failed\n"); |
188 | ERR_print_errors_fp(stderr); | 182 | ERR_print_errors_fp(stderr); |
189 | test1_exit(7); | 183 | exit(7); |
190 | } | 184 | } |
191 | 185 | ||
192 | if (outl + outl2 != cn) { | 186 | if (outl + outl2 != cn) { |
193 | fprintf(stderr, "Ciphertext length mismatch got %d expected %d\n", | 187 | fprintf(stderr, "Ciphertext length mismatch got %d expected %d\n", |
194 | outl + outl2, cn); | 188 | outl + outl2, cn); |
195 | test1_exit(8); | 189 | exit(8); |
196 | } | 190 | } |
197 | 191 | ||
198 | if (memcmp(out, ciphertext, cn)) { | 192 | if (memcmp(out, ciphertext, cn)) { |
199 | fprintf(stderr, "Ciphertext mismatch\n"); | 193 | fprintf(stderr, "Ciphertext mismatch\n"); |
200 | hexdump(stderr, "Got",out,cn); | 194 | hexdump(stderr, "Got",out,cn); |
201 | hexdump(stderr, "Expected",ciphertext,cn); | 195 | hexdump(stderr, "Expected",ciphertext,cn); |
202 | test1_exit(9); | 196 | exit(9); |
203 | } | 197 | } |
204 | } | 198 | } |
205 | 199 | ||
@@ -210,32 +204,32 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
210 | if (!EVP_DecryptInit_ex(ctx, c,NULL, key, eiv)) { | 204 | if (!EVP_DecryptInit_ex(ctx, c,NULL, key, eiv)) { |
211 | fprintf(stderr, "DecryptInit failed\n"); | 205 | fprintf(stderr, "DecryptInit failed\n"); |
212 | ERR_print_errors_fp(stderr); | 206 | ERR_print_errors_fp(stderr); |
213 | test1_exit(11); | 207 | exit(11); |
214 | } | 208 | } |
215 | EVP_CIPHER_CTX_set_padding(ctx, 0); | 209 | EVP_CIPHER_CTX_set_padding(ctx, 0); |
216 | 210 | ||
217 | if (!EVP_DecryptUpdate(ctx, out, &outl, ciphertext, cn)) { | 211 | if (!EVP_DecryptUpdate(ctx, out, &outl, ciphertext, cn)) { |
218 | fprintf(stderr, "Decrypt failed\n"); | 212 | fprintf(stderr, "Decrypt failed\n"); |
219 | ERR_print_errors_fp(stderr); | 213 | ERR_print_errors_fp(stderr); |
220 | test1_exit(6); | 214 | exit(6); |
221 | } | 215 | } |
222 | if (!EVP_DecryptFinal_ex(ctx, out + outl, &outl2)) { | 216 | if (!EVP_DecryptFinal_ex(ctx, out + outl, &outl2)) { |
223 | fprintf(stderr, "DecryptFinal failed\n"); | 217 | fprintf(stderr, "DecryptFinal failed\n"); |
224 | ERR_print_errors_fp(stderr); | 218 | ERR_print_errors_fp(stderr); |
225 | test1_exit(7); | 219 | exit(7); |
226 | } | 220 | } |
227 | 221 | ||
228 | if (outl + outl2 != pn) { | 222 | if (outl + outl2 != pn) { |
229 | fprintf(stderr, "Plaintext length mismatch got %d expected %d\n", | 223 | fprintf(stderr, "Plaintext length mismatch got %d expected %d\n", |
230 | outl + outl2, pn); | 224 | outl + outl2, pn); |
231 | test1_exit(8); | 225 | exit(8); |
232 | } | 226 | } |
233 | 227 | ||
234 | if (memcmp(out, plaintext, pn)) { | 228 | if (memcmp(out, plaintext, pn)) { |
235 | fprintf(stderr, "Plaintext mismatch\n"); | 229 | fprintf(stderr, "Plaintext mismatch\n"); |
236 | hexdump(stderr, "Got",out,pn); | 230 | hexdump(stderr, "Got",out,pn); |
237 | hexdump(stderr, "Expected",plaintext,pn); | 231 | hexdump(stderr, "Expected",plaintext,pn); |
238 | test1_exit(9); | 232 | exit(9); |
239 | } | 233 | } |
240 | } | 234 | } |
241 | 235 | ||
@@ -283,7 +277,7 @@ test_digest(const char *digest, const unsigned char *plaintext, int pn, | |||
283 | if ((ctx = EVP_MD_CTX_new()) == NULL) { | 277 | if ((ctx = EVP_MD_CTX_new()) == NULL) { |
284 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); | 278 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); |
285 | ERR_print_errors_fp(stderr); | 279 | ERR_print_errors_fp(stderr); |
286 | test1_exit(104); | 280 | exit(104); |
287 | } | 281 | } |
288 | if (!EVP_DigestInit_ex(ctx, d, NULL)) { | 282 | if (!EVP_DigestInit_ex(ctx, d, NULL)) { |
289 | fprintf(stderr, "DigestInit failed\n"); | 283 | fprintf(stderr, "DigestInit failed\n"); |