Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_mbedtls::MbedTlsWrapper Class Reference

Classes

class  SHA256State
class  SHA1State
class  AESStateMBEDTLS
class  AESStateMBEDTLSFactory

Static Public Member Functions

static void ComputeSha256Hash (const char *in, size_t in_len, char *out)
static std::string ComputeSha256Hash (const std::string &file_content)
static bool IsValidSha256Signature (const std::string &pubkey, const std::string &signature, const std::string &sha256_hash)
static void Hmac256 (const char *key, size_t key_len, const char *message, size_t message_len, char *out)
static void ToBase16 (char *in, char *out, size_t len)

Static Public Attributes

static constexpr size_t SHA256_HASH_LENGTH_BYTES = 32
static constexpr size_t SHA256_HASH_LENGTH_TEXT = 64
static constexpr size_t SHA1_HASH_LENGTH_BYTES = 20
static constexpr size_t SHA1_HASH_LENGTH_TEXT = 40

Member Function Documentation

◆ ComputeSha256Hash()

void MbedTlsWrapper::ComputeSha256Hash ( const char * in,
size_t in_len,
char * out )
static
597573 {
597574
597575 mbedtls_sha256_context sha_context;
597576 mbedtls_sha256_init(&sha_context);
597577 if (mbedtls_sha256_starts(&sha_context, false) ||
597578 mbedtls_sha256_update(&sha_context, reinterpret_cast<const unsigned char *>(in), in_len) ||
597579 mbedtls_sha256_finish(&sha_context, reinterpret_cast<unsigned char *>(out))) {
597580 throw runtime_error("SHA256 Error");
597581 }
597582 mbedtls_sha256_free(&sha_context);
int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
Definition duckdb.cpp:596790
struct mbedtls_sha256_context mbedtls_sha256_context
The SHA-256 context structure.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
Definition duckdb.cpp:596772
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
Definition duckdb.cpp:596767
int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char *output)
This function finishes the SHA-256 operation, and writes the result to the output buffer.
Definition duckdb.cpp:597242
int mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
Definition duckdb.cpp:597187

◆ IsValidSha256Signature()

bool MbedTlsWrapper::IsValidSha256Signature ( const std::string & pubkey,
const std::string & signature,
const std::string & sha256_hash )
static
597593 {
597594
597595 if (signature.size() != 256 || sha256_hash.size() != 32) {
597596 throw std::runtime_error("Invalid input lengths, expected signature length 256, got " +
597597 to_string(signature.size()) + ", hash length 32, got " +
597598 to_string(sha256_hash.size()));
597599 }
597600
597601 mbedtls_pk_context pk_context;
597602 mbedtls_pk_init(&pk_context);
597603
597604 if (mbedtls_pk_parse_public_key(&pk_context, reinterpret_cast<const unsigned char *>(pubkey.c_str()),
597605 pubkey.size() + 1)) {
597606 throw runtime_error("RSA public key import error");
597607 }
597608
597609 // actually verify
597610 bool valid = mbedtls_pk_verify(&pk_context, MBEDTLS_MD_SHA256,
597611 reinterpret_cast<const unsigned char *>(sha256_hash.data()), sha256_hash.size(),
597612 reinterpret_cast<const unsigned char *>(signature.data()), signature.length()) == 0;
597613
597614 mbedtls_pk_free(&pk_context);
597615 return valid;
@ MBEDTLS_MD_SHA256
Definition duckdb.cpp:576492
struct mbedtls_pk_context mbedtls_pk_context
Public key container.
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
Definition duckdb.cpp:587138
int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature (including padding if relevant).
Definition duckdb.cpp:588185
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
Definition duckdb.cpp:587156
int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen)
Parse a public key in PEM or DER format.
Definition duckdb.cpp:591403
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ Hmac256()

void MbedTlsWrapper::Hmac256 ( const char * key,
size_t key_len,
const char * message,
size_t message_len,
char * out )
static
597619 {
597620 mbedtls_md_context_t hmac_ctx;
597622 if (!md_type) {
597623 throw runtime_error("failed to init hmac");
597624 }
597625
597626 if (mbedtls_md_setup(&hmac_ctx, md_type, 1) ||
597627 mbedtls_md_hmac_starts(&hmac_ctx, reinterpret_cast<const unsigned char *>(key), key_len) ||
597628 mbedtls_md_hmac_update(&hmac_ctx, reinterpret_cast<const unsigned char *>(message), message_len) ||
597629 mbedtls_md_hmac_finish(&hmac_ctx, reinterpret_cast<unsigned char *>(out))) {
597630 throw runtime_error("HMAC256 Error");
597631 }
597632 mbedtls_md_free(&hmac_ctx);
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
This function selects the message digest algorithm to use, and allocates internal structures.
Definition duckdb.cpp:579088
struct mbedtls_md_info_t mbedtls_md_info_t
Definition duckdb.cpp:576546
struct mbedtls_md_context_t mbedtls_md_context_t
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the HMAC operation, and writes the result to the output buffer.
Definition duckdb.cpp:579696
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing HMAC computation.
Definition duckdb.cpp:579687
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
This function sets the HMAC key and prepares to authenticate a new message.
Definition duckdb.cpp:579639
const mbedtls_md_info_t * mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
This function returns the message-digest information associated with the given digest type.
Definition duckdb.cpp:578809
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure,...
Definition duckdb.cpp:578931

◆ ToBase16()

void MbedTlsWrapper::ToBase16 ( char * in,
char * out,
size_t len )
static
597635 {
597636 static char const HEX_CODES[] = "0123456789abcdef";
597637 size_t i, j;
597638
597639 for (j = i = 0; i < len; i++) {
597640 int a = in[i];
597641 out[j++] = HEX_CODES[(a >> 4) & 0xf];
597642 out[j++] = HEX_CODES[a & 0xf];
597643 }

The documentation for this class was generated from the following file: