Laurence Lundblade | affd65a | 2018-12-18 10:50:48 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * t_cose_common.h |
| 3 | * |
| 4 | * Copyright 2019, Laurence Lundblade |
| 5 | * |
| 6 | * SPDX-License-Identifier: BSD-3-Clause |
| 7 | * |
| 8 | * See BSD-3-Clause license in README.mdE. |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | #ifndef __T_COSE_COMMON_H__ |
| 13 | #define __T_COSE_COMMON_H__ |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * \file t_cose_common.h |
| 18 | * |
| 19 | * \brief Defines common to all public t_cose interfaces. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | /* Private value. Intentionally not documented for Doxygen. |
| 25 | * This is the size allocated for the encoded protected headers. It |
| 26 | * needs to be big enough for make_protected_header() to succeed. It |
| 27 | * currently sized for one header with an algorithm ID up to 32 bits |
| 28 | * long -- one byte for the wrapping map, one byte for the label, 5 |
| 29 | * bytes for the ID. If this is made accidentially too small, QCBOR will |
| 30 | * only return an error, and not overrun any buffers. |
| 31 | * |
| 32 | * 9 extra bytes are added, rounding it up to 16 total, in case some |
| 33 | * other protected header is to be added. |
| 34 | */ |
| 35 | #define T_COSE_SIGN1_MAX_PROT_HEADER (1+1+5+9) |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Error codes return by t_cose. |
| 40 | * |
| 41 | * Do not reorder these. It is OK to add |
| 42 | * new ones at the end. |
| 43 | */ |
| 44 | enum t_cose_err_t { |
| 45 | /** |
| 46 | * Operation completed successfully |
| 47 | */ |
| 48 | T_COSE_SUCCESS = 0, |
| 49 | /** |
| 50 | * The requested signing algorithm is not supported. |
| 51 | */ |
| 52 | T_COSE_ERR_UNSUPPORTED_SIGNING_ALG, |
| 53 | /** |
| 54 | * Error constructing the protected headers. |
| 55 | */ |
| 56 | T_COSE_ERR_PROTECTED_HEADERS, |
| 57 | /** |
| 58 | * The hash algorithm needed is not supported. Note that the |
| 59 | * signing algorithm identifier usually identifies the hash |
| 60 | * algorithm. |
| 61 | */ |
| 62 | T_COSE_ERR_UNSUPPORTED_HASH, |
| 63 | /** |
| 64 | * Some system failure when running the hash algorithm. |
| 65 | */ |
| 66 | T_COSE_ERR_HASH_GENERAL_FAIL, |
| 67 | /** |
| 68 | * The buffer to receive a hash result is too small. |
| 69 | */ |
| 70 | T_COSE_ERR_HASH_BUFFER_SIZE, |
| 71 | /** |
| 72 | * The buffer to receive result of a signing operation is too |
| 73 | * small. |
| 74 | */ |
| 75 | T_COSE_ERR_SIG_BUFFER_SIZE, |
| 76 | /** |
| 77 | * The buffer to receive to receive a key is too small. |
| 78 | */ |
| 79 | T_COSE_ERR_KEY_BUFFER_SIZE, |
| 80 | /** |
| 81 | * When verifying a \c COSE_Sign1, something is wrong with the |
| 82 | * format of the CBOR. For example, it is missing something like |
| 83 | * the payload. |
| 84 | */ |
| 85 | T_COSE_ERR_SIGN1_FORMAT, |
| 86 | /** |
| 87 | * When decoding some CBOR like a \c COSE_Sign1, the CBOR was not |
| 88 | * well-formed. Most likely what was supposed to be CBOR was is |
| 89 | * either not or it has been corrupted. |
| 90 | */ |
| 91 | T_COSE_ERR_CBOR_NOT_WELL_FORMED, |
| 92 | /** |
| 93 | * No algorithm ID was found when one is needed. For example, when |
| 94 | * verifying a \c COSE_Sign1. |
| 95 | */ |
| 96 | T_COSE_ERR_NO_ALG_ID, |
| 97 | /** |
| 98 | * No key ID was found when one is needed. For example, when |
| 99 | * verifying a \c COSE_Sign1. |
| 100 | */ |
| 101 | T_COSE_ERR_NO_KID, |
| 102 | /** |
| 103 | * Signature verification failed. For example, the cryptographic |
| 104 | * operations completed successfully but hash wasn't as expected. |
| 105 | */ |
| 106 | T_COSE_ERR_SIG_VERIFY, |
| 107 | /** |
| 108 | * Verification of a short-circuit signature failed. |
| 109 | */ |
| 110 | T_COSE_ERR_BAD_SHORT_CIRCUIT_KID, |
| 111 | /** |
| 112 | * Some (unspecified) argument was not valid. |
| 113 | */ |
| 114 | T_COSE_ERR_INVALID_ARGUMENT, |
| 115 | /** |
| 116 | * Out of heap memory. |
| 117 | */ |
| 118 | T_COSE_ERR_INSUFFICIENT_MEMORY, |
| 119 | /** |
| 120 | * General unspecific failure. |
| 121 | */ |
| 122 | T_COSE_ERR_FAIL, |
| 123 | /** |
| 124 | * Equivalent to \c PSA_ERROR_TAMPERING_DETECTED. |
| 125 | */ |
| 126 | T_COSE_ERR_TAMPERING_DETECTED, |
| 127 | /** |
| 128 | * The key identified by a key slot of a key ID was not found. |
| 129 | */ |
| 130 | T_COSE_ERR_UNKNOWN_KEY, |
| 131 | /** |
| 132 | * The key was found, but it was the wrong type for the operation. |
| 133 | */ |
| 134 | T_COSE_ERR_WRONG_TYPE_OF_KEY, |
| 135 | /** |
| 136 | * Error constructing the \c Sig_structure when signing or verify. |
| 137 | */ |
| 138 | T_COSE_ERR_SIG_STRUCT, |
| 139 | /** |
| 140 | * Signature was short-circuit. THe option to allow verification |
| 141 | * of short-circuit signatures was not set |
| 142 | */ |
| 143 | T_COSE_ERR_SHORT_CIRCUIT_SIG |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | |
| 148 | #endif /* __T_COSE_COMMON_H__ */ |