ctap_crypto.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
22 #include <stdint.h>
23 
24 #include "hashes/sha256.h"
25 #include "fido2/ctap.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define CTAP_CRYPTO_KEY_SIZE 32
35 
39 #define CTAP_CRYPTO_ES256_DER_MAX_SIZE 72
40 
44 typedef struct {
45  uint8_t x[CTAP_CRYPTO_KEY_SIZE];
46  uint8_t y[CTAP_CRYPTO_KEY_SIZE];
48 
54 typedef struct {
56  uint8_t priv[CTAP_CRYPTO_KEY_SIZE];
58 
67 
76 ctap_status_code_t fido2_ctap_crypto_prng(uint8_t *buf, size_t len);
77 
86 
97 
107 
120 ctap_status_code_t fido2_ctap_crypto_sha256(const void *data, size_t len,
121  void *digest);
122 
133  size_t key_length);
134 
145 
156 
172  size_t key_length, const void *data, size_t len,
173  void *digest);
174 
185 
198  ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t key_len);
199 
212 ctap_status_code_t fido2_ctap_crypto_get_sig(uint8_t *hash, size_t hash_len, uint8_t *sig,
213  size_t *sig_len, const uint8_t *key, size_t key_len);
214 
227 ctap_status_code_t fido2_ctap_crypto_aes_enc(uint8_t * out, size_t *out_len, uint8_t * in,
228  size_t in_len, const uint8_t * key, size_t key_len);
229 
242 ctap_status_code_t fido2_ctap_crypto_aes_dec(uint8_t * out, size_t *out_len, uint8_t * in,
243  size_t in_len, const uint8_t * key, size_t key_len);
244 
264  const uint8_t *in, size_t in_len,
265  uint8_t *auth_data, size_t auth_data_len,
266  uint8_t mac_len, uint8_t length_encoding,
267  const uint8_t *nonce, size_t nonce_len,
268  const uint8_t *key, size_t key_len);
269 
289  const uint8_t *in, size_t in_len,
290  uint8_t *auth_data, size_t auth_data_len,
291  uint8_t mac_len, uint8_t length_encoding,
292  const uint8_t *nonce, size_t nonce_len,
293  const uint8_t *key, size_t key_len);
294 #ifdef __cplusplus
295 }
296 #endif
Public FIDO2 CTAP defines, structures and function declarations.
ctap_status_code_t fido2_ctap_crypto_prng(uint8_t *buf, size_t len)
Wrapper function for random_bytes.
ctap_status_code_t fido2_ctap_crypto_init(void)
Initialize crypto helper.
ctap_status_code_t fido2_ctap_crypto_hmac_sha256_init(hmac_context_t *ctx, const void *key, size_t key_length)
Wrapper function for hmac_sha256_init.
ctap_status_code_t fido2_ctap_crypto_sha256_update(sha256_context_t *ctx, const void *data, size_t len)
Wrapper function for sha256_update.
ctap_status_code_t fido2_ctap_crypto_hmac_sha256_final(hmac_context_t *ctx, void *digest)
Wrapper function for hmac_sha256_final.
ctap_status_code_t 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.
ctap_status_code_t fido2_ctap_crypto_sha256(const void *data, size_t len, void *digest)
Wrapper function for sha256.
ctap_status_code_t fido2_ctap_crypto_gen_keypair(ctap_crypto_pub_key_t *pub_key, uint8_t *priv_key, size_t len)
Generate cryptographic key pair.
ctap_status_code_t 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.
ctap_status_code_t 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.
#define CTAP_CRYPTO_KEY_SIZE
Size in bytes of cryptographic keys used.
Definition: ctap_crypto.h:34
ctap_status_code_t 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.
ctap_status_code_t fido2_ctap_crypto_sha256_final(sha256_context_t *ctx, void *digest)
Wrapper for sha256_final.
ctap_status_code_t 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.
ctap_status_code_t fido2_ctap_crypto_hmac_sha256_update(hmac_context_t *ctx, const void *data, size_t len)
Wrapper function for hmac_sha256_update.
ctap_status_code_t 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.
ctap_status_code_t 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.
ctap_status_code_t fido2_ctap_crypto_sha256_init(sha256_context_t *ctx)
Wrapper function for sha256_init.
ctap_status_code_t
CTAP status codes.
Definition: ctap.h:43
Header definitions for the SHA256 hash function.
ctap_crypto_pub_key_t pub
public key
Definition: ctap_crypto.h:55
Elliptic curve public key.
Definition: ctap_crypto.h:44
Context for HMAC operations based on sha256.
Definition: sha256.h:53
Structure to hold the SHA-2XX context.
Definition: sha2xx_common.h:38