libcoap 4.3.5-develop-5347a62
Loading...
Searching...
No Matches
coap_crypto_internal.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3/*
4 * coap_crypto_internal.h -- Structures, Enums & Functions that are not
5 * exposed to application programming
6 *
7 * Copyright (C) 2017-2026 Olaf Bergmann <bergmann@tzi.org>
8 * Copyright (C) 2021-2026 Jon Shallow <supjps-libcoap@jpshallow.com>
9 *
10 * SPDX-License-Identifier: BSD-2-Clause
11 *
12 * This file is part of the CoAP library libcoap. Please see README for terms
13 * of use.
14 */
15
20
21#ifndef COAP_CRYPTO_INTERNAL_H_
22#define COAP_CRYPTO_INTERNAL_H_
23
30
31#include "oscore/oscore_cose.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#ifndef COAP_CRYPTO_MAX_KEY_SIZE
38#define COAP_CRYPTO_MAX_KEY_SIZE (32)
39#endif /* COAP_CRYPTO_MAX_KEY_SIZE */
40
41#ifndef COAP_OSCORE_DEFAULT_REPLAY_WINDOW
42#define COAP_OSCORE_DEFAULT_REPLAY_WINDOW 32
43#endif /* COAP_OSCORE_DEFAULT_REPLAY_WINDOW */
44
49
59
70
75 void *key_tls;
81}; /* typedef in coap_forward_decls.h */
82
87#if COAP_OSCORE_GROUP_SUPPORT
88 oscore_auth_cred_t cred_type;
89 cose_key_type_t cred_kty;
90 cose_curve_t cred_crv;
91 cose_alg_t cred_alg;
92#endif /* COAP_OSCORE_GROUP_SUPPORT */
94 void *key_tls;
104}; /* typedef in coap_forward_decls.h */
105
115
125
139 coap_bin_const_t *data,
140 coap_bin_const_t *aad,
141 uint8_t *result,
142 size_t *max_result_len);
143
157 coap_bin_const_t *data,
158 coap_bin_const_t *aad,
159 uint8_t *result,
160 size_t *max_result_len);
161
175 coap_bin_const_t *key,
176 coap_bin_const_t *data,
177 coap_bin_const_t **hmac);
178
191 const coap_bin_const_t *data,
192 coap_bin_const_t **hash);
193
194#if COAP_OSCORE_GROUP_SUPPORT
195
204int coap_crypto_check_curve_alg(cose_curve_t alg);
205
214int coap_crypto_check_hash_alg(cose_alg_t alg);
215
224int coap_crypto_read_pem_private_key(const char *filename,
225 coap_crypto_pri_key_t **private);
226
235int coap_crypto_read_asn1_private_key(coap_bin_const_t *binary,
236 coap_crypto_pri_key_t **private);
237
247int coap_crypto_read_raw_private_key(cose_curve_t curve,
248 coap_bin_const_t *binary,
249 coap_crypto_pri_key_t **private);
250
258coap_crypto_pri_key_t *coap_crypto_duplicate_private_key(coap_crypto_pri_key_t *key);
259
265void coap_crypto_delete_private_key(coap_crypto_pri_key_t *key);
266
275int coap_crypto_read_pem_public_cred(const char *filename,
276 coap_crypto_cred_t **public);
277
286int coap_crypto_read_asn1_public_cred(coap_bin_const_t *binary,
287 coap_crypto_cred_t **public);
288
298int coap_crypto_read_raw_public_cred(cose_curve_t curve,
299 coap_bin_const_t *binary,
300 coap_crypto_cred_t **public);
301
309coap_crypto_cred_t *coap_crypto_duplicate_public_cred(coap_crypto_cred_t *public_cred);
310
316void coap_crypto_delete_public_cred(coap_crypto_cred_t *public_cred);
317
328int coap_crypto_hash_sign(cose_alg_t hash,
329 coap_binary_t *signature,
330 coap_bin_const_t *text,
331 coap_crypto_pri_key_t *private_key);
332
343int coap_crypto_hash_verify(cose_alg_t hash,
344 coap_binary_t *signature,
345 coap_bin_const_t *text,
346 coap_crypto_cred_t *public_cred);
347
361int coap_crypto_gen_pkey(cose_curve_t curve,
362 coap_bin_const_t **private,
363 coap_bin_const_t **public);
364
377int coap_crypto_derive_shared_secret(cose_alg_t alg_pairwise,
378 coap_bin_const_t *raw_local_private,
379 coap_bin_const_t *raw_peer_public,
380 coap_bin_const_t **shared_secret);
381
382#endif /* COAP_OSCORE_GROUP_SUPPORT */
383
385
386#ifdef __cplusplus
387}
388#endif
389
390#endif /* COAP_CRYPTO_INTERNAL_H_ */
int coap_crypto_hmac(cose_hmac_alg_t hmac_alg, coap_bin_const_t *key, coap_bin_const_t *data, coap_bin_const_t **hmac)
Create a HMAC hash of the provided data.
coap_bin_const_t coap_crypto_key_t
The structure that holds the Crypto Key.
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.
int coap_crypto_hash(cose_alg_t alg, const coap_bin_const_t *data, coap_bin_const_t **hash)
Create a hash of the provided data.
int coap_crypto_check_hkdf_alg(cose_hkdf_alg_t hkdf_alg)
Check whether the defined hkdf algorithm is supported by the underlying crypto library.
int coap_crypto_check_cipher_alg(cose_alg_t alg)
Check whether the defined cipher algorithm is supported by the underlying crypto library.
cose_hkdf_alg_t
cose_hmac_alg_t
cose_curve_t
Definition oscore_cose.h:62
cose_alg_t
cose_key_type_t
Definition oscore_cose.h:71
An implementation of the CBOR Object Signing and Encryption (RFC).
CoAP binary data definition with const data.
Definition coap_str.h:65
CoAP binary data definition.
Definition coap_str.h:57
The structure that holds the AES Crypto information.
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.
size_t wire_sign_size
Size of signature on wire.
coap_bin_const_t * auth_cred
Authentication Credentials of type type.
coap_bin_const_t * pub_raw
Raw Value of the public key abstracted from key_tls.
cose_curve_t sign_curve
Sign Curve.
coap_bin_const_t * cert_der
DER Value of the certificate used for key_tls.
coap_bin_const_t * pub_der
DER Value of the public key abstracted from key_tls.
void * key_tls
Public Key in the used TLS format.
cose_alg_t sign_hash
Sign Hash Algorithm.
The common structure that holds the Crypto information.
union coap_crypto_param_t::@250042334257003036060227022037266106077265366262 params
coap_crypto_key_t key
The key to use.
coap_crypto_aes_ccm_t aes
Used if AES type encryption.
cose_alg_t alg
The COSE algorithm to use.
Holds private key definitions.
size_t wire_sign_size
Size of signature on wire.
coap_bin_const_t * pri_der
DER Value of the private key abstracted from key_tls.
void * key_tls
Private Key in the used TLS format.
coap_bin_const_t * pri_raw
Raw Value of the private key abstracted from key_tls.