2 * Copyright 2019 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
10 #include <openssl/core_names.h>
11 #include <openssl/params.h>
12 #include "self_test.h"
14 static void self_test_event_setparams(OSSL_ST_EVENT *ev)
20 OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_PHASE,
21 (char *)ev->phase, 0);
23 OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_TYPE,
26 OSSL_PARAM_construct_utf8_string(OSSL_PROV_PARAM_SELF_TEST_DESC,
29 ev->params[n++] = OSSL_PARAM_construct_end();
32 void SELF_TEST_EVENT_init(OSSL_ST_EVENT *ev, OSSL_CALLBACK *cb, void *cbarg)
42 self_test_event_setparams(ev);
45 /* Can be used during application testing to log that a test has started. */
46 void SELF_TEST_EVENT_onbegin(OSSL_ST_EVENT *ev, const char *type,
49 if (ev != NULL && ev->cb != NULL) {
50 ev->phase = OSSL_SELF_TEST_PHASE_START;
53 self_test_event_setparams(ev);
54 (void)ev->cb(ev->params, ev->cb_arg);
59 * Can be used during application testing to log that a test has either
62 void SELF_TEST_EVENT_onend(OSSL_ST_EVENT *ev, int ret)
64 if (ev != NULL && ev->cb != NULL) {
66 (ret == 1 ? OSSL_SELF_TEST_PHASE_PASS : OSSL_SELF_TEST_PHASE_FAIL);
67 self_test_event_setparams(ev);
68 (void)ev->cb(ev->params, ev->cb_arg);
70 ev->phase = OSSL_SELF_TEST_PHASE_NONE;
71 ev->type = OSSL_SELF_TEST_TYPE_NONE;
72 ev->desc = OSSL_SELF_TEST_DESC_NONE;
77 * Used for failure testing.
79 * Call the applications SELF_TEST_cb() if it exists.
80 * If the application callback decides to return 0 then the first byte of 'bytes'
81 * is modified (corrupted). This is used to modify output signatures or
82 * ciphertext before they are verified or decrypted.
84 void SELF_TEST_EVENT_oncorrupt_byte(OSSL_ST_EVENT *ev, unsigned char *bytes)
86 if (ev != NULL && ev->cb != NULL) {
87 ev->phase = OSSL_SELF_TEST_PHASE_CORRUPT;
88 self_test_event_setparams(ev);
89 if (!ev->cb(ev->params, ev->cb_arg))