Skip to content

Commit

Permalink
Updated MbedTLS dependency to v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitchedPolygons committed Oct 16, 2021
1 parent dce175a commit 8e56a58
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${CMAKE_MODULE_PATH})

set(${PROJECT_NAME}_MAJOR 4)
set(${PROJECT_NAME}_MINOR 0)
set(${PROJECT_NAME}_PATCH 0)
set(${PROJECT_NAME}_PATCH 1)
set(${PROJECT_NAME}_VERSION_STRING "${${PROJECT_NAME}_MAJOR}.${${PROJECT_NAME}_MINOR}.${${PROJECT_NAME}_PATCH}")

option(${PROJECT_NAME}_ENABLE_TESTS "Build tests." OFF)
Expand Down
4 changes: 2 additions & 2 deletions include/cecies/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ extern "C" {
* The version number of this CECIES implementation.
* TODO: increase this and below string version accordingly BEFORE releasing new updates!
*/
#define CECIES_VERSION 400
#define CECIES_VERSION 401

/**
* The version number of this CECIES implementation (nicely-formatted string).
*/
#define CECIES_VERSION_STR "4.0.0"
#define CECIES_VERSION_STR "4.0.1"

/**
* Key size (in bytes) of an X25519 key (both public and private key have the same length).
Expand Down
2 changes: 1 addition & 1 deletion lib/ccrush
2 changes: 1 addition & 1 deletion lib/mbedtls
4 changes: 2 additions & 2 deletions src/decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <mbedtls/base64.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/md_internal.h>
#include <mbedtls/md.h>

#include <ccrush.h>

Expand Down Expand Up @@ -123,7 +123,7 @@ static int cecies_decrypt(const uint8_t* encrypted_data, const size_t encrypted_
uint8_t pers[256];
cecies_dev_urandom(pers, 128);
snprintf((char*)(pers + 128), 128, "cecies_PERS_3~£,@+14/\\%llu", cecies_get_random_big_integer());
mbedtls_sha512_ret(pers + 128, 128, pers + 128 + 64, 0);
mbedtls_sha512(pers + 128, 128, pers + 128 + 64, 0);

ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, CECIES_MIN(sizeof(pers), (MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - MBEDTLS_CTR_DRBG_ENTROPY_LEN - 1)));
if (ret != 0)
Expand Down
4 changes: 2 additions & 2 deletions src/encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <mbedtls/sha512.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/md_internal.h>
#include <mbedtls/md.h>

#include <ccrush.h>

Expand Down Expand Up @@ -107,7 +107,7 @@ static int cecies_encrypt(const uint8_t* data, const size_t data_length, const i
uint8_t pers[256];
cecies_dev_urandom(pers, 128);
snprintf((char*)(pers + 128), 128, "cecies_PERS_@&=/\\.*67%llu", cecies_get_random_big_integer());
mbedtls_sha512_ret(pers + 128, 128, pers + 128 + 64, 0);
mbedtls_sha512(pers + 128, 128, pers + 128 + 64, 0);

ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, CECIES_MIN(sizeof(pers), (MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - MBEDTLS_CTR_DRBG_ENTROPY_LEN - 1)));
if (ret != 0)
Expand Down
8 changes: 4 additions & 4 deletions src/keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ int cecies_generate_curve25519_keypair(cecies_curve25519_keypair* output, const

if (additional_entropy)
{
mbedtls_sha512_ret(additional_entropy, additional_entropy_length, pers + (sizeof(pers) - 64), 0);
mbedtls_sha512(additional_entropy, additional_entropy_length, pers + (sizeof(pers) - 64), 0);
}
else
{
char tmp[128];
snprintf(tmp, 128, "%llu-cecies_PERS_@67\\##.<?@_<96-/%s", cecies_get_random_big_integer(), (uint8_t*)cecies_new_guid(1, 1).string);
mbedtls_sha512_ret((unsigned char*)tmp, 128, pers + (sizeof(pers) - 64), 0);
mbedtls_sha512((unsigned char*)tmp, 128, pers + (sizeof(pers) - 64), 0);
}

ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, CECIES_MIN(sizeof(pers), (MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - MBEDTLS_CTR_DRBG_ENTROPY_LEN - 1)));
Expand Down Expand Up @@ -186,13 +186,13 @@ int cecies_generate_curve448_keypair(cecies_curve448_keypair* output, const uint

if (additional_entropy)
{
mbedtls_sha512_ret(additional_entropy, additional_entropy_length, pers + (sizeof(pers) - 64), 0);
mbedtls_sha512(additional_entropy, additional_entropy_length, pers + (sizeof(pers) - 64), 0);
}
else
{
char tmp[128];
snprintf(tmp, 128, "%llu-cecies_PERS_#!.$\\+;@58-/%s", cecies_get_random_big_integer(), (uint8_t*)cecies_new_guid(1, 1).string);
mbedtls_sha512_ret((unsigned char*)tmp, 128, pers + (sizeof(pers) - 64), 0);
mbedtls_sha512((unsigned char*)tmp, 128, pers + (sizeof(pers) - 64), 0);
}

ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, CECIES_MIN(sizeof(pers), (MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - MBEDTLS_CTR_DRBG_ENTROPY_LEN - 1)));
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <mbedtls/base64.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/md_internal.h>
#include <mbedtls/md.h>

#include <cecies/util.h>
#include <cecies/keygen.h>
Expand Down

0 comments on commit 8e56a58

Please sign in to comment.