libcoap 4.3.5-develop-5347a62
Loading...
Searching...
No Matches
oscore_cose.c
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3/*
4 * Copyright (c) 2018, SICS, RISE AB
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Institute nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
45
47
48#if COAP_OSCORE_SUPPORT
49
50#include "stdio.h"
51
52struct cose_curve_desc {
53 const char *name;
54 cose_curve_t id;
55};
56
57static struct cose_curve_desc curve_mapping[] = {
58 { "P-256", COSE_CURVE_P_256 },
59 { "X25519", COSE_CURVE_X25519 },
60 { "X448", COSE_CURVE_X448 },
61 { "Ed25519", COSE_CURVE_ED25519 },
62 { "Ed448", COSE_CURVE_ED448 },
63 { "secp256k1", COSE_CURVE_SECP256K1 },
64};
65
66const char *
67cose_get_curve_name(cose_curve_t id, char *buffer, size_t buflen) {
68 for (size_t i = 0; i < sizeof(curve_mapping)/sizeof(curve_mapping[0]); i++) {
69 if (id == curve_mapping[i].id) {
70 snprintf(buffer, buflen, "%s (%d)", curve_mapping[i].name, id);
71 return buffer;
72 }
73 }
74 snprintf(buffer, buflen, "curve Fix me (%d)", id);
75 return buffer;
76}
77
79cose_get_curve_id(const char *name) {
80 for (size_t i = 0; i < sizeof(curve_mapping)/sizeof(curve_mapping[0]); i++) {
81 if (strcmp(name, curve_mapping[i].name) == 0)
82 return curve_mapping[i].id;
83 }
84 return 0;
85}
86
87struct cose_curve_type {
88 cose_curve_t curve;
89 cose_key_type_t type;
90};
91
92static struct cose_curve_type curve_type[] = {
99};
100
103 for (size_t i = 0; i < sizeof(curve_type)/sizeof(curve_type[0]); i++) {
104 if (curve_type[i].curve == curve)
105 return curve_type[i].type;
106 }
107 return COSE_KTY_UNKNOWN;
108}
109
110struct cose_curve_bin_oid {
111 cose_curve_t curve;
112 coap_bin_const_t bin_oid;
113};
114
115static u_char Ed25519[] = { 0x2b, 0x65, 0x70 };
116static struct cose_curve_bin_oid curve_bin_oid[] = {
117 { COSE_CURVE_ED25519, {3, Ed25519 } },
118};
119
122 for (size_t i = 0; i < sizeof(curve_bin_oid)/sizeof(curve_bin_oid[0]); i++) {
123 if (curve_bin_oid[i].curve == curve)
124 return &curve_bin_oid[i].bin_oid;
125 }
126 return NULL;
127}
128
129struct cose_alg_desc {
130 const char *name;
131 cose_alg_t id;
132};
133
134static struct cose_alg_desc alg_mapping[] = {
135 { "ES256K", COSE_ALGORITHM_ES256K },
136 { "SHA-512", COSE_ALGORITHM_SHA_512 },
137 { "SHA-384", COSE_ALGORITHM_SHA_384 },
138 { "ES512", COSE_ALGORITHM_ES512 },
139 { "ES384", COSE_ALGORITHM_ES384 },
140 { "ECDH-SS + HKDF-256", COSE_ALGORITHM_ECDH_SS_HKDF_256 },
141 { "SHA-512/256", COSE_ALGORITHM_SHA_512_256 },
142 { "SHA-256", COSE_ALGORITHM_SHA_256_256 },
143 { "SHA-256/64", COSE_ALGORITHM_SHA_256_64 },
144 { "SHA-1", COSE_ALGORITHM_SHA_1 },
145 { "direct+HKDF-SHA-512", COSE_ALGORITHM_HKDF_SHA_512 },
146 { "direct+HKDF-SHA-256", COSE_ALGORITHM_HKDF_SHA_256 },
147 { "EdDSA", COSE_ALGORITHM_EDDSA },
148 { "ES256", COSE_ALGORITHM_ES256 },
149 { "HMAC 256/64", COSE_ALGORITHM_HMAC256_64 },
150 { "HMAC 256/256", COSE_ALGORITHM_HMAC256_256 },
151 { "HMAC 384/384", COSE_ALGORITHM_HMAC384_384 },
152 { "HMAC 512/512", COSE_ALGORITHM_HMAC512_512 },
153 { "AES-CCM-16-64-128", COSE_ALGORITHM_AES_CCM_16_64_128 },
154 { "AES-CCM-16-64-256", COSE_ALGORITHM_AES_CCM_16_64_256 },
155 { "AES-CCM-64-64-128", COSE_ALGORITHM_AES_CCM_64_64_128 },
156 { "AES-CCM-64-64-256", COSE_ALGORITHM_AES_CCM_64_64_256 },
157 { "ChaCha20/Poly1305", COSE_ALGORITHM_CHACHA20_P1035 },
158 { "AES-CCM-16-128-128", COSE_ALGORITHM_AES_CCM_16_128_128 },
159 { "AES-CCM-16-128-256", COSE_ALGORITHM_AES_CCM_16_128_256 },
160 { "AES-CCM-64-128-128", COSE_ALGORITHM_AES_CCM_64_128_128 },
161 { "AES-CCM-64-128-256", COSE_ALGORITHM_AES_CCM_64_128_256 },
162};
163
164const char *
165cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen) {
166 for (size_t i = 0; i < sizeof(alg_mapping)/sizeof(alg_mapping[0]); i++) {
167 if (id == alg_mapping[i].id) {
168 snprintf(buffer, buflen, "%s (%d)", alg_mapping[i].name, id);
169 return buffer;
170 }
171 }
172 snprintf(buffer, buflen, "alg Fix me (%d)", id);
173 return buffer;
174}
175
177cose_get_alg_id(const char *name) {
178 for (size_t i = 0; i < sizeof(alg_mapping)/sizeof(alg_mapping[0]); i++) {
179 if (strcmp(name, alg_mapping[i].name) == 0)
180 return alg_mapping[i].id;
181 }
182 return 0;
183}
184
185struct cose_hkdf_alg_desc {
186 const char *name;
188};
189
190static struct cose_hkdf_alg_desc hkdf_alg_mapping[] = {
191 { "direct+HKDF-SHA-512", COSE_HKDF_ALG_HKDF_SHA_512 },
192 { "direct+HKDF-SHA-256", COSE_HKDF_ALG_HKDF_SHA_256 },
193};
194
195const char *
196cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen) {
197 for (size_t i = 0; i < sizeof(hkdf_alg_mapping)/sizeof(hkdf_alg_mapping[0]); i++) {
198 if (id == hkdf_alg_mapping[i].id) {
199 snprintf(buffer, buflen, "%s (%d)", hkdf_alg_mapping[i].name, id);
200 return buffer;
201 }
202 }
203 snprintf(buffer, buflen, "hkdf_alg Fix me (%d)", id);
204 return buffer;
205}
206
207/*
208 * The struct hmac_algs and the function cose_get_hmac_alg_for_hkdf() are
209 * used to determine which hmac type to use for the appropriate hkdf
210 */
211static struct hkdf_hmac_algs {
212 cose_hkdf_alg_t hkdf_alg;
213 cose_hmac_alg_t hmac_alg;
214} hkdf_hmacs[] = {
217};
218
219/*
220 * return 0 fail
221 * 1 OK
222 */
223int
225 size_t idx;
226
227 for (idx = 0; idx < sizeof(hkdf_hmacs) / sizeof(struct hkdf_hmac_algs);
228 idx++) {
229 if (hkdf_hmacs[idx].hkdf_alg == hkdf_alg) {
230 *hmac_alg = hkdf_hmacs[idx].hmac_alg;
231 return 1;
232 }
233 }
234 coap_log_debug("cose_get_hmac_alg_for_hkdf: COSE HKDF %d not supported\n",
235 hkdf_alg);
236 return 0;
237}
238
239/* return tag length belonging to cose algorithm */
240size_t
241cose_tag_len(cose_alg_t cose_alg) {
242 switch ((int)cose_alg) {
251 default:
252 return 0;
253 }
254}
255
256/* return hash length belonging to cose algorithm */
257size_t
258cose_hash_len(cose_alg_t cose_alg) {
259 switch ((int)cose_alg) {
282 default:
283 return 0;
284 }
285}
286
287/* return nonce length belonging to cose algorithm */
288size_t
289cose_nonce_len(cose_alg_t cose_alg) {
290 switch ((int)cose_alg) {
299 default:
300 return 0;
301 }
302}
303
304/* return key length belonging to cose algorithm */
305size_t
306cose_key_len(cose_alg_t cose_alg) {
307 switch ((int)cose_alg) {
316 default:
317 return 0;
318 }
319}
320
321/* Return length */
322size_t
323cose_encrypt0_encode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t buf_len) {
324 size_t ret = 0;
325 size_t rem_size = buf_len;
326
327 ret += oscore_cbor_put_array(&buffer, &rem_size, 3);
328 ret += oscore_cbor_put_bytes(&buffer, &rem_size, NULL, 0);
329 /* ret += cose encode attributyes */
330 ret += oscore_cbor_put_bytes(&buffer,
331 &rem_size,
332 ptr->ciphertext.s,
333 ptr->ciphertext.length);
334 return ret;
335}
336
337/*Return status */
338int cose_encrypt0_decode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size);
339
340/* Initiate a new COSE Encrypt0 object. */
341void
343 memset(ptr, 0, sizeof(cose_encrypt0_t));
344}
345
346void
347cose_encrypt0_set_alg(cose_encrypt0_t *ptr, uint8_t alg) {
348 ptr->alg = alg;
349}
350
351void
353 uint8_t *buffer,
354 size_t size) {
355 ptr->ciphertext.s = buffer;
356 ptr->ciphertext.length = size;
357}
358
359void
361 uint8_t *buffer,
362 size_t size) {
363 ptr->plaintext.s = buffer;
364 ptr->plaintext.length = size;
365}
366/* Return length */
367int cose_encrypt0_get_plaintext(cose_encrypt0_t *ptr, uint8_t **buffer);
368
369void
371 coap_bin_const_t *partial_iv) {
372 if (partial_iv == NULL || partial_iv->length == 0) {
373 ptr->partial_iv.s = NULL;
374 ptr->partial_iv.length = 0;
375 } else {
376 if (partial_iv->length > (int)sizeof(ptr->partial_iv_data))
377 partial_iv->length = sizeof(ptr->partial_iv_data);
378 memcpy(ptr->partial_iv_data, partial_iv->s, partial_iv->length);
379 ptr->partial_iv.s = ptr->partial_iv_data;
380 ptr->partial_iv.length = partial_iv->length;
381 }
382}
383
384/* Return length */
387 return ptr->partial_iv;
388}
389
390void
392 if (key_id) {
393 ptr->key_id = *key_id;
394 } else {
395 ptr->key_id.length = 0;
396 ptr->key_id.s = NULL;
397 }
398}
399/* Return length */
400size_t
401cose_encrypt0_get_key_id(cose_encrypt0_t *ptr, const uint8_t **buffer) {
402 *buffer = ptr->key_id.s;
403 return ptr->key_id.length;
404}
405
406size_t
407cose_encrypt0_get_kid_context(cose_encrypt0_t *ptr, const uint8_t **buffer) {
408 *buffer = ptr->kid_context.s;
409 return ptr->kid_context.length;
410}
411
412void
414 coap_bin_const_t *kid_context) {
415 if (kid_context) {
416 ptr->kid_context = *kid_context;
417 } else {
418 ptr->kid_context.length = 0;
419 ptr->kid_context.s = NULL;
420 }
421}
422
423void
425 coap_bin_const_t *external_aad) {
426 if (external_aad) {
427 ptr->external_aad = *external_aad;
428 } else {
429 ptr->external_aad.length = 0;
430 ptr->external_aad.s = NULL;
431 }
432}
433
434void
436 if (aad) {
437 ptr->aad = *aad;
438 } else {
439 ptr->aad.length = 0;
440 ptr->aad.s = NULL;
441 }
442}
443
444/* Returns 1 if successful, 0 if key is of incorrect length. */
445int
447 if (key == NULL || key->length != 16) {
448 return 0;
449 }
450
451 ptr->key = *key;
452 return 1;
453}
454
455void
457 if (nonce) {
458 ptr->nonce = *nonce;
459 } else {
460 ptr->nonce.length = 0;
461 ptr->nonce.s = NULL;
462 }
463}
464
465int
467 uint8_t *ciphertext_buffer,
468 size_t ciphertext_len) {
469 coap_crypto_param_t params;
470 size_t tag_len = cose_tag_len(ptr->alg);
471 size_t max_result_len = ptr->plaintext.length + tag_len;
472
473 if (ptr->key.s == NULL || ptr->key.length != (size_t)cose_key_len(ptr->alg)) {
474 return -1;
475 }
476 if (ptr->nonce.s == NULL ||
477 ptr->nonce.length != (size_t)cose_nonce_len(ptr->alg)) {
478 return -2;
479 }
480 if (ptr->aad.s == NULL || ptr->aad.length == 0) {
481 return -3;
482 }
483 if (ptr->plaintext.s == NULL ||
484 (ptr->plaintext.length + tag_len) > ciphertext_len) {
485 return -4;
486 }
487
488 memset(&params, 0, sizeof(params));
489 params.alg = ptr->alg;
490 params.params.aes.key = ptr->key;
491 params.params.aes.nonce = ptr->nonce.s;
492 params.params.aes.tag_len = tag_len;
493 params.params.aes.l = 15 - ptr->nonce.length;
494 if (!coap_crypto_aead_encrypt(&params,
495 &ptr->plaintext,
496 &ptr->aad,
497 ciphertext_buffer,
498 &max_result_len)) {
499 return -5;
500 }
501 return (int)max_result_len;
502}
503
504int
506 uint8_t *plaintext_buffer,
507 size_t plaintext_len) {
508 int ret_len = 0;
509 coap_crypto_param_t params;
510 size_t tag_len = cose_tag_len(ptr->alg);
511 size_t max_result_len;
512
513 if (ptr->key.s == NULL || ptr->key.length != (size_t)cose_key_len(ptr->alg)) {
514 return -1;
515 }
516 if (ptr->nonce.s == NULL ||
517 ptr->nonce.length != (size_t)cose_nonce_len(ptr->alg)) {
518 return -2;
519 }
520 if (ptr->aad.s == NULL || ptr->aad.length == 0) {
521 return -3;
522 }
523 if (ptr->ciphertext.s == NULL ||
524 ptr->ciphertext.length < tag_len ||
525 ptr->ciphertext.length > (plaintext_len + tag_len)) {
526 return -4;
527 }
528 max_result_len = ptr->ciphertext.length - tag_len;
529
530 memset(&params, 0, sizeof(params));
531 params.alg = ptr->alg;
532 params.params.aes.key = ptr->key;
533 params.params.aes.nonce = ptr->nonce.s;
534 params.params.aes.tag_len = tag_len;
535 params.params.aes.l = 15 - ptr->nonce.length;
536 if (!coap_crypto_aead_decrypt(&params,
537 &ptr->ciphertext,
538 &ptr->aad,
539 plaintext_buffer,
540 &max_result_len)) {
541 return -5;
542 }
543 ret_len = (int)max_result_len;
544 return ret_len;
545}
546
547#if COAP_OSCORE_GROUP_SUPPORT
548/* ed25519 signature functions */
549
550void
551cose_sign1_init(cose_sign1_t *ptr) {
552 memset(ptr, 0, sizeof(cose_sign1_t));
553}
554
555void
556cose_sign1_set_alg(cose_sign1_t *ptr, int alg, int alg_param, int alg_kty) {
557 ptr->alg = alg;
558 ptr->alg_param = alg_param;
559 ptr->alg_kty = alg_kty;
560}
561
562void
563cose_sign1_set_ciphertext(cose_sign1_t *ptr, uint8_t *buffer, size_t size) {
564 ptr->ciphertext.s = buffer;
565 ptr->ciphertext.length = size;
566}
567
568/* Return length */
569int
570cose_sign1_get_signature(cose_sign1_t *ptr, const uint8_t **buffer) {
571 *buffer = ptr->signature.s;
572 return ptr->signature.length;
573}
574
575void
576cose_sign1_set_signature(cose_sign1_t *ptr, uint8_t *buffer, size_t size) {
577 ptr->signature.s = buffer;
578 ptr->signature.length = size;
579}
580
581void
582cose_sign1_set_sigstructure(cose_sign1_t *ptr, uint8_t *buffer, size_t size) {
583 ptr->sigstructure.s = buffer;
584 ptr->sigstructure.length = size;
585}
586
587void
588cose_sign1_set_public_cred(cose_sign1_t *ptr, coap_crypto_cred_t *buffer) {
589 ptr->public_cred = buffer;
590}
591
592void
593cose_sign1_set_private_key(cose_sign1_t *ptr, coap_crypto_pri_key_t *buffer) {
594 ptr->private_key = buffer;
595}
596
597int
598cose_sign1_sign(cose_sign1_t *ptr) {
599 coap_binary_t *signature = &ptr->signature;
600 coap_bin_const_t *text = &ptr->ciphertext;
601 int res;
602
603 if ((res = coap_crypto_hash_sign(ptr->public_cred->sign_hash,
604 signature,
605 text,
606 ptr->private_key)) == 0)
607 return 0;
608
610 coap_log(COAP_LOG_OSCORE, "Sign\n");
612 "Signature",
613 (coap_bin_const_t *)signature);
616 "Private Key",
617 ptr->private_key->pri_der);
619 "Public Cred",
620 ptr->public_cred->pub_der);
621 }
622
623 return res;
624}
625
626int
627cose_sign1_verify(cose_sign1_t *ptr) {
628 coap_binary_t *signature = &ptr->signature;
629 coap_bin_const_t *text = &ptr->ciphertext;
630
632 coap_log(COAP_LOG_OSCORE, "Verify\n");
634 "Signature",
635 (coap_bin_const_t *)signature);
638 "Public Cred",
639 ptr->public_cred->pub_der);
640 }
641 /* As cose_sign1_sign(): the hash of the credential, not the COSE
642 * signature algorithm (e.g. SHA-512, not EdDSA) */
643 return coap_crypto_hash_verify(ptr->public_cred->sign_hash, signature, text,
644 ptr->public_cred);
645}
646#endif /* COAP_OSCORE_GROUP_SUPPORT */
647
648#else /* ! COAP_OSCORE_SUPPORT */
649
650#ifdef __clang__
651/* Make compilers happy that do not like empty modules. As this function is
652 * never used, we ignore -Wunused-function at the end of compiling this file
653 */
654#pragma GCC diagnostic ignored "-Wunused-function"
655#endif
656static inline void
657dummy(void) {
658}
659
660#endif /* ! COAP_OSCORE_SUPPORT */
Library specific build wrapper for coap_internal.h.
#define NULL
Definition coap_option.h:30
int coap_crypto_aead_decrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Decrypt the provided encrypted data into plaintext.
int coap_crypto_aead_encrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Encrypt the provided plaintext data.
#define coap_log_debug(...)
Definition coap_debug.h:126
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition coap_debug.c:103
#define coap_log(level,...)
Logging function.
Definition coap_debug.h:290
@ COAP_LOG_OSCORE
Definition coap_debug.h:65
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
#define COSE_ALGORITHM_ES512_HASH_LEN
void cose_encrypt0_set_plaintext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
int cose_encrypt0_get_plaintext(cose_encrypt0_t *ptr, uint8_t **buffer)
#define COSE_ALGORITHM_HMAC384_384_HASH_LEN
const char * cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen)
cose_key_type_t cose_get_curve_key_type(cose_curve_t curve)
#define COSE_ALGORITHM_AES_CCM_16_128_128_NONCE_LEN
Definition oscore_cose.h:97
int cose_encrypt0_set_key(cose_encrypt0_t *ptr, coap_bin_const_t *key)
#define COSE_ALGORITHM_SHA_256_64_LEN
size_t cose_nonce_len(cose_alg_t cose_alg)
#define COSE_ALGORITHM_AES_CCM_16_128_128_TAG_LEN
Definition oscore_cose.h:98
coap_bin_const_t * cose_get_curve_bin_oid(cose_curve_t curve)
cose_alg_t cose_get_alg_id(const char *name)
#define COSE_ALGORITHM_AES_CCM_64_128_128_TAG_LEN
Definition oscore_cose.h:94
#define COSE_ALGORITHM_AES_CCM_16_64_128_KEY_LEN
Definition oscore_cose.h:88
void cose_encrypt0_set_kid_context(cose_encrypt0_t *ptr, coap_bin_const_t *kid_context)
cose_curve_t cose_get_curve_id(const char *name)
#define COSE_ALGORITHM_HMAC256_64_HASH_LEN
#define COSE_ALGORITHM_AES_CCM_16_128_128_KEY_LEN
Definition oscore_cose.h:96
size_t cose_key_len(cose_alg_t cose_alg)
#define COSE_ALGORITHM_AES_CCM_16_64_128_NONCE_LEN
Definition oscore_cose.h:89
size_t cose_encrypt0_get_key_id(cose_encrypt0_t *ptr, const uint8_t **buffer)
const char * cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen)
#define COSE_ALGORITHM_HMAC512_512_HASH_LEN
int cose_get_hmac_alg_for_hkdf(cose_hkdf_alg_t hkdf_alg, cose_hmac_alg_t *hmac_alg)
coap_bin_const_t cose_encrypt0_get_partial_iv(cose_encrypt0_t *ptr)
cose_hkdf_alg_t
size_t cose_encrypt0_get_kid_context(cose_encrypt0_t *ptr, const uint8_t **buffer)
void cose_encrypt0_set_ciphertext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
size_t cose_hash_len(cose_alg_t cose_alg)
int cose_encrypt0_decrypt(cose_encrypt0_t *ptr, uint8_t *plaintext_buffer, size_t plaintext_len)
#define COSE_ALGORITHM_AES_CCM_64_64_128_TAG_LEN
Definition oscore_cose.h:86
size_t cose_tag_len(cose_alg_t cose_alg)
#define COSE_ALGORITHM_HMAC256_256_HASH_LEN
#define COSE_ALGORITHM_SHA_256_256_LEN
#define COSE_ALGORITHM_AES_CCM_64_64_128_KEY_LEN
Definition oscore_cose.h:84
void cose_encrypt0_set_aad(cose_encrypt0_t *ptr, coap_bin_const_t *aad)
cose_hmac_alg_t
#define COSE_ALGORITHM_AES_CCM_64_64_128_NONCE_LEN
Definition oscore_cose.h:85
int cose_encrypt0_decode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
cose_curve_t
Definition oscore_cose.h:62
int cose_encrypt0_encrypt(cose_encrypt0_t *ptr, uint8_t *ciphertext_buffer, size_t ciphertext_len)
void cose_encrypt0_set_partial_iv(cose_encrypt0_t *ptr, coap_bin_const_t *partial_iv)
#define COSE_ALGORITHM_SHA_512_LEN
#define COSE_ALGORITHM_AES_CCM_16_64_128_TAG_LEN
Definition oscore_cose.h:90
cose_alg_t
#define COSE_ALGORITHM_AES_CCM_64_128_128_KEY_LEN
Definition oscore_cose.h:92
const char * cose_get_curve_name(cose_curve_t id, char *buffer, size_t buflen)
#define COSE_ALGORITHM_AES_CCM_64_128_128_NONCE_LEN
Definition oscore_cose.h:93
cose_key_type_t
Definition oscore_cose.h:71
size_t cose_encrypt0_encode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
void cose_encrypt0_set_external_aad(cose_encrypt0_t *ptr, coap_bin_const_t *external_aad)
#define COSE_ALGORITHM_SHA_512_256_LEN
void cose_encrypt0_init(cose_encrypt0_t *ptr)
void cose_encrypt0_set_alg(cose_encrypt0_t *ptr, uint8_t alg)
void cose_encrypt0_set_key_id(cose_encrypt0_t *ptr, coap_bin_const_t *key_id)
void cose_encrypt0_set_nonce(cose_encrypt0_t *ptr, coap_bin_const_t *nonce)
#define COSE_ALGORITHM_ES384_HASH_LEN
@ COSE_HKDF_ALG_HKDF_SHA_256
@ COSE_HKDF_ALG_HKDF_SHA_512
@ COSE_HMAC_ALG_HMAC256_256
@ COSE_HMAC_ALG_HMAC512_512
@ COSE_CURVE_X25519
Definition oscore_cose.h:64
@ COSE_CURVE_ED448
Definition oscore_cose.h:67
@ COSE_CURVE_P_256
Definition oscore_cose.h:63
@ COSE_CURVE_SECP256K1
Definition oscore_cose.h:68
@ COSE_CURVE_ED25519
Definition oscore_cose.h:66
@ COSE_CURVE_X448
Definition oscore_cose.h:65
@ COSE_ALGORITHM_HMAC256_256
@ COSE_ALGORITHM_AES_CCM_16_128_256
@ COSE_ALGORITHM_ECDH_SS_HKDF_256
@ COSE_ALGORITHM_HMAC512_512
@ COSE_ALGORITHM_SHA_256_64
@ COSE_ALGORITHM_SHA_512_256
@ COSE_ALGORITHM_ES384
@ COSE_ALGORITHM_AES_CCM_64_64_128
@ COSE_ALGORITHM_CHACHA20_P1035
@ COSE_ALGORITHM_HKDF_SHA_512
@ COSE_ALGORITHM_AES_CCM_16_128_128
@ COSE_ALGORITHM_AES_CCM_64_128_256
@ COSE_ALGORITHM_SHA_256_256
@ COSE_ALGORITHM_SHA_1
@ COSE_ALGORITHM_EDDSA
@ COSE_ALGORITHM_HMAC256_64
@ COSE_ALGORITHM_ES256
@ COSE_ALGORITHM_AES_CCM_64_64_256
@ COSE_ALGORITHM_HKDF_SHA_256
@ COSE_ALGORITHM_AES_CCM_16_64_128
@ COSE_ALGORITHM_ES512
@ COSE_ALGORITHM_HMAC384_384
@ COSE_ALGORITHM_SHA_512
@ COSE_ALGORITHM_AES_CCM_64_128_128
@ COSE_ALGORITHM_AES_CCM_16_64_256
@ COSE_ALGORITHM_ES256K
@ COSE_ALGORITHM_SHA_384
@ COSE_KTY_OKP
Definition oscore_cose.h:73
@ COSE_KTY_UNKNOWN
Definition oscore_cose.h:72
@ COSE_KTY_EC2
Definition oscore_cose.h:74
void oscore_log_hex_value(coap_log_t level, const char *name, coap_bin_const_t *value)
struct coap_bin_const_t coap_bin_const_t
CoAP binary data definition with const data.
static void dummy(void)
CoAP binary data definition with const data.
Definition coap_str.h:65
size_t length
length of binary data
Definition coap_str.h:66
const uint8_t * s
read-only binary data
Definition coap_str.h:67
CoAP binary data definition.
Definition coap_str.h:57
size_t l
The number of bytes in the length field.
const uint8_t * nonce
must be exactly 15 - l bytes
coap_crypto_key_t key
The Key to use.
size_t tag_len
The size of the Tag.
Holds credential definitions.
The common structure that holds the Crypto information.
union coap_crypto_param_t::@250042334257003036060227022037266106077265366262 params
coap_crypto_aes_ccm_t aes
Used if AES type encryption.
cose_alg_t alg
The COSE algorithm to use.
Holds private key definitions.
coap_bin_const_t aad
coap_bin_const_t key
coap_bin_const_t ciphertext
coap_bin_const_t plaintext
coap_bin_const_t partial_iv
coap_bin_const_t kid_context
coap_bin_const_t nonce
coap_bin_const_t external_aad
coap_bin_const_t key_id
uint8_t partial_iv_data[8]
cose_alg_t alg