libwebsockets
Lightweight C library for HTML5 websockets
lws-cose.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_cose_key
 
struct  lws_cose_validate_res_t
 
struct  lws_cose_sig_ext_pay_t
 
struct  lws_cose_validate_create_info
 
struct  lws_cose_sign_create_info
 

Macros

#define LCSC_FL_ADD_CBOR_TAG   (1 << 0)
 
#define LCSC_FL_ADD_CBOR_PREFER_MAC0   (1 << 1)
 

Typedefs

typedef int64_t cose_param_t
 
typedef struct lws_cose_key lws_cose_key_t
 
typedef int(* lws_cose_key_import_callback) (struct lws_cose_key *s, void *user)
 
typedef int(* lws_cose_sign_ext_pay_cb_t) (lws_cose_sig_ext_pay_t *x)
 
typedef int(* lws_cose_validate_pay_cb_t) (struct lws_cose_validate_context *cps, void *opaque, const uint8_t *paychunk, size_t paychunk_len)
 
typedef struct lws_cose_validate_create_info lws_cose_validate_create_info_t
 
typedef struct lws_cose_sign_create_info lws_cose_sign_create_info_t
 

Enumerations

enum  {
  LWSCOSE_WKL_ALG = 1 , LWSCOSE_WKL_CRIT , LWSCOSE_WKL_CONTENT_TYPE , LWSCOSE_WKL_KID ,
  LWSCOSE_WKL_IV , LWSCOSE_WKL_IV_PARTIAL , LWSCOSE_WKL_COUNTERSIG , LWSCOSE_WKL_COUNTERSIG0 = 9 ,
  LWSCOSE_WKL_KID_CONTEXT , LWSCOSE_WKL_CUPH_NONCE = 256 , LWSCOSE_WKL_CUPH_OWNER_PUBKEY = 257 , LWSCOSE_WKK_KTY = 1 ,
  LWSCOSE_WKK_KID , LWSCOSE_WKK_ALG , LWSCOSE_WKK_KEY_OPS , LWSCOSE_WKK_BASE_IV ,
  LWSCOSE_WKKO_SIGN = 1 , LWSCOSE_WKKO_VERIFY , LWSCOSE_WKKO_ENCRYPT , LWSCOSE_WKKO_DECRYPT ,
  LWSCOSE_WKKO_WRAP_KEY , LWSCOSE_WKKO_UNWRAP_KEY , LWSCOSE_WKKO_DERIVE_KEY , LWSCOSE_WKKO_DERIVE_BITS ,
  LWSCOSE_WKKO_MAC_CREATE , LWSCOSE_WKKO_MAC_VERIFY , LWSCOSE_WKAECDSA_ALG_ES256 = -7 , LWSCOSE_WKAECDSA_ALG_ES384 = -35 ,
  LWSCOSE_WKAECDSA_ALG_ES512 = -36 , LWSCOSE_WKAEDDSA_ALG_EDDSA = -8 , LWSCOSE_WKAHMAC_256_64 = 4 , LWSCOSE_WKAHMAC_256_256 ,
  LWSCOSE_WKAHMAC_384_384 , LWSCOSE_WKAHMAC_512_512 , LWSCOSE_WKAAES_128_64 = 14 , LWSCOSE_WKAAES_256_64 ,
  LWSCOSE_WKAAES_128_128 = 25 , LWSCOSE_WKAAES_256_128 , LWSCOSE_WKAAESGCM_128 = 1 , LWSCOSE_WKAAESGCM_192 ,
  LWSCOSE_WKAAESGCM_256 , LWSCOSE_WKAAESCCM_16_64_128 = 10 , LWSCOSE_WKAAESCCM_16_64_256 , LWSCOSE_WKAAESCCM_64_64_128 ,
  LWSCOSE_WKAAESCCM_64_64_256 , LWSCOSE_WKAAESCCM_16_128_128 , LWSCOSE_WKAAESCCM_16_128_256 , LWSCOSE_WKAAESCCM_64_128_128 ,
  LWSCOSE_WKAAESCCM_64_128_256 , LWSCOSE_WKACHACHA_POLY1305 = 24 , LWSCOSE_WKAPHKDF_SALT = -20 , LWSCOSE_WKAPCTX_PARTY_U_IDENTITY = -21 ,
  LWSCOSE_WKAPCTX_PARTY_U_NONCE = -22 , LWSCOSE_WKAPCTX_PARTY_U_OTHER = -23 , LWSCOSE_WKAPCTX_PARTY_V_IDENTITY = -24 , LWSCOSE_WKAPCTX_PARTY_V_NONCE = -25 ,
  LWSCOSE_WKAPCTX_PARTY_V_OTHER = -26 , LWSCOSE_WKK_DIRECT_CEK = -6 , LWSCOSE_WKK_DIRECT_HKDF_SHA_256 = -10 , LWSCOSE_WKK_DIRECT_HKDF_SHA_512 = -11 ,
  LWSCOSE_WKK_DIRECT_HKDF_AES_128 = -12 , LWSCOSE_WKK_DIRECT_HKDF_AES_256 = -13 , LWSCOSE_WKK_DIRECT_HKDFKW_SHA_256 = -3 , LWSCOSE_WKK_DIRECT_HKDFKW_SHA_512 = -4 ,
  LWSCOSE_WKK_DIRECT_HKDFKW_AES_128 = -5 , LWSCOSE_WKAECDH_ALG_ES_HKDF_256 = -25 , LWSCOSE_WKAECDH_ALG_ES_HKDF_512 = -26 , LWSCOSE_WKAECDH_ALG_SS_HKDF_256 = -27 ,
  LWSCOSE_WKAECDH_ALG_SS_HKDF_512 = -28 , LWSCOSE_WKAPECDH_EPHEMERAL_KEY = -1 , LWSCOSE_WKAPECDH_STATIC_KEY = -2 , LWSCOSE_WKAPECDH_STATIC_KEY_ID = -3 ,
  LWSCOSE_WKAPECDH_ES_A128KW = -29 , LWSCOSE_WKAPECDH_ES_A192KW = -30 , LWSCOSE_WKAPECDH_ES_A256KW = -31 , LWSCOSE_WKAPECDH_SS_A128KW = -32 ,
  LWSCOSE_WKAPECDH_SS_A192KW = -33 , LWSCOSE_WKAPECDH_SS_A256KW = -34 , LWSCOSE_WKKTV_OKP = 1 , LWSCOSE_WKKTV_EC2 = 2 ,
  LWSCOSE_WKKTV_RSA = 3 , LWSCOSE_WKKTV_SYMMETRIC = 4 , LWSCOSE_WKKTV_HSS_LMS = 5 , LWSCOSE_WKKTV_WALNUTDSA = 6 ,
  LWSCOSE_WKEC_P256 = 1 , LWSCOSE_WKEC_P384 , LWSCOSE_WKEC_P521 , LWSCOSE_WKEC_X25519 ,
  LWSCOSE_WKEC_X448 , LWSCOSE_WKEC_ED25519 , LWSCOSE_WKEC_ED448 , LWSCOSE_WKEC_SECP256K1 ,
  LWSCOSE_WKECKP_CRV = -1 , LWSCOSE_WKECKP_X = -2 , LWSCOSE_WKECKP_Y = -3 , LWSCOSE_WKECKP_D = -4 ,
  LWSCOSE_WKOKP_CRV = -1 , LWSCOSE_WKOKP_X = -2 , LWSCOSE_WKOKP_D = -4 , LWSCOSE_WKKPRSA_N = -1 ,
  LWSCOSE_WKKPRSA_E = -2 , LWSCOSE_WKKPRSA_D = -3 , LWSCOSE_WKKPRSA_P = -4 , LWSCOSE_WKKPRSA_Q = -5 ,
  LWSCOSE_WKKPRSA_DP = -6 , LWSCOSE_WKKPRSA_DQ = -7 , LWSCOSE_WKKPRSA_QINV = -8 , LWSCOSE_WKKPRSA_OTHER = -9 ,
  LWSCOSE_WKKPRSA_RI = -10 , LWSCOSE_WKKPRSA_DI = -11 , LWSCOSE_WKKPRSA_TI = -12 , LWSCOSE_WKSYMKP_KEY_VALUE = 4 ,
  LWSCOAP_CONTENTFORMAT_COSE_SIGN = 98 , LWSCOAP_CONTENTFORMAT_COSE_SIGN1 = 18 , LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT = 96 , LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT0 = 16 ,
  LWSCOAP_CONTENTFORMAT_COSE_MAC = 97 , LWSCOAP_CONTENTFORMAT_COSE_MAC0 = 17 , LWSCOAP_CONTENTFORMAT_COSE_KEY = 101 , LWSCOAP_CONTENTFORMAT_COSE_KEY_SET = 102 ,
  LWSCOSE_WKL_COUNTERSIGNATURE0 = 9 , LWSCOSE_WKARSA_ALG_RS256 = -257 , LWSCOSE_WKARSA_ALG_RS384 = -258 , LWSCOSE_WKARSA_ALG_RS512 = -259
}
 
enum  enum_cose_key_meta_tok {
  COSEKEY_META_KTY , COSEKEY_META_KID , COSEKEY_META_KEY_OPS , COSEKEY_META_BASE_IV ,
  COSEKEY_META_ALG , LWS_COUNT_COSE_KEY_ELEMENTS
}
 
enum  lws_cose_sig_types {
  SIGTYPE_UNKNOWN , SIGTYPE_MULTI , SIGTYPE_SINGLE , SIGTYPE_COUNTERSIGNED ,
  SIGTYPE_MAC , SIGTYPE_MAC0
}
 
enum  { LCOSESIGEXTCB_RET_FINISHED , LCOSESIGEXTCB_RET_AGAIN , LCOSESIGEXTCB_RET_ERROR = -1 }
 

Functions

LWS_VISIBLE LWS_EXTERN const char * lws_cose_alg_to_name (cose_param_t alg)
 
LWS_VISIBLE LWS_EXTERN cose_param_t lws_cose_name_to_alg (const char *name)
 
LWS_VISIBLE LWS_EXTERN lws_cose_key_tlws_cose_key_import (lws_dll2_owner_t *pkey_set, lws_cose_key_import_callback cb, void *user, const uint8_t *in, size_t len)
 
LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_key_export (lws_cose_key_t *ck, lws_lec_pctx_t *ctx, int flags)
 
LWS_VISIBLE LWS_EXTERN lws_cose_key_tlws_cose_key_generate (struct lws_context *context, cose_param_t cose_kty, int use_mask, int bits, const char *curve, const uint8_t *kid, size_t kl)
 
LWS_VISIBLE LWS_EXTERN lws_cose_key_tlws_cose_key_from_set (lws_dll2_owner_t *set, const uint8_t *kid, size_t kl)
 
LWS_VISIBLE LWS_EXTERN void lws_cose_key_destroy (lws_cose_key_t **ck)
 
LWS_VISIBLE LWS_EXTERN void lws_cose_key_set_destroy (lws_dll2_owner_t *o)
 
LWS_VISIBLE LWS_EXTERN void lws_cose_key_dump (const lws_cose_key_t *ck)
 
LWS_VISIBLE LWS_EXTERN struct lws_cose_validate_context * lws_cose_validate_create (const lws_cose_validate_create_info_t *info)
 
LWS_VISIBLE LWS_EXTERN int lws_cose_validate_chunk (struct lws_cose_validate_context *cps, const uint8_t *in, size_t in_len, size_t *used_in)
 
LWS_VISIBLE LWS_EXTERN lws_dll2_owner_tlws_cose_validate_results (struct lws_cose_validate_context *cps)
 
LWS_VISIBLE LWS_EXTERN void lws_cose_validate_destroy (struct lws_cose_validate_context **cps)
 
LWS_VISIBLE LWS_EXTERN struct lws_cose_sign_context * lws_cose_sign_create (const lws_cose_sign_create_info_t *info)
 
LWS_VISIBLE LWS_EXTERN int lws_cose_sign_add (struct lws_cose_sign_context *csc, cose_param_t alg, const lws_cose_key_t *ck)
 
LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_sign_payload_chunk (struct lws_cose_sign_context *csc, const uint8_t *in, size_t in_len)
 
LWS_VISIBLE LWS_EXTERN void lws_cose_sign_destroy (struct lws_cose_sign_context **csc)
 

Data Structure Documentation

◆ lws_cose_key

struct lws_cose_key

Definition at line 271 of file lws-cose.h.

+ Collaboration diagram for lws_cose_key:
Data Fields
struct lws_gencrypto_keyelem e[LWS_GENCRYPTO_MAX_KEYEL_COUNT]
struct lws_gencrypto_keyelem meta[LWS_COUNT_COSE_KEY_ELEMENTS]
lws_dll2_t list
int gencrypto_kty

one of LWS_GENCRYPTO_KTY_

cose_param_t kty
cose_param_t cose_alg
cose_param_t cose_curve
char private_key

◆ lws_cose_validate_res_t

struct lws_cose_validate_res_t

Definition at line 366 of file lws-cose.h.

+ Collaboration diagram for lws_cose_validate_res_t:
Data Fields
lws_dll2_t list
const lws_cose_key_t * cose_key
cose_param_t cose_alg
int result

◆ lws_cose_sig_ext_pay_t

struct lws_cose_sig_ext_pay_t

Definition at line 382 of file lws-cose.h.

+ Collaboration diagram for lws_cose_sig_ext_pay_t:
Data Fields
struct lws_cose_validate_context * cps
const uint8_t * ext
size_t xl

◆ lws_cose_validate_create_info

struct lws_cose_validate_create_info

Definition at line 393 of file lws-cose.h.

+ Collaboration diagram for lws_cose_validate_create_info:
Data Fields
struct lws_context * cx

REQUIRED: the lws context

lws_dll2_owner_t * keyset

REQUIRED: one or more cose_keys

enum lws_cose_sig_types sigtype

0 if a CBOR tag is in the sig, else one of SIGTYPE_MULTI, SIGTYPE_SINGLE, etc

lws_cose_validate_pay_cb_t pay_cb

optional: called back with unvalidated payload pieces

void * pay_opaque

optional: passed into pay_cb callback along with payload chunk

lws_cose_sign_ext_pay_cb_t ext_cb

optional extra application data provision callback

void * ext_opaque

optional extra application data provision callback opaque

size_t ext_len

if we have extra app data, this must be set to the length of it

◆ lws_cose_sign_create_info

struct lws_cose_sign_create_info

Definition at line 456 of file lws-cose.h.

+ Collaboration diagram for lws_cose_sign_create_info:
Data Fields
struct lws_context * cx

REQUIRED: the lws context

lws_dll2_owner_t * keyset

REQUIRED: one or more cose_keys

lws_lec_pctx_t * lec

REQUIRED: the cbor output context to emit to, user must initialize with lws_lec_init() beforehand

lws_cose_sign_ext_pay_cb_t ext_cb

optional extra application data provision callback

void * ext_opaque

optional extra application data provision callback opaque

size_t ext_len

if we have extra app data, this must be set to the length of it

size_t inline_payload_len

REQUIRED: size of the inline payload we will provide

int flags

bitmap of LCSC_FL_*

enum lws_cose_sig_types sigtype

0, or sign type hint

Macro Definition Documentation

◆ LCSC_FL_ADD_CBOR_TAG

#define LCSC_FL_ADD_CBOR_TAG   (1 << 0)

Definition at line 453 of file lws-cose.h.

◆ LCSC_FL_ADD_CBOR_PREFER_MAC0

#define LCSC_FL_ADD_CBOR_PREFER_MAC0   (1 << 1)

Definition at line 454 of file lws-cose.h.

Typedef Documentation

◆ cose_param_t

typedef int64_t cose_param_t

Definition at line 259 of file lws-cose.h.

◆ lws_cose_key_t

typedef struct lws_cose_key lws_cose_key_t

◆ lws_cose_key_import_callback

typedef int(* lws_cose_key_import_callback) (struct lws_cose_key *s, void *user)

Definition at line 284 of file lws-cose.h.

◆ lws_cose_sign_ext_pay_cb_t

typedef int(* lws_cose_sign_ext_pay_cb_t) (lws_cose_sig_ext_pay_t *x)

Definition at line 388 of file lws-cose.h.

◆ lws_cose_validate_pay_cb_t

typedef int(* lws_cose_validate_pay_cb_t) (struct lws_cose_validate_context *cps, void *opaque, const uint8_t *paychunk, size_t paychunk_len)

Definition at line 389 of file lws-cose.h.

◆ lws_cose_validate_create_info_t

◆ lws_cose_sign_create_info_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LWSCOSE_WKL_ALG 
LWSCOSE_WKL_CRIT 
LWSCOSE_WKL_CONTENT_TYPE 
LWSCOSE_WKL_KID 
LWSCOSE_WKL_IV 
LWSCOSE_WKL_IV_PARTIAL 
LWSCOSE_WKL_COUNTERSIG 
LWSCOSE_WKL_COUNTERSIG0 
LWSCOSE_WKL_KID_CONTEXT 
LWSCOSE_WKL_CUPH_NONCE 
LWSCOSE_WKL_CUPH_OWNER_PUBKEY 
LWSCOSE_WKK_KTY 
LWSCOSE_WKK_KID 
LWSCOSE_WKK_ALG 
LWSCOSE_WKK_KEY_OPS 
LWSCOSE_WKK_BASE_IV 
LWSCOSE_WKKO_SIGN 
LWSCOSE_WKKO_VERIFY 
LWSCOSE_WKKO_ENCRYPT 
LWSCOSE_WKKO_DECRYPT 
LWSCOSE_WKKO_WRAP_KEY 
LWSCOSE_WKKO_UNWRAP_KEY 
LWSCOSE_WKKO_DERIVE_KEY 
LWSCOSE_WKKO_DERIVE_BITS 
LWSCOSE_WKKO_MAC_CREATE 
LWSCOSE_WKKO_MAC_VERIFY 
LWSCOSE_WKAECDSA_ALG_ES256 
LWSCOSE_WKAECDSA_ALG_ES384 
LWSCOSE_WKAECDSA_ALG_ES512 
LWSCOSE_WKAEDDSA_ALG_EDDSA 
LWSCOSE_WKAHMAC_256_64 
LWSCOSE_WKAHMAC_256_256 
LWSCOSE_WKAHMAC_384_384 
LWSCOSE_WKAHMAC_512_512 
LWSCOSE_WKAAES_128_64 
LWSCOSE_WKAAES_256_64 
LWSCOSE_WKAAES_128_128 
LWSCOSE_WKAAES_256_128 
LWSCOSE_WKAAESGCM_128 
LWSCOSE_WKAAESGCM_192 
LWSCOSE_WKAAESGCM_256 
LWSCOSE_WKAAESCCM_16_64_128 
LWSCOSE_WKAAESCCM_16_64_256 
LWSCOSE_WKAAESCCM_64_64_128 
LWSCOSE_WKAAESCCM_64_64_256 
LWSCOSE_WKAAESCCM_16_128_128 
LWSCOSE_WKAAESCCM_16_128_256 
LWSCOSE_WKAAESCCM_64_128_128 
LWSCOSE_WKAAESCCM_64_128_256 
LWSCOSE_WKACHACHA_POLY1305 
LWSCOSE_WKAPHKDF_SALT 
LWSCOSE_WKAPCTX_PARTY_U_IDENTITY 
LWSCOSE_WKAPCTX_PARTY_U_NONCE 
LWSCOSE_WKAPCTX_PARTY_U_OTHER 
LWSCOSE_WKAPCTX_PARTY_V_IDENTITY 
LWSCOSE_WKAPCTX_PARTY_V_NONCE 
LWSCOSE_WKAPCTX_PARTY_V_OTHER 
LWSCOSE_WKK_DIRECT_CEK 
LWSCOSE_WKK_DIRECT_HKDF_SHA_256 
LWSCOSE_WKK_DIRECT_HKDF_SHA_512 
LWSCOSE_WKK_DIRECT_HKDF_AES_128 
LWSCOSE_WKK_DIRECT_HKDF_AES_256 
LWSCOSE_WKK_DIRECT_HKDFKW_SHA_256 
LWSCOSE_WKK_DIRECT_HKDFKW_SHA_512 
LWSCOSE_WKK_DIRECT_HKDFKW_AES_128 
LWSCOSE_WKAECDH_ALG_ES_HKDF_256 
LWSCOSE_WKAECDH_ALG_ES_HKDF_512 
LWSCOSE_WKAECDH_ALG_SS_HKDF_256 
LWSCOSE_WKAECDH_ALG_SS_HKDF_512 
LWSCOSE_WKAPECDH_EPHEMERAL_KEY 
LWSCOSE_WKAPECDH_STATIC_KEY 
LWSCOSE_WKAPECDH_STATIC_KEY_ID 
LWSCOSE_WKAPECDH_ES_A128KW 
LWSCOSE_WKAPECDH_ES_A192KW 
LWSCOSE_WKAPECDH_ES_A256KW 
LWSCOSE_WKAPECDH_SS_A128KW 
LWSCOSE_WKAPECDH_SS_A192KW 
LWSCOSE_WKAPECDH_SS_A256KW 
LWSCOSE_WKKTV_OKP 
LWSCOSE_WKKTV_EC2 
LWSCOSE_WKKTV_RSA 
LWSCOSE_WKKTV_SYMMETRIC 
LWSCOSE_WKKTV_HSS_LMS 
LWSCOSE_WKKTV_WALNUTDSA 
LWSCOSE_WKEC_P256 
LWSCOSE_WKEC_P384 
LWSCOSE_WKEC_P521 
LWSCOSE_WKEC_X25519 
LWSCOSE_WKEC_X448 
LWSCOSE_WKEC_ED25519 
LWSCOSE_WKEC_ED448 
LWSCOSE_WKEC_SECP256K1 
LWSCOSE_WKECKP_CRV 
LWSCOSE_WKECKP_X 
LWSCOSE_WKECKP_Y 
LWSCOSE_WKECKP_D 
LWSCOSE_WKOKP_CRV 
LWSCOSE_WKOKP_X 
LWSCOSE_WKOKP_D 
LWSCOSE_WKKPRSA_N 
LWSCOSE_WKKPRSA_E 
LWSCOSE_WKKPRSA_D 
LWSCOSE_WKKPRSA_P 
LWSCOSE_WKKPRSA_Q 
LWSCOSE_WKKPRSA_DP 
LWSCOSE_WKKPRSA_DQ 
LWSCOSE_WKKPRSA_QINV 
LWSCOSE_WKKPRSA_OTHER 
LWSCOSE_WKKPRSA_RI 
LWSCOSE_WKKPRSA_DI 
LWSCOSE_WKKPRSA_TI 
LWSCOSE_WKSYMKP_KEY_VALUE 
LWSCOAP_CONTENTFORMAT_COSE_SIGN 
LWSCOAP_CONTENTFORMAT_COSE_SIGN1 
LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT 
LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT0 
LWSCOAP_CONTENTFORMAT_COSE_MAC 
LWSCOAP_CONTENTFORMAT_COSE_MAC0 
LWSCOAP_CONTENTFORMAT_COSE_KEY 
LWSCOAP_CONTENTFORMAT_COSE_KEY_SET 
LWSCOSE_WKL_COUNTERSIGNATURE0 
LWSCOSE_WKARSA_ALG_RS256 
LWSCOSE_WKARSA_ALG_RS384 
LWSCOSE_WKARSA_ALG_RS512 

Definition at line 33 of file lws-cose.h.

33  {
34  /* RFC8152: Table 2: Common Header Parameters
35  * https://www.iana.org/assignments/cose/cose.xhtml#header-parameters
36  */
37 
38  LWSCOSE_WKL_ALG = 1, /* int / tstr */
39  LWSCOSE_WKL_CRIT, /* [+ label ] */
40  LWSCOSE_WKL_CONTENT_TYPE, /* tstr / uint */
41  LWSCOSE_WKL_KID, /* bstr */
42  LWSCOSE_WKL_IV, /* bstr */
43  LWSCOSE_WKL_IV_PARTIAL, /* bstr */
44  LWSCOSE_WKL_COUNTERSIG, /* COSE sig(s) */
45  LWSCOSE_WKL_COUNTERSIG0 = 9, /* bstr */
46  LWSCOSE_WKL_KID_CONTEXT, /* bstr */
47  LWSCOSE_WKL_CUPH_NONCE = 256, /* bstr */
48  LWSCOSE_WKL_CUPH_OWNER_PUBKEY = 257, /* array */
49 
50  /* RFC8152: Table 3: key map labels */
51 
52  LWSCOSE_WKK_KTY = 1, /* int / tstr */
53  LWSCOSE_WKK_KID, /* bstr */
54  LWSCOSE_WKK_ALG, /* int / tstr */
55  LWSCOSE_WKK_KEY_OPS, /* [ + (int / tstr) ] */
56  LWSCOSE_WKK_BASE_IV, /* bstr */
57 
58  /* RFC8152: Table 4: Key Operation Values */
59 
70 
71  /* RFC8152: Table 5: ECDSA algs */
72 
76 
77  /* RFC8152: Table 6: EDDSA algs */
78 
80 
81  /* RFC8152: Table 7: HMAC algs */
82 
87 
88  /* RFC8152: Table 8: AES algs */
89 
94 
95  /* RFC8152: Table 9: AES GCM algs */
96 
100 
101  /* RFC8152: Table 10: AES CCM algs */
102 
111 
112  /* RFC8152: Table 11: CHACHA20 / Poly1305 */
113 
115 
116  /* RFC8152: Table 13: HKDF param */
117 
118  LWSCOSE_WKAPHKDF_SALT = -20,
119 
120  /* RFC8152: Table 14: Context Algorithm Parameters */
121 
128 
129  /* RFC8152: Table 15: Direct key */
130 
132 
133  /* RFC8152: Table 16: Direct key with KDF */
134 
139 
140  /* RFC8152: Table 17: AES Key Wrap Algorithm Values */
141 
145 
146  /* RFC8152: Table 18: ECDH Algorithm Values */
147 
152 
153  /* RFC8152: Table 19: ECDH Algorithm Parameters */
154 
158 
159  /* RFC8152: Table 20: ECDH Algorithm Parameters with key wrap */
160 
167 
168  /* RFC8152: Table 21: Key Type Values
169  * https://www.iana.org/assignments/cose/cose.xhtml#key-type
170  */
171 
172  LWSCOSE_WKKTV_OKP = 1,
173  LWSCOSE_WKKTV_EC2 = 2,
174  LWSCOSE_WKKTV_RSA = 3,
178 
179 
180  /* RFC8152: Table 22: Elliptic Curves
181  * https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
182  */
183 
184  LWSCOSE_WKEC_P256 = 1,
192 
193  /* RFC8152: Table 23: EC Key Parameters */
194 
195  LWSCOSE_WKECKP_CRV = -1,
196  LWSCOSE_WKECKP_X = -2,
197  LWSCOSE_WKECKP_Y = -3,
198  LWSCOSE_WKECKP_D = -4,
199 
200  /* RFC8152: Table 24: Octet Key Pair (OKP) Parameters */
201 
202  LWSCOSE_WKOKP_CRV = -1,
203  LWSCOSE_WKOKP_X = -2,
204  LWSCOSE_WKOKP_D = -4,
205 
206  /* Additional from
207  * https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters
208  */
209 
210  LWSCOSE_WKKPRSA_N = -1,
211  LWSCOSE_WKKPRSA_E = -2,
212  LWSCOSE_WKKPRSA_D = -3,
213  LWSCOSE_WKKPRSA_P = -4,
214  LWSCOSE_WKKPRSA_Q = -5,
215  LWSCOSE_WKKPRSA_DP = -6,
216  LWSCOSE_WKKPRSA_DQ = -7,
219  LWSCOSE_WKKPRSA_RI = -10,
220  LWSCOSE_WKKPRSA_DI = -11,
221  LWSCOSE_WKKPRSA_TI = -12,
222 
223  /* RFC8152: Table 25: Symmetric Key Parameters */
224 
226 
227  /* RFC8152: Table 26: CoAP Content-Formats for COSE */
228 
237 
238  /* RFC8152: Table 27: Header Parameter for CounterSignature0 */
239 
240  LWSCOSE_WKL_COUNTERSIGNATURE0 = 9, /* bstr */
241 
242  /* RFC8812: Table 1: RSASSA-PKCS1-v1_5 Algorithm Values */
243 
244  LWSCOSE_WKARSA_ALG_RS256 = -257, /* + SHA-256 */
245  LWSCOSE_WKARSA_ALG_RS384 = -258, /* + SHA-384 */
246  LWSCOSE_WKARSA_ALG_RS512 = -259, /* + SHA-512 */
247 };
@ LWSCOSE_WKAAES_128_128
Definition: lws-cose.h:92
@ LWSCOSE_WKAPECDH_STATIC_KEY
Definition: lws-cose.h:156
@ LWSCOSE_WKAAESCCM_64_128_128
Definition: lws-cose.h:109
@ LWSCOSE_WKECKP_CRV
Definition: lws-cose.h:195
@ LWSCOSE_WKAECDSA_ALG_ES384
Definition: lws-cose.h:74
@ LWSCOSE_WKAAESCCM_64_64_128
Definition: lws-cose.h:105
@ LWSCOSE_WKKPRSA_D
Definition: lws-cose.h:212
@ LWSCOSE_WKOKP_D
Definition: lws-cose.h:204
@ LWSCOAP_CONTENTFORMAT_COSE_MAC
Definition: lws-cose.h:233
@ LWSCOSE_WKEC_ED25519
Definition: lws-cose.h:189
@ LWSCOSE_WKL_CUPH_NONCE
Definition: lws-cose.h:47
@ LWSCOSE_WKL_KID
Definition: lws-cose.h:41
@ LWSCOSE_WKKPRSA_Q
Definition: lws-cose.h:214
@ LWSCOSE_WKECKP_D
Definition: lws-cose.h:198
@ LWSCOSE_WKKO_UNWRAP_KEY
Definition: lws-cose.h:65
@ LWSCOSE_WKAAESCCM_64_128_256
Definition: lws-cose.h:110
@ LWSCOSE_WKOKP_X
Definition: lws-cose.h:203
@ LWSCOSE_WKK_KTY
Definition: lws-cose.h:52
@ LWSCOAP_CONTENTFORMAT_COSE_KEY_SET
Definition: lws-cose.h:236
@ LWSCOSE_WKAPCTX_PARTY_U_OTHER
Definition: lws-cose.h:124
@ LWSCOSE_WKAPCTX_PARTY_U_NONCE
Definition: lws-cose.h:123
@ LWSCOSE_WKAAESGCM_256
Definition: lws-cose.h:99
@ LWSCOSE_WKL_IV_PARTIAL
Definition: lws-cose.h:43
@ LWSCOSE_WKKO_VERIFY
Definition: lws-cose.h:61
@ LWSCOSE_WKACHACHA_POLY1305
Definition: lws-cose.h:114
@ LWSCOSE_WKAHMAC_256_256
Definition: lws-cose.h:84
@ LWSCOSE_WKKPRSA_OTHER
Definition: lws-cose.h:218
@ LWSCOSE_WKKTV_WALNUTDSA
Definition: lws-cose.h:177
@ LWSCOSE_WKKTV_SYMMETRIC
Definition: lws-cose.h:175
@ LWSCOSE_WKAPECDH_ES_A128KW
Definition: lws-cose.h:161
@ LWSCOSE_WKAAESCCM_16_64_128
Definition: lws-cose.h:103
@ LWSCOSE_WKK_KEY_OPS
Definition: lws-cose.h:55
@ LWSCOSE_WKKPRSA_TI
Definition: lws-cose.h:221
@ LWSCOSE_WKAECDSA_ALG_ES512
Definition: lws-cose.h:75
@ LWSCOSE_WKKPRSA_RI
Definition: lws-cose.h:219
@ LWSCOSE_WKAPECDH_SS_A256KW
Definition: lws-cose.h:166
@ LWSCOSE_WKL_CONTENT_TYPE
Definition: lws-cose.h:40
@ LWSCOSE_WKAAESCCM_16_64_256
Definition: lws-cose.h:104
@ LWSCOSE_WKAPECDH_SS_A128KW
Definition: lws-cose.h:164
@ LWSCOSE_WKK_DIRECT_HKDFKW_SHA_256
Definition: lws-cose.h:142
@ LWSCOSE_WKAPHKDF_SALT
Definition: lws-cose.h:118
@ LWSCOSE_WKARSA_ALG_RS384
Definition: lws-cose.h:245
@ LWSCOSE_WKAPECDH_ES_A192KW
Definition: lws-cose.h:162
@ LWSCOSE_WKAAESGCM_192
Definition: lws-cose.h:98
@ LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT
Definition: lws-cose.h:231
@ LWSCOSE_WKL_CUPH_OWNER_PUBKEY
Definition: lws-cose.h:48
@ LWSCOSE_WKK_DIRECT_HKDF_AES_256
Definition: lws-cose.h:138
@ LWSCOSE_WKKTV_HSS_LMS
Definition: lws-cose.h:176
@ LWSCOSE_WKKO_DERIVE_BITS
Definition: lws-cose.h:67
@ LWSCOSE_WKAAESGCM_128
Definition: lws-cose.h:97
@ LWSCOSE_WKKO_DERIVE_KEY
Definition: lws-cose.h:66
@ LWSCOSE_WKKTV_RSA
Definition: lws-cose.h:174
@ LWSCOSE_WKECKP_Y
Definition: lws-cose.h:197
@ LWSCOSE_WKK_DIRECT_HKDFKW_AES_128
Definition: lws-cose.h:144
@ LWSCOSE_WKAAESCCM_64_64_256
Definition: lws-cose.h:106
@ LWSCOSE_WKAPCTX_PARTY_U_IDENTITY
Definition: lws-cose.h:122
@ LWSCOSE_WKAPCTX_PARTY_V_IDENTITY
Definition: lws-cose.h:125
@ LWSCOSE_WKEC_X25519
Definition: lws-cose.h:187
@ LWSCOSE_WKSYMKP_KEY_VALUE
Definition: lws-cose.h:225
@ LWSCOSE_WKKTV_OKP
Definition: lws-cose.h:172
@ LWSCOSE_WKAPECDH_EPHEMERAL_KEY
Definition: lws-cose.h:155
@ LWSCOAP_CONTENTFORMAT_COSE_SIGN1
Definition: lws-cose.h:230
@ LWSCOSE_WKKPRSA_E
Definition: lws-cose.h:211
@ LWSCOSE_WKAAES_128_64
Definition: lws-cose.h:90
@ LWSCOSE_WKKTV_EC2
Definition: lws-cose.h:173
@ LWSCOSE_WKL_COUNTERSIGNATURE0
Definition: lws-cose.h:240
@ LWSCOSE_WKAPECDH_STATIC_KEY_ID
Definition: lws-cose.h:157
@ LWSCOSE_WKKPRSA_QINV
Definition: lws-cose.h:217
@ LWSCOSE_WKKO_SIGN
Definition: lws-cose.h:60
@ LWSCOSE_WKEC_ED448
Definition: lws-cose.h:190
@ LWSCOSE_WKL_ALG
Definition: lws-cose.h:38
@ LWSCOAP_CONTENTFORMAT_COSE_KEY
Definition: lws-cose.h:235
@ LWSCOSE_WKARSA_ALG_RS512
Definition: lws-cose.h:246
@ LWSCOSE_WKK_DIRECT_HKDF_SHA_256
Definition: lws-cose.h:135
@ LWSCOSE_WKK_DIRECT_HKDFKW_SHA_512
Definition: lws-cose.h:143
@ LWSCOSE_WKECKP_X
Definition: lws-cose.h:196
@ LWSCOSE_WKK_KID
Definition: lws-cose.h:53
@ LWSCOSE_WKAECDH_ALG_ES_HKDF_512
Definition: lws-cose.h:149
@ LWSCOSE_WKKO_MAC_CREATE
Definition: lws-cose.h:68
@ LWSCOSE_WKAAES_256_128
Definition: lws-cose.h:93
@ LWSCOSE_WKKPRSA_DQ
Definition: lws-cose.h:216
@ LWSCOSE_WKL_COUNTERSIG
Definition: lws-cose.h:44
@ LWSCOSE_WKEC_P521
Definition: lws-cose.h:186
@ LWSCOSE_WKKPRSA_DI
Definition: lws-cose.h:220
@ LWSCOSE_WKK_BASE_IV
Definition: lws-cose.h:56
@ LWSCOSE_WKOKP_CRV
Definition: lws-cose.h:202
@ LWSCOSE_WKK_DIRECT_HKDF_AES_128
Definition: lws-cose.h:137
@ LWSCOSE_WKK_DIRECT_CEK
Definition: lws-cose.h:131
@ LWSCOAP_CONTENTFORMAT_COSE_ENCRYPT0
Definition: lws-cose.h:232
@ LWSCOSE_WKL_CRIT
Definition: lws-cose.h:39
@ LWSCOSE_WKAHMAC_384_384
Definition: lws-cose.h:85
@ LWSCOSE_WKL_COUNTERSIG0
Definition: lws-cose.h:45
@ LWSCOSE_WKEC_P256
Definition: lws-cose.h:184
@ LWSCOSE_WKK_DIRECT_HKDF_SHA_512
Definition: lws-cose.h:136
@ LWSCOSE_WKAAESCCM_16_128_256
Definition: lws-cose.h:108
@ LWSCOAP_CONTENTFORMAT_COSE_SIGN
Definition: lws-cose.h:229
@ LWSCOSE_WKKO_ENCRYPT
Definition: lws-cose.h:62
@ LWSCOSE_WKEC_P384
Definition: lws-cose.h:185
@ LWSCOSE_WKAECDSA_ALG_ES256
Definition: lws-cose.h:73
@ LWSCOSE_WKEC_SECP256K1
Definition: lws-cose.h:191
@ LWSCOSE_WKAAES_256_64
Definition: lws-cose.h:91
@ LWSCOSE_WKEC_X448
Definition: lws-cose.h:188
@ LWSCOSE_WKK_ALG
Definition: lws-cose.h:54
@ LWSCOSE_WKAECDH_ALG_SS_HKDF_256
Definition: lws-cose.h:150
@ LWSCOSE_WKAHMAC_256_64
Definition: lws-cose.h:83
@ LWSCOAP_CONTENTFORMAT_COSE_MAC0
Definition: lws-cose.h:234
@ LWSCOSE_WKAECDH_ALG_SS_HKDF_512
Definition: lws-cose.h:151
@ LWSCOSE_WKAHMAC_512_512
Definition: lws-cose.h:86
@ LWSCOSE_WKL_KID_CONTEXT
Definition: lws-cose.h:46
@ LWSCOSE_WKKO_DECRYPT
Definition: lws-cose.h:63
@ LWSCOSE_WKAPCTX_PARTY_V_NONCE
Definition: lws-cose.h:126
@ LWSCOSE_WKAEDDSA_ALG_EDDSA
Definition: lws-cose.h:79
@ LWSCOSE_WKAECDH_ALG_ES_HKDF_256
Definition: lws-cose.h:148
@ LWSCOSE_WKAPCTX_PARTY_V_OTHER
Definition: lws-cose.h:127
@ LWSCOSE_WKKO_MAC_VERIFY
Definition: lws-cose.h:69
@ LWSCOSE_WKAPECDH_ES_A256KW
Definition: lws-cose.h:163
@ LWSCOSE_WKKPRSA_N
Definition: lws-cose.h:210
@ LWSCOSE_WKARSA_ALG_RS256
Definition: lws-cose.h:244
@ LWSCOSE_WKKPRSA_DP
Definition: lws-cose.h:215
@ LWSCOSE_WKL_IV
Definition: lws-cose.h:42
@ LWSCOSE_WKAAESCCM_16_128_128
Definition: lws-cose.h:107
@ LWSCOSE_WKKPRSA_P
Definition: lws-cose.h:213
@ LWSCOSE_WKKO_WRAP_KEY
Definition: lws-cose.h:64
@ LWSCOSE_WKAPECDH_SS_A192KW
Definition: lws-cose.h:165

◆ enum_cose_key_meta_tok

Enumerator
COSEKEY_META_KTY 
COSEKEY_META_KID 
COSEKEY_META_KEY_OPS 
COSEKEY_META_BASE_IV 
COSEKEY_META_ALG 
LWS_COUNT_COSE_KEY_ELEMENTS 

Definition at line 249 of file lws-cose.h.

249  {
255 
257 };
@ COSEKEY_META_KTY
Definition: lws-cose.h:250
@ COSEKEY_META_KID
Definition: lws-cose.h:251
@ LWS_COUNT_COSE_KEY_ELEMENTS
Definition: lws-cose.h:256
@ COSEKEY_META_BASE_IV
Definition: lws-cose.h:253
@ COSEKEY_META_ALG
Definition: lws-cose.h:254
@ COSEKEY_META_KEY_OPS
Definition: lws-cose.h:252

◆ lws_cose_sig_types

Enumerator
SIGTYPE_UNKNOWN 
SIGTYPE_MULTI 
SIGTYPE_SINGLE 
SIGTYPE_COUNTERSIGNED 
SIGTYPE_MAC 
SIGTYPE_MAC0 

Definition at line 355 of file lws-cose.h.

355  {
359  SIGTYPE_COUNTERSIGNED, /* not yet supported */
360  SIGTYPE_MAC, /* only supported for validation */
361  SIGTYPE_MAC0,
362 };
@ SIGTYPE_MULTI
Definition: lws-cose.h:357
@ SIGTYPE_MAC0
Definition: lws-cose.h:361
@ SIGTYPE_SINGLE
Definition: lws-cose.h:358
@ SIGTYPE_COUNTERSIGNED
Definition: lws-cose.h:359
@ SIGTYPE_UNKNOWN
Definition: lws-cose.h:356
@ SIGTYPE_MAC
Definition: lws-cose.h:360

◆ anonymous enum

anonymous enum
Enumerator
LCOSESIGEXTCB_RET_FINISHED 
LCOSESIGEXTCB_RET_AGAIN 
LCOSESIGEXTCB_RET_ERROR 

Definition at line 376 of file lws-cose.h.

376  {
380 };
@ LCOSESIGEXTCB_RET_FINISHED
Definition: lws-cose.h:377
@ LCOSESIGEXTCB_RET_AGAIN
Definition: lws-cose.h:378
@ LCOSESIGEXTCB_RET_ERROR
Definition: lws-cose.h:379

Function Documentation

◆ lws_cose_alg_to_name()

LWS_VISIBLE LWS_EXTERN const char* lws_cose_alg_to_name ( cose_param_t  alg)

◆ lws_cose_name_to_alg()

LWS_VISIBLE LWS_EXTERN cose_param_t lws_cose_name_to_alg ( const char *  name)

◆ lws_cose_key_import()

LWS_VISIBLE LWS_EXTERN lws_cose_key_t* lws_cose_key_import ( lws_dll2_owner_t pkey_set,
lws_cose_key_import_callback  cb,
void *  user,
const uint8_t *  in,
size_t  len 
)

lws_cose_jwk_import() - Create an lws_cose_key_t object from cose_key CBOR

Parameters
pkey_setNULL, or a pointer to an lws_dll2_owner_t for a cose_key set
cbcallback for each jwk-processed key, or NULL if importing a single key with no parent "keys" JSON
userpointer to be passed to the callback, otherwise ignored by lws. NULL if importing a single key with no parent "keys" JSON
ina single cose_key
lenthe length of the cose_key in bytes

Creates a single lws_cose_key_t if pkey_set is NULL or if the incoming CBOR doesn't start with an array, otherwise expects a CBOR array containing zero or more cose_key CBOR, and adds each to the pkey_set lws_dll2_owner_t struct. Created lws_cose_key_t are filled with data from the COSE representation and can be used with other COSE crypto ops.

◆ lws_cose_key_export()

LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_key_export ( lws_cose_key_t ck,
lws_lec_pctx_t ctx,
int  flags 
)

lws_cose_key_export() - Create cose_key CBOR from an lws_cose_key_t

Parameters
ckthe lws_cose_key_t to export to CBOR
ctxthe CBOR writing context (same as for lws_lec_printf())
flags0 to export only public elements, or LWSJWKF_EXPORT_PRIVATE

Creates an lws_jwk struct filled with data from the COSE representation.

◆ lws_cose_key_generate()

LWS_VISIBLE LWS_EXTERN lws_cose_key_t* lws_cose_key_generate ( struct lws_context *  context,
cose_param_t  cose_kty,
int  use_mask,
int  bits,
const char *  curve,
const uint8_t *  kid,
size_t  kl 
)

lws_cose_key_generate() - generate a fresh key

Parameters
contextthe lws_context used to get random
cose_ktyone of LWSCOSE_WKKTV_ indicating the well-known key type
use_mask0, or a bitfield where (1 << LWSCOSE_WKKO_...) set means valid for use
bitskey bits for RSA
curvefor EC keys, one of "P-256", "P-384" or "P-521" currently
kidstring describing the key, or NULL

Create an lws_cose_key_t of the specified type and return it

◆ lws_cose_key_from_set()

LWS_VISIBLE LWS_EXTERN lws_cose_key_t* lws_cose_key_from_set ( lws_dll2_owner_t set,
const uint8_t *  kid,
size_t  kl 
)

◆ lws_cose_key_destroy()

LWS_VISIBLE LWS_EXTERN void lws_cose_key_destroy ( lws_cose_key_t **  ck)

◆ lws_cose_key_set_destroy()

LWS_VISIBLE LWS_EXTERN void lws_cose_key_set_destroy ( lws_dll2_owner_t o)

◆ lws_cose_key_dump()

LWS_VISIBLE LWS_EXTERN void lws_cose_key_dump ( const lws_cose_key_t ck)

◆ lws_cose_validate_create()

LWS_VISIBLE LWS_EXTERN struct lws_cose_validate_context* lws_cose_validate_create ( const lws_cose_validate_create_info_t info)

lws_cose_validate_create() - create a signature validation context

Parameters
infostruct describing the validation context to create

Creates a signature validation context set up as described in info.

You can then pass the signature cbor chunks to it using lws_cose_validate_chunk(), finialize and get the results list using lws_cose_validate_results() and destroy with lws_cose_validate_destroy().

◆ lws_cose_validate_chunk()

LWS_VISIBLE LWS_EXTERN int lws_cose_validate_chunk ( struct lws_cose_validate_context *  cps,
const uint8_t *  in,
size_t  in_len,
size_t *  used_in 
)

lws_cose_validate_chunk() - passes chunks of CBOR into the signature validator

Parameters
cpsthe validation context
inthe chunk of CBOR (does not have to be logically complete)
in_lennumber of bytes available at in

Parses signature CBOR to produce a list of result objects.

◆ lws_cose_validate_results()

LWS_VISIBLE LWS_EXTERN lws_dll2_owner_t* lws_cose_validate_results ( struct lws_cose_validate_context *  cps)

◆ lws_cose_validate_destroy()

LWS_VISIBLE LWS_EXTERN void lws_cose_validate_destroy ( struct lws_cose_validate_context **  cps)

◆ lws_cose_sign_create()

LWS_VISIBLE LWS_EXTERN struct lws_cose_sign_context* lws_cose_sign_create ( const lws_cose_sign_create_info_t info)

lws_cose_sign_create() - Create a signing context

Parameters
infoa structure describing the signing context you want to create

This allocates and returns a signing context created according to what is in the info parameter.

info must be prepared with the lws_context, a keyset to use, a CBOR output context, and the inline payload length.

Returns NULL on failure or the created signing context ready to add alg(s) to.

◆ lws_cose_sign_add()

LWS_VISIBLE LWS_EXTERN int lws_cose_sign_add ( struct lws_cose_sign_context *  csc,
cose_param_t  alg,
const lws_cose_key_t ck 
)

◆ lws_cose_sign_payload_chunk()

LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_sign_payload_chunk ( struct lws_cose_sign_context *  csc,
const uint8_t *  in,
size_t  in_len 
)

◆ lws_cose_sign_destroy()

LWS_VISIBLE LWS_EXTERN void lws_cose_sign_destroy ( struct lws_cose_sign_context **  csc)