Skip to content

Commit b0b8a18

Browse files
Added aws-c-cal wrapper and basic binding correctness verification. (aws#9)
* Added aws-c-cal wrapper and basic binding correctness verification.
1 parent 774f16b commit b0b8a18

File tree

10 files changed

+702
-13
lines changed

10 files changed

+702
-13
lines changed

CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ if (BUILD_DEPS)
2020
set(AWS_DEPS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/install)
2121
endif()
2222

23-
list(APPEND CMAKE_MODULE_PATH "${AWS_DEPS_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake")
24-
2523
if (NOT DEFINED CMAKE_PREFIX_PATH)
2624
set(CMAKE_PREFIX_PATH ${AWS_DEPS_INSTALL_DIR})
2725
endif()
@@ -39,9 +37,8 @@ if (BUILD_DEPS)
3937
-DANDROID_STL=${ANDROID_STL}
4038
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
4139
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
42-
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
4340
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
44-
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
41+
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
4542
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
4643
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
4744
${CMAKE_CURRENT_SOURCE_DIR}/aws-common-runtime
@@ -80,16 +77,16 @@ if (BUILD_DEPS)
8077
#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
8178
#we don't want happening until we're done with the above code.
8279
list(APPEND CMAKE_PREFIX_PATH "${AWS_DEPS_INSTALL_DIR}")
80+
8381
project(aws-crt-cpp CXX)
8482

8583
else()
8684
#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
8785
#we want happening exactly right now.
8886
project(aws-crt-cpp CXX)
8987

90-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")
9188
endif()
92-
89+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")
9390

9491
if (NOT CMAKE_CXX_STANDARD)
9592
set(CMAKE_CXX_STANDARD 11)
@@ -99,6 +96,10 @@ file(GLOB AWS_CRT_HEADERS
9996
"include/aws/crt/*.h"
10097
)
10198

99+
file(GLOB AWS_CRT_CRYPTO_HEADERS
100+
"include/aws/crt/crypto/*.h"
101+
)
102+
102103
file(GLOB AWS_CRT_IO_HEADERS
103104
"include/aws/crt/io/*.h"
104105
)
@@ -113,14 +114,19 @@ file(GLOB AWS_CRT_EXTERNAL_HEADERS
113114

114115
file(GLOB AWS_CRT_CPP_HEADERS
115116
${AWS_CRT_HEADERS}
116-
${AWS_CRT_IO_HEADERS}
117+
${AWS_CRT_CRYPTO_HEADERS}
118+
${AWS_CRT_IO_HEADERS}
117119
${AWS_CRT_MQTT_HEADERS}
118120
)
119121

120122
file(GLOB AWS_CRT_SRC
121123
"source/*.cpp"
122124
)
123125

126+
file(GLOB AWS_CRT_CRYPTO_SRC
127+
"source/crypto/*.cpp"
128+
)
129+
124130
file (GLOB AWS_CRT_IO_SRC
125131
"source/io/*.cpp"
126132
)
@@ -135,6 +141,7 @@ file(GLOB AWS_CRT_EXTERNAL_CRC
135141

136142
file(GLOB AWS_CRT_CPP_SRC
137143
${AWS_CRT_SRC}
144+
${AWS_CRT_CRYPTO_SRC}
138145
${AWS_CRT_IO_SRC}
139146
${AWS_CRT_MQTT_SRC}
140147
${AWS_CRT_EXTERNAL_CRC}
@@ -143,11 +150,13 @@ file(GLOB AWS_CRT_CPP_SRC
143150
if (WIN32)
144151
if (MSVC)
145152
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS})
153+
source_group("Header Files\\aws\\crt\\crypto" FILES ${AWS_CRT_CRYPTO_HEADERS})
146154
source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS})
147155
source_group("Header Files\\aws\\crt\\mqtt" FILES ${AWS_CRT_MQTT_HEADERS})
148156
source_group("Header Files\\aws\\crt\\external" FILES ${AWS_CRT_EXTERNAL_HEADERS})
149157

150158
source_group("Source Files" FILES ${AWS_CRT_SRC})
159+
source_group("Source Files\\crypto" FILES ${AWS_CRT_CRYPTO_SRC})
151160
source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC})
152161
source_group("Source Files\\mqtt" FILES ${AWS_CRT_MQTT_SRC})
153162
source_group("Source Files\\external" FILES ${AWS_CRT_EXTERNAL_SRC})
@@ -181,9 +190,11 @@ target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
181190
$<INSTALL_INTERFACE:include>)
182191

183192
find_package(aws-c-mqtt REQUIRED)
184-
target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-mqtt)
193+
find_package(aws-c-cal REQUIRED)
194+
target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-cal AWS::aws-c-mqtt)
185195

186196
install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development)
197+
install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development)
187198
install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io" COMPONENT Development)
188199
install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "include/aws/crt/mqtt" COMPONENT Development)
189200
install(FILES ${AWS_CRT_EXTERNAL_HEADERS} DESTINATION "include/aws/crt/external" COMPONENT Development)

aws-common-runtime/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,32 @@ set(AWS_DEPS_DOWNLOAD_DIR "${AWS_DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependen
1717

1818
message("install dir ${AWS_DEPS_INSTALL_DIR}")
1919
set(AWS_C_COMMON_URL "https://github.com/awslabs/aws-c-common.git")
20-
set(AWS_C_COMMON_SHA "v0.3.0")
20+
set(AWS_C_COMMON_SHA "v0.3.2")
2121
include(BuildAwsCCommon)
2222

2323
if (UNIX AND NOT APPLE)
2424
set(S2N_URL "https://github.com/awslabs/s2n.git")
25-
set(s2N_SHA "383586162b3ee60bbd75105fcfe583b14bf60d46")
25+
set(s2N_SHA "ff1a8b2187ded17ee5570fd54f15c58f2175ce51")
2626
include(BuildS2N)
2727
endif()
2828

2929
set(AWS_C_IO_URL "https://github.com/awslabs/aws-c-io.git")
30-
set(AWS_C_IO_SHA "v0.2.0")
30+
set(AWS_C_IO_SHA "v0.2.2")
3131
include(BuildAwsCIO)
3232

3333
set(AWS_C_MQTT_URL "https://github.com/awslabs/aws-c-mqtt.git")
34-
set(AWS_C_MQTT_SHA "v0.2.0")
34+
set(AWS_C_MQTT_SHA "v0.2.1")
3535
include(BuildAwsCMqtt)
3636

37+
set(AWS_C_CAL_URL "https://github.com/awslabs/aws-c-cal.git")
38+
set(AWS_C_CAL_SHA "v0.1.4")
39+
include(BuildAwsCCal)
40+
3741
add_dependencies(AwsCMqtt AwsCIO)
42+
add_dependencies(AwsCCal AwsCCommon)
3843

3944
if (UNIX AND NOT APPLE)
4045
add_dependencies(AwsCIO S2N AwsCCommon)
4146
else()
4247
add_dependencies(AwsCIO AwsCCommon )
43-
endif()
48+
endif()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
if("${TARGET_ARCH}" STREQUAL ANDROID)
2+
ExternalProject_Add(AwsCCal
3+
PREFIX ${AWS_DEPS_BUILD_DIR}
4+
GIT_REPOSITORY ${AWS_C_CAL_URL}
5+
GIT_TAG ${AWS_C_CAL_SHA}
6+
BUILD_IN_SOURCE 0
7+
UPDATE_COMMAND ""
8+
CMAKE_ARGS
9+
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
10+
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
11+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
12+
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
13+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
14+
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL}
15+
-DANDROID_ABI=${ANDROID_ABI}
16+
-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME}
17+
-DANDROID_STANDALONE_TOOLCHAIN=${ANDROID_STANDALONE_TOOLCHAIN}
18+
-DANDROID_STL=${ANDROID_STL}
19+
-DENABLE_HW_OPTIMIZATION=OFF
20+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
21+
)
22+
elseif(MSVC)
23+
ExternalProject_Add(AwsCCal
24+
PREFIX ${AWS_DEPS_BUILD_DIR}
25+
GIT_REPOSITORY ${AWS_C_CAL_URL}
26+
GIT_TAG ${AWS_C_CAL_SHA}
27+
BUILD_IN_SOURCE 0
28+
UPDATE_COMMAND ""
29+
CMAKE_ARGS
30+
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
31+
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
32+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
33+
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
34+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
35+
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
36+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
37+
)
38+
else()
39+
ExternalProject_Add(AwsCCal
40+
PREFIX ${AWS_DEPS_BUILD_DIR}
41+
GIT_REPOSITORY ${AWS_C_CAL_URL}
42+
GIT_TAG ${AWS_C_CAL_SHA}
43+
BUILD_IN_SOURCE 0
44+
UPDATE_COMMAND ""
45+
CMAKE_ARGS
46+
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
47+
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
48+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
49+
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
50+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
51+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
52+
)
53+
endif()

include/aws/crt/crypto/HMAC.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#pragma once
2+
/*
3+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
#include <aws/crt/Exports.h>
17+
#include <aws/crt/Types.h>
18+
19+
struct aws_hmac;
20+
namespace Aws
21+
{
22+
namespace Crt
23+
{
24+
namespace Crypto
25+
{
26+
static const size_t SHA256_HMAC_DIGEST_SIZE = 32;
27+
28+
/**
29+
* Computes a SHA256 HMAC with secret over input, and writes the digest to output. If truncateTo is
30+
* non-zero, the digest will be truncated to the value of truncateTo. Returns true on success. If this
31+
* function fails, Aws::Crt::LastError() will contain the error that occured. Unless you're using
32+
* 'truncateTo', output should have a minimum capacity of SHA256_HMAC_DIGEST_SIZE.
33+
*/
34+
bool AWS_CRT_CPP_API ComputeSHA256HMAC(
35+
Allocator *allocator,
36+
const ByteCursor &secret,
37+
const ByteCursor &input,
38+
ByteBuf &output,
39+
size_t truncateTo = 0) noexcept;
40+
41+
/**
42+
* Computes a SHA256 HMAC using the default allocator with secret over input, and writes the digest to
43+
* output. If truncateTo is non-zero, the digest will be truncated to the value of truncateTo. Returns true
44+
* on success. If this function fails, Aws::Crt::LastError() will contain the error that occured. Unless
45+
* you're using 'truncateTo', output should have a minimum capacity of SHA256_HMAC_DIGEST_SIZE.
46+
*/
47+
bool AWS_CRT_CPP_API ComputeSHA256HMAC(
48+
const ByteCursor &secret,
49+
const ByteCursor &input,
50+
ByteBuf &output,
51+
size_t truncateTo = 0) noexcept;
52+
/**
53+
* Streaming HMAC object. The typical use case is for computing the HMAC of an object that is too large to
54+
* load into memory. You can call Update() mutliple times as you load chunks of data into memory. When
55+
* you're finished simply call Digest(). After Digest() is called, this object is no longer usable.
56+
*/
57+
class AWS_CRT_CPP_API HMAC final
58+
{
59+
public:
60+
~HMAC();
61+
HMAC(const HMAC &) = delete;
62+
HMAC &operator=(const HMAC &) = delete;
63+
HMAC(HMAC &&toMove);
64+
HMAC &operator=(HMAC &&toMove);
65+
66+
inline operator bool() const noexcept { return m_good; }
67+
68+
inline int LastError() const noexcept { return m_lastError; }
69+
70+
/**
71+
* Creates an instance of a Streaming SHA256 HMAC.
72+
*/
73+
static HMAC CreateSHA256HMAC(Allocator *allocator, const ByteCursor &secret) noexcept;
74+
75+
/**
76+
* Creates an instance of a Streaming SHA256 HMAC using the Default Allocator.
77+
*/
78+
static HMAC CreateSHA256HMAC(const ByteCursor &secret) noexcept;
79+
80+
/**
81+
* Updates the running HMAC object with data in toHMAC. Returns true on success. Call
82+
* LastError() for the reason this call failed.
83+
*/
84+
bool Update(const ByteCursor &toHMAC) noexcept;
85+
86+
/**
87+
* Finishes the running HMAC operation and writes the digest into output. The available capacity of
88+
* output must be large enough for the digest. See: SHA256_DIGEST_SIZE and MD5_DIGEST_SIZE for size
89+
* hints. 'truncateTo' is for if you want truncated output (e.g. you only want the first 16 bytes of a
90+
* SHA256 digest. Returns true on success. Call LastError() for the reason this call failed.
91+
*/
92+
bool Digest(ByteBuf &output, size_t truncateTo = 0) noexcept;
93+
94+
private:
95+
HMAC(aws_hmac *hmac) noexcept;
96+
HMAC() = delete;
97+
98+
aws_hmac *m_hmac;
99+
bool m_good;
100+
int m_lastError;
101+
};
102+
103+
} // namespace Crypto
104+
} // namespace Crt
105+
} // namespace Aws

0 commit comments

Comments
 (0)