BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
DefaultSecContext_Private.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 */
22
28#ifndef BSLB_DEFAULT_SECURITY_CONTEXT_PRIVATE_H_
29#define BSLB_DEFAULT_SECURITY_CONTEXT_PRIVATE_H_
30
31#include <stdint.h>
32
33#include <qcbor/qcbor_encode.h>
34
35#include <BPSecLib_Private.h>
36#include <BPSecLib_Public.h>
37#include <CryptoInterface.h>
38
39#include "rfc9173.h"
40
41/*
42 * Convenience struct containing metadata as a block.
43 * Avoids the need to pass many arguments to functions.
44 */
46{
47 uint64_t blk_type;
48 uint64_t blk_num;
49 uint64_t flags;
50 uint64_t crc_type;
51 BSL_Data_t btsd;
53
54typedef struct BSLX_Bytestr_s
55{
56 uint8_t _bytes[BSL_DEFAULT_BYTESTR_LEN + 1];
57 size_t bytelen;
59
60size_t BSLX_Bytestr_GetCapacity(void);
61BSL_Data_t BSLX_Bytestr_AsData(BSLX_Bytestr_t *self);
62
63typedef struct BSLX_BIB_s
64{
65 int64_t key_id;
66 BSL_PrimaryBlock_t primary_block;
67 BSL_CanonicalBlock_t target_block;
68 BSL_CanonicalBlock_t sec_block;
69 int64_t integrity_scope_flags;
70 int64_t sha_variant;
71 int64_t _crypto_sha_variant;
72 BSLX_Bytestr_t wrapped_key;
73 BSLX_Bytestr_t override_key;
74 uint64_t hmac_result_id;
75 BSLX_Bytestr_t hmac_result_val;
77
78int BSLX_BIB_InitFromSecOper(BSLX_BIB_t *self, const BSL_SecOper_t *sec_oper);
79int BSLX_BIB_GenIPPT(BSLX_BIB_t *self, BSL_Data_t ippt_space);
80int BSLX_BIB_GenHMAC(BSLX_BIB_t *self, BSL_Data_t ippt_data);
81
85typedef struct BSLX_BCB_s
86{
87 size_t err_count;
88 uint64_t key_id;
89
90 // Data wrappers and containers for borrowed and owned/allocated buffers
91 // These will ALL be deinitialized at the end, so _Deinit MUST be called.
92 BSL_Data_t authtag;
93 BSL_Data_t iv;
94 BSL_Data_t wrapped_key;
95 BSL_Data_t test_content_enc_key;
96 BSL_Data_t test_init_vector;
97 BSL_Data_t test_key_enc_key;
98 BSL_Data_t btsd_replacement;
99 BSL_Data_t debugstr;
100 BSL_Data_t aad;
101
102 // Cipher mode variants
103 BSL_CipherMode_e crypto_mode;
104 rfc9173_bcb_aes_variant_e aes_variant;
105
106 // Metadata about bundles and blocks
107 BSL_PrimaryBlock_t primary_block;
108 BSL_CanonicalBlock_t sec_block;
109 BSL_CanonicalBlock_t target_block;
110
111 bool success;
112 bool skip_aad_sec_block;
113 bool skip_aad_target_block;
114 bool skip_aad_prim_block;
115 bool skip_keywrap;
117
123{
124 uint8_t *buffer;
125 size_t size;
126 size_t position;
128
133void *BSLX_ScratchSpace_take(BSLX_ScratchSpace_t *scratch, size_t len);
134int BSLX_BCB_GetParams(const BSL_BundleRef_t *bundle, BSLX_BCB_t *bcb_context, const BSL_SecOper_t *sec_oper);
135
136int BSLX_BCB_Init(BSLX_BCB_t *bcb_context, const BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper);
137int BSLX_BCB_ComputeAAD(BSLX_BCB_t *bcb_context);
138int BSLX_BCB_Encrypt(BSLX_BCB_t *bcb_context);
139void BSLX_EncodeHeader(const BSL_CanonicalBlock_t *block, QCBOREncodeContext *encoder);
140
141#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.
Abstract interface for crypto processing.
BSL_CipherMode_e
Enum def to define cipher contexts as encryption or decryption operations.
int BSLX_BIB_InitFromSecOper(BSLX_BIB_t *self, const BSL_SecOper_t *sec_oper)
Populate the BIB parameters convenience struct from the security operation struct.
void * BSLX_ScratchSpace_take(BSLX_ScratchSpace_t *scratch, size_t len)
This means "give me len bytes from the scratch space and increment a counter." This is a convenience ...
int BSLX_BIB_GenHMAC(BSLX_BIB_t *self, BSL_Data_t ippt_data)
Performs the actual HMAC over the given IPPT, placing the result in hmac_result.
int BSLX_BIB_GenIPPT(BSLX_BIB_t *self, BSL_Data_t ippt_space)
Computes the Integrity-Protected Plaintext (IPPT) for a canonical bundle block (non-primary)
struct BSLX_BCB_s BSLX_BCB_t
BCB encryption context with crypto primitives.
struct BSLX_ScratchSpace_s BSLX_ScratchSpace_t
Wrapper for large, variable-sized buffer holding all working data to compete a BCB operation.
Contains constants as defined in IETF RFC 9173 (Default Security Context for BPSec)
rfc9173_bcb_aes_variant_e
https://www.rfc-editor.org/rfc/rfc9173.html#section-4.3.2
Definition rfc9173.h:70
BCB encryption context with crypto primitives.
Wrapper for large, variable-sized buffer holding all working data to compete a BCB operation.
Reference to a Bundle owned and stored in the host BPA.
Structure containing parsed Canonical Block fields.
Heap data storage and views.
Contains Bundle Primary Block fields and metadata.