From 9b6bf32f887899e88eda88dfb4727daaba4fd370 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 2 Oct 2019 15:52:16 +0200 Subject: [PATCH] use `unsigned long` for the length of a string --- doc/crypt.tex | 8 +++++--- src/headers/tomcrypt_private.h | 2 +- src/misc/ssh/ssh_decode_sequence_multi.c | 6 +++--- src/misc/ssh/ssh_encode_sequence_multi.c | 6 +++--- src/pk/ecc/ecc_recover_key.c | 4 ++-- src/pk/ecc/ecc_sign_hash.c | 2 +- src/pk/ecc/ecc_ssh_ecdsa_encode_name.c | 2 +- src/pk/ecc/ecc_verify_hash.c | 4 ++-- tests/ssh_test.c | 4 ++-- 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/doc/crypt.tex b/doc/crypt.tex index 6299955c..d57bceec 100644 --- a/doc/crypt.tex +++ b/doc/crypt.tex @@ -7247,7 +7247,7 @@ The following enum is used to indicate a specific SSH data type \begin{center} \begin{small} \begin{tabular}{|l|l|l|} -\hline \textbf{Definition} & \textbf{arg data Type} & \textbf{SSH Type} \\ +\hline \textbf{Definition} & \textbf{arg data Type} & \textbf{SSH Type} \\ \hline LTC\_SSHDATA\_EOL & - & End of SSH data sequence. \\ \hline LTC\_SSHDATA\_BYTE & \texttt{unsigned char} & \texttt{byte} type \\ \hline LTC\_SSHDATA\_BOOLEAN & \texttt{unsigned char} & \texttt{boolean} type \\ @@ -7284,7 +7284,8 @@ on function invocation to the length of the destination buffer and after returning it will be filled with the number of octets written to the buffer. The encoding function \texttt{ssh\_encode\_sequence\_multi()} expects its items to be a pair of \texttt{(type, data)}, -except for the \texttt{string} resp. \texttt{name-list} type, which expects the triple \texttt{(type, data, size)}. +except for the \texttt{string} resp. \texttt{name-list} type, which expects the triple \texttt{(type, data, size)} +with \texttt{size} being of type \texttt{unsigned long}. \begin{verbatim} @@ -7296,7 +7297,8 @@ on function invocation to the length of the sequence and after returning it will be filled with the decoded number of octets. The decoding function \texttt{ssh\_decode\_sequence\_multi()} expects its items to be a pair of \texttt{(type, data*)}, -except for the \texttt{string} resp. \texttt{name-list} type, which expects the triple \texttt{(type, data, size*)}. +except for the \texttt{string} resp. \texttt{name-list} type, which expects the triple \texttt{(type, data, size*)} +with \texttt{size*} being of type \texttt{unsigned long*}. \chapter{Miscellaneous} \mysection{Base64 Encoding and Decoding} diff --git a/src/headers/tomcrypt_private.h b/src/headers/tomcrypt_private.h index 90b513cd..d080d6c2 100644 --- a/src/headers/tomcrypt_private.h +++ b/src/headers/tomcrypt_private.h @@ -240,7 +240,7 @@ int ecc_set_curve_by_size(int size, ecc_key *key); int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key); #ifdef LTC_SSH -int ecc_ssh_ecdsa_encode_name(char *buffer, ulong32 *buflen, const ecc_key *key); +int ecc_ssh_ecdsa_encode_name(char *buffer, unsigned long *buflen, const ecc_key *key); #endif /* low level functions */ diff --git a/src/misc/ssh/ssh_decode_sequence_multi.c b/src/misc/ssh/ssh_decode_sequence_multi.c index 4b19ec7f..a3be11ef 100644 --- a/src/misc/ssh/ssh_decode_sequence_multi.c +++ b/src/misc/ssh/ssh_decode_sequence_multi.c @@ -20,7 +20,7 @@ Decode a SSH sequence using a VA list @param in The input buffer @param inlen [in/out] The length of the input buffer and on output the amount of decoded data - @remark <...> is of the form (int, ) except for string&name-list (int, void*, ulong32*) + @remark <...> is of the form (int, ) except for string&name-list (int, void*, unsigned long*) @return CRYPT_OK on success */ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long *inlen, ...) @@ -33,7 +33,7 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long *inlen, ... char *sdata; ulong32 *u32data; ulong64 *u64data; - ulong32 *bufsize; + unsigned long *bufsize; ulong32 size; unsigned long remaining; @@ -124,7 +124,7 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long *inlen, ... case LTC_SSHDATA_STRING: case LTC_SSHDATA_NAMELIST: sdata = vdata; - bufsize = va_arg(args, ulong32*); + bufsize = va_arg(args, unsigned long*); if (bufsize == NULL) { err = CRYPT_INVALID_ARG; goto error; diff --git a/src/misc/ssh/ssh_encode_sequence_multi.c b/src/misc/ssh/ssh_encode_sequence_multi.c index e461b0db..ed81e9f0 100644 --- a/src/misc/ssh/ssh_encode_sequence_multi.c +++ b/src/misc/ssh/ssh_encode_sequence_multi.c @@ -20,7 +20,7 @@ Encode a SSH sequence using a VA list @param out [out] Destination for data @param outlen [in/out] Length of buffer and resulting length of output - @remark <...> is of the form (int, ) except for string&name-list (int, void*, ulong32) + @remark <...> is of the form (int, ) except for string&name-list (int, void*, unsigned long) @return CRYPT_OK on success */ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...) @@ -59,7 +59,7 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...) case LTC_SSHDATA_STRING: case LTC_SSHDATA_NAMELIST: LTC_UNUSED_PARAM( va_arg(args, char*) ); - size += va_arg(args, ulong32); + size += va_arg(args, unsigned long); size += 4; break; case LTC_SSHDATA_MPINT: @@ -118,7 +118,7 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...) case LTC_SSHDATA_STRING: case LTC_SSHDATA_NAMELIST: sdata = va_arg(args, char*); - size = va_arg(args, ulong32); + size = va_arg(args, unsigned long); STORE32H(size, out); out += 4; XMEMCPY(out, sdata, size); diff --git a/src/pk/ecc/ecc_recover_key.c b/src/pk/ecc/ecc_recover_key.c index e0233160..9b7da110 100644 --- a/src/pk/ecc/ecc_recover_key.c +++ b/src/pk/ecc/ecc_recover_key.c @@ -114,8 +114,8 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen, #ifdef LTC_SSH else if (sigformat == LTC_ECCSIG_RFC5656) { char name[64], name2[64]; - ulong32 namelen = sizeof(name); - ulong32 name2len = sizeof(name2); + unsigned long namelen = sizeof(name); + unsigned long name2len = sizeof(name2); /* Decode as SSH data sequence, per RFC4251 */ if ((err = ssh_decode_sequence_multi(sig, &siglen, diff --git a/src/pk/ecc/ecc_sign_hash.c b/src/pk/ecc/ecc_sign_hash.c index 2b8fd709..bb7a2e96 100644 --- a/src/pk/ecc/ecc_sign_hash.c +++ b/src/pk/ecc/ecc_sign_hash.c @@ -159,7 +159,7 @@ int ecc_sign_hash_ex(const unsigned char *in, unsigned long inlen, else if (sigformat == LTC_ECCSIG_RFC5656) { /* Get identifier string */ char name[64]; - ulong32 namelen = sizeof(name); + unsigned long namelen = sizeof(name); if ((err = ecc_ssh_ecdsa_encode_name(name, &namelen, key)) != CRYPT_OK) { goto errnokey; } /* Store as SSH data sequence, per RFC4251 */ diff --git a/src/pk/ecc/ecc_ssh_ecdsa_encode_name.c b/src/pk/ecc/ecc_ssh_ecdsa_encode_name.c index dc1da34d..d29346bb 100644 --- a/src/pk/ecc/ecc_ssh_ecdsa_encode_name.c +++ b/src/pk/ecc/ecc_ssh_ecdsa_encode_name.c @@ -21,7 +21,7 @@ @param key A public or private ECC key @return CRYPT_OK if successful */ -int ecc_ssh_ecdsa_encode_name(char *buffer, ulong32 *buflen, const ecc_key *key) +int ecc_ssh_ecdsa_encode_name(char *buffer, unsigned long *buflen, const ecc_key *key) { char oidstr[64]; unsigned long oidlen = sizeof(oidstr); diff --git a/src/pk/ecc/ecc_verify_hash.c b/src/pk/ecc/ecc_verify_hash.c index 75339f2d..20a89c25 100644 --- a/src/pk/ecc/ecc_verify_hash.c +++ b/src/pk/ecc/ecc_verify_hash.c @@ -100,8 +100,8 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen, #ifdef LTC_SSH else if (sigformat == LTC_ECCSIG_RFC5656) { char name[64], name2[64]; - ulong32 namelen = sizeof(name); - ulong32 name2len = sizeof(name2); + unsigned long namelen = sizeof(name); + unsigned long name2len = sizeof(name2); /* Decode as SSH data sequence, per RFC4251 */ if ((err = ssh_decode_sequence_multi(sig, &siglen, diff --git a/tests/ssh_test.c b/tests/ssh_test.c index ff9b01d6..eee97793 100644 --- a/tests/ssh_test.c +++ b/tests/ssh_test.c @@ -61,7 +61,7 @@ static int _ssh_encoding_test(void) { unsigned char buffer[BUFSIZE]; unsigned long buflen; - ulong32 len; + unsigned long len; void *v, *zero; int err; @@ -200,7 +200,7 @@ static int _ssh_decoding_test(void) { char strbuf[BUFSIZE]; void *u, *v; - ulong32 size; + unsigned long size; ulong32 tmp32; ulong64 tmp64; unsigned char tmp8;