mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 10:46:51 -07:00
Remove redundant __SWITCH__ with CHIAKI_LIB_ENABLE_MBEDTLS definition
This commit is contained in:
parent
6e2d93ec2c
commit
44b6058e06
5 changed files with 19 additions and 19 deletions
|
@ -27,7 +27,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
#include "mbedtls/ecdh.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#endif
|
||||
|
@ -38,9 +38,9 @@ extern "C" {
|
|||
typedef struct chiaki_ecdh_t
|
||||
{
|
||||
// the following lines may lead to memory corruption
|
||||
// __SWITCH__ or CHIAKI_LIB_ENABLE_MBEDTLS must be defined
|
||||
// CHIAKI_LIB_ENABLE_MBEDTLS must be defined
|
||||
// globally (whole project)
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// mbedtls ecdh context
|
||||
mbedtls_ecdh_context ctx;
|
||||
// deterministic random bit generator
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <chiaki/ecdh.h>
|
||||
#include <chiaki/base64.h>
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/md.h"
|
||||
#else
|
||||
|
@ -38,7 +38,7 @@
|
|||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_init(ChiakiECDH *ecdh)
|
||||
{
|
||||
memset(ecdh, 0, sizeof(ChiakiECDH));
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
#define CHECK(err) if((err) != 0) { \
|
||||
chiaki_ecdh_fini(ecdh); \
|
||||
return CHIAKI_ERR_UNKNOWN; }
|
||||
|
@ -85,7 +85,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_init(ChiakiECDH *ecdh)
|
|||
|
||||
CHIAKI_EXPORT void chiaki_ecdh_fini(ChiakiECDH *ecdh)
|
||||
{
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
mbedtls_ecdh_free(&ecdh->ctx);
|
||||
mbedtls_ctr_drbg_free(&ecdh->drbg);
|
||||
#else
|
||||
|
@ -97,7 +97,7 @@ CHIAKI_EXPORT void chiaki_ecdh_fini(ChiakiECDH *ecdh)
|
|||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_set_local_key(ChiakiECDH *ecdh, const uint8_t *private_key, size_t private_key_size, const uint8_t *public_key, size_t public_key_size)
|
||||
{
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
//https://tls.mbed.org/discussions/generic/publickey-binary-data-in-der
|
||||
// Load keys from buffers (i.e: config file)
|
||||
// TODO test
|
||||
|
@ -166,7 +166,7 @@ error_priv:
|
|||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_get_local_pub_key(ChiakiECDH *ecdh, uint8_t *key_out, size_t *key_out_size, const uint8_t *handshake_key, uint8_t *sig_out, size_t *sig_out_size)
|
||||
{
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
mbedtls_md_context_t ctx;
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
|
@ -213,7 +213,7 @@ error:
|
|||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_derive_secret(ChiakiECDH *ecdh, uint8_t *secret_out, const uint8_t *remote_key, size_t remote_key_size, const uint8_t *handshake_key, const uint8_t *remote_sig, size_t remote_sig_size)
|
||||
{
|
||||
//compute DH shared key
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// https://github.com/ARMmbed/mbedtls/blob/development/programs/pkey/ecdh_curve25519.c#L151
|
||||
#define GOTO_ERROR(err) do { \
|
||||
if((err) !=0){ \
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
|
@ -138,7 +138,7 @@ static ChiakiErrorCode gkcrypt_gen_key_iv(ChiakiGKCrypt *gkcrypt, uint8_t index,
|
|||
|
||||
uint8_t hmac[CHIAKI_GKCRYPT_BLOCK_SIZE*2];
|
||||
size_t hmac_size = sizeof(hmac);
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
mbedtls_md_context_t ctx;
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
|
@ -198,7 +198,7 @@ CHIAKI_EXPORT void chiaki_gkcrypt_gen_gmac_key(uint64_t index, const uint8_t *ke
|
|||
memcpy(data, key_base, 0x10);
|
||||
counter_add(data + 0x10, iv, index * CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_IV_OFFSET);
|
||||
uint8_t md[0x20];
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// last param
|
||||
// is224 Determines which function to use.
|
||||
// This must be either 0 for SHA-256, or 1 for SHA-224.
|
||||
|
@ -230,7 +230,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_gen_key_stream(ChiakiGKCrypt *gkcry
|
|||
assert(key_pos % CHIAKI_GKCRYPT_BLOCK_SIZE == 0);
|
||||
assert(buf_size % CHIAKI_GKCRYPT_BLOCK_SIZE == 0);
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// build mbedtls aes context
|
||||
mbedtls_aes_context ctx;
|
||||
mbedtls_aes_init(&ctx);
|
||||
|
@ -262,7 +262,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_gen_key_stream(ChiakiGKCrypt *gkcry
|
|||
for(uint8_t *cur = buf, *end = buf + buf_size; cur < end; cur += CHIAKI_GKCRYPT_BLOCK_SIZE)
|
||||
counter_add(cur, gkcrypt->iv, counter_offset++);
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
for(int i=0; i<buf_size; i=i+16){
|
||||
// loop over all blocks of 16 bytes (128 bits)
|
||||
if(mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, buf+i, buf+i) != 0){
|
||||
|
@ -374,7 +374,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_gmac(ChiakiGKCrypt *gkcrypt, size_t
|
|||
gmac_key = gmac_key_tmp;
|
||||
}
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// build mbedtls gcm context AES_128_GCM
|
||||
// Encryption
|
||||
mbedtls_gcm_context actx;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <chiaki/random.h>
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
//#include <mbedtls/havege.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_random_bytes_crypt(uint8_t *buf, size_t buf_size)
|
||||
{
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
// mbedtls_havege_state hs;
|
||||
// mbedtls_havege_init(&hs);
|
||||
// int r = mbedtls_havege_random( &hs, buf, sizeof( buf ) );
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <chiaki/rpcrypt.h>
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/md.h"
|
||||
#else
|
||||
|
@ -83,7 +83,7 @@ CHIAKI_EXPORT void chiaki_rpcrypt_init_regist(ChiakiRPCrypt *rpcrypt, const uint
|
|||
rpcrypt->bright[3] ^= (uint8_t)((pin >> 0x00) & 0xff);
|
||||
}
|
||||
|
||||
#if defined(__SWITCH__) || defined(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
#ifdef CHIAKI_LIB_ENABLE_MBEDTLS
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_rpcrypt_generate_iv(ChiakiRPCrypt *rpcrypt, uint8_t *iv, uint64_t counter)
|
||||
{
|
||||
uint8_t hmac_key[] = { 0xac, 0x07, 0x88, 0x83, 0xc8, 0x3a, 0x1f, 0xe8, 0x11, 0x46, 0x3a, 0xf3, 0x9e, 0xe3, 0xe3, 0x77 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue