From 1d7c719d41bdafacfc8b88134a6888c021084eea Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:01:37 +0900 Subject: [PATCH 1/7] Merge aes.hpp into aes.h --- CMakeLists.txt | 1 - README.md | 2 -- aes.h | 8 ++++++++ aes.hpp | 12 ------------ test.cpp | 1 - 5 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 aes.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 539cd68..519b2cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ target_sources(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/aes.c INTERFACE ${CMAKE_CURRENT_LIST_DIR}/aes.h - ${CMAKE_CURRENT_LIST_DIR}/aes.hpp ) target_include_directories(${PROJECT_NAME} diff --git a/README.md b/README.md index 6811e0e..ab52af7 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ Important notes: You can choose to use any or all of the modes-of-operations, by defining the symbols CBC, CTR or ECB in [`aes.h`](https://github.com/kokke/tiny-AES-c/blob/master/aes.h) (read the comments for clarification). -C++ users should `#include` [aes.hpp](https://github.com/kokke/tiny-AES-c/blob/master/aes.hpp) instead of [aes.h](https://github.com/kokke/tiny-AES-c/blob/master/aes.h) - There is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input. The module uses less than 200 bytes of RAM and 1-2K ROM when compiled for ARM, but YMMV depending on which modes are enabled. diff --git a/aes.h b/aes.h index b29b668..c80660c 100644 --- a/aes.h +++ b/aes.h @@ -1,6 +1,10 @@ #ifndef _AES_H_ #define _AES_H_ +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + #include #include @@ -87,5 +91,9 @@ void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); #endif // #if defined(CTR) && (CTR == 1) +#ifdef __cplusplus +} +#endif //__cplusplus + #endif // _AES_H_ diff --git a/aes.hpp b/aes.hpp deleted file mode 100644 index ade1642..0000000 --- a/aes.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _AES_HPP_ -#define _AES_HPP_ - -#ifndef __cplusplus -#error Do not include the hpp header in a c project! -#endif //__cplusplus - -extern "C" { -#include "aes.h" -} - -#endif //_AES_HPP_ diff --git a/test.cpp b/test.cpp index b7c8304..1873518 100644 --- a/test.cpp +++ b/test.cpp @@ -1,2 +1 @@ -#include "aes.hpp" #include "test.c" From adc915d6f1b16b0030b9a5292588915844865d36 Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:10:48 +0900 Subject: [PATCH 2/7] Fix comment in https://github.com/kokke/tiny-AES-c/issues/206 --- aes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aes.h b/aes.h index c80660c..876d976 100644 --- a/aes.h +++ b/aes.h @@ -66,7 +66,7 @@ void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf); void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf); -#endif // #if defined(ECB) && (ECB == !) +#endif // #if defined(ECB) && (ECB == 1) #if defined(CBC) && (CBC == 1) From a2a3298c41c388935003ad6cf43d19540c66a18d Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:16:27 +0900 Subject: [PATCH 3/7] Fix spacing --- aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aes.c b/aes.c index 4481f7b..07c4ecf 100644 --- a/aes.c +++ b/aes.c @@ -554,7 +554,7 @@ void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) { /* inc will overflow */ if (ctx->Iv[bi] == 255) - { + { ctx->Iv[bi] = 0; continue; } From e772dac9d0a934a8fb11196776d5e6fd715e6915 Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:16:44 +0900 Subject: [PATCH 4/7] Fix spacing (another) --- aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aes.c b/aes.c index 07c4ecf..8e27c5b 100644 --- a/aes.c +++ b/aes.c @@ -552,7 +552,7 @@ void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) /* Increment Iv and handle overflow */ for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi) { - /* inc will overflow */ + /* inc will overflow */ if (ctx->Iv[bi] == 255) { ctx->Iv[bi] = 0; From 0d9ed26f2059e42f07d6dbfa5e9eec9e154db40b Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:25:07 +0900 Subject: [PATCH 5/7] Fix spacing here --- test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test.c b/test.c index 6796283..041eb68 100644 --- a/test.c +++ b/test.c @@ -98,8 +98,8 @@ static void test_encrypt_ecb_verbose(void) for (i = 0; i < 4; ++i) { - AES_ECB_encrypt(&ctx, plain_text + (i * 16)); - phex(plain_text + (i * 16)); + AES_ECB_encrypt(&ctx, plain_text + (i * 16)); + phex(plain_text + (i * 16)); } printf("\n"); } @@ -265,12 +265,12 @@ static int test_xcrypt_ctr(const char* xcrypt) 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; struct AES_ctx ctx; - + AES_init_ctx_iv(&ctx, key, iv); AES_CTR_xcrypt_buffer(&ctx, in, 64); - + printf("CTR %s: ", xcrypt); - + if (0 == memcmp((char *) out, (char *) in, 64)) { printf("SUCCESS!\n"); return(0); From 5dc64323262556f67f63e40a6f29bd96389481ef Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:33:09 +0900 Subject: [PATCH 6/7] Fix spacing in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab52af7..e04368b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); ``` -Important notes: +Important notes: * No padding is provided so for CBC and ECB all buffers should be multiples of 16 bytes. For padding [PKCS7](https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7) is recommendable. * ECB mode is considered unsafe for most uses and is not implemented in streaming mode. If you need this mode, call the function for every block of 16 bytes you need encrypted. See [wikipedia's article on ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_(ECB)) for more details. * This library is designed for small code size and simplicity, intended for cases where small binary size, low memory footprint and portability is more important than high performance. If speed is a concern, you can try more complex libraries, e.g. [Mbed TLS](https://tls.mbed.org/), [OpenSSL](https://www.openssl.org/) etc. @@ -37,7 +37,7 @@ There is no built-in error checking or protection from out-of-bounds memory acce The module uses less than 200 bytes of RAM and 1-2K ROM when compiled for ARM, but YMMV depending on which modes are enabled. -It is one of the smallest implementations in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). +It is one of the smallest implementations in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). I've successfully used the code on 64bit x86, 32bit ARM and 8 bit AVR platforms. From 835d62c51a983e41a0d0cbb40cb0df93972adfd0 Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 22 Jun 2022 21:34:50 +0900 Subject: [PATCH 7/7] Fix possible conanfile error --- conanfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index 8a75744..386d0f0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class TinyAesCConan(ConanFile): settings = "os", "compiler", "build_type", "arch" generators = "cmake" - exports_sources = ["CMakeLists.txt", "*.c", '*.h', '*.hpp'] + exports_sources = ["CMakeLists.txt", "*.c", '*.h'] exports = ["unlicense.txt"] _options_dict = { @@ -65,7 +65,6 @@ def build(self): def package(self): self.copy("*.h", dst="include") - self.copy("*.hpp", dst="include") self.copy("*.a", dst="lib", keep_path=False) self.copy("unlicense.txt")