t_cose
Loading...
Searching...
No Matches
t_cose_sign1_verify.h
Go to the documentation of this file.
1/*
2 * t_cose_sign1_verify.h
3 *
4 * Copyright 2019-2021, Laurence Lundblade
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 * See BSD-3-Clause license in README.md
9 */
10
11
12#ifndef __T_COSE_SIGN1_VERIFY_H__
13#define __T_COSE_SIGN1_VERIFY_H__
14
15#include <stdint.h>
16#include <stdbool.h>
17#include "t_cose/q_useful_buf.h"
19#include "qcbor/qcbor_common.h"
20
21#ifdef __cplusplus
22extern "C" {
23#if 0
24} /* Keep editor indention formatting happy */
25#endif
26#endif
27
28#ifndef QCBOR_SPIFFY_DECODE
29#error This version of t_cose requires a version of QCBOR that supports spiffy decode
30#endif
31
79
82 struct q_useful_buf_c kid;
83
86 struct q_useful_buf_c iv;
87
90 struct q_useful_buf_c partial_iv;
91
92#ifndef T_COSE_DISABLE_CONTENT_TYPE
95 struct q_useful_buf_c content_type_tstr;
96
101#endif /* T_COSE_DISABLE_CONTENT_TYPE */
102};
103
104
109#define T_COSE_UNSET_ALGORITHM_ID 0
110
111
112
113
121#define T_COSE_OPT_ALLOW_SHORT_CIRCUIT 0x00000001
122
123
131#define T_COSE_OPT_REQUIRE_KID 0x00000002
132
133
148#define T_COSE_OPT_TAG_REQUIRED 0x00000004
149
150
160#define T_COSE_OPT_TAG_PROHIBITED 0x00000010
161
162
177#define T_COSE_OPT_DECODE_ONLY 0x00000008
178
179
188#define T_COSE_OPT_UNKNOWN_CRIT_ALLOWED 0x00000020
189
190
197#define T_COSE_MAX_TAGS_TO_RETURN 4
198
199
206 /* Private data structure */
207 struct t_cose_key verification_key;
208 uint32_t option_flags;
209 uint64_t auTags[T_COSE_MAX_TAGS_TO_RETURN];
210
211#ifndef T_COSE_DISABLE_EDDSA
217 struct q_useful_buf auxiliary_buffer;
218
219 /* The size of the serialized Sig_Structure used in the last
220 * verification. This can be used by the user to determine a
221 * suitable auxiliary buffer size.
222 */
223 size_t auxiliary_buffer_size;
224#endif
225};
226
227
236static void
238 uint32_t option_flags);
239
240
289static void
291 struct t_cose_key verification_key);
292
293
316static void
318 struct q_useful_buf auxiliary_buffer);
319
339static size_t
341
391static enum t_cose_err_t
393 struct q_useful_buf_c sign1,
394 struct q_useful_buf_c *payload,
395 struct t_cose_parameters *parameters);
396
397
425static enum t_cose_err_t
427 struct q_useful_buf_c sign1,
428 struct q_useful_buf_c aad,
429 struct q_useful_buf_c *payload,
430 struct t_cose_parameters *parameters);
431
432
457static inline enum t_cose_err_t
459 struct q_useful_buf_c cose_sign1,
460 struct q_useful_buf_c aad,
461 struct q_useful_buf_c detached_payload,
462 struct t_cose_parameters *parameters);
463
464
483static uint64_t
485 size_t n);
486
487
488
489
490/* ------------------------------------------------------------------------
491 * Inline implementations of public functions defined above.
492 */
493static inline void
495 uint32_t option_flags)
496{
497 memset(me, 0, sizeof(*me));
498 me->option_flags = option_flags;
499
500#ifndef T_COSE_DISABLE_EDDSA
501 /* Start with large (but NULL) auxiliary buffer. If EdDSA is used,
502 * the Sig_Structure data will be serialized here.
503 */
504 me->auxiliary_buffer.len = SIZE_MAX;
505#endif
506}
507
508
509static inline void
511 struct t_cose_key verification_key)
512{
513 me->verification_key = verification_key;
514}
515
516static inline void
518 struct q_useful_buf auxiliary_buffer)
519{
520#ifndef T_COSE_DISABLE_EDDSA
521 me->auxiliary_buffer = auxiliary_buffer;
522#else
523 (void)me;
524 (void)auxiliary_buffer;
525#endif
526}
527
528static inline size_t
530{
531#ifndef T_COSE_DISABLE_EDDSA
532 return me->auxiliary_buffer_size;
533#else
534 /* If EdDSA is disabled we don't ever need an auxiliary buffer. */
535 (void)me;
536 return 0;
537#endif
538}
539
540
541static inline uint64_t
543 size_t n)
544{
546 return CBOR_TAG_INVALID64;
547 }
548 return context->auTags[n];
549}
550
551
570enum t_cose_err_t
572 struct q_useful_buf_c sign1,
573 struct q_useful_buf_c aad,
574 struct q_useful_buf_c *payload,
575 struct t_cose_parameters *parameters,
576 bool is_detached);
577
578
579static inline enum t_cose_err_t
581 struct q_useful_buf_c sign1,
582 struct q_useful_buf_c *payload,
583 struct t_cose_parameters *parameters)
584{
586 sign1,
587 NULL_Q_USEFUL_BUF_C,
588 payload,
589 parameters,
590 false);
591}
592
593
594static inline enum t_cose_err_t
596 struct q_useful_buf_c cose_sign1,
597 struct q_useful_buf_c aad,
598 struct q_useful_buf_c *payload,
599 struct t_cose_parameters *parameters)
600{
602 cose_sign1,
603 aad,
604 payload,
605 parameters,
606 false);
607}
608
609
610static inline enum t_cose_err_t
612 struct q_useful_buf_c cose_sign1,
613 struct q_useful_buf_c aad,
614 struct q_useful_buf_c detached_payload,
615 struct t_cose_parameters *parameters)
616{
618 cose_sign1,
619 aad,
620 &detached_payload,
621 parameters,
622 true);
623}
624
625#ifdef __cplusplus
626}
627#endif
628
629#endif /* __T_COSE_SIGN1_VERIFY_H__ */
This is a TF-M coding style version of UsefulBuf. See UsefulBuf for documentation of these functions.
Definition t_cose_common.h:186
Definition t_cose_sign1_verify.h:71
struct q_useful_buf_c iv
Definition t_cose_sign1_verify.h:86
struct q_useful_buf_c kid
Definition t_cose_sign1_verify.h:82
int32_t cose_algorithm_id
Definition t_cose_sign1_verify.h:78
struct q_useful_buf_c partial_iv
Definition t_cose_sign1_verify.h:90
uint32_t content_type_uint
Definition t_cose_sign1_verify.h:100
struct q_useful_buf_c content_type_tstr
Definition t_cose_sign1_verify.h:95
Definition t_cose_sign1_verify.h:205
struct q_useful_buf auxiliary_buffer
Definition t_cose_sign1_verify.h:217
This file contains definitions common to all public t_cose interfaces.
t_cose_err_t
Definition t_cose_common.h:250
static size_t t_cose_sign1_verify_auxiliary_buffer_size(struct t_cose_sign1_verify_ctx *context)
Get the required auxiliary buffer size for the most recent verification operation.
Definition t_cose_sign1_verify.h:529
static enum t_cose_err_t t_cose_sign1_verify_detached(struct t_cose_sign1_verify_ctx *context, struct q_useful_buf_c cose_sign1, struct q_useful_buf_c aad, struct q_useful_buf_c detached_payload, struct t_cose_parameters *parameters)
Verify a COSE_Sign1 with detached payload.
Definition t_cose_sign1_verify.h:611
#define T_COSE_MAX_TAGS_TO_RETURN
Definition t_cose_sign1_verify.h:197
static uint64_t t_cose_sign1_get_nth_tag(const struct t_cose_sign1_verify_ctx *context, size_t n)
Return unprocessed tags from most recent signature verify.
Definition t_cose_sign1_verify.h:542
static void t_cose_sign1_verify_init(struct t_cose_sign1_verify_ctx *context, uint32_t option_flags)
Initialize for COSE_Sign1 message verification.
Definition t_cose_sign1_verify.h:494
static void t_cose_sign1_set_verification_key(struct t_cose_sign1_verify_ctx *context, struct t_cose_key verification_key)
Set key for COSE_Sign1 message verification.
Definition t_cose_sign1_verify.h:510
static enum t_cose_err_t t_cose_sign1_verify(struct t_cose_sign1_verify_ctx *context, struct q_useful_buf_c sign1, struct q_useful_buf_c *payload, struct t_cose_parameters *parameters)
Verify a COSE_Sign1.
Definition t_cose_sign1_verify.h:580
static enum t_cose_err_t t_cose_sign1_verify_aad(struct t_cose_sign1_verify_ctx *context, struct q_useful_buf_c sign1, struct q_useful_buf_c aad, struct q_useful_buf_c *payload, struct t_cose_parameters *parameters)
Verify a COSE_Sign1 with Additional Authenticated Data.
Definition t_cose_sign1_verify.h:595
enum t_cose_err_t t_cose_sign1_verify_internal(struct t_cose_sign1_verify_ctx *me, struct q_useful_buf_c sign1, struct q_useful_buf_c aad, struct q_useful_buf_c *payload, struct t_cose_parameters *parameters, bool is_detached)
Semi-private function to verify a COSE_Sign1.
static void t_cose_sign1_verify_set_auxiliary_buffer(struct t_cose_sign1_verify_ctx *context, struct q_useful_buf auxiliary_buffer)
Configure a buffer used to serialize the Sig_Structure.
Definition t_cose_sign1_verify.h:517