BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
DefaultSecContext.c
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
27#include <stdio.h>
28#include <stdlib.h>
29#include <time.h>
30
31#include <qcbor/qcbor_encode.h>
32#include <qcbor/qcbor_spiffy_decode.h>
33
34#include <BPSecLib_Private.h>
35#include <CryptoInterface.h>
36
37#include "DefaultSecContext.h"
39#include "rfc9173.h"
40
41void BSLX_EncodeHeader(const BSL_CanonicalBlock_t *block, QCBOREncodeContext *encoder)
42{
43 ASSERT_ARG_NONNULL(block);
44 ASSERT_ARG_NONNULL(encoder);
45 BSL_LOG_INFO(" >>> AAD Encoding: %lu, %lu, %lu", block->type_code, block->block_num, block->flags);
46 QCBOREncode_AddUInt64(encoder, block->type_code);
47 QCBOREncode_AddUInt64(encoder, block->block_num);
48 QCBOREncode_AddUInt64(encoder, block->flags);
49}
50
52{
53 assert(scratch != NULL);
54 assert(scratch->position + len < scratch->size);
55
56 uint8_t *target = &scratch->buffer[scratch->position];
57 memset(target, 0, len);
58 // We give a padding of 16 bytes between objects for safety
59 scratch->position += (len + 16);
60 return target;
61}
Single entry-point include file for all of the BPSec Lib (BSL) frontend API.
#define BSL_LOG_INFO(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Abstract interface for crypto processing.
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 ...
Header for the implementation of an example default security context (RFC 9173).
Contains functions only used internally, however, test utilities can include this to unit test them.
Contains constants as defined in IETF RFC 9173 (Default Security Context for BPSec)
Wrapper for large, variable-sized buffer holding all working data to compete a BCB operation.
Structure containing parsed Canonical Block fields.
uint64_t flags
CBOR-decoded flags field.
uint64_t block_num
CBOR-decoded block number (should always be > 0)
uint64_t type_code
CBOR-decoded block type code (should be > 0)