48#if COAP_OSCORE_SUPPORT
52struct cose_curve_desc {
57static struct cose_curve_desc curve_mapping[] = {
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);
74 snprintf(buffer, buflen,
"curve Fix me (%d)",
id);
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;
87struct cose_curve_type {
92static struct cose_curve_type curve_type[] = {
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;
110struct cose_curve_bin_oid {
115static u_char Ed25519[] = { 0x2b, 0x65, 0x70 };
116static struct cose_curve_bin_oid curve_bin_oid[] = {
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;
129struct cose_alg_desc {
134static struct cose_alg_desc alg_mapping[] = {
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);
172 snprintf(buffer, buflen,
"alg Fix me (%d)",
id);
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;
185struct cose_hkdf_alg_desc {
190static struct cose_hkdf_alg_desc hkdf_alg_mapping[] = {
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);
203 snprintf(buffer, buflen,
"hkdf_alg Fix me (%d)",
id);
211static struct hkdf_hmac_algs {
227 for (idx = 0; idx <
sizeof(hkdf_hmacs) /
sizeof(
struct hkdf_hmac_algs);
229 if (hkdf_hmacs[idx].hkdf_alg == hkdf_alg) {
230 *hmac_alg = hkdf_hmacs[idx].hmac_alg;
234 coap_log_debug(
"cose_get_hmac_alg_for_hkdf: COSE HKDF %d not supported\n",
242 switch ((
int)cose_alg) {
259 switch ((
int)cose_alg) {
290 switch ((
int)cose_alg) {
307 switch ((
int)cose_alg) {
325 size_t rem_size = buf_len;
372 if (partial_iv ==
NULL || partial_iv->
length == 0) {
467 uint8_t *ciphertext_buffer,
468 size_t ciphertext_len) {
488 memset(¶ms, 0,
sizeof(params));
501 return (
int)max_result_len;
506 uint8_t *plaintext_buffer,
507 size_t plaintext_len) {
511 size_t max_result_len;
530 memset(¶ms, 0,
sizeof(params));
543 ret_len = (int)max_result_len;
547#if COAP_OSCORE_GROUP_SUPPORT
551cose_sign1_init(cose_sign1_t *ptr) {
552 memset(ptr, 0,
sizeof(cose_sign1_t));
556cose_sign1_set_alg(cose_sign1_t *ptr,
int alg,
int alg_param,
int alg_kty) {
558 ptr->alg_param = alg_param;
559 ptr->alg_kty = alg_kty;
563cose_sign1_set_ciphertext(cose_sign1_t *ptr, uint8_t *buffer,
size_t size) {
564 ptr->ciphertext.s = buffer;
565 ptr->ciphertext.length = size;
570cose_sign1_get_signature(cose_sign1_t *ptr,
const uint8_t **buffer) {
571 *buffer = ptr->signature.s;
572 return ptr->signature.length;
576cose_sign1_set_signature(cose_sign1_t *ptr, uint8_t *buffer,
size_t size) {
577 ptr->signature.s = buffer;
578 ptr->signature.length = size;
582cose_sign1_set_sigstructure(cose_sign1_t *ptr, uint8_t *buffer,
size_t size) {
583 ptr->sigstructure.s = buffer;
584 ptr->sigstructure.length = size;
589 ptr->public_cred = buffer;
594 ptr->private_key = buffer;
598cose_sign1_sign(cose_sign1_t *ptr) {
603 if ((res = coap_crypto_hash_sign(ptr->public_cred->sign_hash,
606 ptr->private_key)) == 0)
617 ptr->private_key->pri_der);
620 ptr->public_cred->pub_der);
627cose_sign1_verify(cose_sign1_t *ptr) {
639 ptr->public_cred->pub_der);
643 return coap_crypto_hash_verify(ptr->public_cred->sign_hash, signature, text,
654#pragma GCC diagnostic ignored "-Wunused-function"
Library specific build wrapper for coap_internal.h.
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(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
#define coap_log(level,...)
Logging function.
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
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
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
#define COSE_ALGORITHM_AES_CCM_16_64_128_KEY_LEN
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
size_t cose_key_len(cose_alg_t cose_alg)
#define COSE_ALGORITHM_AES_CCM_16_64_128_NONCE_LEN
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)
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
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
void cose_encrypt0_set_aad(cose_encrypt0_t *ptr, coap_bin_const_t *aad)
#define COSE_ALGORITHM_AES_CCM_64_64_128_NONCE_LEN
int cose_encrypt0_decode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
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
#define COSE_ALGORITHM_AES_CCM_64_128_128_KEY_LEN
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
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_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_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_HMAC256_64
@ COSE_ALGORITHM_AES_CCM_64_64_256
@ COSE_ALGORITHM_HKDF_SHA_256
@ COSE_ALGORITHM_AES_CCM_16_64_128
@ COSE_ALGORITHM_HMAC384_384
@ COSE_ALGORITHM_AES_CCM_64_128_128
@ COSE_ALGORITHM_AES_CCM_16_64_256
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.
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
CoAP binary data definition.
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 ciphertext
coap_bin_const_t plaintext
coap_bin_const_t partial_iv
coap_bin_const_t kid_context
coap_bin_const_t external_aad
uint8_t partial_iv_data[8]