1 /* 2 * t_cose_test.h 3 * 4 * Copyright 2019-2020, Laurence Lundblade 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 * 8 * See BSD-3-Clause license in README.md 9 */ 10 11 #ifndef t_cose_test_h 12 #define t_cose_test_h 13 14 #include <stdint.h> 15 16 /** 17 * \file t_cose_test.h 18 * 19 * \brief Entry points for the basic t_cose_tests. 20 * 21 * These tests can be performed without any crypto library such as OpenSSL 22 * integrated with t_cose. 23 */ 24 25 26 /** 27 * \brief Minimal message creation test using a short-circuit signature. 28 * 29 * \return non-zero on failure. 30 * 31 * This test makes a simple COSE_Sign1 and verify it. It uses 32 * short-circuit signatures so no keys or even integration with public 33 * key crypto is necessary. 34 */ 35 int_fast32_t short_circuit_self_test(void); 36 37 38 /** 39 * \brief Test where payload bytes are corrupted and sig fails. 40 * 41 * \return non-zero on failure. 42 * 43 * This test makes a simple COSE_Sign1 modifies the payload and sees that 44 * verification fails. It uses short-circuit signatures so no keys or 45 * even integration with public key crypto is necessary. 46 */ 47 int_fast32_t short_circuit_verify_fail_test(void); 48 49 50 /** 51 * \brief Tests error condidtions for creating COSE_Sign1. 52 * 53 * \return non-zero on failure. 54 * 55 * It uses short-circuit signatures so no keys or even integration 56 * with public key crypto is necessary. 57 */ 58 int_fast32_t short_circuit_signing_error_conditions_test(void); 59 60 61 /* Make a CWT and see that it compares to the sample in the CWT RFC 62 */ 63 int_fast32_t short_circuit_make_cwt_test(void); 64 65 66 /* 67 * Test the decode only mode, the mode where the 68 * headers are returned, but the signature is no 69 * verified. 70 */ 71 int_fast32_t short_circuit_decode_only_test(void); 72 73 74 /* 75 - protected header parameters not well formed CBOR 76 - unprotected header parameters not well formed CBOR 77 - unknown algorithm ID 78 - No algorithm ID parameter 79 80 */ 81 int_fast32_t bad_parameters_test(void); 82 83 84 /* Test that makes a CWT (CBOR Web Token) 85 */ 86 int_fast32_t cose_example_test(void); 87 88 89 /* 90 Various tests involving the crit parameter. 91 */ 92 int_fast32_t crit_parameters_test(void); 93 94 95 /* 96 Check that all types of headers are correctly returned. 97 */ 98 int_fast32_t all_header_parameters_test(void); 99 100 /* 101 * Check that setting the content type works 102 */ 103 int_fast32_t content_type_test(void); 104 105 106 /* 107 * Check that setting the content type works 108 */ 109 int_fast32_t sign1_structure_decode_test(void); 110 111 112 #ifdef T_COSE_ENABLE_HASH_FAIL_TEST 113 /* 114 * This forces / simulates failures in the hash algorithm implementation 115 * to test t_cose's handling of those condidtions. This test is off 116 * by default because it needs a hacked version of a hash algorithm. 117 * It is very hard to get hash algorithms to fail, so this hacked 118 * version is necessary. This test will not run correctly with 119 * OpenSSL or PSA hashes because they aren't (and shouldn't be) hacked. 120 * It works only with the b_con hash bundled and not intended for 121 * commercial use (though it is a perfectly fine implementation). 122 */ 123 int_fast32_t short_circuit_hash_fail_test(void); 124 125 #endif /* T_COSE_ENABLE_HASH_FAIL_TEST*/ 126 127 128 #endif /* t_cose_test_h */ 129