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