2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include <openssl/evp.h>
15 #include <openssl/pem.h>
16 #include <openssl/err.h>
17 #include <openssl/x509v3.h>
18 #include <openssl/pkcs12.h>
19 #include <openssl/kdf.h>
20 #include "internal/numbers.h"
22 /* Remove spaces from beginning and end of a string */
24 static void remove_space(char **pval)
26 unsigned char *p = (unsigned char *)*pval;
33 p = p + strlen(*pval) - 1;
35 /* Remove trailing space */
41 * Given a line of the form:
42 * name = value # comment
43 * extract name and value. NB: modifies passed buffer.
46 static int parse_line(char **pkw, char **pval, char *linebuf)
50 p = linebuf + strlen(linebuf) - 1;
53 fprintf(stderr, "FATAL: missing EOL\n");
59 p = strchr(linebuf, '#');
65 p = strchr(linebuf, '=');
76 /* Remove spaces from keyword and value */
84 * Unescape some escape sequences in string literals.
85 * Return the result in a newly allocated buffer.
86 * Currently only supports '\n'.
87 * If the input length is 0, returns a valid 1-byte buffer, but sets
90 static unsigned char* unescape(const char *input, size_t input_len,
93 unsigned char *ret, *p;
97 return OPENSSL_zalloc(1);
100 /* Escaping is non-expanding; over-allocate original size for simplicity. */
101 ret = p = OPENSSL_malloc(input_len);
105 for (i = 0; i < input_len; i++) {
106 if (input[i] == '\\') {
107 if (i == input_len - 1 || input[i+1] != 'n')
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)
131 /* Check for empty value */
134 * Don't return NULL for zero length buffer.
135 * This is needed for some tests with empty keys: HMAC_Init_ex() expects
136 * a non-NULL key buffer even if the key length is 0, in order to detect
139 *buf = OPENSSL_malloc(1);
147 /* Check for NULL literal */
148 if (strcmp(value, "NULL") == 0) {
154 /* Check for string literal */
155 if (value[0] == '"') {
158 vlen = strlen(value);
159 if (value[vlen - 1] != '"')
162 *buf = unescape(value, vlen, buflen);
168 /* Otherwise assume as hex literal and convert it to binary buffer */
169 *buf = OPENSSL_hexstr2buf(value, &len);
171 fprintf(stderr, "Value=%s\n", value);
172 ERR_print_errors_fp(stderr);
175 /* Size of input buffer means we'll never overflow */
179 #ifndef OPENSSL_NO_SCRYPT
180 /* Currently only used by scrypt tests */
181 /* Parse unsigned decimal 64 bit integer value */
182 static int test_uint64(const char *value, uint64_t *pr)
184 const char *p = value;
186 fprintf(stderr, "Invalid empty integer value\n");
191 if (*pr > UINT64_MAX/10) {
192 fprintf(stderr, "Integer string overflow value=%s\n", value);
196 if (*p < '0' || *p > '9') {
197 fprintf(stderr, "Invalid integer string value=%s\n", value);
207 /* Structure holding test information */
209 /* file being read */
211 /* temp memory BIO for reading in keys */
213 /* List of public and private keys */
214 struct key_list *private;
215 struct key_list *public;
216 /* method for this test */
217 const struct evp_test_method *meth;
218 /* current line being processed */
220 /* start line of current test */
221 unsigned int start_line;
222 /* Error string for test */
223 const char *err, *aux_err;
224 /* Expected error value of test */
226 /* Expected error function string */
228 /* Expected error reason string */
230 /* Number of tests */
234 /* Number of tests skipped */
236 /* If output mismatch expected and got value */
237 unsigned char *out_received;
238 size_t out_received_len;
239 unsigned char *out_expected;
240 size_t out_expected_len;
241 /* test specific data */
243 /* Current test should be skipped */
250 struct key_list *next;
253 /* Test method structure */
254 struct evp_test_method {
255 /* Name of test as it appears in file */
257 /* Initialise test for "alg" */
258 int (*init) (struct evp_test * t, const char *alg);
259 /* Clean up method */
260 void (*cleanup) (struct evp_test * t);
261 /* Test specific name value pair processing */
262 int (*parse) (struct evp_test * t, const char *name, const char *value);
263 /* Run the test itself */
264 int (*run_test) (struct evp_test * t);
267 static const struct evp_test_method digest_test_method, cipher_test_method;
268 static const struct evp_test_method mac_test_method;
269 static const struct evp_test_method psign_test_method, pverify_test_method;
270 static const struct evp_test_method pdecrypt_test_method;
271 static const struct evp_test_method pverify_recover_test_method;
272 static const struct evp_test_method pderive_test_method;
273 static const struct evp_test_method pbe_test_method;
274 static const struct evp_test_method encode_test_method;
275 static const struct evp_test_method kdf_test_method;
277 static const struct evp_test_method *evp_test_list[] = {
282 &pverify_test_method,
283 &pdecrypt_test_method,
284 &pverify_recover_test_method,
285 &pderive_test_method,
292 static const struct evp_test_method *evp_find_test(const char *name)
294 const struct evp_test_method **tt;
296 for (tt = evp_test_list; *tt; tt++) {
297 if (strcmp(name, (*tt)->name) == 0)
303 static void hex_print(const char *name, const unsigned char *buf, size_t len)
306 fprintf(stderr, "%s ", name);
307 for (i = 0; i < len; i++)
308 fprintf(stderr, "%02X", buf[i]);
312 static void free_expected(struct evp_test *t)
314 OPENSSL_free(t->expected_err);
315 t->expected_err = NULL;
316 OPENSSL_free(t->func);
318 OPENSSL_free(t->reason);
320 OPENSSL_free(t->out_expected);
321 OPENSSL_free(t->out_received);
322 t->out_expected = NULL;
323 t->out_received = NULL;
324 t->out_expected_len = 0;
325 t->out_received_len = 0;
330 static void print_expected(struct evp_test *t)
332 if (t->out_expected == NULL && t->out_received == NULL)
334 hex_print("Expected:", t->out_expected, t->out_expected_len);
335 hex_print("Got: ", t->out_received, t->out_received_len);
339 static int check_test_error(struct evp_test *t)
344 if (!t->err && !t->expected_err)
346 if (t->err && !t->expected_err) {
347 if (t->aux_err != NULL) {
348 fprintf(stderr, "Test line %d(%s): unexpected error %s\n",
349 t->start_line, t->aux_err, t->err);
351 fprintf(stderr, "Test line %d: unexpected error %s\n",
352 t->start_line, t->err);
357 if (!t->err && t->expected_err) {
358 fprintf(stderr, "Test line %d: succeeded expecting %s\n",
359 t->start_line, t->expected_err);
363 if (strcmp(t->err, t->expected_err) != 0) {
364 fprintf(stderr, "Test line %d: expecting %s got %s\n",
365 t->start_line, t->expected_err, t->err);
369 if (t->func == NULL && t->reason == NULL)
372 if (t->func == NULL || t->reason == NULL) {
373 fprintf(stderr, "Test line %d: missing function or reason code\n",
378 err = ERR_peek_error();
380 fprintf(stderr, "Test line %d, expected error \"%s:%s\" not set\n",
381 t->start_line, t->func, t->reason);
385 func = ERR_func_error_string(err);
386 reason = ERR_reason_error_string(err);
388 if (func == NULL && reason == NULL) {
389 fprintf(stderr, "Test line %d: expected error \"%s:%s\", no strings available. Skipping...\n",
390 t->start_line, t->func, t->reason);
394 if (strcmp(func, t->func) == 0 && strcmp(reason, t->reason) == 0)
397 fprintf(stderr, "Test line %d: expected error \"%s:%s\", got \"%s:%s\"\n",
398 t->start_line, t->func, t->reason, func, reason);
403 /* Setup a new test, run any existing test */
405 static int setup_test(struct evp_test *t, const struct evp_test_method *tmeth)
407 /* If we already have a test set up run it */
414 if (t->err == NULL && t->meth->run_test(t) != 1) {
415 fprintf(stderr, "%s test error line %d\n",
416 t->meth->name, t->start_line);
419 if (!check_test_error(t)) {
421 ERR_print_errors_fp(stderr);
427 if (t->data != NULL) {
429 OPENSSL_free(t->data);
432 OPENSSL_free(t->expected_err);
433 t->expected_err = NULL;
440 static int find_key(EVP_PKEY **ppk, const char *name, struct key_list *lst)
442 for (; lst; lst = lst->next) {
443 if (strcmp(lst->name, name) == 0) {
452 static void free_key_list(struct key_list *lst)
454 while (lst != NULL) {
455 struct key_list *ltmp;
456 EVP_PKEY_free(lst->key);
457 OPENSSL_free(lst->name);
464 static int check_unsupported()
466 long err = ERR_peek_error();
467 if (ERR_GET_LIB(err) == ERR_LIB_EVP
468 && ERR_GET_REASON(err) == EVP_R_UNSUPPORTED_ALGORITHM) {
476 static int read_key(struct evp_test *t)
480 t->key = BIO_new(BIO_s_mem());
481 else if (BIO_reset(t->key) <= 0)
483 if (t->key == NULL) {
484 fprintf(stderr, "Error allocating key memory BIO\n");
487 /* Read to PEM end line and place content in memory BIO */
488 while (BIO_gets(t->in, tmpbuf, sizeof(tmpbuf))) {
490 if (BIO_puts(t->key, tmpbuf) <= 0) {
491 fprintf(stderr, "Error writing to key memory BIO\n");
494 if (strncmp(tmpbuf, "-----END", 8) == 0)
497 fprintf(stderr, "Can't find key end\n");
501 static int process_test(struct evp_test *t, char *buf, int verbose)
503 char *keyword = NULL, *value = NULL;
504 int rv = 0, add_key = 0;
505 struct key_list **lst = NULL, *key = NULL;
507 const struct evp_test_method *tmeth = NULL;
510 if (!parse_line(&keyword, &value, buf))
512 if (strcmp(keyword, "PrivateKey") == 0) {
515 pk = PEM_read_bio_PrivateKey(t->key, NULL, 0, NULL);
516 if (pk == NULL && !check_unsupported()) {
517 fprintf(stderr, "Error reading private key %s\n", value);
518 ERR_print_errors_fp(stderr);
524 if (strcmp(keyword, "PublicKey") == 0) {
527 pk = PEM_read_bio_PUBKEY(t->key, NULL, 0, NULL);
528 if (pk == NULL && !check_unsupported()) {
529 fprintf(stderr, "Error reading public key %s\n", value);
530 ERR_print_errors_fp(stderr);
536 /* If we have a key add to list */
538 if (find_key(NULL, value, *lst)) {
539 fprintf(stderr, "Duplicate key %s\n", value);
542 key = OPENSSL_malloc(sizeof(*key));
545 key->name = OPENSSL_strdup(value);
552 /* See if keyword corresponds to a test start */
553 tmeth = evp_find_test(keyword);
555 if (!setup_test(t, tmeth))
557 t->start_line = t->line;
559 if (!tmeth->init(t, value)) {
560 fprintf(stderr, "Unknown %s: %s\n", keyword, value);
564 } else if (t->skip) {
566 } else if (strcmp(keyword, "Result") == 0) {
567 if (t->expected_err) {
568 fprintf(stderr, "Line %d: multiple result lines\n", t->line);
571 t->expected_err = OPENSSL_strdup(value);
572 if (t->expected_err == NULL)
574 } else if (strcmp(keyword, "Function") == 0) {
575 if (t->func != NULL) {
576 fprintf(stderr, "Line %d: multiple function lines\n", t->line);
579 t->func = OPENSSL_strdup(value);
582 } else if (strcmp(keyword, "Reason") == 0) {
583 if (t->reason != NULL) {
584 fprintf(stderr, "Line %d: multiple reason lines\n", t->line);
587 t->reason = OPENSSL_strdup(value);
588 if (t->reason == NULL)
591 /* Must be test specific line: try to parse it */
593 rv = t->meth->parse(t, keyword, value);
596 fprintf(stderr, "line %d: unexpected keyword %s\n",
600 fprintf(stderr, "line %d: error processing keyword %s\n",
608 static int check_var_length_output(struct evp_test *t,
609 const unsigned char *expected,
611 const unsigned char *received,
614 if (expected_len == received_len &&
615 memcmp(expected, received, expected_len) == 0) {
619 /* The result printing code expects a non-NULL buffer. */
620 t->out_expected = OPENSSL_memdup(expected, expected_len ? expected_len : 1);
621 t->out_expected_len = expected_len;
622 t->out_received = OPENSSL_memdup(received, received_len ? received_len : 1);
623 t->out_received_len = received_len;
624 if (t->out_expected == NULL || t->out_received == NULL) {
625 fprintf(stderr, "Memory allocation error!\n");
631 static int check_output(struct evp_test *t,
632 const unsigned char *expected,
633 const unsigned char *received,
636 return check_var_length_output(t, expected, len, received, len);
639 int main(int argc, char **argv)
646 fprintf(stderr, "usage: evp_test testfile.txt\n");
650 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
652 memset(&t, 0, sizeof(t));
654 in = BIO_new_file(argv[1], "rb");
656 fprintf(stderr, "Can't open %s for reading\n", argv[1]);
661 while (BIO_gets(in, buf, sizeof(buf))) {
663 if (!process_test(&t, buf, 0))
666 /* Run any final test we have */
667 if (!setup_test(&t, NULL))
669 fprintf(stderr, "%d tests completed with %d errors, %d skipped\n",
670 t.ntests, t.errors, t.nskip);
671 free_key_list(t.public);
672 free_key_list(t.private);
676 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
677 if (CRYPTO_mem_leaks_fp(stderr) <= 0)
685 static void test_free(void *d)
690 /* Message digest tests */
693 /* Digest this test is for */
694 const EVP_MD *digest;
695 /* Input to digest */
696 unsigned char *input;
698 /* Repeat count for input */
700 /* Expected output */
701 unsigned char *output;
705 static int digest_test_init(struct evp_test *t, const char *alg)
707 const EVP_MD *digest;
708 struct digest_data *mdat;
709 digest = EVP_get_digestbyname(alg);
711 /* If alg has an OID assume disabled algorithm */
712 if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) {
718 mdat = OPENSSL_malloc(sizeof(*mdat));
719 mdat->digest = digest;
727 static void digest_test_cleanup(struct evp_test *t)
729 struct digest_data *mdat = t->data;
730 test_free(mdat->input);
731 test_free(mdat->output);
734 static int digest_test_parse(struct evp_test *t,
735 const char *keyword, const char *value)
737 struct digest_data *mdata = t->data;
738 if (strcmp(keyword, "Input") == 0)
739 return test_bin(value, &mdata->input, &mdata->input_len);
740 if (strcmp(keyword, "Output") == 0)
741 return test_bin(value, &mdata->output, &mdata->output_len);
742 if (strcmp(keyword, "Count") == 0) {
743 long nrpt = atoi(value);
746 mdata->nrpt = (size_t)nrpt;
752 static int digest_test_run(struct evp_test *t)
754 struct digest_data *mdata = t->data;
756 const char *err = "INTERNAL_ERROR";
758 unsigned char md[EVP_MAX_MD_SIZE];
760 mctx = EVP_MD_CTX_new();
763 err = "DIGESTINIT_ERROR";
764 if (!EVP_DigestInit_ex(mctx, mdata->digest, NULL))
766 err = "DIGESTUPDATE_ERROR";
767 for (i = 0; i < mdata->nrpt; i++) {
768 if (!EVP_DigestUpdate(mctx, mdata->input, mdata->input_len))
771 err = "DIGESTFINAL_ERROR";
772 if (!EVP_DigestFinal(mctx, md, &md_len))
774 err = "DIGEST_LENGTH_MISMATCH";
775 if (md_len != mdata->output_len)
777 err = "DIGEST_MISMATCH";
778 if (check_output(t, mdata->output, md, md_len))
782 EVP_MD_CTX_free(mctx);
787 static const struct evp_test_method digest_test_method = {
797 const EVP_CIPHER *cipher;
799 /* EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE or EVP_CIPH_OCB_MODE if AEAD */
805 unsigned char *plaintext;
806 size_t plaintext_len;
807 unsigned char *ciphertext;
808 size_t ciphertext_len;
816 static int cipher_test_init(struct evp_test *t, const char *alg)
818 const EVP_CIPHER *cipher;
819 struct cipher_data *cdat = t->data;
820 cipher = EVP_get_cipherbyname(alg);
822 /* If alg has an OID assume disabled algorithm */
823 if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) {
829 cdat = OPENSSL_malloc(sizeof(*cdat));
830 cdat->cipher = cipher;
834 cdat->ciphertext = NULL;
835 cdat->plaintext = NULL;
839 if (EVP_CIPHER_mode(cipher) == EVP_CIPH_GCM_MODE
840 || EVP_CIPHER_mode(cipher) == EVP_CIPH_OCB_MODE
841 || EVP_CIPHER_mode(cipher) == EVP_CIPH_CCM_MODE)
842 cdat->aead = EVP_CIPHER_mode(cipher);
843 else if (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
851 static void cipher_test_cleanup(struct evp_test *t)
853 struct cipher_data *cdat = t->data;
854 test_free(cdat->key);
856 test_free(cdat->ciphertext);
857 test_free(cdat->plaintext);
858 test_free(cdat->aad);
859 test_free(cdat->tag);
862 static int cipher_test_parse(struct evp_test *t, const char *keyword,
865 struct cipher_data *cdat = t->data;
866 if (strcmp(keyword, "Key") == 0)
867 return test_bin(value, &cdat->key, &cdat->key_len);
868 if (strcmp(keyword, "IV") == 0)
869 return test_bin(value, &cdat->iv, &cdat->iv_len);
870 if (strcmp(keyword, "Plaintext") == 0)
871 return test_bin(value, &cdat->plaintext, &cdat->plaintext_len);
872 if (strcmp(keyword, "Ciphertext") == 0)
873 return test_bin(value, &cdat->ciphertext, &cdat->ciphertext_len);
875 if (strcmp(keyword, "AAD") == 0)
876 return test_bin(value, &cdat->aad, &cdat->aad_len);
877 if (strcmp(keyword, "Tag") == 0)
878 return test_bin(value, &cdat->tag, &cdat->tag_len);
881 if (strcmp(keyword, "Operation") == 0) {
882 if (strcmp(value, "ENCRYPT") == 0)
884 else if (strcmp(value, "DECRYPT") == 0)
893 static int cipher_test_enc(struct evp_test *t, int enc,
894 size_t out_misalign, size_t inp_misalign, int frag)
896 struct cipher_data *cdat = t->data;
897 unsigned char *in, *out, *tmp = NULL;
898 size_t in_len, out_len, donelen = 0;
899 int tmplen, chunklen, tmpflen;
900 EVP_CIPHER_CTX *ctx = NULL;
902 err = "INTERNAL_ERROR";
903 ctx = EVP_CIPHER_CTX_new();
906 EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
908 in = cdat->plaintext;
909 in_len = cdat->plaintext_len;
910 out = cdat->ciphertext;
911 out_len = cdat->ciphertext_len;
913 in = cdat->ciphertext;
914 in_len = cdat->ciphertext_len;
915 out = cdat->plaintext;
916 out_len = cdat->plaintext_len;
918 if (inp_misalign == (size_t)-1) {
920 * Exercise in-place encryption
922 tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH);
925 in = memcpy(tmp + out_misalign, in, in_len);
927 inp_misalign += 16 - ((out_misalign + in_len) & 15);
929 * 'tmp' will store both output and copy of input. We make the copy
930 * of input to specifically aligned part of 'tmp'. So we just
931 * figured out how much padding would ensure the required alignment,
932 * now we allocate extended buffer and finally copy the input just
933 * past inp_misalign in expression below. Output will be written
934 * past out_misalign...
936 tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +
937 inp_misalign + in_len);
940 in = memcpy(tmp + out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +
941 inp_misalign, in, in_len);
943 err = "CIPHERINIT_ERROR";
944 if (!EVP_CipherInit_ex(ctx, cdat->cipher, NULL, NULL, NULL, enc))
946 err = "INVALID_IV_LENGTH";
949 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
952 } else if (cdat->iv_len != (size_t)EVP_CIPHER_CTX_iv_length(ctx))
958 * If encrypting or OCB just set tag length initially, otherwise
959 * set tag length and value.
961 if (enc || cdat->aead == EVP_CIPH_OCB_MODE) {
962 err = "TAG_LENGTH_SET_ERROR";
965 err = "TAG_SET_ERROR";
968 if (tag || cdat->aead != EVP_CIPH_GCM_MODE) {
969 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
975 err = "INVALID_KEY_LENGTH";
976 if (!EVP_CIPHER_CTX_set_key_length(ctx, cdat->key_len))
978 err = "KEY_SET_ERROR";
979 if (!EVP_CipherInit_ex(ctx, NULL, NULL, cdat->key, cdat->iv, -1))
982 if (!enc && cdat->aead == EVP_CIPH_OCB_MODE) {
983 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
984 cdat->tag_len, cdat->tag)) {
985 err = "TAG_SET_ERROR";
990 if (cdat->aead == EVP_CIPH_CCM_MODE) {
991 if (!EVP_CipherUpdate(ctx, NULL, &tmplen, NULL, out_len)) {
992 err = "CCM_PLAINTEXT_LENGTH_SET_ERROR";
997 err = "AAD_SET_ERROR";
999 if (!EVP_CipherUpdate(ctx, NULL, &chunklen, cdat->aad,
1004 * Supply the AAD in chunks less than the block size where possible
1006 if (cdat->aad_len > 0) {
1007 if (!EVP_CipherUpdate(ctx, NULL, &chunklen, cdat->aad, 1))
1011 if (cdat->aad_len > 2) {
1012 if (!EVP_CipherUpdate(ctx, NULL, &chunklen, cdat->aad + donelen,
1015 donelen += cdat->aad_len - 2;
1017 if (cdat->aad_len > 1
1018 && !EVP_CipherUpdate(ctx, NULL, &chunklen,
1019 cdat->aad + donelen, 1))
1023 EVP_CIPHER_CTX_set_padding(ctx, 0);
1024 err = "CIPHERUPDATE_ERROR";
1027 /* We supply the data all in one go */
1028 if (!EVP_CipherUpdate(ctx, tmp + out_misalign, &tmplen, in, in_len))
1031 /* Supply the data in chunks less than the block size where possible */
1033 if (!EVP_CipherUpdate(ctx, tmp + out_misalign, &chunklen, in, 1))
1040 if (!EVP_CipherUpdate(ctx, tmp + out_misalign + tmplen, &chunklen,
1048 if (!EVP_CipherUpdate(ctx, tmp + out_misalign + tmplen, &chunklen,
1054 if (cdat->aead == EVP_CIPH_CCM_MODE)
1057 err = "CIPHERFINAL_ERROR";
1058 if (!EVP_CipherFinal_ex(ctx, tmp + out_misalign + tmplen, &tmpflen))
1061 err = "LENGTH_MISMATCH";
1062 if (out_len != (size_t)(tmplen + tmpflen))
1064 err = "VALUE_MISMATCH";
1065 if (check_output(t, out, tmp + out_misalign, out_len))
1067 if (enc && cdat->aead) {
1068 unsigned char rtag[16];
1069 if (cdat->tag_len > sizeof(rtag)) {
1070 err = "TAG_LENGTH_INTERNAL_ERROR";
1073 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
1074 cdat->tag_len, rtag)) {
1075 err = "TAG_RETRIEVE_ERROR";
1078 if (check_output(t, cdat->tag, rtag, cdat->tag_len)) {
1079 err = "TAG_VALUE_MISMATCH";
1086 EVP_CIPHER_CTX_free(ctx);
1091 static int cipher_test_run(struct evp_test *t)
1093 struct cipher_data *cdat = t->data;
1095 size_t out_misalign, inp_misalign;
1101 if (!cdat->iv && EVP_CIPHER_iv_length(cdat->cipher)) {
1102 /* IV is optional and usually omitted in wrap mode */
1103 if (EVP_CIPHER_mode(cdat->cipher) != EVP_CIPH_WRAP_MODE) {
1108 if (cdat->aead && !cdat->tag) {
1112 for (out_misalign = 0; out_misalign <= 1;) {
1113 static char aux_err[64];
1114 t->aux_err = aux_err;
1115 for (inp_misalign = (size_t)-1; inp_misalign != 2; inp_misalign++) {
1116 if (inp_misalign == (size_t)-1) {
1117 /* kludge: inp_misalign == -1 means "exercise in-place" */
1118 BIO_snprintf(aux_err, sizeof(aux_err),
1119 "%s in-place, %sfragmented",
1120 out_misalign ? "misaligned" : "aligned",
1121 frag ? "" : "not ");
1123 BIO_snprintf(aux_err, sizeof(aux_err),
1124 "%s output and %s input, %sfragmented",
1125 out_misalign ? "misaligned" : "aligned",
1126 inp_misalign ? "misaligned" : "aligned",
1127 frag ? "" : "not ");
1130 rv = cipher_test_enc(t, 1, out_misalign, inp_misalign, frag);
1131 /* Not fatal errors: return */
1138 if (cdat->enc != 1) {
1139 rv = cipher_test_enc(t, 0, out_misalign, inp_misalign, frag);
1140 /* Not fatal errors: return */
1149 if (out_misalign == 1 && frag == 0) {
1151 * XTS, CCM and Wrap modes have special requirements about input
1152 * lengths so we don't fragment for those
1154 if (cdat->aead == EVP_CIPH_CCM_MODE
1155 || EVP_CIPHER_mode(cdat->cipher) == EVP_CIPH_XTS_MODE
1156 || EVP_CIPHER_mode(cdat->cipher) == EVP_CIPH_WRAP_MODE)
1169 static const struct evp_test_method cipher_test_method = {
1172 cipher_test_cleanup,
1180 /* Algorithm string for this MAC */
1186 unsigned char *input;
1188 /* Expected output */
1189 unsigned char *output;
1193 static int mac_test_init(struct evp_test *t, const char *alg)
1196 struct mac_data *mdat;
1197 if (strcmp(alg, "HMAC") == 0) {
1198 type = EVP_PKEY_HMAC;
1199 } else if (strcmp(alg, "CMAC") == 0) {
1200 #ifndef OPENSSL_NO_CMAC
1201 type = EVP_PKEY_CMAC;
1209 mdat = OPENSSL_malloc(sizeof(*mdat));
1214 mdat->output = NULL;
1219 static void mac_test_cleanup(struct evp_test *t)
1221 struct mac_data *mdat = t->data;
1222 test_free(mdat->alg);
1223 test_free(mdat->key);
1224 test_free(mdat->input);
1225 test_free(mdat->output);
1228 static int mac_test_parse(struct evp_test *t,
1229 const char *keyword, const char *value)
1231 struct mac_data *mdata = t->data;
1232 if (strcmp(keyword, "Key") == 0)
1233 return test_bin(value, &mdata->key, &mdata->key_len);
1234 if (strcmp(keyword, "Algorithm") == 0) {
1235 mdata->alg = OPENSSL_strdup(value);
1240 if (strcmp(keyword, "Input") == 0)
1241 return test_bin(value, &mdata->input, &mdata->input_len);
1242 if (strcmp(keyword, "Output") == 0)
1243 return test_bin(value, &mdata->output, &mdata->output_len);
1247 static int mac_test_run(struct evp_test *t)
1249 struct mac_data *mdata = t->data;
1250 const char *err = "INTERNAL_ERROR";
1251 EVP_MD_CTX *mctx = NULL;
1252 EVP_PKEY_CTX *pctx = NULL, *genctx = NULL;
1253 EVP_PKEY *key = NULL;
1254 const EVP_MD *md = NULL;
1255 unsigned char *mac = NULL;
1258 #ifdef OPENSSL_NO_DES
1259 if (mdata->alg != NULL && strstr(mdata->alg, "DES") != NULL) {
1266 err = "MAC_PKEY_CTX_ERROR";
1267 genctx = EVP_PKEY_CTX_new_id(mdata->type, NULL);
1271 err = "MAC_KEYGEN_INIT_ERROR";
1272 if (EVP_PKEY_keygen_init(genctx) <= 0)
1274 if (mdata->type == EVP_PKEY_CMAC) {
1275 err = "MAC_ALGORITHM_SET_ERROR";
1276 if (EVP_PKEY_CTX_ctrl_str(genctx, "cipher", mdata->alg) <= 0)
1280 err = "MAC_KEY_SET_ERROR";
1281 if (EVP_PKEY_CTX_set_mac_key(genctx, mdata->key, mdata->key_len) <= 0)
1284 err = "MAC_KEY_GENERATE_ERROR";
1285 if (EVP_PKEY_keygen(genctx, &key) <= 0)
1287 if (mdata->type == EVP_PKEY_HMAC) {
1288 err = "MAC_ALGORITHM_SET_ERROR";
1289 md = EVP_get_digestbyname(mdata->alg);
1293 mctx = EVP_MD_CTX_new();
1296 err = "DIGESTSIGNINIT_ERROR";
1297 if (!EVP_DigestSignInit(mctx, &pctx, md, NULL, key))
1300 err = "DIGESTSIGNUPDATE_ERROR";
1301 if (!EVP_DigestSignUpdate(mctx, mdata->input, mdata->input_len))
1303 err = "DIGESTSIGNFINAL_LENGTH_ERROR";
1304 if (!EVP_DigestSignFinal(mctx, NULL, &mac_len))
1306 mac = OPENSSL_malloc(mac_len);
1308 fprintf(stderr, "Error allocating mac buffer!\n");
1311 if (!EVP_DigestSignFinal(mctx, mac, &mac_len))
1313 err = "MAC_LENGTH_MISMATCH";
1314 if (mac_len != mdata->output_len)
1316 err = "MAC_MISMATCH";
1317 if (check_output(t, mdata->output, mac, mac_len))
1321 EVP_MD_CTX_free(mctx);
1323 EVP_PKEY_CTX_free(genctx);
1329 static const struct evp_test_method mac_test_method = {
1338 * Public key operations. These are all very similar and can share
1339 * a lot of common code.
1343 /* Context for this operation */
1345 /* Key operation to perform */
1346 int (*keyop) (EVP_PKEY_CTX *ctx,
1347 unsigned char *sig, size_t *siglen,
1348 const unsigned char *tbs, size_t tbslen);
1350 unsigned char *input;
1352 /* Expected output */
1353 unsigned char *output;
1358 * Perform public key operation setup: lookup key, allocated ctx and call
1359 * the appropriate initialisation function
1361 static int pkey_test_init(struct evp_test *t, const char *name,
1363 int (*keyopinit) (EVP_PKEY_CTX *ctx),
1364 int (*keyop) (EVP_PKEY_CTX *ctx,
1365 unsigned char *sig, size_t *siglen,
1366 const unsigned char *tbs,
1370 struct pkey_data *kdata;
1371 EVP_PKEY *pkey = NULL;
1374 rv = find_key(&pkey, name, t->public);
1376 rv = find_key(&pkey, name, t->private);
1377 if (!rv || pkey == NULL) {
1382 kdata = OPENSSL_malloc(sizeof(*kdata));
1384 EVP_PKEY_free(pkey);
1388 kdata->input = NULL;
1389 kdata->output = NULL;
1390 kdata->keyop = keyop;
1392 kdata->ctx = EVP_PKEY_CTX_new(pkey, NULL);
1395 if (keyopinit(kdata->ctx) <= 0)
1396 t->err = "KEYOP_INIT_ERROR";
1400 static void pkey_test_cleanup(struct evp_test *t)
1402 struct pkey_data *kdata = t->data;
1404 OPENSSL_free(kdata->input);
1405 OPENSSL_free(kdata->output);
1406 EVP_PKEY_CTX_free(kdata->ctx);
1409 static int pkey_test_ctrl(struct evp_test *t, EVP_PKEY_CTX *pctx,
1415 tmpval = OPENSSL_strdup(value);
1418 p = strchr(tmpval, ':');
1421 rv = EVP_PKEY_CTX_ctrl_str(pctx, tmpval, p);
1423 t->err = "PKEY_CTRL_INVALID";
1425 } else if (p != NULL && rv <= 0) {
1426 /* If p has an OID and lookup fails assume disabled algorithm */
1427 int nid = OBJ_sn2nid(p);
1428 if (nid == NID_undef)
1429 nid = OBJ_ln2nid(p);
1430 if ((nid != NID_undef) && EVP_get_digestbynid(nid) == NULL &&
1431 EVP_get_cipherbynid(nid) == NULL) {
1435 t->err = "PKEY_CTRL_ERROR";
1439 OPENSSL_free(tmpval);
1443 static int pkey_test_parse(struct evp_test *t,
1444 const char *keyword, const char *value)
1446 struct pkey_data *kdata = t->data;
1447 if (strcmp(keyword, "Input") == 0)
1448 return test_bin(value, &kdata->input, &kdata->input_len);
1449 if (strcmp(keyword, "Output") == 0)
1450 return test_bin(value, &kdata->output, &kdata->output_len);
1451 if (strcmp(keyword, "Ctrl") == 0)
1452 return pkey_test_ctrl(t, kdata->ctx, value);
1456 static int pkey_test_run(struct evp_test *t)
1458 struct pkey_data *kdata = t->data;
1459 unsigned char *out = NULL;
1461 const char *err = "KEYOP_LENGTH_ERROR";
1462 if (kdata->keyop(kdata->ctx, NULL, &out_len, kdata->input,
1463 kdata->input_len) <= 0)
1465 out = OPENSSL_malloc(out_len);
1467 fprintf(stderr, "Error allocating output buffer!\n");
1470 err = "KEYOP_ERROR";
1472 (kdata->ctx, out, &out_len, kdata->input, kdata->input_len) <= 0)
1474 err = "KEYOP_LENGTH_MISMATCH";
1475 if (out_len != kdata->output_len)
1477 err = "KEYOP_MISMATCH";
1478 if (check_output(t, kdata->output, out, out_len))
1487 static int sign_test_init(struct evp_test *t, const char *name)
1489 return pkey_test_init(t, name, 0, EVP_PKEY_sign_init, EVP_PKEY_sign);
1492 static const struct evp_test_method psign_test_method = {
1500 static int verify_recover_test_init(struct evp_test *t, const char *name)
1502 return pkey_test_init(t, name, 1, EVP_PKEY_verify_recover_init,
1503 EVP_PKEY_verify_recover);
1506 static const struct evp_test_method pverify_recover_test_method = {
1508 verify_recover_test_init,
1514 static int decrypt_test_init(struct evp_test *t, const char *name)
1516 return pkey_test_init(t, name, 0, EVP_PKEY_decrypt_init,
1520 static const struct evp_test_method pdecrypt_test_method = {
1528 static int verify_test_init(struct evp_test *t, const char *name)
1530 return pkey_test_init(t, name, 1, EVP_PKEY_verify_init, 0);
1533 static int verify_test_run(struct evp_test *t)
1535 struct pkey_data *kdata = t->data;
1536 if (EVP_PKEY_verify(kdata->ctx, kdata->output, kdata->output_len,
1537 kdata->input, kdata->input_len) <= 0)
1538 t->err = "VERIFY_ERROR";
1542 static const struct evp_test_method pverify_test_method = {
1551 static int pderive_test_init(struct evp_test *t, const char *name)
1553 return pkey_test_init(t, name, 0, EVP_PKEY_derive_init, 0);
1556 static int pderive_test_parse(struct evp_test *t,
1557 const char *keyword, const char *value)
1559 struct pkey_data *kdata = t->data;
1561 if (strcmp(keyword, "PeerKey") == 0) {
1563 if (find_key(&peer, value, t->public) == 0)
1565 if (EVP_PKEY_derive_set_peer(kdata->ctx, peer) <= 0)
1569 if (strcmp(keyword, "SharedSecret") == 0)
1570 return test_bin(value, &kdata->output, &kdata->output_len);
1571 if (strcmp(keyword, "Ctrl") == 0)
1572 return pkey_test_ctrl(t, kdata->ctx, value);
1576 static int pderive_test_run(struct evp_test *t)
1578 struct pkey_data *kdata = t->data;
1579 unsigned char *out = NULL;
1581 const char *err = "INTERNAL_ERROR";
1583 out_len = kdata->output_len;
1584 out = OPENSSL_malloc(out_len);
1586 fprintf(stderr, "Error allocating output buffer!\n");
1589 err = "DERIVE_ERROR";
1590 if (EVP_PKEY_derive(kdata->ctx, out, &out_len) <= 0)
1592 err = "SHARED_SECRET_LENGTH_MISMATCH";
1593 if (out_len != kdata->output_len)
1595 err = "SHARED_SECRET_MISMATCH";
1596 if (check_output(t, kdata->output, out, out_len))
1605 static const struct evp_test_method pderive_test_method = {
1615 #define PBE_TYPE_SCRYPT 1
1616 #define PBE_TYPE_PBKDF2 2
1617 #define PBE_TYPE_PKCS12 3
1623 /* scrypt parameters */
1624 uint64_t N, r, p, maxmem;
1626 /* PKCS#12 parameters */
1631 unsigned char *pass;
1635 unsigned char *salt;
1638 /* Expected output */
1643 #ifndef OPENSSL_NO_SCRYPT
1644 static int scrypt_test_parse(struct evp_test *t,
1645 const char *keyword, const char *value)
1647 struct pbe_data *pdata = t->data;
1649 if (strcmp(keyword, "N") == 0)
1650 return test_uint64(value, &pdata->N);
1651 if (strcmp(keyword, "p") == 0)
1652 return test_uint64(value, &pdata->p);
1653 if (strcmp(keyword, "r") == 0)
1654 return test_uint64(value, &pdata->r);
1655 if (strcmp(keyword, "maxmem") == 0)
1656 return test_uint64(value, &pdata->maxmem);
1661 static int pbkdf2_test_parse(struct evp_test *t,
1662 const char *keyword, const char *value)
1664 struct pbe_data *pdata = t->data;
1666 if (strcmp(keyword, "iter") == 0) {
1667 pdata->iter = atoi(value);
1668 if (pdata->iter <= 0)
1672 if (strcmp(keyword, "MD") == 0) {
1673 pdata->md = EVP_get_digestbyname(value);
1674 if (pdata->md == NULL)
1681 static int pkcs12_test_parse(struct evp_test *t,
1682 const char *keyword, const char *value)
1684 struct pbe_data *pdata = t->data;
1686 if (strcmp(keyword, "id") == 0) {
1687 pdata->id = atoi(value);
1692 return pbkdf2_test_parse(t, keyword, value);
1695 static int pbe_test_init(struct evp_test *t, const char *alg)
1697 struct pbe_data *pdat;
1700 if (strcmp(alg, "scrypt") == 0) {
1701 #ifndef OPENSSL_NO_SCRYPT
1702 pbe_type = PBE_TYPE_SCRYPT;
1707 } else if (strcmp(alg, "pbkdf2") == 0) {
1708 pbe_type = PBE_TYPE_PBKDF2;
1709 } else if (strcmp(alg, "pkcs12") == 0) {
1710 pbe_type = PBE_TYPE_PKCS12;
1712 fprintf(stderr, "Unknown pbe algorithm %s\n", alg);
1714 pdat = OPENSSL_malloc(sizeof(*pdat));
1715 pdat->pbe_type = pbe_type;
1729 static void pbe_test_cleanup(struct evp_test *t)
1731 struct pbe_data *pdat = t->data;
1732 test_free(pdat->pass);
1733 test_free(pdat->salt);
1734 test_free(pdat->key);
1737 static int pbe_test_parse(struct evp_test *t,
1738 const char *keyword, const char *value)
1740 struct pbe_data *pdata = t->data;
1742 if (strcmp(keyword, "Password") == 0)
1743 return test_bin(value, &pdata->pass, &pdata->pass_len);
1744 if (strcmp(keyword, "Salt") == 0)
1745 return test_bin(value, &pdata->salt, &pdata->salt_len);
1746 if (strcmp(keyword, "Key") == 0)
1747 return test_bin(value, &pdata->key, &pdata->key_len);
1748 if (pdata->pbe_type == PBE_TYPE_PBKDF2)
1749 return pbkdf2_test_parse(t, keyword, value);
1750 else if (pdata->pbe_type == PBE_TYPE_PKCS12)
1751 return pkcs12_test_parse(t, keyword, value);
1752 #ifndef OPENSSL_NO_SCRYPT
1753 else if (pdata->pbe_type == PBE_TYPE_SCRYPT)
1754 return scrypt_test_parse(t, keyword, value);
1759 static int pbe_test_run(struct evp_test *t)
1761 struct pbe_data *pdata = t->data;
1762 const char *err = "INTERNAL_ERROR";
1765 key = OPENSSL_malloc(pdata->key_len);
1768 if (pdata->pbe_type == PBE_TYPE_PBKDF2) {
1769 err = "PBKDF2_ERROR";
1770 if (PKCS5_PBKDF2_HMAC((char *)pdata->pass, pdata->pass_len,
1771 pdata->salt, pdata->salt_len,
1772 pdata->iter, pdata->md,
1773 pdata->key_len, key) == 0)
1775 #ifndef OPENSSL_NO_SCRYPT
1776 } else if (pdata->pbe_type == PBE_TYPE_SCRYPT) {
1777 err = "SCRYPT_ERROR";
1778 if (EVP_PBE_scrypt((const char *)pdata->pass, pdata->pass_len,
1779 pdata->salt, pdata->salt_len,
1780 pdata->N, pdata->r, pdata->p, pdata->maxmem,
1781 key, pdata->key_len) == 0)
1784 } else if (pdata->pbe_type == PBE_TYPE_PKCS12) {
1785 err = "PKCS12_ERROR";
1786 if (PKCS12_key_gen_uni(pdata->pass, pdata->pass_len,
1787 pdata->salt, pdata->salt_len,
1788 pdata->id, pdata->iter, pdata->key_len,
1789 key, pdata->md) == 0)
1792 err = "KEY_MISMATCH";
1793 if (check_output(t, pdata->key, key, pdata->key_len))
1802 static const struct evp_test_method pbe_test_method = {
1813 BASE64_CANONICAL_ENCODING = 0,
1814 BASE64_VALID_ENCODING = 1,
1815 BASE64_INVALID_ENCODING = 2
1816 } base64_encoding_type;
1818 struct encode_data {
1819 /* Input to encoding */
1820 unsigned char *input;
1822 /* Expected output */
1823 unsigned char *output;
1825 base64_encoding_type encoding;
1828 static int encode_test_init(struct evp_test *t, const char *encoding)
1830 struct encode_data *edata = OPENSSL_zalloc(sizeof(*edata));
1832 if (strcmp(encoding, "canonical") == 0) {
1833 edata->encoding = BASE64_CANONICAL_ENCODING;
1834 } else if (strcmp(encoding, "valid") == 0) {
1835 edata->encoding = BASE64_VALID_ENCODING;
1836 } else if (strcmp(encoding, "invalid") == 0) {
1837 edata->encoding = BASE64_INVALID_ENCODING;
1838 t->expected_err = OPENSSL_strdup("DECODE_ERROR");
1839 if (t->expected_err == NULL)
1842 fprintf(stderr, "Bad encoding: %s. Should be one of "
1843 "{canonical, valid, invalid}\n", encoding);
1850 static void encode_test_cleanup(struct evp_test *t)
1852 struct encode_data *edata = t->data;
1853 test_free(edata->input);
1854 test_free(edata->output);
1855 memset(edata, 0, sizeof(*edata));
1858 static int encode_test_parse(struct evp_test *t,
1859 const char *keyword, const char *value)
1861 struct encode_data *edata = t->data;
1862 if (strcmp(keyword, "Input") == 0)
1863 return test_bin(value, &edata->input, &edata->input_len);
1864 if (strcmp(keyword, "Output") == 0)
1865 return test_bin(value, &edata->output, &edata->output_len);
1869 static int encode_test_run(struct evp_test *t)
1871 struct encode_data *edata = t->data;
1872 unsigned char *encode_out = NULL, *decode_out = NULL;
1873 int output_len, chunk_len;
1874 const char *err = "INTERNAL_ERROR";
1875 EVP_ENCODE_CTX *decode_ctx = EVP_ENCODE_CTX_new();
1877 if (decode_ctx == NULL)
1880 if (edata->encoding == BASE64_CANONICAL_ENCODING) {
1881 EVP_ENCODE_CTX *encode_ctx = EVP_ENCODE_CTX_new();
1882 if (encode_ctx == NULL)
1884 encode_out = OPENSSL_malloc(EVP_ENCODE_LENGTH(edata->input_len));
1885 if (encode_out == NULL)
1888 EVP_EncodeInit(encode_ctx);
1889 EVP_EncodeUpdate(encode_ctx, encode_out, &chunk_len,
1890 edata->input, edata->input_len);
1891 output_len = chunk_len;
1893 EVP_EncodeFinal(encode_ctx, encode_out + chunk_len, &chunk_len);
1894 output_len += chunk_len;
1896 EVP_ENCODE_CTX_free(encode_ctx);
1898 if (check_var_length_output(t, edata->output, edata->output_len,
1899 encode_out, output_len)) {
1900 err = "BAD_ENCODING";
1905 decode_out = OPENSSL_malloc(EVP_DECODE_LENGTH(edata->output_len));
1906 if (decode_out == NULL)
1909 EVP_DecodeInit(decode_ctx);
1910 if (EVP_DecodeUpdate(decode_ctx, decode_out, &chunk_len, edata->output,
1911 edata->output_len) < 0) {
1912 err = "DECODE_ERROR";
1915 output_len = chunk_len;
1917 if (EVP_DecodeFinal(decode_ctx, decode_out + chunk_len, &chunk_len) != 1) {
1918 err = "DECODE_ERROR";
1921 output_len += chunk_len;
1923 if (edata->encoding != BASE64_INVALID_ENCODING &&
1924 check_var_length_output(t, edata->input, edata->input_len,
1925 decode_out, output_len)) {
1926 err = "BAD_DECODING";
1933 OPENSSL_free(encode_out);
1934 OPENSSL_free(decode_out);
1935 EVP_ENCODE_CTX_free(decode_ctx);
1939 static const struct evp_test_method encode_test_method = {
1942 encode_test_cleanup,
1947 /* KDF operations */
1950 /* Context for this operation */
1952 /* Expected output */
1953 unsigned char *output;
1958 * Perform public key operation setup: lookup key, allocated ctx and call
1959 * the appropriate initialisation function
1961 static int kdf_test_init(struct evp_test *t, const char *name)
1963 struct kdf_data *kdata;
1965 kdata = OPENSSL_malloc(sizeof(*kdata));
1969 kdata->output = NULL;
1971 kdata->ctx = EVP_PKEY_CTX_new_id(OBJ_sn2nid(name), NULL);
1972 if (kdata->ctx == NULL)
1974 if (EVP_PKEY_derive_init(kdata->ctx) <= 0)
1979 static void kdf_test_cleanup(struct evp_test *t)
1981 struct kdf_data *kdata = t->data;
1982 OPENSSL_free(kdata->output);
1983 EVP_PKEY_CTX_free(kdata->ctx);
1986 static int kdf_test_parse(struct evp_test *t,
1987 const char *keyword, const char *value)
1989 struct kdf_data *kdata = t->data;
1990 if (strcmp(keyword, "Output") == 0)
1991 return test_bin(value, &kdata->output, &kdata->output_len);
1992 if (strncmp(keyword, "Ctrl", 4) == 0)
1993 return pkey_test_ctrl(t, kdata->ctx, value);
1997 static int kdf_test_run(struct evp_test *t)
1999 struct kdf_data *kdata = t->data;
2000 unsigned char *out = NULL;
2001 size_t out_len = kdata->output_len;
2002 const char *err = "INTERNAL_ERROR";
2003 out = OPENSSL_malloc(out_len);
2005 fprintf(stderr, "Error allocating output buffer!\n");
2008 err = "KDF_DERIVE_ERROR";
2009 if (EVP_PKEY_derive(kdata->ctx, out, &out_len) <= 0)
2011 err = "KDF_LENGTH_MISMATCH";
2012 if (out_len != kdata->output_len)
2014 err = "KDF_MISMATCH";
2015 if (check_output(t, kdata->output, out, out_len))
2024 static const struct evp_test_method kdf_test_method = {