Loading...
Searching...
No Matches
ctap_crypto.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
23#ifndef FIDO2_CTAP_CTAP_CRYPTO_H
24#define FIDO2_CTAP_CTAP_CRYPTO_H
25
26#include <stdint.h>
27
28#include "hashes/sha256.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
37#define CTAP_CRYPTO_KEY_SIZE 32
38
42#define CTAP_CRYPTO_ES256_DER_MAX_SIZE 72
43
47typedef struct {
51
61
70
79int fido2_ctap_crypto_prng(uint8_t *buf, size_t len);
80
89
99int fido2_ctap_crypto_sha256_update(sha256_context_t *ctx, const void *data, size_t len);
100
110
123int fido2_ctap_crypto_sha256(const void *data, size_t len,
124 void *digest);
125
136 size_t key_length);
137
147int fido2_ctap_crypto_hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len);
148
159
175 size_t key_length, const void *data, size_t len,
176 void *digest);
177
187int fido2_ctap_crypto_gen_keypair(ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t len);
188
200int fido2_ctap_crypto_ecdh(uint8_t *out, size_t len,
201 ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t key_len);
202
215int fido2_ctap_crypto_get_sig(uint8_t *hash, size_t hash_len, uint8_t *sig,
216 size_t *sig_len, const uint8_t *key, size_t key_len);
217
230int fido2_ctap_crypto_aes_enc(uint8_t * out, size_t *out_len, uint8_t * in,
231 size_t in_len, const uint8_t * key, size_t key_len);
232
245int fido2_ctap_crypto_aes_dec(uint8_t * out, size_t *out_len, uint8_t * in,
246 size_t in_len, const uint8_t * key, size_t key_len);
247
266int fido2_ctap_crypto_aes_ccm_enc(uint8_t *out, size_t out_len,
267 const uint8_t *in, size_t in_len,
268 uint8_t *auth_data, size_t auth_data_len,
269 uint8_t mac_len, uint8_t length_encoding,
270 const uint8_t *nonce, size_t nonce_len,
271 const uint8_t *key, size_t key_len);
272
291int fido2_ctap_crypto_aes_ccm_dec(uint8_t *out, size_t out_len,
292 const uint8_t *in, size_t in_len,
293 uint8_t *auth_data, size_t auth_data_len,
294 uint8_t mac_len, uint8_t length_encoding,
295 const uint8_t *nonce, size_t nonce_len,
296 const uint8_t *key, size_t key_len);
297#ifdef __cplusplus
298}
299#endif
300#endif /* FIDO2_CTAP_CTAP_CRYPTO_H */
int fido2_ctap_crypto_gen_keypair(ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t len)
Generate cryptographic key pair.
int fido2_ctap_crypto_sha256(const void *data, size_t len, void *digest)
Wrapper function for sha256.
int fido2_ctap_crypto_aes_ccm_dec(uint8_t *out, size_t out_len, const uint8_t *in, size_t in_len, uint8_t *auth_data, size_t auth_data_len, uint8_t mac_len, uint8_t length_encoding, const uint8_t *nonce, size_t nonce_len, const uint8_t *key, size_t key_len)
Encrypt data using AES-128-CCM.
int fido2_ctap_crypto_prng(uint8_t *buf, size_t len)
Wrapper function for random_bytes.
int fido2_ctap_crypto_sha256_update(sha256_context_t *ctx, const void *data, size_t len)
Wrapper function for sha256_update.
int fido2_ctap_crypto_ecdh(uint8_t *out, size_t len, ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t key_len)
Elliptic-curve Diffie-Hellmann.
int fido2_ctap_crypto_hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len)
Wrapper function for hmac_sha256_update.
#define CTAP_CRYPTO_KEY_SIZE
Size in bytes of cryptographic keys used.
Definition ctap_crypto.h:37
int fido2_ctap_crypto_aes_dec(uint8_t *out, size_t *out_len, uint8_t *in, size_t in_len, const uint8_t *key, size_t key_len)
Decrypt data using AES-256-CBC.
int fido2_ctap_crypto_hmac_sha256_final(hmac_context_t *ctx, void *digest)
Wrapper function for hmac_sha256_final.
int fido2_ctap_crypto_aes_ccm_enc(uint8_t *out, size_t out_len, const uint8_t *in, size_t in_len, uint8_t *auth_data, size_t auth_data_len, uint8_t mac_len, uint8_t length_encoding, const uint8_t *nonce, size_t nonce_len, const uint8_t *key, size_t key_len)
Encrypt data using AES-128-CCM.
int fido2_ctap_crypto_hmac_sha256(const void *key, size_t key_length, const void *data, size_t len, void *digest)
Wrapper function for hmac_sha256.
int fido2_ctap_crypto_aes_enc(uint8_t *out, size_t *out_len, uint8_t *in, size_t in_len, const uint8_t *key, size_t key_len)
Encrypt data using AES-256-CBC.
int fido2_ctap_crypto_hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length)
Wrapper function for hmac_sha256_init.
int fido2_ctap_crypto_get_sig(uint8_t *hash, size_t hash_len, uint8_t *sig, size_t *sig_len, const uint8_t *key, size_t key_len)
Create cryptographic signature.
int fido2_ctap_crypto_sha256_init(sha256_context_t *ctx)
Wrapper function for sha256_init.
int fido2_ctap_crypto_sha256_final(sha256_context_t *ctx, void *digest)
Wrapper for sha256_final.
int fido2_ctap_crypto_init(void)
Initialize crypto helper.
Header definitions for the SHA256 hash function.
ctap_crypto_pub_key_t pub
public key
Definition ctap_crypto.h:58
Elliptic curve public key.
Definition ctap_crypto.h:47
Context for HMAC operations based on sha256.
Definition sha256.h:77
Structure to hold the SHA-2XX context.