credman.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 HAW Hamburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
26 #include <unistd.h>
27 #include <stdint.h>
28 #include "modules.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
42 #ifndef CONFIG_CREDMAN_MAX_CREDENTIALS
43 #define CONFIG_CREDMAN_MAX_CREDENTIALS (2)
44 #endif
45 
49 #ifndef CONFIG_CREDMAN_MAX_ASN1_OBJ
50 #define CONFIG_CREDMAN_MAX_ASN1_OBJ (8)
51 #endif
57 typedef struct {
58  const void *s;
59  size_t len;
61 
65 typedef struct {
69 } psk_params_t;
70 
74 typedef struct {
75  const void *x;
76  const void *y;
78 
82 typedef struct {
83  const void *private_key;
88 
92 typedef uint16_t credman_tag_t;
93 
97 #define CREDMAN_TAG_EMPTY (0)
98 
102 typedef enum {
112 
116 typedef struct {
119  union {
122  } params;
124 
128 enum {
136 };
137 
157 int credman_add(const credman_credential_t *credential);
158 
171  credman_type_t type);
172 
182 
191 
192 #if IS_USED(MODULE_CREDMAN_LOAD) || DOXYGEN
213 int credman_load_public_key(const void *buf, size_t buf_len, ecdsa_public_key_t *out);
214 
237 int credman_load_private_key(const void *buf, size_t buf_len, credman_credential_t *cred);
238 
259 int credman_load_private_ecc_key(const void *buf, size_t buf_len, credman_credential_t *cred);
260 #endif /* MODULE_CREDMAN_LOAD || DOXYGEN */
261 
262 #ifdef TEST_SUITES
266 void credman_reset(void);
267 #endif /*TEST_SUITES */
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
int credman_load_public_key(const void *buf, size_t buf_len, ecdsa_public_key_t *out)
Load a public key from a buffer, as a SubjectPublicKeyInfo sequence, according to RFC5280.
void credman_delete(credman_tag_t tag, credman_type_t type)
Delete a credential from the credential pool.
int credman_get_used_count(void)
Gets the number of credentials currently in the credential pool.
int credman_add(const credman_credential_t *credential)
Adds a credential to the credential pool.
int credman_load_private_key(const void *buf, size_t buf_len, credman_credential_t *cred)
Load a private key from a buffer, as a OneAsymmetricKey sequence, according to RFC5958.
int credman_load_private_ecc_key(const void *buf, size_t buf_len, credman_credential_t *cred)
Load an ECC private key from a buffer, as an ECPrivateKey sequence, according to RFC5915.
uint16_t credman_tag_t
Tag of the credential.
Definition: credman.h:92
credman_type_t
Credential types.
Definition: credman.h:102
int credman_get(credman_credential_t *credential, credman_tag_t tag, credman_type_t type)
Gets a credential from credential pool.
void credman_reset(void)
Empties the credential pool.
@ CREDMAN_EXIST
Credential already exist in system pool.
Definition: credman.h:130
@ CREDMAN_NOT_FOUND
Credential not found in the system pool.
Definition: credman.h:132
@ CREDMAN_ERROR
Other errors.
Definition: credman.h:135
@ CREDMAN_INVALID
Invalid input parameter(s)
Definition: credman.h:133
@ CREDMAN_OK
No error.
Definition: credman.h:129
@ CREDMAN_NO_SPACE
No space in system pool for new credential.
Definition: credman.h:131
@ CREDMAN_TYPE_UNKNOWN
Unknown credential type.
Definition: credman.h:134
@ CREDMAN_TYPE_EMPTY
Empty type.
Definition: credman.h:108
@ CREDMAN_TYPE_ECDSA
ECDSA credential type.
Definition: credman.h:110
@ CREDMAN_TYPE_PSK
PSK credential type.
Definition: credman.h:109
Common macros and compiler attributes/pragmas configuration.
Buffer of the credential.
Definition: credman.h:57
size_t len
Length of credman_buffer_t::s.
Definition: credman.h:59
const void * s
Pointer to the buffer.
Definition: credman.h:58
Credential information.
Definition: credman.h:116
psk_params_t psk
PSK credential parameters.
Definition: credman.h:120
credman_type_t type
Type of the credential.
Definition: credman.h:117
ecdsa_params_t ecdsa
ECDSA credential parameters.
Definition: credman.h:121
credman_tag_t tag
Tag of the credential.
Definition: credman.h:118
ECDSA parameters.
Definition: credman.h:82
const void * private_key
Pointer to the private key.
Definition: credman.h:83
size_t client_keys_size
Size of ecdsa_params_t::clients_keys.
Definition: credman.h:86
ecdsa_public_key_t public_key
Public key.
Definition: credman.h:84
ecdsa_public_key_t * client_keys
Array of clients public keys.
Definition: credman.h:85
ECDSA public keys.
Definition: credman.h:74
const void * x
X part of the public key.
Definition: credman.h:75
const void * y
Y part of the public key.
Definition: credman.h:76
PSK parameters.
Definition: credman.h:65
credman_buffer_t hint
Hint buffer.
Definition: credman.h:68
credman_buffer_t key
Key buffer.
Definition: credman.h:66
credman_buffer_t id
ID buffer.
Definition: credman.h:67