Skip to content

Commit

Permalink
use unsigned long for the length of a string
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaeckel committed Oct 13, 2019
1 parent 27ec31d commit 9b6bf32
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
8 changes: 5 additions & 3 deletions doc/crypt.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7247,7 +7247,7 @@ \subsection{Data types}
\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 \\
Expand Down Expand Up @@ -7284,7 +7284,8 @@ \subsection{De- and Encoding with Multiple Argument Lists}
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}
Expand All @@ -7296,7 +7297,8 @@ \subsection{De- and Encoding with Multiple Argument Lists}
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}
Expand Down
2 changes: 1 addition & 1 deletion src/headers/tomcrypt_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/misc/ssh/ssh_decode_sequence_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type, data*> (int, <unsigned char*,ulong32*,ulong64*>) except for string&name-list <type, data, size*> (int, void*, ulong32*)
@remark <...> is of the form <type, data*> (int, <unsigned char*,ulong32*,ulong64*>) except for string&name-list <type, data, size*> (int, void*, unsigned long*)
@return CRYPT_OK on success
*/
int ssh_decode_sequence_multi(const unsigned char *in, unsigned long *inlen, ...)
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/misc/ssh/ssh_encode_sequence_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type, data> (int, <int,ulong32,ulong64>) except for string&name-list <type, data, size> (int, void*, ulong32)
@remark <...> is of the form <type, data> (int, <int,ulong32,ulong64>) except for string&name-list <type, data, size> (int, void*, unsigned long)
@return CRYPT_OK on success
*/
int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/pk/ecc/ecc_recover_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_sign_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/pk/ecc/ecc_ssh_ecdsa_encode_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/pk/ecc/ecc_verify_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/ssh_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9b6bf32

Please sign in to comment.