Skip to content

Commit

Permalink
Merge branch 'cross_compile' into 'main'
Browse files Browse the repository at this point in the history
reenable cross compilation to Windows

See merge request elykseer/elykseer-crypto!38
  • Loading branch information
CodiePP committed Feb 17, 2025
2 parents 44a29f5 + 3570578 commit 7f809e6
Show file tree
Hide file tree
Showing 37 changed files with 104 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ ext/Linux_x86_64
ext/_ccache
ext/w64devkit
ext/xWindows_x86_64
ext/zlib-1.3

.cache
build/compile_commands.json
dist
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ project(elykseer-crypto CXX)
# The version number.
set (${PROJECT_NAME}_VERSION_MAJOR 2)
set (${PROJECT_NAME}_VERSION_MINOR 0)
set (${PROJECT_NAME}_VERSION_PATCH 1)
set (${PROJECT_NAME}_VERSION_PATCH 2)
set (${PROJECT_NAME}_VERSION_STRING ${elykseer-crypto_VERSION_MAJOR}.${elykseer-crypto_VERSION_MINOR}.${elykseer-crypto_VERSION_PATCH})

# choose either one
Expand All @@ -50,7 +50,7 @@ set(CMAKE_CXX_SCAN_FOR_MODULES ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(PkgConfig REQUIRED)
find_package(ZLIB REQUIRED)
#find_package(ZLIB REQUIRED)
#find_package(OpenMP REQUIRED)

if(NOT CMAKE_CROSSCOMPILING)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ base library that provides cryptographic functions to _elykseer_ implementations

```sh
cd build
cmake --fresh -DCMAKE_TOOLCHAIN_FILE=Toolchain_Darwin_to_Windows.cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
cmake --fresh -DCMAKE_TOOLCHAIN_FILE=../support/Toolchain_Darwin_to_Windows.cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
```

./test/cpp/utelykseer-crypto --show_progress
Expand Down
2 changes: 1 addition & 1 deletion ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ $(fset_gpgme):
echo "making gpgme"
cd ./gpgme; \
./autogen.sh; \
./configure --enable-static --disable-shared --enable-languages=cpp --disable-gpgsm-test --disable-g13-test --disable-gpg-test --disable-gpgconf-test --disable-doc --with-pic --with-libassuan-prefix=${TARGETDIR} --with-libgpg-error-prefix=${TARGETDIR} --prefix=${TARGETDIR} ${HOST_SELECTOR}; \
./configure --enable-static --disable-shared --disable-gpgsm-test --disable-g13-test --disable-gpg-test --disable-gpgconf-test --disable-doc --with-pic --with-libassuan-prefix=${TARGETDIR} --with-libgpg-error-prefix=${TARGETDIR} --prefix=${TARGETDIR} ${HOST_SELECTOR}; \
$(MAKE); \
$(MAKE) install

Expand Down
18 changes: 14 additions & 4 deletions ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ gpgme

### Windows

Compile project using platform file:

1. mkdir -p dist; cd build

2. cmake --fresh -DCMAKE_TOOLCHAIN_FILE=../support/Toolchain_Darwin_to_Windows.cmake --install-prefix=$(pwd)/../dist -DCMAKE_BUILD_TYPE=Release -GNinja ..

3. make && make install/strip


### dependencies

Prepare dependencies in "ext":

Expand All @@ -74,11 +84,11 @@ Prepare dependencies in "ext":
4. run `make xWin64`


Compile project using platform file:

1. cd build

2. cmake --fresh -DCMAKE_TOOLCHAIN_FILE=Toolchain_Darwin_to_Windows.cmake -DCMAKE_BUILD_TYPE=Release .
#### zlib: https://zlib.net/zlib-1.3.tar.xz

2.1 mkdir build; cd build

2.2 cmake --fresh -DCMAKE_TOOLCHAIN_FILE=../../../support/Toolchain_Darwin_to_Windows.cmake --install-prefix=$(pwd)/../../xWindows_x86_64 -DCMAKE_BUILD_TYPE=Release ..

2.3 make & make install
2 changes: 1 addition & 1 deletion ext/gpgme
Submodule gpgme updated from aae967 to baa174
2 changes: 1 addition & 1 deletion ext/libassuan
Submodule libassuan updated from 6b50ee to 70d454
2 changes: 1 addition & 1 deletion ext/libgpg-error
Submodule libgpg-error updated from a25cea to b0bb92
2 changes: 1 addition & 1 deletion ext/x_Darwin_to_Windows.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

MINGW_PATH="/opt/homebrew/Cellar/mingw-w64/11.0.1/toolchain-x86_64"
MINGW_PATH="/opt/homebrew/Cellar/mingw-w64/12.0.0_1/toolchain-x86_64"
if [ ! -d ${MINGW_PATH} ]; then
echo "missing path to mingw toolchain"
exit 1
Expand Down
19 changes: 5 additions & 14 deletions src/cpp/aes.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <memory>
#include <string>

#include "sizebounded/sizebounded.hpp"

import lxr_key128;
Expand Down Expand Up @@ -72,31 +75,25 @@ class AesEncrypt : public Aes
// C binding interface
#include "lxr-cbindings.hpp"

extern "C" {
export struct CAesEncrypt {
void *ptr;
unsigned int lastpos;
unsigned char buf[lxr::Aes::datasz];
};

extern "C" EXPORT
export CAesEncrypt* mk_AesEncrypt(CKey256 *k, CKey128 *iv);

extern "C" EXPORT
export void release_AesEncrypt(CAesEncrypt *cl);

extern "C" EXPORT
export int proc_AesEncrypt(CAesEncrypt *cl, unsigned int inlen, unsigned char const *);

extern "C" EXPORT
export int fin_AesEncrypt(CAesEncrypt *cl);

extern "C" EXPORT
export unsigned int len_AesEncrypt(CAesEncrypt *cl);

extern "C" EXPORT
export unsigned int copy_AesEncrypt(CAesEncrypt *cl, unsigned int outlen, unsigned char *);

extern "C" EXPORT
export unsigned int sz_AesEncrypt();

export struct CAesDecrypt {
Expand All @@ -105,23 +102,17 @@ export struct CAesDecrypt {
unsigned char buf[lxr::Aes::datasz];
};

extern "C" EXPORT
export CAesDecrypt* mk_AesDecrypt(CKey256 *k, CKey128 *iv);

extern "C" EXPORT
export void release_AesDecrypt(CAesDecrypt *cl);

extern "C" EXPORT
export int proc_AesDecrypt(CAesDecrypt *cl, unsigned int inlen, unsigned char const *);

extern "C" EXPORT
export int fin_AesDecrypt(CAesDecrypt *cl);

extern "C" EXPORT
export unsigned int len_AesDecrypt(CAesDecrypt *cl);

extern "C" EXPORT
export unsigned int copy_AesDecrypt(CAesDecrypt *cl, unsigned int outlen, unsigned char *);

extern "C" EXPORT
export unsigned int sz_AesDecrypt();
}
6 changes: 3 additions & 3 deletions src/cpp/aes_cbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ module;

#include "lxr-cbindings.hpp"

import lxr_key128;
import lxr_key256;

#include "sizebounded/sizebounded.hpp"
#include "sizebounded/sizebounded.ipp"

import lxr_key128;
import lxr_key256;


module lxr_aes;

Expand Down
6 changes: 5 additions & 1 deletion src/cpp/aes_cryptopp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ module;

#if CRYPTOLIB == CRYPTOPP

#include <cstddef>
#include <memory>
#include <string>

#include "cryptopp/filters.h"
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"

#endif

#include "sizebounded/sizebounded.ipp"
#include "sizebounded/sizebounded.hpp"

import lxr_key128;
import lxr_key256;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/base64.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Base64
// C binding interface
#include "lxr-cbindings.hpp"

extern "C" EXPORT
extern "C" {
export int base64_encode(int mlen, const char * m, int outlen, unsigned char * out);

extern "C" EXPORT
export int base64_decode(int mlen, const char * m, int outlen, unsigned char * out);
}
1 change: 1 addition & 0 deletions src/cpp/gpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <memory>
#include <iostream>
#include <sstream>
Expand Down
1 change: 1 addition & 0 deletions src/cpp/gpg.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <memory>
#include <iostream>
#include <optional>
Expand Down
1 change: 1 addition & 0 deletions src/cpp/hmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <string>
#include <cassert>

Expand Down
6 changes: 3 additions & 3 deletions src/cpp/hmac.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <iostream>
#include <string>
#include <memory>
Expand Down Expand Up @@ -54,11 +55,10 @@ class HMAC
// C binding interface
#include "lxr-cbindings.hpp"

extern "C" EXPORT
extern "C" {
export CKey128* hmac_Md5(int klen, const char k[], int mlen, const char *m);

extern "C" EXPORT
export CKey256* hmac_Sha256(int klen, const char k[], int mlen, const char *m);

extern "C" EXPORT
export CKey160* hmac_Sha1(int klen, const char k[], int mlen, const char *m);
}
2 changes: 1 addition & 1 deletion src/cpp/hmac_cbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <string>
#include <cstring>

#if CRYPTOLIB == OPENSSL
// #include "openssl/hmac.h"
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include <string>

import lxr_random;

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/key.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <iostream>
#include <string>
#include <memory>
#include <functional>


Expand Down
4 changes: 4 additions & 0 deletions src/cpp/key128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <memory>
#include <string>

#include "sizebounded/sizebounded.hpp"
#include "sizebounded/sizebounded.ipp"

Expand Down
9 changes: 3 additions & 6 deletions src/cpp/key128.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module;

#include <functional>
#include <memory>
#include <string>

import lxr_key;

Expand Down Expand Up @@ -59,24 +60,20 @@ class Key128 : public Key

// #define CKey128 lxr::Key128

extern "C" {
export struct CKey128 {
void * ptr;
};

extern "C" EXPORT
export CKey128* mk_Key128();

extern "C" EXPORT
export void release_Key128(CKey128*);

extern "C" EXPORT
export int len_Key128(CKey128*);

extern "C" EXPORT
export char* bytes_Key128(CKey128*);

extern "C" EXPORT
export char* tohex_Key128(CKey128*);

extern "C" EXPORT
export CKey128* fromhex_Key128(const char*);
}
1 change: 1 addition & 0 deletions src/cpp/key128_cbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <string>
#include <cstring>

Expand Down
4 changes: 4 additions & 0 deletions src/cpp/key160.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstddef>
#include <memory>
#include <string>

#include "sizebounded/sizebounded.hpp"
#include "sizebounded/sizebounded.ipp"

Expand Down
9 changes: 3 additions & 6 deletions src/cpp/key160.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module;

#include <functional>
#include <memory>
#include <string>

import lxr_key;

Expand Down Expand Up @@ -59,24 +60,20 @@ class Key160 : public Key

// #define CKey160 lxr::Key160

extern "C" {
export struct CKey160 {
void * ptr;
};

extern "C" EXPORT
export CKey160* mk_Key160();

extern "C" EXPORT
export void release_Key160(CKey160*);

extern "C" EXPORT
export int len_Key160(CKey160*);

extern "C" EXPORT
export char* bytes_Key160(CKey160*);

extern "C" EXPORT
export char* tohex_Key160(CKey160*);

extern "C" EXPORT
export CKey160* fromhex_Key160(const char*);
}
Loading

0 comments on commit 7f809e6

Please sign in to comment.