Loading...
Searching...
No Matches
oscore_cose.c
Go to the documentation of this file.
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Copyright (c) 2018, SICS, RISE AB
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "coap3/coap_libcoap_build.h"
#include "stdio.h"
struct cose_curve_desc {
const char *name;
cose_curve_t id;
};
static struct cose_curve_desc curve_mapping[] = {
{ "P-256", COSE_CURVE_P_256 },
{ "X25519", COSE_CURVE_X25519 },
{ "X448", COSE_CURVE_X448 },
{ "Ed25519", COSE_CURVE_ED25519 },
{ "Ed448", COSE_CURVE_ED448 },
{ "secp256k1", COSE_CURVE_SECP256K1 },
};
const char *
cose_get_curve_name(cose_curve_t id, char *buffer, size_t buflen) {
for (size_t i = 0; i < sizeof(curve_mapping)/sizeof(curve_mapping[0]); i++) {
if (id == curve_mapping[i].id) {
snprintf(buffer, buflen, "%s (%d)", curve_mapping[i].name, id);
return buffer;
}
}
snprintf(buffer, buflen, "curve Fix me (%d)", id);
return buffer;
}
cose_curve_t
cose_get_curve_id(const char *name) {
for (size_t i = 0; i < sizeof(curve_mapping)/sizeof(curve_mapping[0]); i++) {
if (strcmp(name, curve_mapping[i].name) == 0)
return curve_mapping[i].id;
}
return 0;
}
struct cose_alg_desc {
const char *name;
cose_alg_t id;
};
static struct cose_alg_desc alg_mapping[] = {
{ "ES256K", COSE_ALGORITHM_ES256K },
{ "SHA-512", COSE_ALGORITHM_SHA_512 },
{ "SHA-384", COSE_ALGORITHM_SHA_384 },
{ "ES512", COSE_ALGORITHM_ES512 },
{ "ES384", COSE_ALGORITHM_ES384 },
{ "ECDH-SS + HKDF-256", COSE_ALGORITHM_ECDH_SS_HKDF_256 },
{ "SHA-512/256", COSE_ALGORITHM_SHA_512_256 },
{ "SHA-256", COSE_ALGORITHM_SHA_256_256 },
{ "SHA-256/64", COSE_ALGORITHM_SHA_256_64 },
{ "SHA-1", COSE_ALGORITHM_SHA_1 },
{ "direct+HKDF-SHA-512", COSE_ALGORITHM_HKDF_SHA_512 },
{ "direct+HKDF-SHA-256", COSE_ALGORITHM_HKDF_SHA_256 },
{ "EdDSA", COSE_ALGORITHM_EDDSA },
{ "ES256", COSE_ALGORITHM_ES256 },
{ "HMAC 256/64", COSE_ALGORITHM_HMAC256_64 },
{ "HMAC 256/256", COSE_ALGORITHM_HMAC256_256 },
{ "HMAC 384/384", COSE_ALGORITHM_HMAC384_384 },
{ "HMAC 512/512", COSE_ALGORITHM_HMAC512_512 },
{ "AES-CCM-16-64-128", COSE_ALGORITHM_AES_CCM_16_64_128 },
{ "AES-CCM-16-64-256", COSE_ALGORITHM_AES_CCM_16_64_256 },
{ "AES-CCM-64-64-128", COSE_ALGORITHM_AES_CCM_64_64_128 },
{ "AES-CCM-64-64-256", COSE_ALGORITHM_AES_CCM_64_64_256 },
{ "ChaCha20/Poly1305", COSE_ALGORITHM_CHACHA20_P1035 },
{ "AES-CCM-16-128-128", COSE_ALGORITHM_AES_CCM_16_128_128 },
{ "AES-CCM-16-128-256", COSE_ALGORITHM_AES_CCM_16_128_256 },
{ "AES-CCM-64-128-128", COSE_ALGORITHM_AES_CCM_64_128_128 },
{ "AES-CCM-64-128-256", COSE_ALGORITHM_AES_CCM_64_128_256 },
};
const char *
cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen) {
for (size_t i = 0; i < sizeof(alg_mapping)/sizeof(alg_mapping[0]); i++) {
if (id == alg_mapping[i].id) {
snprintf(buffer, buflen, "%s (%d)", alg_mapping[i].name, id);
return buffer;
}
}
snprintf(buffer, buflen, "alg Fix me (%d)", id);
return buffer;
}
cose_alg_t
cose_get_alg_id(const char *name) {
for (size_t i = 0; i < sizeof(alg_mapping)/sizeof(alg_mapping[0]); i++) {
if (strcmp(name, alg_mapping[i].name) == 0)
return alg_mapping[i].id;
}
return 0;
}
struct cose_hkdf_alg_desc {
const char *name;
cose_hkdf_alg_t id;
};
static struct cose_hkdf_alg_desc hkdf_alg_mapping[] = {
{ "direct+HKDF-SHA-512", COSE_HKDF_ALG_HKDF_SHA_512 },
{ "direct+HKDF-SHA-256", COSE_HKDF_ALG_HKDF_SHA_256 },
};
const char *
cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen) {
for (size_t i = 0; i < sizeof(hkdf_alg_mapping)/sizeof(hkdf_alg_mapping[0]); i++) {
if (id == hkdf_alg_mapping[i].id) {
snprintf(buffer, buflen, "%s (%d)", hkdf_alg_mapping[i].name, id);
return buffer;
}
}
snprintf(buffer, buflen, "hkdf_alg Fix me (%d)", id);
return buffer;
}
/*
* The struct hmac_algs and the function cose_get_hmac_alg_for_hkdf() are
* used to determine which hmac type to use for the appropriate hkdf
*/
static struct hkdf_hmac_algs {
cose_hkdf_alg_t hkdf_alg;
cose_hmac_alg_t hmac_alg;
} hkdf_hmacs[] = {
{COSE_HKDF_ALG_HKDF_SHA_256, COSE_HMAC_ALG_HMAC256_256},
{COSE_HKDF_ALG_HKDF_SHA_512, COSE_HMAC_ALG_HMAC512_512},
};
/*
* return 0 fail
* 1 OK
*/
int
cose_get_hmac_alg_for_hkdf(cose_hkdf_alg_t hkdf_alg, cose_hmac_alg_t *hmac_alg) {
size_t idx;
for (idx = 0; idx < sizeof(hkdf_hmacs) / sizeof(struct hkdf_hmac_algs);
idx++) {
if (hkdf_hmacs[idx].hkdf_alg == hkdf_alg) {
*hmac_alg = hkdf_hmacs[idx].hmac_alg;
return 1;
}
}
coap_log_debug("cose_get_hmac_alg_for_hkdf: COSE HKDF %d not supported\n",
hkdf_alg);
return 0;
}
/* return tag length belonging to cose algorithm */
size_t
cose_tag_len(cose_alg_t cose_alg) {
switch ((int)cose_alg) {
case COSE_ALGORITHM_AES_CCM_16_64_128:
return COSE_ALGORITHM_AES_CCM_16_64_128_TAG_LEN;
case COSE_ALGORITHM_AES_CCM_64_64_128:
return COSE_ALGORITHM_AES_CCM_64_64_128_TAG_LEN;
case COSE_ALGORITHM_AES_CCM_16_128_128:
return COSE_ALGORITHM_AES_CCM_16_128_128_TAG_LEN;
case COSE_ALGORITHM_AES_CCM_64_128_128:
return COSE_ALGORITHM_AES_CCM_64_128_128_TAG_LEN;
default:
return 0;
}
}
/* return hash length belonging to cose algorithm */
size_t
cose_hash_len(cose_alg_t cose_alg) {
switch ((int)cose_alg) {
case COSE_ALGORITHM_ES256:
return COSE_ALGORITHM_HMAC256_256_HASH_LEN;
case COSE_ALGORITHM_ES512:
return COSE_ALGORITHM_ES512_HASH_LEN;
case COSE_ALGORITHM_ES384:
return COSE_ALGORITHM_ES384_HASH_LEN;
case COSE_ALGORITHM_HMAC256_64:
return COSE_ALGORITHM_HMAC256_64_HASH_LEN;
case COSE_ALGORITHM_HMAC256_256:
return COSE_ALGORITHM_HMAC256_256_HASH_LEN;
case COSE_ALGORITHM_HMAC384_384:
return COSE_ALGORITHM_HMAC384_384_HASH_LEN;
case COSE_ALGORITHM_HMAC512_512:
return COSE_ALGORITHM_HMAC512_512_HASH_LEN;
case COSE_ALGORITHM_SHA_256_64:
return COSE_ALGORITHM_SHA_256_64_LEN;
case COSE_ALGORITHM_SHA_256_256:
return COSE_ALGORITHM_SHA_256_256_LEN;
case COSE_ALGORITHM_SHA_512_256:
return COSE_ALGORITHM_SHA_512_256_LEN;
case COSE_ALGORITHM_SHA_512:
return COSE_ALGORITHM_SHA_512_LEN;
default:
return 0;
}
}
/* return nonce length belonging to cose algorithm */
size_t
cose_nonce_len(cose_alg_t cose_alg) {
switch ((int)cose_alg) {
case COSE_ALGORITHM_AES_CCM_16_64_128:
return COSE_ALGORITHM_AES_CCM_16_64_128_NONCE_LEN;
case COSE_ALGORITHM_AES_CCM_64_64_128:
return COSE_ALGORITHM_AES_CCM_64_64_128_NONCE_LEN;
case COSE_ALGORITHM_AES_CCM_16_128_128:
return COSE_ALGORITHM_AES_CCM_16_128_128_NONCE_LEN;
case COSE_ALGORITHM_AES_CCM_64_128_128:
return COSE_ALGORITHM_AES_CCM_64_128_128_NONCE_LEN;
default:
return 0;
}
}
/* return key length belonging to cose algorithm */
size_t
cose_key_len(cose_alg_t cose_alg) {
switch ((int)cose_alg) {
case COSE_ALGORITHM_AES_CCM_16_64_128:
return COSE_ALGORITHM_AES_CCM_16_64_128_KEY_LEN;
case COSE_ALGORITHM_AES_CCM_64_64_128:
return COSE_ALGORITHM_AES_CCM_64_64_128_KEY_LEN;
case COSE_ALGORITHM_AES_CCM_16_128_128:
return COSE_ALGORITHM_AES_CCM_16_128_128_KEY_LEN;
case COSE_ALGORITHM_AES_CCM_64_128_128:
return COSE_ALGORITHM_AES_CCM_64_128_128_KEY_LEN;
default:
return 0;
}
}
/* Return length */
size_t
cose_encrypt0_encode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t buf_len) {
size_t ret = 0;
size_t rem_size = buf_len;
ret += oscore_cbor_put_array(&buffer, &rem_size, 3);
ret += oscore_cbor_put_bytes(&buffer, &rem_size, NULL, 0);
/* ret += cose encode attributyes */
ret += oscore_cbor_put_bytes(&buffer,
&rem_size,
ptr->ciphertext.s,
ptr->ciphertext.length);
return ret;
}
/*Return status */
int cose_encrypt0_decode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size);
/* Initiate a new COSE Encrypt0 object. */
void
cose_encrypt0_init(cose_encrypt0_t *ptr) {
memset(ptr, 0, sizeof(cose_encrypt0_t));
}
void
cose_encrypt0_set_alg(cose_encrypt0_t *ptr, uint8_t alg) {
ptr->alg = alg;
}
void
cose_encrypt0_set_ciphertext(cose_encrypt0_t *ptr,
uint8_t *buffer,
size_t size) {
ptr->ciphertext.s = buffer;
ptr->ciphertext.length = size;
}
void
cose_encrypt0_set_plaintext(cose_encrypt0_t *ptr,
uint8_t *buffer,
size_t size) {
ptr->plaintext.s = buffer;
ptr->plaintext.length = size;
}
/* Return length */
int cose_encrypt0_get_plaintext(cose_encrypt0_t *ptr, uint8_t **buffer);
void
cose_encrypt0_set_partial_iv(cose_encrypt0_t *ptr,
coap_bin_const_t *partial_iv) {
if (partial_iv == NULL || partial_iv->length == 0) {
ptr->partial_iv.s = NULL;
ptr->partial_iv.length = 0;
} else {
if (partial_iv->length > (int)sizeof(ptr->partial_iv_data))
partial_iv->length = sizeof(ptr->partial_iv_data);
memcpy(ptr->partial_iv_data, partial_iv->s, partial_iv->length);
ptr->partial_iv.s = ptr->partial_iv_data;
ptr->partial_iv.length = partial_iv->length;
}
}
/* Return length */
coap_bin_const_t
cose_encrypt0_get_partial_iv(cose_encrypt0_t *ptr) {
return ptr->partial_iv;
}
void
cose_encrypt0_set_key_id(cose_encrypt0_t *ptr, coap_bin_const_t *key_id) {
if (key_id) {
ptr->key_id = *key_id;
} else {
ptr->key_id.length = 0;
ptr->key_id.s = NULL;
}
}
/* Return length */
size_t
cose_encrypt0_get_key_id(cose_encrypt0_t *ptr, const uint8_t **buffer) {
*buffer = ptr->key_id.s;
return ptr->key_id.length;
}
size_t
cose_encrypt0_get_kid_context(cose_encrypt0_t *ptr, const uint8_t **buffer) {
*buffer = ptr->kid_context.s;
return ptr->kid_context.length;
}
void
cose_encrypt0_set_kid_context(cose_encrypt0_t *ptr,
coap_bin_const_t *kid_context) {
if (kid_context) {
ptr->kid_context = *kid_context;
} else {
ptr->kid_context.length = 0;
ptr->kid_context.s = NULL;
}
}
void
cose_encrypt0_set_external_aad(cose_encrypt0_t *ptr,
coap_bin_const_t *external_aad) {
if (external_aad) {
ptr->external_aad = *external_aad;
} else {
ptr->external_aad.length = 0;
ptr->external_aad.s = NULL;
}
}
void
cose_encrypt0_set_aad(cose_encrypt0_t *ptr, coap_bin_const_t *aad) {
if (aad) {
ptr->aad = *aad;
} else {
ptr->aad.length = 0;
ptr->aad.s = NULL;
}
}
/* Returns 1 if successfull, 0 if key is of incorrect length. */
int
cose_encrypt0_set_key(cose_encrypt0_t *ptr, coap_bin_const_t *key) {
if (key == NULL || key->length != 16) {
return 0;
}
ptr->key = *key;
return 1;
}
void
cose_encrypt0_set_nonce(cose_encrypt0_t *ptr, coap_bin_const_t *nonce) {
if (nonce) {
ptr->nonce = *nonce;
} else {
ptr->nonce.length = 0;
ptr->nonce.s = NULL;
}
}
int
cose_encrypt0_encrypt(cose_encrypt0_t *ptr,
uint8_t *ciphertext_buffer,
size_t ciphertext_len) {
coap_crypto_param_t params;
size_t tag_len = cose_tag_len(ptr->alg);
size_t max_result_len = ptr->plaintext.length + tag_len;
if (ptr->key.s == NULL || ptr->key.length != (size_t)cose_key_len(ptr->alg)) {
return -1;
}
if (ptr->nonce.s == NULL ||
ptr->nonce.length != (size_t)cose_nonce_len(ptr->alg)) {
return -2;
}
if (ptr->aad.s == NULL || ptr->aad.length == 0) {
return -3;
}
if (ptr->plaintext.s == NULL ||
(ptr->plaintext.length + tag_len) > ciphertext_len) {
return -4;
}
memset(&params, 0, sizeof(params));
params.alg = ptr->alg;
params.params.aes.key = ptr->key;
params.params.aes.nonce = ptr->nonce.s;
params.params.aes.tag_len = tag_len;
params.params.aes.l = 15 - ptr->nonce.length;
if (!coap_crypto_aead_encrypt(&params,
&ptr->plaintext,
&ptr->aad,
ciphertext_buffer,
&max_result_len)) {
return -5;
}
return (int)max_result_len;
}
int
cose_encrypt0_decrypt(cose_encrypt0_t *ptr,
uint8_t *plaintext_buffer,
size_t plaintext_len) {
int ret_len = 0;
coap_crypto_param_t params;
size_t tag_len = cose_tag_len(ptr->alg);
size_t max_result_len = ptr->ciphertext.length - tag_len;
if (ptr->key.s == NULL || ptr->key.length != (size_t)cose_key_len(ptr->alg)) {
return -1;
}
if (ptr->nonce.s == NULL ||
ptr->nonce.length != (size_t)cose_nonce_len(ptr->alg)) {
return -2;
}
if (ptr->aad.s == NULL || ptr->aad.length == 0) {
return -3;
}
if (ptr->ciphertext.s == NULL ||
ptr->ciphertext.length > (plaintext_len + tag_len)) {
return -4;
}
memset(&params, 0, sizeof(params));
params.alg = ptr->alg;
params.params.aes.key = ptr->key;
params.params.aes.nonce = ptr->nonce.s;
params.params.aes.tag_len = tag_len;
params.params.aes.l = 15 - ptr->nonce.length;
if (!coap_crypto_aead_decrypt(&params,
&ptr->ciphertext,
&ptr->aad,
plaintext_buffer,
&max_result_len)) {
return -5;
}
ret_len = (int)max_result_len;
return ret_len;
}
coap_libcoap_build.h
Library specific build wrapper for coap_internal.h.
coap_crypto_aead_decrypt
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.
coap_crypto_aead_encrypt
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.
coap_log_debug
#define coap_log_debug(...)
Definition coap_debug.h:120
oscore_cbor_put_bytes
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
Definition oscore_cbor.c:100
oscore_cbor_put_array
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
Definition oscore_cbor.c:92
COSE_ALGORITHM_ES512_HASH_LEN
#define COSE_ALGORITHM_ES512_HASH_LEN
Definition oscore_cose.h:110
cose_encrypt0_set_plaintext
void cose_encrypt0_set_plaintext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
Definition oscore_cose.c:315
COSE_ALGORITHM_HMAC384_384_HASH_LEN
#define COSE_ALGORITHM_HMAC384_384_HASH_LEN
Definition oscore_cose.h:122
cose_get_hkdf_alg_name
const char * cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen)
Definition oscore_cose.c:151
COSE_ALGORITHM_AES_CCM_16_128_128_NONCE_LEN
#define COSE_ALGORITHM_AES_CCM_16_128_128_NONCE_LEN
Definition oscore_cose.h:94
cose_encrypt0_set_key
int cose_encrypt0_set_key(cose_encrypt0_t *ptr, coap_bin_const_t *key)
Definition oscore_cose.c:401
COSE_ALGORITHM_SHA_256_64_LEN
#define COSE_ALGORITHM_SHA_256_64_LEN
Definition oscore_cose.h:118
cose_nonce_len
size_t cose_nonce_len(cose_alg_t cose_alg)
Definition oscore_cose.c:244
COSE_ALGORITHM_AES_CCM_16_128_128_TAG_LEN
#define COSE_ALGORITHM_AES_CCM_16_128_128_TAG_LEN
Definition oscore_cose.h:95
cose_get_alg_id
cose_alg_t cose_get_alg_id(const char *name)
Definition oscore_cose.c:132
COSE_ALGORITHM_AES_CCM_64_128_128_TAG_LEN
#define COSE_ALGORITHM_AES_CCM_64_128_128_TAG_LEN
Definition oscore_cose.h:91
COSE_ALGORITHM_AES_CCM_16_64_128_KEY_LEN
#define COSE_ALGORITHM_AES_CCM_16_64_128_KEY_LEN
Definition oscore_cose.h:85
cose_encrypt0_set_kid_context
void cose_encrypt0_set_kid_context(cose_encrypt0_t *ptr, coap_bin_const_t *kid_context)
Definition oscore_cose.c:368
cose_get_curve_id
cose_curve_t cose_get_curve_id(const char *name)
Definition oscore_cose.c:76
COSE_ALGORITHM_HMAC256_64_HASH_LEN
#define COSE_ALGORITHM_HMAC256_64_HASH_LEN
Definition oscore_cose.h:120
COSE_ALGORITHM_AES_CCM_16_128_128_KEY_LEN
#define COSE_ALGORITHM_AES_CCM_16_128_128_KEY_LEN
Definition oscore_cose.h:93
cose_key_len
size_t cose_key_len(cose_alg_t cose_alg)
Definition oscore_cose.c:261
COSE_ALGORITHM_AES_CCM_16_64_128_NONCE_LEN
#define COSE_ALGORITHM_AES_CCM_16_64_128_NONCE_LEN
Definition oscore_cose.h:86
cose_encrypt0_get_key_id
size_t cose_encrypt0_get_key_id(cose_encrypt0_t *ptr, const uint8_t **buffer)
Definition oscore_cose.c:356
cose_get_alg_name
const char * cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen)
Definition oscore_cose.c:120
COSE_ALGORITHM_HMAC512_512_HASH_LEN
#define COSE_ALGORITHM_HMAC512_512_HASH_LEN
Definition oscore_cose.h:123
cose_get_hmac_alg_for_hkdf
int cose_get_hmac_alg_for_hkdf(cose_hkdf_alg_t hkdf_alg, cose_hmac_alg_t *hmac_alg)
Definition oscore_cose.c:179
cose_encrypt0_get_partial_iv
coap_bin_const_t cose_encrypt0_get_partial_iv(cose_encrypt0_t *ptr)
Definition oscore_cose.c:341
cose_hkdf_alg_t
cose_hkdf_alg_t
Definition oscore_cose.h:165
cose_encrypt0_get_kid_context
size_t cose_encrypt0_get_kid_context(cose_encrypt0_t *ptr, const uint8_t **buffer)
Definition oscore_cose.c:362
cose_encrypt0_set_ciphertext
void cose_encrypt0_set_ciphertext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
Definition oscore_cose.c:307
cose_hash_len
size_t cose_hash_len(cose_alg_t cose_alg)
Definition oscore_cose.c:213
cose_encrypt0_decrypt
int cose_encrypt0_decrypt(cose_encrypt0_t *ptr, uint8_t *plaintext_buffer, size_t plaintext_len)
Definition oscore_cose.c:460
COSE_ALGORITHM_AES_CCM_64_64_128_TAG_LEN
#define COSE_ALGORITHM_AES_CCM_64_64_128_TAG_LEN
Definition oscore_cose.h:83
cose_tag_len
size_t cose_tag_len(cose_alg_t cose_alg)
Definition oscore_cose.c:196
COSE_ALGORITHM_HMAC256_256_HASH_LEN
#define COSE_ALGORITHM_HMAC256_256_HASH_LEN
Definition oscore_cose.h:121
COSE_ALGORITHM_SHA_256_256_LEN
#define COSE_ALGORITHM_SHA_256_256_LEN
Definition oscore_cose.h:117
COSE_ALGORITHM_AES_CCM_64_64_128_KEY_LEN
#define COSE_ALGORITHM_AES_CCM_64_64_128_KEY_LEN
Definition oscore_cose.h:81
cose_encrypt0_set_aad
void cose_encrypt0_set_aad(cose_encrypt0_t *ptr, coap_bin_const_t *aad)
Definition oscore_cose.c:390
cose_hmac_alg_t
cose_hmac_alg_t
Definition oscore_cose.h:157
COSE_ALGORITHM_AES_CCM_64_64_128_NONCE_LEN
#define COSE_ALGORITHM_AES_CCM_64_64_128_NONCE_LEN
Definition oscore_cose.h:82
cose_curve_t
cose_curve_t
Definition oscore_cose.h:60
cose_encrypt0_encrypt
int cose_encrypt0_encrypt(cose_encrypt0_t *ptr, uint8_t *ciphertext_buffer, size_t ciphertext_len)
Definition oscore_cose.c:421
cose_encrypt0_set_partial_iv
void cose_encrypt0_set_partial_iv(cose_encrypt0_t *ptr, coap_bin_const_t *partial_iv)
Definition oscore_cose.c:325
COSE_ALGORITHM_SHA_512_LEN
#define COSE_ALGORITHM_SHA_512_LEN
Definition oscore_cose.h:115
COSE_ALGORITHM_AES_CCM_16_64_128_TAG_LEN
#define COSE_ALGORITHM_AES_CCM_16_64_128_TAG_LEN
Definition oscore_cose.h:87
cose_alg_t
cose_alg_t
Definition oscore_cose.h:126
COSE_ALGORITHM_AES_CCM_64_128_128_KEY_LEN
#define COSE_ALGORITHM_AES_CCM_64_128_128_KEY_LEN
Definition oscore_cose.h:89
cose_get_curve_name
const char * cose_get_curve_name(cose_curve_t id, char *buffer, size_t buflen)
Definition oscore_cose.c:64
COSE_ALGORITHM_AES_CCM_64_128_128_NONCE_LEN
#define COSE_ALGORITHM_AES_CCM_64_128_128_NONCE_LEN
Definition oscore_cose.h:90
cose_encrypt0_encode
size_t cose_encrypt0_encode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t buf_len)
Definition oscore_cose.c:278
cose_encrypt0_set_external_aad
void cose_encrypt0_set_external_aad(cose_encrypt0_t *ptr, coap_bin_const_t *external_aad)
Definition oscore_cose.c:379
COSE_ALGORITHM_SHA_512_256_LEN
#define COSE_ALGORITHM_SHA_512_256_LEN
Definition oscore_cose.h:116
cose_encrypt0_init
void cose_encrypt0_init(cose_encrypt0_t *ptr)
Definition oscore_cose.c:297
cose_encrypt0_set_alg
void cose_encrypt0_set_alg(cose_encrypt0_t *ptr, uint8_t alg)
Definition oscore_cose.c:302
cose_encrypt0_set_key_id
void cose_encrypt0_set_key_id(cose_encrypt0_t *ptr, coap_bin_const_t *key_id)
Definition oscore_cose.c:346
cose_encrypt0_set_nonce
void cose_encrypt0_set_nonce(cose_encrypt0_t *ptr, coap_bin_const_t *nonce)
Definition oscore_cose.c:411
COSE_ALGORITHM_ES384_HASH_LEN
#define COSE_ALGORITHM_ES384_HASH_LEN
Definition oscore_cose.h:105
COSE_HKDF_ALG_HKDF_SHA_256
@ COSE_HKDF_ALG_HKDF_SHA_256
Definition oscore_cose.h:167
COSE_HKDF_ALG_HKDF_SHA_512
@ COSE_HKDF_ALG_HKDF_SHA_512
Definition oscore_cose.h:166
COSE_HMAC_ALG_HMAC256_256
@ COSE_HMAC_ALG_HMAC256_256
Definition oscore_cose.h:159
COSE_HMAC_ALG_HMAC512_512
@ COSE_HMAC_ALG_HMAC512_512
Definition oscore_cose.h:161
COSE_CURVE_X25519
@ COSE_CURVE_X25519
Definition oscore_cose.h:62
COSE_CURVE_ED448
@ COSE_CURVE_ED448
Definition oscore_cose.h:65
COSE_CURVE_P_256
@ COSE_CURVE_P_256
Definition oscore_cose.h:61
COSE_CURVE_SECP256K1
@ COSE_CURVE_SECP256K1
Definition oscore_cose.h:66
COSE_CURVE_ED25519
@ COSE_CURVE_ED25519
Definition oscore_cose.h:64
COSE_CURVE_X448
@ COSE_CURVE_X448
Definition oscore_cose.h:63
COSE_ALGORITHM_HMAC256_256
@ COSE_ALGORITHM_HMAC256_256
Definition oscore_cose.h:142
COSE_ALGORITHM_AES_CCM_16_128_256
@ COSE_ALGORITHM_AES_CCM_16_128_256
Definition oscore_cose.h:151
COSE_ALGORITHM_ECDH_SS_HKDF_256
@ COSE_ALGORITHM_ECDH_SS_HKDF_256
Definition oscore_cose.h:132
COSE_ALGORITHM_HMAC512_512
@ COSE_ALGORITHM_HMAC512_512
Definition oscore_cose.h:144
COSE_ALGORITHM_SHA_256_64
@ COSE_ALGORITHM_SHA_256_64
Definition oscore_cose.h:135
COSE_ALGORITHM_SHA_512_256
@ COSE_ALGORITHM_SHA_512_256
Definition oscore_cose.h:133
COSE_ALGORITHM_ES384
@ COSE_ALGORITHM_ES384
Definition oscore_cose.h:131
COSE_ALGORITHM_AES_CCM_64_64_128
@ COSE_ALGORITHM_AES_CCM_64_64_128
Definition oscore_cose.h:147
COSE_ALGORITHM_CHACHA20_P1035
@ COSE_ALGORITHM_CHACHA20_P1035
Definition oscore_cose.h:149
COSE_ALGORITHM_HKDF_SHA_512
@ COSE_ALGORITHM_HKDF_SHA_512
Definition oscore_cose.h:137
COSE_ALGORITHM_AES_CCM_16_128_128
@ COSE_ALGORITHM_AES_CCM_16_128_128
Definition oscore_cose.h:150
COSE_ALGORITHM_AES_CCM_64_128_256
@ COSE_ALGORITHM_AES_CCM_64_128_256
Definition oscore_cose.h:153
COSE_ALGORITHM_SHA_256_256
@ COSE_ALGORITHM_SHA_256_256
Definition oscore_cose.h:134
COSE_ALGORITHM_SHA_1
@ COSE_ALGORITHM_SHA_1
Definition oscore_cose.h:136
COSE_ALGORITHM_EDDSA
@ COSE_ALGORITHM_EDDSA
Definition oscore_cose.h:139
COSE_ALGORITHM_HMAC256_64
@ COSE_ALGORITHM_HMAC256_64
Definition oscore_cose.h:141
COSE_ALGORITHM_ES256
@ COSE_ALGORITHM_ES256
Definition oscore_cose.h:140
COSE_ALGORITHM_AES_CCM_64_64_256
@ COSE_ALGORITHM_AES_CCM_64_64_256
Definition oscore_cose.h:148
COSE_ALGORITHM_HKDF_SHA_256
@ COSE_ALGORITHM_HKDF_SHA_256
Definition oscore_cose.h:138
COSE_ALGORITHM_AES_CCM_16_64_128
@ COSE_ALGORITHM_AES_CCM_16_64_128
Definition oscore_cose.h:145
COSE_ALGORITHM_ES512
@ COSE_ALGORITHM_ES512
Definition oscore_cose.h:130
COSE_ALGORITHM_HMAC384_384
@ COSE_ALGORITHM_HMAC384_384
Definition oscore_cose.h:143
COSE_ALGORITHM_SHA_512
@ COSE_ALGORITHM_SHA_512
Definition oscore_cose.h:128
COSE_ALGORITHM_AES_CCM_64_128_128
@ COSE_ALGORITHM_AES_CCM_64_128_128
Definition oscore_cose.h:152
COSE_ALGORITHM_AES_CCM_16_64_256
@ COSE_ALGORITHM_AES_CCM_16_64_256
Definition oscore_cose.h:146
COSE_ALGORITHM_ES256K
@ COSE_ALGORITHM_ES256K
Definition oscore_cose.h:127
COSE_ALGORITHM_SHA_384
@ COSE_ALGORITHM_SHA_384
Definition oscore_cose.h:129
cose_encrypt0_get_plaintext
int cose_encrypt0_get_plaintext(cose_encrypt0_t *ptr, uint8_t **buffer)
alg_mapping
static struct cose_alg_desc alg_mapping[]
Definition oscore_cose.c:89
hkdf_hmacs
static struct hkdf_hmac_algs hkdf_hmacs[]
hkdf_alg_mapping
static struct cose_hkdf_alg_desc hkdf_alg_mapping[]
Definition oscore_cose.c:145
curve_mapping
static struct cose_curve_desc curve_mapping[]
Definition oscore_cose.c:54
cose_encrypt0_decode
int cose_encrypt0_decode(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
coap_bin_const_t
CoAP binary data definition with const data.
Definition coap_str.h:64
coap_bin_const_t::length
size_t length
length of binary data
Definition coap_str.h:65
coap_bin_const_t::s
const uint8_t * s
read-only binary data
Definition coap_str.h:66
coap_crypto_aes_ccm_t::l
size_t l
The number of bytes in the length field.
Definition coap_crypto_internal.h:53
coap_crypto_aes_ccm_t::nonce
const uint8_t * nonce
must be exactly 15 - l bytes
Definition coap_crypto_internal.h:51
coap_crypto_aes_ccm_t::key
coap_crypto_key_t key
The Key to use.
Definition coap_crypto_internal.h:50
coap_crypto_aes_ccm_t::tag_len
size_t tag_len
The size of the Tag.
Definition coap_crypto_internal.h:52
coap_crypto_param_t
The common structure that holds the Crypto information.
Definition coap_crypto_internal.h:59
coap_crypto_param_t::params
union coap_crypto_param_t::@164333007307147104157111121134063027154151104316 params
coap_crypto_param_t::aes
coap_crypto_aes_ccm_t aes
Used if AES type encryption.
Definition coap_crypto_internal.h:62
coap_crypto_param_t::alg
cose_alg_t alg
The COSE algorith to use.
Definition coap_crypto_internal.h:60
cose_alg_desc
Definition oscore_cose.c:84
cose_alg_desc::id
cose_alg_t id
Definition oscore_cose.c:86
cose_alg_desc::name
const char * name
Definition oscore_cose.c:85
cose_curve_desc
Definition oscore_cose.c:49
cose_curve_desc::name
const char * name
Definition oscore_cose.c:50
cose_curve_desc::id
cose_curve_t id
Definition oscore_cose.c:51
cose_encrypt0_t
Definition oscore_cose.h:197
cose_encrypt0_t::aad
coap_bin_const_t aad
Definition oscore_cose.h:208
cose_encrypt0_t::key
coap_bin_const_t key
Definition oscore_cose.h:199
cose_encrypt0_t::ciphertext
coap_bin_const_t ciphertext
Definition oscore_cose.h:210
cose_encrypt0_t::plaintext
coap_bin_const_t plaintext
Definition oscore_cose.h:209
cose_encrypt0_t::partial_iv
coap_bin_const_t partial_iv
Definition oscore_cose.h:202
cose_encrypt0_t::kid_context
coap_bin_const_t kid_context
Definition oscore_cose.h:204
cose_encrypt0_t::nonce
coap_bin_const_t nonce
Definition oscore_cose.h:206
cose_encrypt0_t::external_aad
coap_bin_const_t external_aad
Definition oscore_cose.h:207
cose_encrypt0_t::key_id
coap_bin_const_t key_id
Definition oscore_cose.h:203
cose_encrypt0_t::partial_iv_data
uint8_t partial_iv_data[8]
Definition oscore_cose.h:200
cose_encrypt0_t::alg
cose_alg_t alg
Definition oscore_cose.h:198
cose_hkdf_alg_desc
Definition oscore_cose.c:140
cose_hkdf_alg_desc::name
const char * name
Definition oscore_cose.c:141
cose_hkdf_alg_desc::id
cose_hkdf_alg_t id
Definition oscore_cose.c:142
hkdf_hmac_algs
Definition oscore_cose.c:166
hkdf_hmac_algs::hmac_alg
cose_hmac_alg_t hmac_alg
Definition oscore_cose.c:168
hkdf_hmac_algs::hkdf_alg
cose_hkdf_alg_t hkdf_alg
Definition oscore_cose.c:167