From cd1db241ad15ea61f3e63547d1178476e1b1a0f4 Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 13:50:14 +0100 Subject: [PATCH 1/6] First version of Conan recipe --- CMakeLists.txt | 16 ++++++++++++++++ conanfile.py | 29 +++++++++++++++++++++++++++++ test_package/CMakeLists.txt | 8 ++++++++ test_package/conanfile.py | 17 +++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 conanfile.py create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5b98934 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 2.8.12) + +project(tinyaes C ASM) + +add_library(tiny-aes + aes.c + ) + +target_compile_definitions(tiny-aes PRIVATE + -DAES128=1 + -DCBC=1 + -DECB=1 + -DCTR=1 + ) + +target_include_directories(tiny-aes PRIVATE tiny-AES-c/) diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..019c3cb --- /dev/null +++ b/conanfile.py @@ -0,0 +1,29 @@ +from conans import ConanFile, CMake + + +class TinyAesCConan(ConanFile): + name = "tiny-AES-c" + version = "1.0.0" + license = "MIT" + author = "Torfinn Berset " + url = "https://github.com/kokke/tiny-AES-c" + description = "Small portable AES128/192/256 in C" + topics = ("encryption", "crypto", "AES") + settings = "os", "compiler", "build_type", "arch" + + generators = "cmake" + exports_sources = ["CMakeLists.txt", "*.c", '*.h', '*.h'] + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + self.copy("*.h", dst="include") + self.copy("*.hpp", dst="include") + + self.copy("*.a", dst="lib", keep_path=False) + + def package_info(self): + self.cpp_info.libs = ["tiny-aes"] diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..89cddf4 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 2.8.12) +project(TinyAesPackageTest C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(example ../test.c) +target_link_libraries(example ${CONAN_LIBS}) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..08f550f --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TinyAesCTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + os.chdir("bin") + self.run(".%sexample" % os.sep) From 139cebe407a32f5cbed3ebe409ded69e681d02d3 Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 14:11:26 +0100 Subject: [PATCH 2/6] Add Conan package options --- CMakeLists.txt | 7 ------- conanfile.py | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b98934..3c6081f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,4 @@ add_library(tiny-aes aes.c ) -target_compile_definitions(tiny-aes PRIVATE - -DAES128=1 - -DCBC=1 - -DECB=1 - -DCTR=1 - ) - target_include_directories(tiny-aes PRIVATE tiny-AES-c/) diff --git a/conanfile.py b/conanfile.py index 019c3cb..f3a2a9c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,17 +12,52 @@ class TinyAesCConan(ConanFile): settings = "os", "compiler", "build_type", "arch" generators = "cmake" - exports_sources = ["CMakeLists.txt", "*.c", '*.h', '*.h'] + exports_sources = ["CMakeLists.txt", "*.c", '*.h', '*.hpp'] + + _options_dict = { + # enable AES128 + "AES128": [True, False], + + # enable AES192 + "AES192": [True, False], + + # enable AES256 + "AES256": [True, False], + + # enable AES encryption in CBC-mode of operation + "CBC": [True, False], + + # enable the basic ECB 16-byte block algorithm + "ECB": [True, False], + + # enable encryption in counter-mode + "CTR": [True, False], + } + + options = _options_dict + + default_options = { + "AES128": True, + "AES192": False, + "AES256": False, + "CBC": False, + "ECB": False, + "CTR": False + } def build(self): cmake = CMake(self) + + for key in self._options_dict.keys(): + if self.options[key]: + cmake.definitions["CMAKE_CFLAGS"].append(key) + cmake.configure() cmake.build() def package(self): self.copy("*.h", dst="include") self.copy("*.hpp", dst="include") - self.copy("*.a", dst="lib", keep_path=False) def package_info(self): From ba0f2fd14dfe7af838fb19b1ed83a134c4a00505 Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 14:15:30 +0100 Subject: [PATCH 3/6] Remove Package author, and add Unlicense --- conanfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index f3a2a9c..20023bd 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,8 +4,7 @@ from conans import ConanFile, CMake class TinyAesCConan(ConanFile): name = "tiny-AES-c" version = "1.0.0" - license = "MIT" - author = "Torfinn Berset " + license = "The Unlicense" url = "https://github.com/kokke/tiny-AES-c" description = "Small portable AES128/192/256 in C" topics = ("encryption", "crypto", "AES") @@ -13,6 +12,7 @@ class TinyAesCConan(ConanFile): generators = "cmake" exports_sources = ["CMakeLists.txt", "*.c", '*.h', '*.hpp'] + exports = ["unlicense.txt"] _options_dict = { # enable AES128 @@ -59,6 +59,7 @@ class TinyAesCConan(ConanFile): self.copy("*.h", dst="include") self.copy("*.hpp", dst="include") self.copy("*.a", dst="lib", keep_path=False) + self.copy("unlicense.txt") def package_info(self): self.cpp_info.libs = ["tiny-aes"] From 7468e2ec1240b424ee604cf980b9bca885c62acd Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 14:19:48 +0100 Subject: [PATCH 4/6] Also try to compile C++ version of test --- .gitignore | 1 + test.cpp | 2 ++ test_package/CMakeLists.txt | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test.cpp diff --git a/.gitignore b/.gitignore index 1f1148f..8a9761d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /*.o /test.elf /test.map +test_package/build diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..b7c8304 --- /dev/null +++ b/test.cpp @@ -0,0 +1,2 @@ +#include "aes.hpp" +#include "test.c" diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 89cddf4..2e4b243 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required(VERSION 2.8.12) -project(TinyAesPackageTest C) +project(TinyAesPackageTest C CXX) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(example ../test.c) +add_executable(example_cpp ../test.cpp) + target_link_libraries(example ${CONAN_LIBS}) +target_link_libraries(example_cpp ${CONAN_LIBS}) \ No newline at end of file From 8f778c3d8854bc392bcac5067eb979be7f206882 Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 14:25:36 +0100 Subject: [PATCH 5/6] Check if at least one encryption mode is selected --- conanfile.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/conanfile.py b/conanfile.py index 20023bd..2baa361 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,5 @@ from conans import ConanFile, CMake +from conans.errors import ConanException class TinyAesCConan(ConanFile): @@ -40,11 +41,15 @@ class TinyAesCConan(ConanFile): "AES128": True, "AES192": False, "AES256": False, - "CBC": False, - "ECB": False, - "CTR": False + "CBC": True, + "ECB": True, + "CTR": True } + def configure(self): + if not self.options.CBC and not self.options.ECB and not self.options.CTR: + raise ConanException("Need to at least specify one of CBC, ECB or CTR modes") + def build(self): cmake = CMake(self) From 597569f2edd8be54ddfc075b8446ba6881899277 Mon Sep 17 00:00:00 2001 From: Torfinn Berset Date: Thu, 31 Jan 2019 14:28:09 +0100 Subject: [PATCH 6/6] Add check for AES key-size option --- conanfile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conanfile.py b/conanfile.py index 2baa361..8a75744 100644 --- a/conanfile.py +++ b/conanfile.py @@ -50,6 +50,9 @@ class TinyAesCConan(ConanFile): if not self.options.CBC and not self.options.ECB and not self.options.CTR: raise ConanException("Need to at least specify one of CBC, ECB or CTR modes") + if not self.options.AES128 and not self.options.AES192 and not self.options.AES256: + raise ConanException("Need to at least specify one of AES{128, 192, 256} modes") + def build(self): cmake = CMake(self)