diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f0fde7ad..4fc023abd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: linux-compat: runs-on: ubuntu-22.04 # latest strategy: + fail-fast: false matrix: image: - manylinux2014-x64 diff --git a/CMakeLists.txt b/CMakeLists.txt index fb54a14e0..560ed5259 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.9) if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) @@ -83,40 +83,47 @@ if(BUILD_DEPS) add_subdirectory(crt/aws-c-common) if(UNIX AND NOT APPLE AND NOT BYO_CRYPTO) + include(AwsPrebuildDependency) if(NOT USE_OPENSSL) - set(DISABLE_PERL ON CACHE BOOL "Disable Perl for AWS-LC.") - set(DISABLE_GO ON CACHE BOOL "Disable Go for AWS-LC.") - set(BUILD_LIBSSL OFF CACHE BOOL "Build libssl for AWS-LC.") - # temporarily disable certain warnings as errors for the aws-lc build - set(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + set(AWSLC_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + # temporarily disable certain warnings as errors for the aws-lc build if(NOT MSVC) check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW) if(HAS_WNO_STRINGOP_OVERFLOW) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overflow") + set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-stringop-overflow") endif() check_c_compiler_flag(-Wno-array-parameter HAS_WNO_ARRAY_PARAMETER) if(HAS_WNO_ARRAY_PARAMETER) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-parameter") + set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-array-parameter") endif() endif() - add_subdirectory(crt/aws-lc) - - # restore previous build flags - set(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}") - - set(SEARCH_LIBCRYPTO OFF CACHE BOOL "Let S2N use libcrypto from AWS-LC.") - else() - set(SEARCH_LIBCRYPTO ON CACHE BOOL "Let S2N search libcrypto in the system.") + # s2n-tls uses libcrypto during its configuration, so we need to prebuild aws-lc. + aws_prebuild_dependency( + DEPENDENCY_NAME AWSLC + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/crt/aws-lc + CMAKE_ARGUMENTS + -DDISABLE_GO=ON + -DDISABLE_PERL=ON + -DBUILD_LIBSSL=OFF + -DBUILD_TESTING=OFF + -DCMAKE_C_FLAGS=${AWSLC_CMAKE_C_FLAGS} + ) endif() - set(UNSAFE_TREAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Disable warnings-as-errors when building S2N") - add_subdirectory(crt/s2n) + # prebuild s2n-tls. + aws_prebuild_dependency( + DEPENDENCY_NAME S2N + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/crt/s2n + CMAKE_ARGUMENTS + -DUNSAFE_TREAT_WARNINGS_AS_ERRORS=OFF + -DBUILD_TESTING=OFF + ) endif() add_subdirectory(crt/aws-c-sdkutils) @@ -147,6 +154,10 @@ file(GLOB AWS_CRT_AUTH_HEADERS "include/aws/crt/auth/*.h" ) +file(GLOB AWS_CRT_CHECKSUM_HEADERS + "include/aws/crt/checksum/*.h" +) + file(GLOB AWS_CRT_CRYPTO_HEADERS "include/aws/crt/crypto/*.h" ) @@ -178,6 +189,7 @@ file(GLOB AWS_CRT_CBOR_HEADERS file(GLOB AWS_CRT_PUBLIC_HEADERS ${AWS_CRT_HEADERS} ${AWS_CRT_AUTH_HEADERS} + ${AWS_CRT_CHECKSUM_HEADERS} ${AWS_CRT_CRYPTO_HEADERS} ${AWS_CRT_IO_HEADERS} ${AWS_CRT_IOT_HEADERS} @@ -204,6 +216,10 @@ file(GLOB AWS_CRT_AUTH_SRC "source/auth/*.cpp" ) +file(GLOB AWS_CRT_CHECKSUM_SRC + "source/checksum/*.cpp" +) + file(GLOB AWS_CRT_CRYPTO_SRC "source/crypto/*.cpp" ) @@ -235,6 +251,7 @@ file(GLOB AWS_CRT_CBOR_SRC file(GLOB AWS_CRT_CPP_SRC ${AWS_CRT_SRC} ${AWS_CRT_AUTH_SRC} + ${AWS_CRT_CHECKSUM_SRC} ${AWS_CRT_CRYPTO_SRC} ${AWS_CRT_IO_SRC} ${AWS_CRT_IOT_SRC} @@ -248,6 +265,7 @@ if(WIN32) if(MSVC) source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS}) source_group("Header Files\\aws\\crt\\auth" FILES ${AWS_CRT_AUTH_HEADERS}) + source_group("Header Files\\aws\\crt\\checksum" FILES ${AWS_CRT_CHECKSUM_HEADERS}) source_group("Header Files\\aws\\crt\\crypto" FILES ${AWS_CRT_CRYPTO_HEADERS}) source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS}) source_group("Header Files\\aws\\iot" FILES ${AWS_CRT_IOT_HEADERS}) @@ -258,6 +276,7 @@ if(WIN32) source_group("Source Files" FILES ${AWS_CRT_SRC}) source_group("Source Files\\auth" FILES ${AWS_CRT_AUTH_SRC}) + source_group("Source Files\\checksum" FILES ${AWS_CRT_CHECKSUM_SRC}) source_group("Source Files\\crypto" FILES ${AWS_CRT_CRYPTO_SRC}) source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC}) source_group("Source Files\\iot" FILES ${AWS_CRT_IOT_SRC}) @@ -283,6 +302,7 @@ endif() set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON) aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_CRT_CPP") @@ -328,6 +348,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS}) install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development) install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "include/aws/crt/auth" COMPONENT Development) +install(FILES ${AWS_CRT_CHECKSUM_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development) install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development) install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io" COMPONENT Development) install(FILES ${AWS_CRT_IOT_HEADERS} DESTINATION "include/aws/iot" COMPONENT Development) diff --git a/VERSION b/VERSION index a37255a85..ae6dd4e20 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.28.2 +0.29.0 diff --git a/crt/aws-c-auth b/crt/aws-c-auth index 877c029fc..3982bd75f 160000 --- a/crt/aws-c-auth +++ b/crt/aws-c-auth @@ -1 +1 @@ -Subproject commit 877c029fc4e93d205f9c6855188c3c51f6b497b4 +Subproject commit 3982bd75fea74efd8f9b462b27fedd4599db4f53 diff --git a/crt/aws-c-cal b/crt/aws-c-cal index 2cb1d2eac..656762aef 160000 --- a/crt/aws-c-cal +++ b/crt/aws-c-cal @@ -1 +1 @@ -Subproject commit 2cb1d2eac925e2dbc45025eb89af82bd790c23a0 +Subproject commit 656762aefbee2bc8f509cb23cd107abff20a72bb diff --git a/crt/aws-c-common b/crt/aws-c-common index 672cc0032..f41b772f0 160000 --- a/crt/aws-c-common +++ b/crt/aws-c-common @@ -1 +1 @@ -Subproject commit 672cc0032eb28d69fbdd22c9463253c89d7a6f30 +Subproject commit f41b772f0de9454a4e7a65750b58c2379533bbf1 diff --git a/crt/aws-c-compression b/crt/aws-c-compression index f36d01672..c6c1191e5 160000 --- a/crt/aws-c-compression +++ b/crt/aws-c-compression @@ -1 +1 @@ -Subproject commit f36d01672d61e49d96a777870d456f66fa391cd4 +Subproject commit c6c1191e525e5aa6ead9e1afc392e35d3b50331e diff --git a/crt/aws-c-event-stream b/crt/aws-c-event-stream index 1b3825fc9..d2dcc9344 160000 --- a/crt/aws-c-event-stream +++ b/crt/aws-c-event-stream @@ -1 +1 @@ -Subproject commit 1b3825fc9cae2e9c7ed7479ee5d354d52ebdf7a0 +Subproject commit d2dcc9344dae24de320866045d85166d8a91a0d1 diff --git a/crt/aws-c-http b/crt/aws-c-http index 4e74ab1e3..74b3a0dd1 160000 --- a/crt/aws-c-http +++ b/crt/aws-c-http @@ -1 +1 @@ -Subproject commit 4e74ab1e3702763e0b87bd1752f5a37c2f0400ac +Subproject commit 74b3a0dd1396b72f701c8bdf24e5c6f41e52cf87 diff --git a/crt/aws-c-io b/crt/aws-c-io index c345d7727..fe93d0afc 160000 --- a/crt/aws-c-io +++ b/crt/aws-c-io @@ -1 +1 @@ -Subproject commit c345d77274db83c0c2e30331814093e7c84c45e2 +Subproject commit fe93d0afcc1cede32ac9569abd8669ed011b1b8c diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index ed7bbd68c..627c3334e 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit ed7bbd68c03d7022c915a2924740ab7992ad2311 +Subproject commit 627c3334e52021aa8d5772b6ca076884610f3219 diff --git a/crt/aws-c-s3 b/crt/aws-c-s3 index 0ab4d58ef..8c1969bce 160000 --- a/crt/aws-c-s3 +++ b/crt/aws-c-s3 @@ -1 +1 @@ -Subproject commit 0ab4d58ef0bd97970d43828cb6b57a3de5747343 +Subproject commit 8c1969bce5bfe0e063cbc719182dbe344342b880 diff --git a/crt/aws-c-sdkutils b/crt/aws-c-sdkutils index 4658412a6..0818f28ee 160000 --- a/crt/aws-c-sdkutils +++ b/crt/aws-c-sdkutils @@ -1 +1 @@ -Subproject commit 4658412a61ad5749db92a8d1e0717cb5e76ada1c +Subproject commit 0818f28ee436b892f09fbe8e3a6ae37ff40e9436 diff --git a/crt/aws-checksums b/crt/aws-checksums index aac442a2d..0d2f5521f 160000 --- a/crt/aws-checksums +++ b/crt/aws-checksums @@ -1 +1 @@ -Subproject commit aac442a2dbbb5e72d0a3eca8313cf65e7e1cac2f +Subproject commit 0d2f5521f61215f38f791d106ae304402208112d diff --git a/crt/aws-lc b/crt/aws-lc index 2f1879759..8ffe277c2 160000 --- a/crt/aws-lc +++ b/crt/aws-lc @@ -1 +1 @@ -Subproject commit 2f1879759b2e0fc70592665bdf10087b64f44b7d +Subproject commit 8ffe277c21915ca82dc78a3bdc6a92e10c284b92 diff --git a/crt/s2n b/crt/s2n index 87f4a0585..ffe0bf42d 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit 87f4a0585dc3056433f193b9305f587cff239be3 +Subproject commit ffe0bf42da8f139eff8fd2237f47fbde40b478fb diff --git a/include/aws/crt/checksum/CRC.h b/include/aws/crt/checksum/CRC.h new file mode 100644 index 000000000..023d1d21a --- /dev/null +++ b/include/aws/crt/checksum/CRC.h @@ -0,0 +1,39 @@ +#pragma once +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ +#include +#include + +namespace Aws +{ + namespace Crt + { + namespace Checksum + { + /** + * The entry point function to perform a CRC32 (Ethernet, gzip) computation. + * Selects a suitable implementation based on hardware capabilities. + * Pass previousCRC32 if updating a running checksum. + */ + uint32_t AWS_CRT_CPP_API ComputeCRC32(ByteCursor input, uint32_t previousCRC32 = 0) noexcept; + + /** + * The entry point function to perform a Castagnoli CRC32c (iSCSI) computation. + * Selects a suitable implementation based on hardware capabilities. + * Pass previousCRC32C if updating a running checksum. + */ + uint32_t AWS_CRT_CPP_API ComputeCRC32C(ByteCursor input, uint32_t previousCRC32C = 0) noexcept; + + /** + * The entry point function to perform a CRC64-NVME (a.k.a. CRC64-Rocksoft) computation. + * Selects a suitable implementation based on hardware capabilities. + * Pass previousCRC64NVME if updating a running checksum. + * There are many variants of CRC64 algorithms. This CRC64 variant is bit-reflected (based on + * the non bit-reflected polynomial 0xad93d23594c93659) and inverts the CRC input and output bits. + */ + uint64_t AWS_CRT_CPP_API ComputeCRC64NVME(ByteCursor input, uint64_t previousCRC64NVME = 0) noexcept; + } // namespace Checksum + } // namespace Crt +} // namespace Aws diff --git a/include/aws/crt/crypto/Hash.h b/include/aws/crt/crypto/Hash.h index 98e3e3c93..af8a7c7d2 100644 --- a/include/aws/crt/crypto/Hash.h +++ b/include/aws/crt/crypto/Hash.h @@ -189,7 +189,7 @@ namespace Aws /** * Complete the hash computation and write the final digest to output. - * This cannote be called more than once. + * This cannot be called more than once. * If truncate_to is something other than 0, the output must be truncated to that number of bytes. * Raise an AWS error and return false to indicate failure. */ diff --git a/source/checksum/CRC.cpp b/source/checksum/CRC.cpp new file mode 100644 index 000000000..65ed70e28 --- /dev/null +++ b/source/checksum/CRC.cpp @@ -0,0 +1,32 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ +#include + +#include + +namespace Aws +{ + namespace Crt + { + namespace Checksum + { + uint32_t ComputeCRC32(ByteCursor input, uint32_t previousCRC32) noexcept + { + return aws_checksums_crc32_ex(input.ptr, input.len, previousCRC32); + } + + uint32_t ComputeCRC32C(ByteCursor input, uint32_t previousCRC32C) noexcept + { + return aws_checksums_crc32c_ex(input.ptr, input.len, previousCRC32C); + } + + uint64_t ComputeCRC64NVME(ByteCursor input, uint64_t previousCRC64NVME) noexcept + { + return aws_checksums_crc64nvme_ex(input.ptr, input.len, previousCRC64NVME); + } + + } // namespace Checksum + } // namespace Crt +} // namespace Aws diff --git a/tests/CRCTest.cpp b/tests/CRCTest.cpp new file mode 100644 index 000000000..464fe4862 --- /dev/null +++ b/tests/CRCTest.cpp @@ -0,0 +1,46 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ +#include +#include +#include + +static int s_TestCRC32Piping(struct aws_allocator *allocator, void *) +{ + Aws::Crt::ApiHandle apiHandle(allocator); + uint8_t data[32] = {0}; + + Aws::Crt::ByteCursor dataCur = aws_byte_cursor_from_array(data, sizeof(data)); + + ASSERT_UINT_EQUALS(0x190A55AD, Aws::Crt::Checksum::ComputeCRC32(dataCur)); + + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE(CRC32Piping, s_TestCRC32Piping) + +static int s_TestCRC32CPiping(struct aws_allocator *allocator, void *) +{ + Aws::Crt::ApiHandle apiHandle(allocator); + uint8_t data[32] = {0}; + + Aws::Crt::ByteCursor dataCur = aws_byte_cursor_from_array(data, sizeof(data)); + + ASSERT_UINT_EQUALS(0x8A9136AA, Aws::Crt::Checksum::ComputeCRC32C(dataCur)); + + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE(CRC32CPiping, s_TestCRC32CPiping) + +static int s_TestCRC64NVMEPiping(struct aws_allocator *allocator, void *) +{ + Aws::Crt::ApiHandle apiHandle(allocator); + uint8_t data[32] = {0}; + + Aws::Crt::ByteCursor dataCur = aws_byte_cursor_from_array(data, sizeof(data)); + + ASSERT_UINT_EQUALS(0xCF3473434D4ECF3B, Aws::Crt::Checksum::ComputeCRC64NVME(dataCur)); + + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE(CRC64NVMEPiping, s_TestCRC64NVMEPiping)