83a9372bf55f758a0e2e2bb5a9425cb68fafde63
[openssl.git] / crypto / evp / evp_test.c
1 /* evp_test.c */
2 /*
3  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4  * project.
5  */
6 /* ====================================================================
7  * Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in
18  *    the documentation and/or other materials provided with the
19  *    distribution.
20  *
21  * 3. All advertising materials mentioning features or use of this
22  *    software must display the following acknowledgment:
23  *    "This product includes software developed by the OpenSSL Project
24  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25  *
26  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27  *    endorse or promote products derived from this software without
28  *    prior written permission. For written permission, please contact
29  *    licensing@OpenSSL.org.
30  *
31  * 5. Products derived from this software may not be called "OpenSSL"
32  *    nor may "OpenSSL" appear in their names without prior written
33  *    permission of the OpenSSL Project.
34  *
35  * 6. Redistributions of any form whatsoever must retain the following
36  *    acknowledgment:
37  *    "This product includes software developed by the OpenSSL Project
38  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51  * OF THE POSSIBILITY OF SUCH DAMAGE.
52  * ====================================================================
53  */
54
55 #include <stdio.h>
56 #include <string.h>
57 #include <stdlib.h>
58 #include <ctype.h>
59 #include <openssl/evp.h>
60 #include <openssl/err.h>
61 #include <openssl/x509v3.h>
62
63 /* Remove spaces from beginning and end of a string */
64
65 static void remove_space(char **pval)
66 {
67     unsigned char *p = (unsigned char *)*pval;
68
69     while (isspace(*p))
70         p++;
71
72     *pval = (char *)p;
73
74     p = p + strlen(*pval) - 1;
75
76     /* Remove trailing space */
77     while (isspace(*p))
78         *p-- = 0;
79 }
80
81 /*
82  * Given a line of the form:
83  *      name = value # comment
84  * extract name and value. NB: modifies passed buffer.
85  */
86
87 static int parse_line(char **pkw, char **pval, char *linebuf)
88 {
89     char *p;
90
91     p = linebuf + strlen(linebuf) - 1;
92
93     if (*p != '\n') {
94         fprintf(stderr, "FATAL: missing EOL\n");
95         exit(1);
96     }
97
98     /* Look for # */
99
100     p = strchr(linebuf, '#');
101
102     if (p)
103         *p = '\0';
104
105     /* Look for = sign */
106     p = strchr(linebuf, '=');
107
108     /* If no '=' exit */
109     if (!p)
110         return 0;
111
112     *p++ = '\0';
113
114     *pkw = linebuf;
115     *pval = p;
116
117     /* Remove spaces from keyword and value */
118     remove_space(pkw);
119     remove_space(pval);
120
121     return 1;
122 }
123
124 /* For a hex string "value" convert to a binary allocated buffer */
125 static int test_bin(const char *value, unsigned char **buf, size_t *buflen)
126 {
127     long len;
128     if (!*value) {
129         /* Don't return NULL for zero length buffer */
130         *buf = OPENSSL_malloc(1);
131         if (!*buf)
132             return 0;
133         **buf = 0;
134         *buflen = 0;
135         return 1;
136     }
137     *buf = string_to_hex(value, &len);
138     if (!*buf) {
139         fprintf(stderr, "Value=%s\n", value);
140         ERR_print_errors_fp(stderr);
141         return -1;
142     }
143     /* Size of input buffer means we'll never overflow */
144     *buflen = len;
145     return 1;
146 }
147
148 /* Structure holding test information */
149 struct evp_test {
150     /* method for this test */
151     const struct evp_test_method *meth;
152     /* current line being processed */
153     unsigned int line;
154     /* start line of current test */
155     unsigned int start_line;
156     /* Error string for test */
157     const char *err;
158     /* Expected error value of test */
159     char *expected_err;
160     /* Number of tests */
161     int ntests;
162     /* Error count */
163     int errors;
164     /* If output mismatch expected and got value */
165     unsigned char *out_got;
166     unsigned char *out_expected;
167     size_t out_len;
168     /* test specific data */
169     void *data;
170 };
171 /* Test method structure */
172 struct evp_test_method {
173     /* Name of test as it appears in file */
174     const char *name;
175     /* Initialise test for "alg" */
176     int (*init) (struct evp_test * t, const char *alg);
177     /* Clean up method */
178     void (*cleanup) (struct evp_test * t);
179     /* Test specific name value pair processing */
180     int (*parse) (struct evp_test * t, const char *name, const char *value);
181     /* Run the test itself */
182     int (*run_test) (struct evp_test * t);
183 };
184
185 static const struct evp_test_method digest_test_method, cipher_test_method;
186 static const struct evp_test_method aead_test_method;
187
188 static const struct evp_test_method *evp_test_list[] = {
189     &digest_test_method,
190     &cipher_test_method,
191     NULL,
192 };
193
194 static const struct evp_test_method *evp_find_test(const char *name)
195 {
196     const struct evp_test_method **tt;
197     for (tt = evp_test_list; *tt; tt++) {
198         if (!strcmp(name, (*tt)->name))
199             return *tt;
200     }
201     return NULL;
202 }
203
204 static void hex_print(const char *name, const unsigned char *buf, size_t len)
205 {
206     size_t i;
207     fprintf(stderr, "%s ", name);
208     for (i = 0; i < len; i++)
209         fprintf(stderr, "%02X", buf[i]);
210     fputs("\n", stderr);
211 }
212
213 static void print_expected(struct evp_test *t)
214 {
215     if (t->out_expected == NULL)
216         return;
217     hex_print("Expected:", t->out_expected, t->out_len);
218     hex_print("Got:     ", t->out_got, t->out_len);
219     OPENSSL_free(t->out_expected);
220     OPENSSL_free(t->out_got);
221     t->out_expected = NULL;
222     t->out_got = NULL;
223 }
224
225 static int check_test_error(struct evp_test *t)
226 {
227     if (!t->err && !t->expected_err)
228         return 1;
229     if (t->err && !t->expected_err) {
230         fprintf(stderr, "Test line %d: unexpected error %s\n",
231                 t->start_line, t->err);
232         print_expected(t);
233         return 0;
234     }
235     if (!t->err && t->expected_err) {
236         fprintf(stderr, "Test line %d: succeeded expecting %s\n",
237                 t->start_line, t->expected_err);
238         return 0;
239     }
240     if (!strcmp(t->err, t->expected_err))
241         return 1;
242
243     fprintf(stderr, "Test line %d: expecting %s got %s\n",
244             t->start_line, t->expected_err, t->err);
245     return 0;
246 }
247
248 /* Setup a new test, run any existing test */
249
250 static int setup_test(struct evp_test *t, const struct evp_test_method *tmeth)
251 {
252     /* If we already have a test set up run it */
253     if (t->meth) {
254         t->ntests++;
255         t->err = NULL;
256         if (t->meth->run_test(t) != 1) {
257             fprintf(stderr, "%s test error line %d\n",
258                     t->meth->name, t->start_line);
259             return 0;
260         }
261         if (!check_test_error(t)) {
262             if (t->err)
263                 ERR_print_errors_fp(stderr);
264             t->errors++;
265         }
266         ERR_clear_error();
267         t->meth->cleanup(t);
268         /* If new test type free old data */
269         if (tmeth != t->meth && t->data) {
270             OPENSSL_free(t->data);
271             t->data = NULL;
272         }
273         if (t->expected_err) {
274             OPENSSL_free(t->expected_err);
275             t->expected_err = NULL;
276         }
277     }
278     t->meth = tmeth;
279     return 1;
280 }
281
282 static int process_test(struct evp_test *t, char *buf, int verbose)
283 {
284     char *keyword, *value;
285     int rv = 0;
286     const struct evp_test_method *tmeth;
287     if (verbose)
288         fputs(buf, stdout);
289     if (!parse_line(&keyword, &value, buf))
290         return 1;
291     /* See if keyword corresponds to a test start */
292     tmeth = evp_find_test(keyword);
293     if (tmeth) {
294         if (!setup_test(t, tmeth))
295             return 0;
296         t->start_line = t->line;
297         if (!tmeth->init(t, value)) {
298             fprintf(stderr, "Unknown %s: %s\n", keyword, value);
299             return 0;
300         }
301         return 1;
302     } else if (!strcmp(keyword, "Result")) {
303         if (t->expected_err) {
304             fprintf(stderr, "Line %d: multiple result lines\n", t->line);
305             return 0;
306         }
307         t->expected_err = BUF_strdup(value);
308         if (!t->expected_err)
309             return 0;
310     } else {
311         /* Must be test specific line: try to parse it */
312         if (t->meth)
313             rv = t->meth->parse(t, keyword, value);
314
315         if (rv == 0)
316             fprintf(stderr, "line %d: unexpected keyword %s\n",
317                     t->line, keyword);
318
319         if (rv < 0)
320             fprintf(stderr, "line %d: error processing keyword %s\n",
321                     t->line, keyword);
322         if (rv <= 0)
323             return 0;
324     }
325     return 1;
326 }
327
328 static int check_output(struct evp_test *t, const unsigned char *expected,
329                         const unsigned char *got, size_t len)
330 {
331     if (!memcmp(expected, got, len))
332         return 0;
333     t->out_expected = BUF_memdup(expected, len);
334     t->out_got = BUF_memdup(got, len);
335     t->out_len = len;
336     if (t->out_expected == NULL || t->out_got == NULL) {
337         fprintf(stderr, "Memory allocation error!\n");
338         exit(1);
339     }
340     return 1;
341 }
342
343 int main(int argc, char **argv)
344 {
345     FILE *in = NULL;
346     char buf[10240];
347     struct evp_test t;
348
349     if (argc != 2) {
350         fprintf(stderr, "usage: evp_test testfile.txt\n");
351         return 1;
352     }
353
354     ERR_load_crypto_strings();
355     OpenSSL_add_all_algorithms();
356     t.meth = NULL;
357     t.err = NULL;
358     t.line = 0;
359     t.start_line = -1;
360     t.errors = 0;
361     t.ntests = 0;
362     t.out_expected = NULL;
363     t.out_got = NULL;
364     t.out_len = 0;
365     in = fopen(argv[1], "r");
366     while (fgets(buf, sizeof(buf), in)) {
367         t.line++;
368         if (!process_test(&t, buf, 0))
369             exit(1);
370     }
371     /* Run any final test we have */
372     if (!setup_test(&t, NULL))
373         exit(1);
374     fprintf(stderr, "%d tests completed with %d errors\n",
375             t.ntests, t.errors);
376     fclose(in);
377     if (t.errors)
378         return 1;
379     return 0;
380 }
381
382 static void test_free(void *d)
383 {
384     if (d)
385         OPENSSL_free(d);
386 }
387
388 /* Message digest tests */
389
390 struct digest_data {
391     /* Digest this test is for */
392     const EVP_MD *digest;
393     /* Input to digest */
394     unsigned char *input;
395     size_t input_len;
396     /* Expected output */
397     unsigned char *output;
398     size_t output_len;
399 };
400
401 static int digest_test_init(struct evp_test *t, const char *alg)
402 {
403     const EVP_MD *digest;
404     struct digest_data *mdat = t->data;
405     digest = EVP_get_digestbyname(alg);
406     if (!digest)
407         return 0;
408     mdat = OPENSSL_malloc(sizeof(struct digest_data));
409     mdat->digest = digest;
410     mdat->input = NULL;
411     mdat->output = NULL;
412     t->data = mdat;
413     return 1;
414 }
415
416 static void digest_test_cleanup(struct evp_test *t)
417 {
418     struct digest_data *mdat = t->data;
419     test_free(mdat->input);
420     test_free(mdat->output);
421 }
422
423 static int digest_test_parse(struct evp_test *t,
424                              const char *keyword, const char *value)
425 {
426     struct digest_data *mdata = t->data;
427     if (!strcmp(keyword, "Input"))
428         return test_bin(value, &mdata->input, &mdata->input_len);
429     if (!strcmp(keyword, "Output"))
430         return test_bin(value, &mdata->output, &mdata->output_len);
431     return 0;
432 }
433
434 static int digest_test_run(struct evp_test *t)
435 {
436     struct digest_data *mdata = t->data;
437     const char *err = "INTERNAL_ERROR";
438     EVP_MD_CTX *mctx;
439     unsigned char md[EVP_MAX_MD_SIZE];
440     unsigned int md_len;
441     mctx = EVP_MD_CTX_create();
442     if (!mctx)
443         goto err;
444     err = "DIGESTINIT_ERROR";
445     if (!EVP_DigestInit_ex(mctx, mdata->digest, NULL))
446         goto err;
447     err = "DIGESTUPDATE_ERROR";
448     if (!EVP_DigestUpdate(mctx, mdata->input, mdata->input_len))
449         goto err;
450     err = "DIGESTFINAL_ERROR";
451     if (!EVP_DigestFinal(mctx, md, &md_len))
452         goto err;
453     err = "DIGEST_LENGTH_MISMATCH";
454     if (md_len != mdata->output_len)
455         goto err;
456     err = "DIGEST_MISMATCH";
457     if (check_output(t, mdata->output, md, md_len))
458         goto err;
459     err = NULL;
460  err:
461     if (mctx)
462         EVP_MD_CTX_destroy(mctx);
463     t->err = err;
464     return 1;
465 }
466
467 static const struct evp_test_method digest_test_method = {
468     "Digest",
469     digest_test_init,
470     digest_test_cleanup,
471     digest_test_parse,
472     digest_test_run
473 };
474
475 /* Cipher tests */
476 struct cipher_data {
477     const EVP_CIPHER *cipher;
478     int enc;
479     /* Set to EVP_CIPH_GCM_MODE or EVP_CIPH_CCM_MODE if AEAD */
480     int aead;
481     unsigned char *key;
482     size_t key_len;
483     unsigned char *iv;
484     size_t iv_len;
485     unsigned char *plaintext;
486     size_t plaintext_len;
487     unsigned char *ciphertext;
488     size_t ciphertext_len;
489     /* GCM, CCM only */
490     unsigned char *aad;
491     size_t aad_len;
492     unsigned char *tag;
493     size_t tag_len;
494 };
495
496 static int cipher_test_init(struct evp_test *t, const char *alg)
497 {
498     const EVP_CIPHER *cipher;
499     struct cipher_data *cdat = t->data;
500     cipher = EVP_get_cipherbyname(alg);
501     if (!cipher)
502         return 0;
503     cdat = OPENSSL_malloc(sizeof(struct cipher_data));
504     cdat->cipher = cipher;
505     cdat->enc = -1;
506     cdat->key = NULL;
507     cdat->iv = NULL;
508     cdat->ciphertext = NULL;
509     cdat->plaintext = NULL;
510     cdat->aad = NULL;
511     cdat->tag = NULL;
512     t->data = cdat;
513     if (EVP_CIPHER_mode(cipher) == EVP_CIPH_GCM_MODE
514         || EVP_CIPHER_mode(cipher) == EVP_CIPH_CCM_MODE)
515         cdat->aead = EVP_CIPHER_mode(cipher);
516     else
517         cdat->aead = 0;
518
519     return 1;
520 }
521
522 static void cipher_test_cleanup(struct evp_test *t)
523 {
524     struct cipher_data *cdat = t->data;
525     test_free(cdat->key);
526     test_free(cdat->iv);
527     test_free(cdat->ciphertext);
528     test_free(cdat->plaintext);
529     test_free(cdat->aad);
530     test_free(cdat->tag);
531 }
532
533 static int cipher_test_parse(struct evp_test *t, const char *keyword,
534                              const char *value)
535 {
536     struct cipher_data *cdat = t->data;
537     if (!strcmp(keyword, "Key"))
538         return test_bin(value, &cdat->key, &cdat->key_len);
539     if (!strcmp(keyword, "IV"))
540         return test_bin(value, &cdat->iv, &cdat->iv_len);
541     if (!strcmp(keyword, "Plaintext"))
542         return test_bin(value, &cdat->plaintext, &cdat->plaintext_len);
543     if (!strcmp(keyword, "Ciphertext"))
544         return test_bin(value, &cdat->ciphertext, &cdat->ciphertext_len);
545     if (cdat->aead) {
546         if (!strcmp(keyword, "AAD"))
547             return test_bin(value, &cdat->aad, &cdat->aad_len);
548         if (!strcmp(keyword, "Tag"))
549             return test_bin(value, &cdat->tag, &cdat->tag_len);
550     }
551
552     if (!strcmp(keyword, "Operation")) {
553         if (!strcmp(value, "ENCRYPT"))
554             cdat->enc = 1;
555         else if (!strcmp(value, "DECRYPT"))
556             cdat->enc = 0;
557         else
558             return 0;
559         return 1;
560     }
561     return 0;
562 }
563
564 static int cipher_test_enc(struct evp_test *t, int enc)
565 {
566     struct cipher_data *cdat = t->data;
567     unsigned char *in, *out, *tmp = NULL;
568     size_t in_len, out_len;
569     int tmplen, tmpflen;
570     EVP_CIPHER_CTX *ctx = NULL;
571     const char *err;
572     err = "INTERNAL_ERROR";
573     ctx = EVP_CIPHER_CTX_new();
574     if (!ctx)
575         goto err;
576     EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
577     if (enc) {
578         in = cdat->plaintext;
579         in_len = cdat->plaintext_len;
580         out = cdat->ciphertext;
581         out_len = cdat->ciphertext_len;
582     } else {
583         in = cdat->ciphertext;
584         in_len = cdat->ciphertext_len;
585         out = cdat->plaintext;
586         out_len = cdat->plaintext_len;
587     }
588     tmp = OPENSSL_malloc(in_len + 2 * EVP_MAX_BLOCK_LENGTH);
589     if (!tmp)
590         goto err;
591     err = "CIPHERINIT_ERROR";
592     if (!EVP_CipherInit_ex(ctx, cdat->cipher, NULL, NULL, NULL, enc))
593         goto err;
594     err = "INVALID_IV_LENGTH";
595     if (cdat->iv) {
596         if (cdat->aead == EVP_CIPH_GCM_MODE) {
597             if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN,
598                                      cdat->iv_len, 0))
599                 goto err;
600         } else if (cdat->aead == EVP_CIPH_CCM_MODE) {
601             if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN,
602                                      cdat->iv_len, 0))
603                 goto err;
604         } else if (cdat->iv_len != (size_t)EVP_CIPHER_CTX_iv_length(ctx))
605             goto err;
606     }
607     if (cdat->aead) {
608         unsigned char *tag;
609         /*
610          * If encrypting just set tag length. If decrypting set
611          * tag length and value.
612          */
613         if (enc) {
614             err = "TAG_LENGTH_SET_ERROR";
615             tag = NULL;
616         } else {
617             err = "TAG_SET_ERROR";
618             tag = cdat->tag;
619         }
620         if (cdat->aead == EVP_CIPH_GCM_MODE && tag) {
621             if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG,
622                                      cdat->tag_len, tag))
623                 goto err;
624         } else if (cdat->aead == EVP_CIPH_CCM_MODE) {
625             if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG,
626                                      cdat->tag_len, tag))
627                 goto err;
628         }
629     }
630
631     err = "INVALID_KEY_LENGTH";
632     if (!EVP_CIPHER_CTX_set_key_length(ctx, cdat->key_len))
633         goto err;
634     err = "KEY_SET_ERROR";
635     if (!EVP_CipherInit_ex(ctx, NULL, NULL, cdat->key, cdat->iv, -1))
636         goto err;
637
638     if (cdat->aead == EVP_CIPH_CCM_MODE) {
639         if (!EVP_CipherUpdate(ctx, NULL, &tmplen, NULL, out_len)) {
640             err = "CCM_PLAINTEXT_LENGTH_SET_ERROR";
641             goto err;
642         }
643     }
644     if (cdat->aad) {
645         if (!EVP_CipherUpdate(ctx, NULL, &tmplen, cdat->aad, cdat->aad_len)) {
646             err = "AAD_SET_ERROR";
647             goto err;
648         }
649     }
650     EVP_CIPHER_CTX_set_padding(ctx, 0);
651     err = "CIPHERUPDATE_ERROR";
652     if (!EVP_CipherUpdate(ctx, tmp, &tmplen, in, in_len))
653         goto err;
654     if (cdat->aead == EVP_CIPH_CCM_MODE)
655         tmpflen = 0;
656     else {
657         err = "CIPHERFINAL_ERROR";
658         if (!EVP_CipherFinal_ex(ctx, tmp + tmplen, &tmpflen))
659             goto err;
660     }
661     err = "LENGTH_MISMATCH";
662     if (out_len != (size_t)(tmplen + tmpflen))
663         goto err;
664     err = "VALUE_MISMATCH";
665     if (check_output(t, out, tmp, out_len))
666         goto err;
667     if (enc && cdat->aead) {
668         unsigned char rtag[16];
669         if (cdat->tag_len > sizeof(rtag)) {
670             err = "TAG_LENGTH_INTERNAL_ERROR";
671             goto err;
672         }
673         /* EVP_CTRL_CCM_GET_TAG and EVP_CTRL_GCM_GET_TAG are equal. */
674         if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG,
675                                  cdat->tag_len, rtag)) {
676             err = "TAG_RETRIEVE_ERROR";
677             goto err;
678         }
679         if (check_output(t, cdat->tag, rtag, cdat->tag_len)) {
680             err = "TAG_VALUE_MISMATCH";
681             goto err;
682         }
683     }
684     err = NULL;
685  err:
686     if (tmp)
687         OPENSSL_free(tmp);
688     EVP_CIPHER_CTX_free(ctx);
689     t->err = err;
690     return err ? 0 : 1;
691 }
692
693 static int cipher_test_run(struct evp_test *t)
694 {
695     struct cipher_data *cdat = t->data;
696     int rv;
697     if (!cdat->key) {
698         t->err = "NO_KEY";
699         return 0;
700     }
701     if (!cdat->iv && EVP_CIPHER_iv_length(cdat->cipher)) {
702         /* IV is optional and usually omitted in wrap mode */
703         if (EVP_CIPHER_mode(cdat->cipher) != EVP_CIPH_WRAP_MODE) {
704             t->err = "NO_IV";
705             return 0;
706         }
707     }
708     if (cdat->aead && !cdat->tag) {
709         t->err = "NO_TAG";
710         return 0;
711     }
712     if (cdat->enc) {
713         rv = cipher_test_enc(t, 1);
714         /* Not fatal errors: return */
715         if (rv != 1) {
716             if (rv < 0)
717                 return 0;
718             return 1;
719         }
720     }
721     if (cdat->enc != 1) {
722         rv = cipher_test_enc(t, 0);
723         /* Not fatal errors: return */
724         if (rv != 1) {
725             if (rv < 0)
726                 return 0;
727             return 1;
728         }
729     }
730     return 1;
731 }
732
733 static const struct evp_test_method cipher_test_method = {
734     "Cipher",
735     cipher_test_init,
736     cipher_test_cleanup,
737     cipher_test_parse,
738     cipher_test_run
739 };