From c498f013eeb5a5decd93e5830fa61929e4c650cc Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Sat, 7 Dec 2013 14:16:00 +0400 Subject: [PATCH 1/1] consistent use of 'const' --- crypto.c | 2 +- crypto_if.h | 18 ++++++++++-------- gnu_crypto.c | 16 +++++++++------- ossl_crypto.c | 16 +++++++++------- tom_crypto.c | 18 ++++++++++-------- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/crypto.c b/crypto.c index 88670ee..cb996e8 100644 --- a/crypto.c +++ b/crypto.c @@ -42,7 +42,7 @@ static struct crypto_interface *ifs[] = { #ifdef HAVE_GCRYPT &gnu_crypto_if, #endif - (void*)0, + (struct crypto_interface *)0, }; #define MAX_IF (sizeof(ifs)/sizeof(struct crypto_interface *)-2) diff --git a/crypto_if.h b/crypto_if.h index f569596..e2c7579 100644 --- a/crypto_if.h +++ b/crypto_if.h @@ -26,14 +26,16 @@ freely, subject to the following restrictions: struct crypto_interface { const char *(*init)(void); - unsigned long (*encrypt)(void *key, int keylen, void *iv, - void *pt, void *ct, int tlen); - unsigned long (*decrypt)(void *key, int keylen, void *iv, - void *ct, void *pt, int tlen); - unsigned long (*hash)(void *pt, int tlen, void *tag, int *taglen); - unsigned long (*hmac)(void *key, int keylen, - void *pt, int tlen, void *tag, int *taglen); - const char *(*errstr)(unsigned long err); + unsigned long (*encrypt)(const void *key, const int keylen, void *iv, + const void *pt, void *ct, const int tlen); + unsigned long (*decrypt)(const void *key, const int keylen, void *iv, + const void *ct, void *pt, const int tlen); + unsigned long (*hash)(const void *pt, const int tlen, + void *tag, int *taglen); + unsigned long (*hmac)(const void *key, const int keylen, + const void *pt, const int tlen, + void *tag, int *taglen); + const char *(*errstr)(const unsigned long err); }; #endif diff --git a/gnu_crypto.c b/gnu_crypto.c index 1b6092b..5c8621d 100644 --- a/gnu_crypto.c +++ b/gnu_crypto.c @@ -36,8 +36,8 @@ static const char *gnu_init(void) return "gcrypt"; } -static unsigned long gnu_encrypt(void *key, int keylen, void *iv, - void *pt, void *ct, int tlen) +static unsigned long gnu_encrypt(const void *key, const int keylen, void *iv, + const void *pt, void *ct, const int tlen) { gcry_error_t err; gcry_cipher_hd_t hd; @@ -56,8 +56,8 @@ static unsigned long gnu_encrypt(void *key, int keylen, void *iv, return 0UL; } -static unsigned long gnu_decrypt(void *key, int keylen, void *iv, - void *ct, void *pt, int tlen) +static unsigned long gnu_decrypt(const void *key, const int keylen, void *iv, + const void *ct, void *pt, const int tlen) { gcry_error_t err; gcry_cipher_hd_t hd; @@ -76,7 +76,8 @@ static unsigned long gnu_decrypt(void *key, int keylen, void *iv, return 0UL; } -static unsigned long gnu_hash(void *pt, int tlen, void *tag, int *taglen) +static unsigned long gnu_hash(const void *pt, const int tlen, + void *tag, int *taglen) { gcry_error_t err; gcry_md_hd_t hd; @@ -94,7 +95,8 @@ static unsigned long gnu_hash(void *pt, int tlen, void *tag, int *taglen) return 0UL; } -static unsigned long gnu_hmac(void *key, int keylen, void *pt, int tlen, +static unsigned long gnu_hmac(const void *key, const int keylen, + const void *pt, const int tlen, void *tag, int *taglen) { gcry_error_t err; @@ -116,7 +118,7 @@ static unsigned long gnu_hmac(void *key, int keylen, void *pt, int tlen, return 0UL; } -static const char *gnu_errstr(unsigned long err) +static const char *gnu_errstr(const unsigned long err) { return gcry_strerror((gcry_error_t)err); } diff --git a/ossl_crypto.c b/ossl_crypto.c index 837fac0..e0e10bc 100644 --- a/ossl_crypto.c +++ b/ossl_crypto.c @@ -37,8 +37,8 @@ static const char *ossl_init(void) return "openssl"; } -static unsigned long ossl_encrypt(void *key, int keylen, void *iv, - void *pt, void *ct, int tlen) +static unsigned long ossl_encrypt(const void *key, const int keylen, void *iv, + const void *pt, void *ct, const int tlen) { AES_KEY akey; @@ -48,8 +48,8 @@ static unsigned long ossl_encrypt(void *key, int keylen, void *iv, return 0UL; } -static unsigned long ossl_decrypt(void *key, int keylen, void *iv, - void *ct, void *pt, int tlen) +static unsigned long ossl_decrypt(const void *key, const int keylen, void *iv, + const void *ct, void *pt, const int tlen) { AES_KEY akey; @@ -59,7 +59,8 @@ static unsigned long ossl_decrypt(void *key, int keylen, void *iv, return 0UL; } -static unsigned long ossl_hash(void *pt, int tlen, void *tag, int *taglen) +static unsigned long ossl_hash(const void *pt, const int tlen, + void *tag, int *taglen) { SHA_CTX sctx; @@ -70,7 +71,8 @@ static unsigned long ossl_hash(void *pt, int tlen, void *tag, int *taglen) return 0UL; } -static unsigned long ossl_hmac(void *key, int keylen, void *pt, int tlen, +static unsigned long ossl_hmac(const void *key, int const keylen, + const void *pt, const int tlen, void *tag, int *taglen) { #if 1 @@ -91,7 +93,7 @@ static unsigned long ossl_hmac(void *key, int keylen, void *pt, int tlen, return 0UL; } -static const char *ossl_errstr(unsigned long err) +static const char *ossl_errstr(const unsigned long err) { return ERR_error_string(err, NULL); } diff --git a/tom_crypto.c b/tom_crypto.c index 7d49f5d..b5bed3e 100644 --- a/tom_crypto.c +++ b/tom_crypto.c @@ -34,8 +34,8 @@ static const char *tom_init(void) return "tomcrypt"; } -static unsigned long tom_encrypt(void *key, int keylen, void *iv, - void *pt, void *ct, int tlen) +static unsigned long tom_encrypt(const void *key, const int keylen, void *iv, + const void *pt, void *ct, const int tlen) { symmetric_CBC cbc; int index, err; @@ -49,8 +49,8 @@ static unsigned long tom_encrypt(void *key, int keylen, void *iv, return err; } -static unsigned long tom_decrypt(void *key, int keylen, void *iv, - void *ct, void *pt, int tlen) +static unsigned long tom_decrypt(const void *key, const int keylen, void *iv, + const void *ct, void *pt, const int tlen) { symmetric_CBC cbc; int index, err; @@ -64,7 +64,8 @@ static unsigned long tom_decrypt(void *key, int keylen, void *iv, return err; } -static unsigned long tom_hash(void *pt, int tlen, void *tag, int *taglen) +static unsigned long tom_hash(const void *pt, const int tlen, + void *tag, int *taglen) { int index, rc; unsigned long ltaglen = *taglen; @@ -76,8 +77,9 @@ static unsigned long tom_hash(void *pt, int tlen, void *tag, int *taglen) return rc; } -static unsigned long tom_hmac(void *key, int keylen, - void *pt, int tlen, void *tag, int *taglen) +static unsigned long tom_hmac(const void *key, const int keylen, + const void *pt, const int tlen, + void *tag, int *taglen) { int index, rc; unsigned long ltaglen = *taglen; @@ -89,7 +91,7 @@ static unsigned long tom_hmac(void *key, int keylen, return rc; } -static const char *tom_errstr(unsigned long err) +static const char *tom_errstr(const unsigned long err) { return error_to_string((int)err); } -- 2.39.2