From 5057af3ef141e88d6c6ecf35b56a602d4737851e Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Fri, 15 Sep 2017 09:47:29 +0200 Subject: [PATCH 1/2] fix char* vs. const char* --- src/headers/tomcrypt_argchk.h | 2 +- src/headers/tomcrypt_cipher.h | 2 +- src/headers/tomcrypt_hash.h | 2 +- src/headers/tomcrypt_math.h | 2 +- src/headers/tomcrypt_pk.h | 14 +++++++------- src/headers/tomcrypt_prng.h | 2 +- src/misc/crypt/crypt_argchk.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/headers/tomcrypt_argchk.h b/src/headers/tomcrypt_argchk.h index 17390e6..be9ef0f 100644 --- a/src/headers/tomcrypt_argchk.h +++ b/src/headers/tomcrypt_argchk.h @@ -20,7 +20,7 @@ #define NORETURN #endif -void crypt_argchk(char *v, char *s, int d) NORETURN; +void crypt_argchk(const char *v, const char *s, int d) NORETURN; #define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0) #define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0) diff --git a/src/headers/tomcrypt_cipher.h b/src/headers/tomcrypt_cipher.h index 6839e2d..c4361cd 100644 --- a/src/headers/tomcrypt_cipher.h +++ b/src/headers/tomcrypt_cipher.h @@ -349,7 +349,7 @@ typedef struct { /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */ extern struct ltc_cipher_descriptor { /** name of cipher */ - char *name; + const char *name; /** internal ID */ unsigned char ID; /** min keysize (octets) */ diff --git a/src/headers/tomcrypt_hash.h b/src/headers/tomcrypt_hash.h index cbd9d7c..ef494f7 100644 --- a/src/headers/tomcrypt_hash.h +++ b/src/headers/tomcrypt_hash.h @@ -204,7 +204,7 @@ typedef union Hash_state { /** hash descriptor */ extern struct ltc_hash_descriptor { /** name of hash */ - char *name; + const char *name; /** internal ID */ unsigned char ID; /** Size of digest in octets */ diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index b655346..45c3a13 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -35,7 +35,7 @@ int radix_to_bin(const void *in, int radix, void *out, unsigned long *len); /** math descriptor */ typedef struct { /** Name of the math provider */ - char *name; + const char *name; /** Bits per digit, amount of bits must fit in an unsigned long */ int bits_per_digit; diff --git a/src/headers/tomcrypt_pk.h b/src/headers/tomcrypt_pk.h index 837baa7..802c244 100644 --- a/src/headers/tomcrypt_pk.h +++ b/src/headers/tomcrypt_pk.h @@ -230,7 +230,7 @@ int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key); #ifdef LTC_SOURCE typedef struct { int size; - char *name, *base, *prime; + const char *name, *base, *prime; } ltc_dh_set_type; extern const ltc_dh_set_type ltc_dh_sets[]; @@ -257,22 +257,22 @@ typedef struct { int size; /** name of curve */ - char *name; + const char *name; /** The prime that defines the field the curve is in (encoded in hex) */ - char *prime; + const char *prime; /** The fields B param (hex) */ - char *B; + const char *B; /** The order of the curve (hex) */ - char *order; + const char *order; /** The x co-ordinate of the base point on the curve (hex) */ - char *Gx; + const char *Gx; /** The y co-ordinate of the base point on the curve (hex) */ - char *Gy; + const char *Gy; } ltc_ecc_set_type; /** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */ diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h index 1163367..c516b8c 100644 --- a/src/headers/tomcrypt_prng.h +++ b/src/headers/tomcrypt_prng.h @@ -81,7 +81,7 @@ typedef struct { /** PRNG descriptor */ extern struct ltc_prng_descriptor { /** Name of the PRNG */ - char *name; + const char *name; /** size in bytes of exported state */ int export_size; /** Start a PRNG state diff --git a/src/misc/crypt/crypt_argchk.c b/src/misc/crypt/crypt_argchk.c index 3b66067..da7306b 100644 --- a/src/misc/crypt/crypt_argchk.c +++ b/src/misc/crypt/crypt_argchk.c @@ -14,7 +14,7 @@ */ #if (ARGTYPE == 0) -void crypt_argchk(char *v, char *s, int d) +void crypt_argchk(const char *v, const char *s, int d) { fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n", v, d, s); From b2813480bf879dd03dbe26bc3273733842a2639b Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Fri, 15 Sep 2017 10:01:03 +0200 Subject: [PATCH 2/2] LTC_CFLAGS += -Wwrite-strings --- makefile_include.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/makefile_include.mk b/makefile_include.mk index f422135..975b49e 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -70,6 +70,7 @@ LTC_CFLAGS += -Wextra LTC_CFLAGS += -Wsystem-headers -Wbad-function-cast -Wcast-align LTC_CFLAGS += -Wstrict-prototypes -Wpointer-arith LTC_CFLAGS += -Wdeclaration-after-statement +LTC_CFLAGS += -Wwrite-strings endif LTC_CFLAGS += -Wno-type-limits