Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
96904bc
Merge pull request #10 from jakcron/master
jakcron Jun 19, 2019
4ee4be2
delete docs
jakcron Jun 19, 2019
963771b
Add src, uncompleted
jakcron Jul 18, 2025
e0dbbbe
Merge remote-tracking branch 'origin/development' into ec-cryptopgrap…
jakcron Jul 18, 2025
4b2a987
Add comment about EccKeys not being compressed.
jakcron Aug 3, 2025
1f29535
Fix typo in EccCurveType.h
jakcron Aug 3, 2025
8993506
Bugfix eccIntegerBitLength() for ECC_CURVE_TYPE_SECP224R1
jakcron Aug 3, 2025
5658595
EccKeyGeneratorImpl - include mbedtls error in exception message.
jakcron Aug 3, 2025
d0319dc
Flex out EccKeyGenerator unit test.
jakcron Aug 3, 2025
0fec0df
Add unit test workflow
jakcron Aug 3, 2025
5dabbf2
Tweak unit-test exec
jakcron Aug 4, 2025
a0ce56d
Try to more cleanly copy ByteData to string
jakcron Aug 4, 2025
30fb26c
Fix copy/paste mistake in EccKeyGeneratorImpl.h
jakcron Aug 4, 2025
dfbdff1
update vs project files.
jakcron Aug 4, 2025
a267d88
Fix typo in EccKeyGeneratorImpl.h
jakcron Aug 4, 2025
0768123
Skip slow tests for Windows
jakcron Aug 4, 2025
58a6f6c
Add tc::os::getTempDirPath()
jakcron Aug 5, 2025
8584fcd
Return value from execution of unit test program
jakcron Aug 5, 2025
e778dfd
Removed windows header from Environment.cpp
jakcron Aug 5, 2025
0e53f74
Add string header back to Environment.cpp
jakcron Aug 5, 2025
5e8b8b7
Add fileapi.h to Environment.cpp
jakcron Aug 5, 2025
3d88412
replace fileapi.h with windows.h in Environment.cpp
jakcron Aug 5, 2025
26f1336
Add (T)DES optimisations to BlockUtilImpl.h
jakcron Aug 5, 2025
5b1017a
Add EcdhSharedSecretGenerator
jakcron Aug 5, 2025
ef7f4fa
Short term fix to getTempDirPath() for Windows builds
jakcron Aug 7, 2025
a3e4f77
Change GH Actions to only run unit tests for PRs, and builds for push…
jakcron Aug 7, 2025
b5fc0a6
Misc.
jakcron Aug 7, 2025
d57b5b7
Fix duplicate entries in vsxproj file
jakcron Aug 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/compile_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Compile Project (Push/PR/Release)
on:
push:
branches: [ development-tip, stable ]
pull_request:
branches: [ development-tip, stable ]
release:
types: [ created ]

Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/execute_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run Unit-Tests (PR)

on:
pull_request:
branches: [ development-tip, stable ]

jobs:
build_makefile:
name: ${{ matrix.dist }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
dist: [ubuntu_x86_64, macos_x86_64, macos_arm64]
prog: [libtoolchain_test]
include:
- dist: ubuntu_x86_64
os: ubuntu-latest
arch: x86_64
bin_ext:
- dist: macos_x86_64
os: macos-latest
arch: x86_64
bin_ext:
- dist: macos_arm64
os: macos-latest
arch: arm64
bin_ext:
steps:
- uses: actions/checkout@v4
- name: Clone submodules
run: git submodule init && git submodule update
- name: Compile ${{ matrix.prog }}
run: make PROJECT_PLATFORM_ARCH=${{ matrix.arch }} deps all
- name: Run unit-tests ${{ matrix.prog }}
run: ./bin/${{ matrix.prog }}${{ matrix.bin_ext }} --exres PASS --slow
build_visualstudio:
name: ${{ matrix.dist }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
dist: [win_x64, win_x86]
vs_sln: [libtoolchain]
bin_name: [libtoolchain-test]
include:
- dist: win_x64
os: windows-latest
platform: x64
configuration: Release
build_path: x64\Release
bin_ext: .exe
- dist: win_x86
os: windows-latest
platform: x86
configuration: Release
build_path: Release
bin_ext: .exe
steps:
- uses: actions/checkout@v4
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- name: Clone submodules
run: git submodule init && git submodule update
- name: Compile ${{ matrix.vs_sln }}
run: msbuild .\build\visualstudio\${{ matrix.vs_sln }}.sln /p:configuration=${{ matrix.configuration }} /p:platform=${{ matrix.platform }}
- name: Run unit-tests ${{ matrix.bin_name }}
run: .\build\visualstudio\${{ matrix.build_path }}\${{ matrix.bin_name }}${{ matrix.bin_ext }} --exres PASS
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<ClCompile Include="..\..\..\test\crypto_CmacTdes168Generator_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_Des56CbcEncryptor_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_Des56EcbEncryptor_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_EccKeyGenerator_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_HmacMd5Generator_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_HmacSha1Generator_TestClass.cpp" />
<ClCompile Include="..\..\..\test\crypto_HmacSha2256Generator_TestClass.cpp" />
Expand Down Expand Up @@ -285,6 +286,7 @@
<ClInclude Include="..\..\..\test\crypto_CmacTdes168Generator_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_Des56CbcEncryptor_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_Des56EcbEncryptor_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_EccKeyGenerator_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_HmacMd5Generator_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_HmacSha1Generator_TestClass.h" />
<ClInclude Include="..\..\..\test\crypto_HmacSha2256Generator_TestClass.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<ClCompile Include="..\..\..\test\crypto_Des56EcbEncryptor_TestClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\crypto_EccKeyGenerator_TestClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\crypto_HmacMd5Generator_TestClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -470,7 +473,6 @@
<ClInclude Include="..\..\..\test\crypto_Aes256XtsEncryptor_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>

<ClInclude Include="..\..\..\test\crypto_CmacAes128Generator_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -486,13 +488,15 @@
<ClInclude Include="..\..\..\test\crypto_CmacTdes168Generator_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>

<ClInclude Include="..\..\..\test\crypto_Des56CbcEncryptor_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\test\crypto_Des56EcbEncryptor_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\test\crypto_EccKeyGenerator_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\test\crypto_HmacMd5Generator_TestClass.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
18 changes: 13 additions & 5 deletions build/visualstudio/libtoolchain/libtoolchain.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@
<ClInclude Include="..\..\..\include\tc\crypto\Des56EcbEncryptor.h" />
<ClInclude Include="..\..\..\include\tc\crypto\DesEncryptor.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EcbEncryptor.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EccCurveType.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EccKey.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EccKeyGenerator.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EccUtil.h" />
<ClInclude Include="..\..\..\include\tc\crypto\EcdhSharedSecretGenerator.h" />
<ClInclude Include="..\..\..\include\tc\crypto\HmacGenerator.h" />
<ClInclude Include="..\..\..\include\tc\crypto\HmacMd5Generator.h" />
<ClInclude Include="..\..\..\include\tc\crypto\HmacSha1Generator.h" />
Expand Down Expand Up @@ -223,6 +228,8 @@
<ClInclude Include="..\..\..\include\tc\crypto\detail\CtrModeImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\DesImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\EcbModeImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\EccKeyGeneratorImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\EcdhSharedSecretGeneratorImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\HmacImpl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\Md5Impl.h" />
<ClInclude Include="..\..\..\include\tc\crypto\detail\Pbkdf1Impl.h" />
Expand All @@ -242,11 +249,6 @@
<ClInclude Include="..\..\..\include\tc\encode.h" />
<ClInclude Include="..\..\..\include\tc\io\BasicPathResolver.h" />
<ClInclude Include="..\..\..\include\tc\io\ConcatenatedStream.h" />
<ClInclude Include="..\..\..\include\tc\io\EmptyStream.h" />
<ClInclude Include="..\..\..\include\tc\io\DirectoryNotEmptyException.h" />
<ClInclude Include="..\..\..\include\tc\io\DirectoryNotFoundException.h" />
<ClInclude Include="..\..\..\include\tc\io\BasicPathResolver.h" />
<ClInclude Include="..\..\..\include\tc\io\ConcatenatedStream.h" />
<ClInclude Include="..\..\..\include\tc\io\DirectoryNotEmptyException.h" />
<ClInclude Include="..\..\..\include\tc\io\DirectoryNotFoundException.h" />
<ClInclude Include="..\..\..\include\tc\io\EmptyStream.h" />
Expand Down Expand Up @@ -320,6 +322,10 @@
<ClCompile Include="..\..\..\src\crypto\CmacTdes168Generator.cpp" />
<ClCompile Include="..\..\..\src\crypto\Des56CbcEncryptor.cpp" />
<ClCompile Include="..\..\..\src\crypto\Des56EcbEncryptor.cpp" />
<ClCompile Include="..\..\..\src\crypto\EccKey.cpp" />
<ClCompile Include="..\..\..\src\crypto\EccKeyGenerator.cpp" />
<ClCompile Include="..\..\..\src\crypto\EccUtil.cpp" />
<ClCompile Include="..\..\..\src\crypto\EcdhSharedSecretGenerator.cpp" />
<ClCompile Include="..\..\..\src\crypto\HmacMd5Generator.cpp" />
<ClCompile Include="..\..\..\src\crypto\HmacSha1Generator.cpp" />
<ClCompile Include="..\..\..\src\crypto\HmacSha2256Generator.cpp" />
Expand Down Expand Up @@ -350,6 +356,8 @@
<ClCompile Include="..\..\..\src\crypto\Tdes168EcbEncryptor.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\AesImpl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\DesImpl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\EccKeyGeneratorImpl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\EcdhSharedSecretGeneratorImpl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\Md5Impl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\PrbgImpl.cpp" />
<ClCompile Include="..\..\..\src\crypto\detail\RsaImpl.cpp" />
Expand Down
39 changes: 39 additions & 0 deletions build/visualstudio/libtoolchain/libtoolchain.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
<ClCompile Include="..\..\..\src\crypto\Des56EcbEncryptor.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\EccKey.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\EccKeyGenerator.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\EccUtil.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\EcdhSharedSecretGenerator.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\HmacMd5Generator.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
Expand Down Expand Up @@ -172,6 +184,12 @@
<ClCompile Include="..\..\..\src\crypto\detail\DesImpl.cpp">
<Filter>Source Files\crypto\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\detail\EccKeyGeneratorImpl.cpp">
<Filter>Source Files\crypto\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\detail\EcdhSharedSecretGeneratorImpl.cpp">
<Filter>Source Files\crypto\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\crypto\detail\Md5Impl.cpp">
<Filter>Source Files\crypto\detail</Filter>
</ClCompile>
Expand Down Expand Up @@ -432,6 +450,21 @@
<ClInclude Include="..\..\..\include\tc\crypto\EcbEncryptor.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\EccCurveType.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\EccKey.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\EccKeyGenerator.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\EccUtil.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\EcdhSharedSecretGenerator.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\HmacGenerator.h" >
<Filter>Header Files\tc\crypto</Filter>
</ClInclude>
Expand Down Expand Up @@ -564,6 +597,12 @@
<ClInclude Include="..\..\..\include\tc\crypto\detail\EcbModeImpl.h" >
<Filter>Header Files\tc\crypto\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\detail\EccKeyGeneratorImpl.h" >
<Filter>Header Files\tc\crypto\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\detail\EcdhSharedSecretGeneratorImpl.h" >
<Filter>Header Files\tc\crypto\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\tc\crypto\detail\HmacImpl.h" >
<Filter>Header Files\tc\crypto\detail</Filter>
</ClInclude>
Expand Down
33 changes: 33 additions & 0 deletions include/tc/crypto/EccCurveType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file EccCurveType.h
* @brief Declaration of tc::crypto::EccCurveType
* @author Jack (jakcron)
* @version 0.1
* @date 2025/06/01
**/
#pragma once

namespace tc { namespace crypto {

/**
* @struct EccCurveType
* @brief Defines supported ECC curves
*/
enum EccCurveType
{
ECC_CURVE_TYPE_SECP192R1, /**< The 192-bit curve defined by FIPS 186-4 and SEC1. */
ECC_CURVE_TYPE_SECP224R1, /**< The 224-bit curve defined by FIPS 186-4 and SEC1. */
ECC_CURVE_TYPE_SECP256R1, /**< The 256-bit curve defined by FIPS 186-4 and SEC1. */
ECC_CURVE_TYPE_SECP384R1, /**< The 384-bit curve defined by FIPS 186-4 and SEC1. */
ECC_CURVE_TYPE_SECP521R1, /**< The 521-bit curve defined by FIPS 186-4 and SEC1. */
ECC_CURVE_TYPE_BP256R1, /**< 256-bit Brainpool curve. */
ECC_CURVE_TYPE_BP384R1, /**< 384-bit Brainpool curve. */
ECC_CURVE_TYPE_BP512R1, /**< 512-bit Brainpool curve. */
ECC_CURVE_TYPE_CURVE25519, /**< Curve25519. */
ECC_CURVE_TYPE_SECP192K1, /**< 192-bit "Koblitz" curve. */
ECC_CURVE_TYPE_SECP224K1, /**< 224-bit "Koblitz" curve. */
ECC_CURVE_TYPE_SECP256K1, /**< 256-bit "Koblitz" curve. */
ECC_CURVE_TYPE_CURVE448, /**< Curve448. */
};

}} // namespace tc::crypto
95 changes: 95 additions & 0 deletions include/tc/crypto/EccKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @file EccKey.h
* @brief Declarations for structures to store ECC keys.
* @author Jack (jakcron)
* @version 0.1
* @date 2025/06/01
**/
#pragma once
#include <tc/types.h>
#include <tc/ByteData.h>
#include <tc/crypto/EccCurveType.h>

#include <tc/ArgumentException.h>

namespace tc { namespace crypto {


/**
* @struct EccKey
* @brief Struct for storing a ECC key. For use with ECC operations.
*
* @note The public/private components are not compressed.
*/
struct EccKey
{
EccCurveType curve_type;
tc::ByteData d; /**< Private component - big endian d integer */
tc::ByteData Q; /**< Public component - big endian Q point */
};

/**
* @struct EccPublicKey
* @brief This extends EccKey, exposing a constructor to create an ECC public key.
*/
struct EccPublicKey : public EccKey
{
/**
* @brief This constructs a @ref EccKey from the public component.
*
* @param[in] curve_type ECC Curve Type.
* @param[in] Q Buffer containing big-endian Q point.
* @param[in] Q_size Size in bytes of Q.
*
* @pre @p ec_type must be of type @ref EccCurveType
* @pre @p Q != nullptr
* @pre @p Q_size != 0
*/
EccPublicKey(EccCurveType curve_type, const byte_t* Q, size_t Q_size);
};

/**
* @struct EccPrivateKey
* @brief This extends EccKey, exposing a constructor to create an ECC private key from a modulus and private exponent.
*/
struct EccPrivateKey : public EccKey
{
/**
* @brief This constructs a @ref EccKey from the private and public components.
*
* @param[in] curve_type ECC Curve Type
* @param[in] d Buffer containing big-endian d integer.
* @param[in] d_size Size in bytes of d.
* @param[in] Q Buffer containing big-endian Q point.
* @param[in] Q_size Size in bytes of Q.
*
* @pre @p ec_type must be of type @ref EccCurveType
* @pre @p d != nullptr
* @pre @p d_size != 0
* @pre @p Q != nullptr
* @pre @p Q_size != 0
*/
EccPrivateKey(EccCurveType curve_type, const byte_t* d, size_t d_size, const byte_t* Q, size_t Q_size);

/**
* @brief This constructs a @ref EccKey from the private component (and generate the public component).
*
* @param[in] curve_type ECC Curve Type
* @param[in] d Buffer containing big-endian d integer.
* @param[in] d_size Size in bytes of d.
*
* @pre @p ec_type must be of type @ref EccCurveType
* @pre @p d != nullptr
* @pre @p d_size != 0
*/
EccPrivateKey(EccCurveType curve_type, const byte_t* d, size_t d_size);

/**
* @brief Generate public key from this private key.
*
* @return EccKey containing the public key.
*/
EccKey getPublicKey();
};

}} // namespace tc::crypto
Loading
Loading