Skip to content

Commit

Permalink
Merge pull request #16 from awslabs/once_fixes
Browse files Browse the repository at this point in the history
Fixes for changes to aws_thread_call_once on windows
  • Loading branch information
Justin Boswell authored Sep 11, 2019
2 parents 3896a60 + 59a8c45 commit 9f0e4f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions source/bcrypt/bcrypt_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ struct bcrypt_hash_handle {
uint8_t *hash_obj;
};

static void s_load_sha256_alg_handle(void) {
static void s_load_sha256_alg_handle(void *user_data) {
(void)user_data;
/* this function is incredibly slow, LET IT LEAK*/
BCryptOpenAlgorithmProvider(&s_sha256_alg, BCRYPT_SHA256_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
AWS_ASSERT(s_sha256_alg);
Expand All @@ -63,7 +64,8 @@ static void s_load_sha256_alg_handle(void) {
s_sha256_alg, BCRYPT_OBJECT_LENGTH, (PBYTE)&s_sha256_obj_len, sizeof(s_sha256_obj_len), &result_length, 0);
}

static void s_load_md5_alg_handle(void) {
static void s_load_md5_alg_handle(void *user_data) {
(void)user_data;
/* this function is incredibly slow, LET IT LEAK*/
BCryptOpenAlgorithmProvider(&s_md5_alg, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
AWS_ASSERT(s_md5_alg);
Expand All @@ -72,7 +74,7 @@ static void s_load_md5_alg_handle(void) {
}

struct aws_hash *aws_sha256_default_new(struct aws_allocator *allocator) {
aws_thread_call_once(&s_sha256_once, s_load_sha256_alg_handle);
aws_thread_call_once(&s_sha256_once, s_load_sha256_alg_handle, NULL);

struct bcrypt_hash_handle *bcrypt_hash;
uint8_t *hash_obj;
Expand Down Expand Up @@ -101,7 +103,7 @@ struct aws_hash *aws_sha256_default_new(struct aws_allocator *allocator) {
}

struct aws_hash *aws_md5_default_new(struct aws_allocator *allocator) {
aws_thread_call_once(&s_md5_once, s_load_md5_alg_handle);
aws_thread_call_once(&s_md5_once, s_load_md5_alg_handle, NULL);

struct bcrypt_hash_handle *bcrypt_hash;
uint8_t *hash_obj;
Expand Down
5 changes: 3 additions & 2 deletions source/bcrypt/bcrypt_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct bcrypt_hmac_handle {
uint8_t *hash_obj;
};

static void s_load_alg_handle(void) {
static void s_load_alg_handle(void *user_data) {
(void)user_data;
/* this function is incredibly slow, LET IT LEAK*/
BCryptOpenAlgorithmProvider(
&s_sha256_hmac_alg, BCRYPT_SHA256_ALGORITHM, MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
Expand All @@ -59,7 +60,7 @@ static void s_load_alg_handle(void) {
}

struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) {
aws_thread_call_once(&s_sha256_hmac_once, s_load_alg_handle);
aws_thread_call_once(&s_sha256_hmac_once, s_load_alg_handle, NULL);

struct bcrypt_hmac_handle *bcrypt_hmac;
uint8_t *hash_obj;
Expand Down

0 comments on commit 9f0e4f6

Please sign in to comment.