BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
CryptoInterface.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 The Johns Hopkins University Applied Physics
3 * Laboratory LLC.
4 *
5 * This file is part of the Bundle Protocol Security Library (BSL).
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * This work was performed for the Jet Propulsion Laboratory, California
18 * Institute of Technology, sponsored by the United States Government under
19 * the prime contract 80NM0018D0004 between the Caltech and NASA under
20 * subcontract 1700763.
21 */
57#ifndef BSL_FRONTEND_CRYPTO_INTERFACE_H_
58#define BSL_FRONTEND_CRYPTO_INTERFACE_H_
59
60#include <stdint.h>
61
62#include "BPSecLib_Private.h"
63#include "BPSecLib_Public.h"
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#define BSL_CRYPTO_AESGCM_AUTH_TAG_LEN (16)
70
74typedef enum
75{
77 // BSL_CRYPTO_UNDEFINED = 0,
79 BSL_CRYPTO_DECRYPT
81
82typedef enum
83{
84 BSL_CRYPTO_SHA_256,
85 BSL_CRYPTO_SHA_384,
86 BSL_CRYPTO_SHA_512
87} BSL_CryptoCipherSHAVariant_e;
88
89typedef enum
90{
91 BSL_CRYPTO_AES_128,
92 BSL_CRYPTO_AES_256
93} BSL_CryptoCipherAESVariant_e;
94
98typedef struct BSL_AuthCtx_s
99{
103 BSL_CryptoCipherSHAVariant_e SHA_variant;
110
114typedef struct BSL_Cipher_s
115{
121 BSL_CryptoCipherAESVariant_e AES_variant;
125
129void BSL_CryptoInit(void);
130
134void BSL_CryptoDeinit(void);
135
144int BSL_AuthCtx_Init(BSL_AuthCtx_t *hmac_ctx, uint64_t keyid, BSL_CryptoCipherSHAVariant_e sha_var);
145
154int BSL_AuthCtx_DigestBuffer(BSL_AuthCtx_t *hmac_ctx, const void *data, size_t data_len);
155
163
171int BSL_AuthCtx_Finalize(BSL_AuthCtx_t *hmac_ctx, void **hmac, size_t *hmac_len);
172
178int BSL_AuthCtx_Deinit(BSL_AuthCtx_t *hmac_ctx);
179
183int BSL_Crypto_UnwrapKey(BSL_Data_t *unwrapped_key_output, BSL_Data_t wrapped_key_plaintext, size_t key_id,
184 size_t aes_variant);
185
189int BSL_Crypto_WrapKey(BSL_Data_t *wrapped_key, BSL_Data_t cek, size_t content_key_id, size_t aes_variant);
190
201int BSL_Cipher_Init(BSL_Cipher_t *cipher_ctx, BSL_CipherMode_e enc, BSL_CryptoCipherAESVariant_e aes_var,
202 const void *init_vec, int iv_len, BSL_Data_t content_enc_key);
203
211int BSLB_Crypto_GetRegistryKey(uint64_t keyid, const uint8_t **secret, size_t *secret_len);
212
220int BSL_Cipher_AddAAD(BSL_Cipher_t *cipher_ctx, const void *aad, int aad_len);
221
225int BSL_Cipher_AddData(BSL_Cipher_t *cipher_ctx, BSL_Data_t plaintext, BSL_Data_t ciphertext);
226
234int BSL_Cipher_AddSeq(BSL_Cipher_t *cipher_ctx, BSL_SeqReader_t *reader, BSL_SeqWriter_t *writer);
235
242int BSL_Cipher_GetTag(BSL_Cipher_t *cipher_ctx, void **tag);
243
251int BSL_Cipher_SetTag(BSL_Cipher_t *cipher_ctx, const void *tag);
252
260int BSL_Cipher_FinalizeSeq(BSL_Cipher_t *cipher_ctx, BSL_SeqWriter_t *writer);
261int BSL_Cipher_FinalizeData(BSL_Cipher_t *cipher_ctx, BSL_Data_t *extra);
262
268int BSL_Cipher_Deinit(BSL_Cipher_t *cipher_ctx);
269
270int BSL_Crypto_GenKey(uint8_t *key_buffer, size_t key_length);
271
278int BSL_Crypto_GenIV(void *buf, int size);
279
287int BSL_Crypto_AddRegistryKey(uint64_t keyid, const uint8_t *secret, size_t secret_len);
288
289#ifdef __cplusplus
290} // extern C
291#endif
292
293#endif
Single entry-point include file for all of the BPSec Lib (BSL) frontend API.
Single entry-point include file for all of the "Public" BPSec Lib (BSL) frontend API.
#define BSL_REQUIRE_CHECK
This annotation on a function requires the caller to capture and inspect the return value.
int BSL_AuthCtx_Finalize(BSL_AuthCtx_t *hmac_ctx, void **hmac, size_t *hmac_len)
Finalize HMAC tag.
int BSL_Crypto_GenIV(void *buf, int size)
Generate initialization vector (IV) for AES-GCM for BCBs.
int BSL_AuthCtx_DigestSeq(BSL_AuthCtx_t *hmac_ctx, BSL_SeqReader_t *reader)
Input data to HMAC sign to context.
int BSL_Crypto_AddRegistryKey(uint64_t keyid, const uint8_t *secret, size_t secret_len)
Add a new key to the crypto key registry.
int BSL_Cipher_AddData(BSL_Cipher_t *cipher_ctx, BSL_Data_t plaintext, BSL_Data_t ciphertext)
int BSL_AuthCtx_Deinit(BSL_AuthCtx_t *hmac_ctx)
Deinitialize HMAC context resources.
int BSLB_Crypto_GetRegistryKey(uint64_t keyid, const uint8_t **secret, size_t *secret_len)
Get pointers to an existing key, if present.
BSL_REQUIRE_CHECK int BSL_AuthCtx_DigestBuffer(BSL_AuthCtx_t *hmac_ctx, const void *data, size_t data_len)
Input data to HMAC sign to context.
int BSL_Cipher_Init(BSL_Cipher_t *cipher_ctx, BSL_CipherMode_e enc, BSL_CryptoCipherAESVariant_e aes_var, const void *init_vec, int iv_len, BSL_Data_t content_enc_key)
Initialize crypto context resources and set as encoding or decoding.
BSL_CipherMode_e
Enum def to define cipher contexts as encryption or decryption operations.
@ BSL_CRYPTO_ENCRYPT
We use undefined for zero, in case this value is never explicitly set and is just zero by default.
int BSL_Crypto_WrapKey(BSL_Data_t *wrapped_key, BSL_Data_t cek, size_t content_key_id, size_t aes_variant)
void BSL_CryptoInit(void)
Initialize the crypto subsystem.
int BSL_Cipher_Deinit(BSL_Cipher_t *cipher_ctx)
De-initialize crypto context resources.
struct BSL_AuthCtx_s BSL_AuthCtx_t
Struct def for HMAC operation context.
int BSL_Cipher_FinalizeSeq(BSL_Cipher_t *cipher_ctx, BSL_SeqWriter_t *writer)
Finalize crypto operation.
int BSL_Cipher_AddAAD(BSL_Cipher_t *cipher_ctx, const void *aad, int aad_len)
Add additional authenticated data (AAD) to cipher context.
BSL_REQUIRE_CHECK int BSL_AuthCtx_Init(BSL_AuthCtx_t *hmac_ctx, uint64_t keyid, BSL_CryptoCipherSHAVariant_e sha_var)
Initialize HMAC context resources and set private key and SHA variant.
int BSL_Crypto_UnwrapKey(BSL_Data_t *unwrapped_key_output, BSL_Data_t wrapped_key_plaintext, size_t key_id, size_t aes_variant)
void BSL_CryptoDeinit(void)
Deinitialize the crypto subsystem.
int BSL_Cipher_SetTag(BSL_Cipher_t *cipher_ctx, const void *tag)
Set the tag of the crypto operation.
int BSL_Cipher_GetTag(BSL_Cipher_t *cipher_ctx, void **tag)
Get the tag of the crypto operation.
int BSL_Cipher_AddSeq(BSL_Cipher_t *cipher_ctx, BSL_SeqReader_t *reader, BSL_SeqWriter_t *writer)
Add data to encrypt or decrypt to the context sequentially.
struct BSL_Cipher_s BSL_Cipher_t
Struct def for cipher operation context.
Struct def for HMAC operation context.
size_t block_size
Block size used by backend.
void * libhandle
pointer to library specific data
BSL_CryptoCipherSHAVariant_e SHA_variant
SHA variant of context.
Struct def for cipher operation context.
BSL_CipherMode_e enc
indicates if operation is encryption or decryption
BSL_CryptoCipherAESVariant_e AES_variant
AES variant of context.
size_t block_size
block size of cipher context
void * libhandle
pointer to library specific data
Heap data storage and views.
Definition of a simple flat buffer iterator.
Definition of a simple flat buffer iterator.