![]() |
Contiki-NG
|
Stateless helpers for the small subset of COSE used by EDHOC: COSE_Encrypt0 with AES-CCM* and COSE_Sign1 with ES256. More...
Functions | |
| size_t | cose_encrypt0_seal (uint8_t alg, const uint8_t *key, const uint8_t *nonce, const uint8_t *external_aad, size_t external_aad_len, uint8_t *buf, size_t plaintext_len, size_t buf_capacity) |
| AEAD-encrypt a buffer in place as a COSE_Encrypt0. | |
| size_t | cose_encrypt0_open (uint8_t alg, const uint8_t *key, const uint8_t *nonce, const uint8_t *external_aad, size_t external_aad_len, uint8_t *buf, size_t ciphertext_len) |
| AEAD-decrypt a buffer in place as a COSE_Encrypt0. | |
| size_t | cose_sign1_sign (int8_t alg, const uint8_t *private_key, const uint8_t *protected_hdr, size_t protected_hdr_len, const uint8_t *external_aad, size_t external_aad_len, const uint8_t *payload, size_t payload_len, uint8_t *signature) |
| Produce a COSE_Sign1 signature. | |
| bool | cose_sign1_verify (int8_t alg, const uint8_t *public_key, const uint8_t *protected_hdr, size_t protected_hdr_len, const uint8_t *external_aad, size_t external_aad_len, const uint8_t *payload, size_t payload_len, const uint8_t *signature, size_t signature_len) |
| Verify a COSE_Sign1 signature. | |
| uint8_t | cose_get_key_len (uint8_t alg_id) |
| Get the symmetric key length for a COSE AEAD algorithm. | |
| uint8_t | cose_get_iv_len (uint8_t alg_id) |
| Get the nonce/IV length for a COSE AEAD algorithm. | |
| uint8_t | cose_get_tag_len (uint8_t alg_id) |
| Get the authentication tag length for a COSE AEAD algorithm. | |
Stateless helpers for the small subset of COSE used by EDHOC: COSE_Encrypt0 with AES-CCM* and COSE_Sign1 with ES256.
| size_t cose_encrypt0_open | ( | uint8_t | alg, |
| const uint8_t * | key, | ||
| const uint8_t * | nonce, | ||
| const uint8_t * | external_aad, | ||
| size_t | external_aad_len, | ||
| uint8_t * | buf, | ||
| size_t | ciphertext_len ) |
AEAD-decrypt a buffer in place as a COSE_Encrypt0.
| alg | COSE AEAD algorithm identifier. |
| key | Symmetric key (length implied by alg). |
| nonce | Nonce/IV (length implied by alg). |
| external_aad | CBOR-encoded external Additional Authenticated Data. |
| external_aad_len | Length of external_aad in bytes. |
| buf | In/out buffer; on entry holds plaintext || tag, on return holds the recovered plaintext. |
| ciphertext_len | Length of plaintext || tag in buf. |
The protected header is treated as empty, matching how EDHOC uses COSE_Encrypt0.
buf holds unauthenticated, attacker-influenced data. Callers must discard buf unless the return value is nonzero. Definition at line 149 of file cose.c.
References cose_get_iv_len(), cose_get_key_len(), and cose_get_tag_len().
| size_t cose_encrypt0_seal | ( | uint8_t | alg, |
| const uint8_t * | key, | ||
| const uint8_t * | nonce, | ||
| const uint8_t * | external_aad, | ||
| size_t | external_aad_len, | ||
| uint8_t * | buf, | ||
| size_t | plaintext_len, | ||
| size_t | buf_capacity ) |
AEAD-encrypt a buffer in place as a COSE_Encrypt0.
| alg | COSE AEAD algorithm identifier. |
| key | Symmetric key (length implied by alg). |
| nonce | Nonce/IV (length implied by alg). |
| external_aad | CBOR-encoded external Additional Authenticated Data. |
| external_aad_len | Length of external_aad in bytes. |
| buf | In/out buffer; on entry holds the plaintext, on return holds plaintext || authentication tag. |
| plaintext_len | Length of the plaintext in buf. |
| buf_capacity | Total number of bytes available in buf. Must be at least plaintext_len plus the tag length for alg, or the call fails without writing the tag. |
The protected header is treated as empty, matching how EDHOC uses COSE_Encrypt0. The Enc_structure built internally is [ "Encrypt0", h'', external_aad ].
Definition at line 103 of file cose.c.
References cose_get_iv_len(), cose_get_key_len(), and cose_get_tag_len().
| uint8_t cose_get_iv_len | ( | uint8_t | alg_id | ) |
Get the nonce/IV length for a COSE AEAD algorithm.
| alg_id | COSE algorithm identifier. |
Definition at line 294 of file cose.c.
Referenced by cose_encrypt0_open(), and cose_encrypt0_seal().
| uint8_t cose_get_key_len | ( | uint8_t | alg_id | ) |
Get the symmetric key length for a COSE AEAD algorithm.
| alg_id | COSE algorithm identifier. |
Definition at line 280 of file cose.c.
Referenced by cose_encrypt0_open(), and cose_encrypt0_seal().
| uint8_t cose_get_tag_len | ( | uint8_t | alg_id | ) |
Get the authentication tag length for a COSE AEAD algorithm.
| alg_id | COSE algorithm identifier. |
Definition at line 308 of file cose.c.
Referenced by cose_encrypt0_open(), and cose_encrypt0_seal().
| size_t cose_sign1_sign | ( | int8_t | alg, |
| const uint8_t * | private_key, | ||
| const uint8_t * | protected_hdr, | ||
| size_t | protected_hdr_len, | ||
| const uint8_t * | external_aad, | ||
| size_t | external_aad_len, | ||
| const uint8_t * | payload, | ||
| size_t | payload_len, | ||
| uint8_t * | signature ) |
Produce a COSE_Sign1 signature.
| alg | Signing algorithm identifier (only ES256 is supported). |
| private_key | ECDSA private key. |
| protected_hdr | CBOR-encoded protected header bytes. |
| protected_hdr_len | Length of protected_hdr. |
| external_aad | CBOR-encoded external Additional Authenticated Data. |
| external_aad_len | Length of external_aad. |
| payload | Payload bytes to sign. |
| payload_len | Length of payload. |
| signature | Output buffer for the signature (P256_SIGNATURE_LEN bytes for ES256). |
Definition at line 209 of file cose.c.
References ecc_sign_hash(), and P256_SIGNATURE_LEN.
Referenced by edhoc_generate_message_2(), and edhoc_generate_message_3().
| bool cose_sign1_verify | ( | int8_t | alg, |
| const uint8_t * | public_key, | ||
| const uint8_t * | protected_hdr, | ||
| size_t | protected_hdr_len, | ||
| const uint8_t * | external_aad, | ||
| size_t | external_aad_len, | ||
| const uint8_t * | payload, | ||
| size_t | payload_len, | ||
| const uint8_t * | signature, | ||
| size_t | signature_len ) |
Verify a COSE_Sign1 signature.
| alg | Signing algorithm identifier (only ES256 is supported). |
| public_key | ECDSA public key (2 * ECC_KEY_LEN bytes for ES256). |
| protected_hdr | CBOR-encoded protected header bytes. |
| protected_hdr_len | Length of protected_hdr. |
| external_aad | CBOR-encoded external Additional Authenticated Data. |
| external_aad_len | Length of external_aad. |
| payload | Payload bytes that were signed. |
| payload_len | Length of payload. |
| signature | Signature to verify. |
| signature_len | Length of signature. |
Definition at line 242 of file cose.c.
References ecc_verify_hash(), and P256_SIGNATURE_LEN.
Referenced by edhoc_authenticate_msg().