Skip to content

Commit

Permalink
Merge pull request #8 from awslabs/windows_build_fixes
Browse files Browse the repository at this point in the history
Thanks for the productive day Microsoft.
  • Loading branch information
JonathanHenson authored Feb 14, 2019
2 parents 5bff919 + 69f99b1 commit a31832e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ project(aws-c-cal LANGUAGES C VERSION 0.1.0)

option(BYO_CRYPTO "Set this if you want to provide your own cryptography implementation. This will cause the defaults to not be compiled." OFF)

if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH ${CMAKE_PREFIX_PATH} CMAKE_PREFIX_PATH)
endif()

if (DEFINED CMAKE_INSTALL_PREFIX)
file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX)
endif()

if (UNIX AND NOT APPLE)
include(GNUInstallDirs)
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
Expand Down
16 changes: 8 additions & 8 deletions codebuild/common-windows.bat
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
set CMAKE_ARGS=%*
set BUILDS_DIR=%TEMP%/builds
set INSTALL_DIR=%BUILDS_DIR%/install
set BUILDS_DIR=%TEMP%\builds
set INSTALL_DIR=%BUILDS_DIR%\install
mkdir %BUILDS_DIR%
mkdir %INSTALL_DIR%

CALL :install_library aws-c-common

mkdir %BUILDS_DIR%/aws-c-cal-build
cd %BUILDS_DIR%/aws-c-cal-build
cmake %CMAKE_ARGS% -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% %CODEBUILD_SRC_DIR% || goto error
mkdir %BUILDS_DIR%\aws-c-cal-build
cd %BUILDS_DIR%\aws-c-cal-build
cmake %CMAKE_ARGS% -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" -DCMAKE_PREFIX_PATH="%INSTALL_DIR%" %CODEBUILD_SRC_DIR% || goto error
cmake --build . --config RelWithDebInfo || goto error
ctest -V || goto error

goto :EOF

:install_library
mkdir %BUILDS_DIR%/%~1-build
cd %BUILDS_DIR%/%~1-build
mkdir %BUILDS_DIR%\%~1-build
cd %BUILDS_DIR%\%~1-build
git clone https://github.com/awslabs/%~1.git
cmake %CMAKE_ARGS% -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% %~1 || goto error
cmake %CMAKE_ARGS% -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" -DCMAKE_PREFIX_PATH="%INSTALL_DIR%" %~1 || goto error
cmake --build . --target install --config RelWithDebInfo || goto error
exit /b %errorlevel%

Expand Down
11 changes: 5 additions & 6 deletions source/bcrypt/bcrypt_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <bcrypt.h>
#include <winerror.h>
#include <winternl.h>

static BCRYPT_ALG_HANDLE s_sha256_alg = NULL;
static size_t s_sha256_obj_len = 0;
Expand Down Expand Up @@ -93,7 +92,7 @@ struct aws_hash *aws_sha256_default_new(struct aws_allocator *allocator) {
NTSTATUS status = BCryptCreateHash(
s_sha256_alg, &bcrypt_hash->hash_handle, bcrypt_hash->hash_obj, (ULONG)s_sha256_obj_len, NULL, 0, 0);

if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
aws_mem_release(allocator, bcrypt_hash);
return NULL;
}
Expand Down Expand Up @@ -122,7 +121,7 @@ struct aws_hash *aws_md5_default_new(struct aws_allocator *allocator) {
NTSTATUS status =
BCryptCreateHash(s_md5_alg, &bcrypt_hash->hash_handle, bcrypt_hash->hash_obj, (ULONG)s_md5_obj_len, NULL, 0, 0);

if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
aws_mem_release(allocator, bcrypt_hash);
return NULL;
}
Expand All @@ -144,7 +143,7 @@ static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash
struct bcrypt_hash_handle *ctx = hash->impl;
NTSTATUS status = BCryptHashData(ctx->hash_handle, to_hash->ptr, (ULONG)to_hash->len, 0);

if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
hash->good = false;
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
Expand All @@ -165,10 +164,10 @@ static int s_finalize(struct aws_hash *hash, struct aws_byte_buf *output) {
return aws_raise_error(AWS_ERROR_SHORT_BUFFER);
}

NTSTATUS status = BCryptFinishHash(ctx->hash_handle, output->buffer + output->len, (ULONG)buffer_len, 0);
NTSTATUS status = BCryptFinishHash(ctx->hash_handle, output->buffer + output->len, (ULONG)hash->digest_size, 0);

hash->good = false;
if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}

Expand Down
9 changes: 4 additions & 5 deletions source/bcrypt/bcrypt_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <bcrypt.h>
#include <winerror.h>
#include <winternl.h>

static BCRYPT_ALG_HANDLE s_sha256_hmac_alg = NULL;
static size_t s_sha256_hmac_obj_len = 0;
Expand Down Expand Up @@ -87,7 +86,7 @@ struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, co
(ULONG)secret->len,
0);

if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
aws_mem_release(allocator, bcrypt_hmac);
return NULL;
}
Expand All @@ -109,7 +108,7 @@ static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hash
struct bcrypt_hmac_handle *ctx = hmac->impl;
NTSTATUS status = BCryptHashData(ctx->hash_handle, to_hash->ptr, (ULONG)to_hash->len, 0);

if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
hmac->good = false;
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
Expand All @@ -130,10 +129,10 @@ static int s_finalize(struct aws_hmac *hmac, struct aws_byte_buf *output) {
return aws_raise_error(AWS_ERROR_SHORT_BUFFER);
}

NTSTATUS status = BCryptFinishHash(ctx->hash_handle, output->buffer + output->len, (ULONG)buffer_len, 0);
NTSTATUS status = BCryptFinishHash(ctx->hash_handle, output->buffer + output->len, (ULONG)hmac->digest_size, 0);

hmac->good = false;
if (!NT_SUCCESS(status)) {
if (((NTSTATUS)status) < 0) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}

Expand Down

0 comments on commit a31832e

Please sign in to comment.