From 5bd470128af32bce378ec51e9ef62d35c44f7200 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Wed, 13 Feb 2019 16:48:37 -0800 Subject: [PATCH 1/2] Added const modifiers where it made sense. --- include/aws/cal/hash.h | 8 ++++---- include/aws/cal/hmac.h | 12 ++++++------ source/bcrypt/bcrypt_hash.c | 4 ++-- source/bcrypt/bcrypt_hmac.c | 6 +++--- source/commoncrypto/commoncrypto_hmac.c | 6 +++--- source/commoncrypto/commoncrypto_md5.c | 4 ++-- source/commoncrypto/commoncrypto_sha256.c | 4 ++-- source/hash.c | 8 ++++---- source/hmac.c | 12 ++++++------ source/opensslcrypto/opensslcrypto_hash.c | 4 ++-- source/opensslcrypto/opensslcrypto_hmac.c | 6 +++--- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/include/aws/cal/hash.h b/include/aws/cal/hash.h index 86c53fba..f6c154c5 100644 --- a/include/aws/cal/hash.h +++ b/include/aws/cal/hash.h @@ -28,7 +28,7 @@ struct aws_hash_vtable { const char *alg_name; const char *provider; void (*destroy)(struct aws_hash *hash); - int (*update)(struct aws_hash *hash, struct aws_byte_cursor *buf); + int (*update)(struct aws_hash *hash, const struct aws_byte_cursor *buf); int (*finalize)(struct aws_hash *hash, struct aws_byte_buf *out); }; @@ -58,7 +58,7 @@ AWS_CAL_API void aws_hash_destroy(struct aws_hash *hash); /** * Updates the running hash with to_hash. this can be called multiple times. */ -AWS_CAL_API int aws_hash_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash); +AWS_CAL_API int aws_hash_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash); /** * Completes the hash computation and writes the final digest to output. * Allocation of output is the caller's responsibility. If you specify @@ -76,7 +76,7 @@ AWS_CAL_API int aws_hash_finalize(struct aws_hash *hash, struct aws_byte_buf *ou */ AWS_CAL_API int aws_md5_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *input, + const struct aws_byte_cursor *input, struct aws_byte_buf *output, size_t truncate_to); @@ -90,7 +90,7 @@ AWS_CAL_API int aws_md5_compute( */ AWS_CAL_API int aws_sha256_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *input, + const struct aws_byte_cursor *input, struct aws_byte_buf *output, size_t truncate_to); diff --git a/include/aws/cal/hmac.h b/include/aws/cal/hmac.h index 8ce94107..fd519edd 100644 --- a/include/aws/cal/hmac.h +++ b/include/aws/cal/hmac.h @@ -27,7 +27,7 @@ struct aws_hmac_vtable { const char *alg_name; const char *provider; void (*destroy)(struct aws_hmac *hmac); - int (*update)(struct aws_hmac *hmac, struct aws_byte_cursor *buf); + int (*update)(struct aws_hmac *hmac, const struct aws_byte_cursor *buf); int (*finalize)(struct aws_hmac *hmac, struct aws_byte_buf *out); }; @@ -39,14 +39,14 @@ struct aws_hmac { void *impl; }; -typedef struct aws_hmac *(aws_hmac_new_fn)(struct aws_allocator *allocator, struct aws_byte_cursor *secret); +typedef struct aws_hmac *(aws_hmac_new_fn)(struct aws_allocator *allocator, const struct aws_byte_cursor *secret); AWS_EXTERN_C_BEGIN /** * Allocates and initializes a sha256 hmac instance. Secret is the key to be * used for the hmac process. */ -AWS_CAL_API struct aws_hmac *aws_sha256_hmac_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret); +AWS_CAL_API struct aws_hmac *aws_sha256_hmac_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret); /** * Cleans up and deallocates hmac. @@ -56,7 +56,7 @@ AWS_CAL_API void aws_hmac_destroy(struct aws_hmac *hmac); /** * Updates the running hmac with to_hash. this can be called multiple times. */ -AWS_CAL_API int aws_hmac_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac); +AWS_CAL_API int aws_hmac_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac); /** * Completes the hmac computation and writes the final digest to output. * Allocation of output is the caller's responsibility. If you specify @@ -76,8 +76,8 @@ AWS_CAL_API int aws_hmac_finalize(struct aws_hmac *hmac, struct aws_byte_buf *ou */ AWS_CAL_API int aws_sha256_hmac_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *secret, - struct aws_byte_cursor *to_hmac, + const struct aws_byte_cursor *secret, + const struct aws_byte_cursor *to_hmac, struct aws_byte_buf *output, size_t truncate_to); /** diff --git a/source/bcrypt/bcrypt_hash.c b/source/bcrypt/bcrypt_hash.c index 3a4f8e27..20d95237 100644 --- a/source/bcrypt/bcrypt_hash.c +++ b/source/bcrypt/bcrypt_hash.c @@ -30,7 +30,7 @@ static size_t s_md5_obj_len = 0; static aws_thread_once s_md5_once = AWS_THREAD_ONCE_STATIC_INIT; static void s_destroy(struct aws_hash *hash); -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash); +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash); static int s_finalize(struct aws_hash *hash, struct aws_byte_buf *output); static struct aws_hash_vtable s_sha256_vtable = { @@ -136,7 +136,7 @@ static void s_destroy(struct aws_hash *hash) { aws_mem_release(hash->allocator, ctx); } -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash) { +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash) { if (!hash->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/bcrypt/bcrypt_hmac.c b/source/bcrypt/bcrypt_hmac.c index dd4d9ac7..a66e1065 100644 --- a/source/bcrypt/bcrypt_hmac.c +++ b/source/bcrypt/bcrypt_hmac.c @@ -27,7 +27,7 @@ static size_t s_sha256_hmac_obj_len = 0; static aws_thread_once s_sha256_hmac_once = AWS_THREAD_ONCE_STATIC_INIT; static void s_destroy(struct aws_hmac *hash); -static int s_update(struct aws_hmac *hash, struct aws_byte_cursor *to_hash); +static int s_update(struct aws_hmac *hash, const struct aws_byte_cursor *to_hash); static int s_finalize(struct aws_hmac *hash, struct aws_byte_buf *output); static struct aws_hmac_vtable s_sha256_hmac_vtable = { @@ -59,7 +59,7 @@ static void s_load_alg_handle(void) { 0); } -struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret) { +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); struct bcrypt_hmac_handle *bcrypt_hmac; @@ -101,7 +101,7 @@ static void s_destroy(struct aws_hmac *hmac) { aws_mem_release(hmac->allocator, ctx); } -static int s_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hash) { +static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hash) { if (!hmac->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/commoncrypto/commoncrypto_hmac.c b/source/commoncrypto/commoncrypto_hmac.c index eaaf52eb..2da3a941 100644 --- a/source/commoncrypto/commoncrypto_hmac.c +++ b/source/commoncrypto/commoncrypto_hmac.c @@ -17,7 +17,7 @@ #include static void s_destroy(struct aws_hmac *hmac); -static int s_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac); +static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac); static int s_finalize(struct aws_hmac *hmac, struct aws_byte_buf *output); static struct aws_hmac_vtable s_sha256_hmac_vtable = { @@ -33,7 +33,7 @@ struct cc_hmac { CCHmacContext cc_hmac_ctx; }; -struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret) { +struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) { assert(secret->ptr); struct cc_hmac *cc_hmac = aws_mem_acquire(allocator, sizeof(struct cc_hmac)); @@ -58,7 +58,7 @@ static void s_destroy(struct aws_hmac *hmac) { aws_mem_release(hmac->allocator, ctx); } -static int s_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac) { +static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac) { if (!hmac->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/commoncrypto/commoncrypto_md5.c b/source/commoncrypto/commoncrypto_md5.c index 75265042..56d33834 100644 --- a/source/commoncrypto/commoncrypto_md5.c +++ b/source/commoncrypto/commoncrypto_md5.c @@ -17,7 +17,7 @@ #include static void s_destroy(struct aws_hash *hash); -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash); +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash); static int s_finalize(struct aws_hash *hash, struct aws_byte_buf *output); static struct aws_hash_vtable s_vtable = { @@ -54,7 +54,7 @@ static void s_destroy(struct aws_hash *hash) { aws_mem_release(hash->allocator, ctx); } -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash) { +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash) { if (!hash->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/commoncrypto/commoncrypto_sha256.c b/source/commoncrypto/commoncrypto_sha256.c index 1c6269fc..fcbece14 100644 --- a/source/commoncrypto/commoncrypto_sha256.c +++ b/source/commoncrypto/commoncrypto_sha256.c @@ -17,7 +17,7 @@ #include static void s_destroy(struct aws_hash *hash); -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash); +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash); static int s_finalize(struct aws_hash *hash, struct aws_byte_buf *output); static struct aws_hash_vtable s_vtable = { @@ -55,7 +55,7 @@ static void s_destroy(struct aws_hash *hash) { aws_mem_release(hash->allocator, ctx); } -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash) { +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash) { if (!hash->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/hash.c b/source/hash.c index 0d78d9e2..2f817306 100644 --- a/source/hash.c +++ b/source/hash.c @@ -50,7 +50,7 @@ void aws_hash_destroy(struct aws_hash *hash) { hash->vtable->destroy(hash); } -int aws_hash_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash) { +int aws_hash_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash) { return hash->vtable->update(hash, to_hash); } @@ -82,7 +82,7 @@ int aws_hash_finalize(struct aws_hash *hash, struct aws_byte_buf *output, size_t static inline int compute_hash( struct aws_hash *hash, - struct aws_byte_cursor *input, + const struct aws_byte_cursor *input, struct aws_byte_buf *output, size_t truncate_to) { if (!hash) { @@ -105,7 +105,7 @@ static inline int compute_hash( int aws_md5_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *input, + const struct aws_byte_cursor *input, struct aws_byte_buf *output, size_t truncate_to) { return compute_hash(aws_md5_new(allocator), input, output, truncate_to); @@ -113,7 +113,7 @@ int aws_md5_compute( int aws_sha256_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *input, + const struct aws_byte_cursor *input, struct aws_byte_buf *output, size_t truncate_to) { return compute_hash(aws_sha256_new(allocator), input, output, truncate_to); diff --git a/source/hmac.c b/source/hmac.c index 42aa2697..cff2a26a 100644 --- a/source/hmac.c +++ b/source/hmac.c @@ -15,10 +15,10 @@ #include #ifndef AWS_BYO_CRYPTO -extern struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret); +extern struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret); static aws_hmac_new_fn *s_sha256_hmac_new_fn = aws_sha256_hmac_default_new; #else -static struct aws_hmac *aws_hmac_new_abort(struct aws_allocator *allocator, struct aws_byte_cursor *secret) { +static struct aws_hmac *aws_hmac_new_abort(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) { (void)allocator; (void)secret; abort(); @@ -27,7 +27,7 @@ static struct aws_hmac *aws_hmac_new_abort(struct aws_allocator *allocator, stru static aws_hmac_new_fn *s_sha256_hmac_new_fn = aws_hmac_new_abort; #endif -struct aws_hmac *aws_sha256_hmac_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret) { +struct aws_hmac *aws_sha256_hmac_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) { return s_sha256_hmac_new_fn(allocator, secret); } @@ -39,7 +39,7 @@ void aws_hmac_destroy(struct aws_hmac *hmac) { hmac->vtable->destroy(hmac); } -int aws_hmac_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac) { +int aws_hmac_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac) { return hmac->vtable->update(hmac, to_hmac); } @@ -70,8 +70,8 @@ int aws_hmac_finalize(struct aws_hmac *hmac, struct aws_byte_buf *output, size_t int aws_sha256_hmac_compute( struct aws_allocator *allocator, - struct aws_byte_cursor *secret, - struct aws_byte_cursor *to_hmac, + const struct aws_byte_cursor *secret, + const struct aws_byte_cursor *to_hmac, struct aws_byte_buf *output, size_t truncate_to) { struct aws_hmac *hmac = aws_sha256_hmac_new(allocator, secret); diff --git a/source/opensslcrypto/opensslcrypto_hash.c b/source/opensslcrypto/opensslcrypto_hash.c index e9887612..8f3d53b3 100644 --- a/source/opensslcrypto/opensslcrypto_hash.c +++ b/source/opensslcrypto/opensslcrypto_hash.c @@ -18,7 +18,7 @@ #include static void s_destroy(struct aws_hash *hash); -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash); +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash); static int s_finalize(struct aws_hash *hash, struct aws_byte_buf *output); static struct aws_hash_vtable s_md5_vtable = { @@ -103,7 +103,7 @@ static void s_destroy(struct aws_hash *hash) { aws_mem_release(hash->allocator, hash); } -static int s_update(struct aws_hash *hash, struct aws_byte_cursor *to_hash) { +static int s_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash) { if (!hash->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } diff --git a/source/opensslcrypto/opensslcrypto_hmac.c b/source/opensslcrypto/opensslcrypto_hmac.c index 68fd6387..990a0a7c 100644 --- a/source/opensslcrypto/opensslcrypto_hmac.c +++ b/source/opensslcrypto/opensslcrypto_hmac.c @@ -30,7 +30,7 @@ #define OPENSSL_VERSION_LESS_1_1 (OPENSSL_VERSION_NUMBER < 0x10100003L) static void s_destroy(struct aws_hmac *hmac); -static int s_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac); +static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac); static int s_finalize(struct aws_hmac *hmac, struct aws_byte_buf *output); static struct aws_hmac_vtable s_sha256_hmac_vtable = { @@ -41,7 +41,7 @@ static struct aws_hmac_vtable s_sha256_hmac_vtable = { .provider = "OpenSSL Compatible libcrypto", }; -struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, struct aws_byte_cursor *secret) { +struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) { assert(secret->ptr); struct aws_hmac *hmac = aws_mem_acquire(allocator, sizeof(struct aws_hmac)); @@ -100,7 +100,7 @@ static void s_destroy(struct aws_hmac *hmac) { aws_mem_release(hmac->allocator, hmac); } -static int s_update(struct aws_hmac *hmac, struct aws_byte_cursor *to_hmac) { +static int s_update(struct aws_hmac *hmac, const struct aws_byte_cursor *to_hmac) { if (!hmac->good) { return aws_raise_error(AWS_ERROR_INVALID_STATE); } From 9c6f7278573fd55cab6c8b4b2357b317f3ad43c0 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Wed, 13 Feb 2019 16:54:37 -0800 Subject: [PATCH 2/2] Clang-format updates. --- source/hmac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/hmac.c b/source/hmac.c index cff2a26a..e30a20f4 100644 --- a/source/hmac.c +++ b/source/hmac.c @@ -15,7 +15,9 @@ #include #ifndef AWS_BYO_CRYPTO -extern struct aws_hmac *aws_sha256_hmac_default_new(struct aws_allocator *allocator, const struct aws_byte_cursor *secret); +extern struct aws_hmac *aws_sha256_hmac_default_new( + struct aws_allocator *allocator, + const struct aws_byte_cursor *secret); static aws_hmac_new_fn *s_sha256_hmac_new_fn = aws_sha256_hmac_default_new; #else static struct aws_hmac *aws_hmac_new_abort(struct aws_allocator *allocator, const struct aws_byte_cursor *secret) {