From 51e9d3c00a3471f284e89ec1f59f38ca25f10c5f Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 12 Apr 2005 20:04:56 +0000 Subject: [PATCH] Unify GET_32BIT()/PUT_32BIT() et al from numerous source files into misc.h. I've done a bit of testing (not exhaustive), and I don't _think_ I've broken anything... git-svn-id: svn://svn.tartarus.org/sgt/putty@5632 cda61777-01e9-0310-a592-d414129be87e --- import.c | 12 ------------ misc.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ portfwd.c | 40 ---------------------------------------- sftp.c | 12 ------------ ssh.c | 12 ------------ sshaes.c | 12 ------------ sshblowf.c | 24 ------------------------ sshcrcda.c | 6 ------ sshdes.c | 12 ------------ sshdss.c | 12 ------------ sshpubk.c | 12 ------------ sshrsa.c | 12 ------------ unix/uxagentc.c | 6 ------ unix/uxnet.c | 10 ---------- windows/winpgnt.c | 12 ------------ windows/winpgntc.c | 6 ------ x11fwd.c | 40 ---------------------------------------- 17 files changed, 44 insertions(+), 240 deletions(-) diff --git a/import.c b/import.c index cf91a4dc..25012d28 100644 --- a/import.c +++ b/import.c @@ -12,18 +12,6 @@ #include "ssh.h" #include "misc.h" -#define PUT_32BIT(cp, value) do { \ - (cp)[3] = (unsigned char)(value); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[0] = (unsigned char)((value) >> 24); } while (0) - -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - int openssh_encrypted(const Filename *filename); struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase, const char **errmsg_p); diff --git a/misc.h b/misc.h index ae883e16..73467793 100644 --- a/misc.h +++ b/misc.h @@ -80,4 +80,48 @@ void debug_memdump(void *buf, int len, int L); #define max(x,y) ( (x) > (y) ? (x) : (y) ) #endif +#define GET_32BIT_LSB_FIRST(cp) \ + (((unsigned long)(unsigned char)(cp)[0]) | \ + ((unsigned long)(unsigned char)(cp)[1] << 8) | \ + ((unsigned long)(unsigned char)(cp)[2] << 16) | \ + ((unsigned long)(unsigned char)(cp)[3] << 24)) + +#define PUT_32BIT_LSB_FIRST(cp, value) ( \ + (cp)[0] = (unsigned char)(value), \ + (cp)[1] = (unsigned char)((value) >> 8), \ + (cp)[2] = (unsigned char)((value) >> 16), \ + (cp)[3] = (unsigned char)((value) >> 24) ) + +#define GET_16BIT_LSB_FIRST(cp) \ + (((unsigned long)(unsigned char)(cp)[0]) | \ + ((unsigned long)(unsigned char)(cp)[1] << 8)) + +#define PUT_16BIT_LSB_FIRST(cp, value) ( \ + (cp)[0] = (unsigned char)(value), \ + (cp)[1] = (unsigned char)((value) >> 8) ) + +#define GET_32BIT_MSB_FIRST(cp) \ + (((unsigned long)(unsigned char)(cp)[0] << 24) | \ + ((unsigned long)(unsigned char)(cp)[1] << 16) | \ + ((unsigned long)(unsigned char)(cp)[2] << 8) | \ + ((unsigned long)(unsigned char)(cp)[3])) + +#define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp) + +#define PUT_32BIT_MSB_FIRST(cp, value) ( \ + (cp)[0] = (unsigned char)((value) >> 24), \ + (cp)[1] = (unsigned char)((value) >> 16), \ + (cp)[2] = (unsigned char)((value) >> 8), \ + (cp)[3] = (unsigned char)(value) ) + +#define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value) + +#define GET_16BIT_MSB_FIRST(cp) \ + (((unsigned long)(unsigned char)(cp)[0] << 8) | \ + ((unsigned long)(unsigned char)(cp)[1])) + +#define PUT_16BIT_MSB_FIRST(cp, value) ( \ + (cp)[0] = (unsigned char)((value) >> 8), \ + (cp)[1] = (unsigned char)(value) ) + #endif diff --git a/portfwd.c b/portfwd.c index 3b772599..54a68769 100644 --- a/portfwd.c +++ b/portfwd.c @@ -11,46 +11,6 @@ #define TRUE 1 #endif -#define GET_32BIT_LSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0]) | \ - ((unsigned long)(unsigned char)(cp)[1] << 8) | \ - ((unsigned long)(unsigned char)(cp)[2] << 16) | \ - ((unsigned long)(unsigned char)(cp)[3] << 24)) - -#define PUT_32BIT_LSB_FIRST(cp, value) ( \ - (cp)[0] = (value), \ - (cp)[1] = (value) >> 8, \ - (cp)[2] = (value) >> 16, \ - (cp)[3] = (value) >> 24 ) - -#define GET_16BIT_LSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0]) | \ - ((unsigned long)(unsigned char)(cp)[1] << 8)) - -#define PUT_16BIT_LSB_FIRST(cp, value) ( \ - (cp)[0] = (value), \ - (cp)[1] = (value) >> 8 ) - -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (value) >> 24, \ - (cp)[1] = (value) >> 16, \ - (cp)[2] = (value) >> 8, \ - (cp)[3] = (value) ) - -#define GET_16BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 8) | \ - ((unsigned long)(unsigned char)(cp)[1])) - -#define PUT_16BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (value) >> 8, \ - (cp)[1] = (value) ) - struct PFwdPrivate { const struct plug_function_table *fn; /* the above variable absolutely *must* be the first in this structure */ diff --git a/sftp.c b/sftp.c index cee7f8ea..a30b2428 100644 --- a/sftp.c +++ b/sftp.c @@ -13,18 +13,6 @@ #include "tree234.h" #include "sftp.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - struct sftp_packet { char *data; unsigned length, maxlen; diff --git a/ssh.c b/ssh.c index b0cfa11a..b5f34a52 100644 --- a/ssh.c +++ b/ssh.c @@ -256,18 +256,6 @@ static char *ssh2_pkt_type(int pkt_ctx, int type) #undef translate #undef translatec -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - /* Enumeration values for fields in SSH-1 packets */ enum { PKT_END, PKT_INT, PKT_CHAR, PKT_DATA, PKT_STR, PKT_BIGNUM, diff --git a/sshaes.c b/sshaes.c index 828a0dec..5664f775 100644 --- a/sshaes.c +++ b/sshaes.c @@ -38,18 +38,6 @@ #define mulby2(x) ( ((x&0x7F) << 1) ^ (x & 0x80 ? 0x1B : 0) ) -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[3]) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[0] << 24)) - -#define PUT_32BIT_MSB_FIRST(cp, value) do { \ - (cp)[3] = (value); \ - (cp)[2] = (value) >> 8; \ - (cp)[1] = (value) >> 16; \ - (cp)[0] = (value) >> 24; } while (0) - typedef struct AESContext AESContext; struct AESContext { diff --git a/sshblowf.c b/sshblowf.c index 650f9b9f..eeb7c27a 100644 --- a/sshblowf.c +++ b/sshblowf.c @@ -13,30 +13,6 @@ typedef struct { word32 iv0, iv1; /* for CBC mode */ } BlowfishContext; -#define GET_32BIT_LSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0]) | \ - ((unsigned long)(unsigned char)(cp)[1] << 8) | \ - ((unsigned long)(unsigned char)(cp)[2] << 16) | \ - ((unsigned long)(unsigned char)(cp)[3] << 24)) - -#define PUT_32BIT_LSB_FIRST(cp, value) do { \ - (cp)[0] = (value); \ - (cp)[1] = (value) >> 8; \ - (cp)[2] = (value) >> 16; \ - (cp)[3] = (value) >> 24; } while (0) - -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT_MSB_FIRST(cp, value) do { \ - (cp)[0] = (value) >> 24; \ - (cp)[1] = (value) >> 16; \ - (cp)[2] = (value) >> 8; \ - (cp)[3] = (value); } while (0) - /* * The Blowfish init data: hex digits of the fractional part of pi. * (ie pi as a hex fraction is 3.243F6A8885A308D3...) diff --git a/sshcrcda.c b/sshcrcda.c index 09e5f8d0..8d77cbb6 100644 --- a/sshcrcda.c +++ b/sshcrcda.c @@ -42,12 +42,6 @@ typedef unsigned short uint16; #define HASH_MINBLOCKS (7*SSH_BLOCKSIZE) -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - /* Hash function (Input keys are cipher results) */ #define HASH(x) GET_32BIT_MSB_FIRST(x) diff --git a/sshdes.c b/sshdes.c index 14ac7f68..506e2458 100644 --- a/sshdes.c +++ b/sshdes.c @@ -600,18 +600,6 @@ static void des_decipher(word32 * output, word32 L, word32 R, output[1] = R; } -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[3]) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[0] << 24)) - -#define PUT_32BIT_MSB_FIRST(cp, value) do { \ - (cp)[3] = (value); \ - (cp)[2] = (value) >> 8; \ - (cp)[1] = (value) >> 16; \ - (cp)[0] = (value) >> 24; } while (0) - static void des_cbc_encrypt(unsigned char *dest, const unsigned char *src, unsigned int len, DESContext * sched) { diff --git a/sshdss.c b/sshdss.c index fa3ac384..41974c23 100644 --- a/sshdss.c +++ b/sshdss.c @@ -5,18 +5,6 @@ #include "ssh.h" #include "misc.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - static void sha_mpint(SHA_State * s, Bignum b) { unsigned char lenbuf[4]; diff --git a/sshpubk.c b/sshpubk.c index 57a4222e..2d5ff1d7 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -13,18 +13,6 @@ #include "ssh.h" #include "misc.h" -#define PUT_32BIT(cp, value) do { \ - (cp)[3] = (value); \ - (cp)[2] = (value) >> 8; \ - (cp)[1] = (value) >> 16; \ - (cp)[0] = (value) >> 24; } while (0) - -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - #define rsa_signature "SSH PRIVATE KEY FILE FORMAT 1.1\n" #define BASE64_TOINT(x) ( (x)-'A'<26 ? (x)-'A'+0 :\ diff --git a/sshrsa.c b/sshrsa.c index 4f95fb38..b862d3f6 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -10,18 +10,6 @@ #include "ssh.h" #include "misc.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - int makekey(unsigned char *data, int len, struct RSAKey *result, unsigned char **keystr, int order) { diff --git a/unix/uxagentc.c b/unix/uxagentc.c index b612f52f..826e4394 100644 --- a/unix/uxagentc.c +++ b/unix/uxagentc.c @@ -14,12 +14,6 @@ #include "tree234.h" #include "puttymem.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - int agent_exists(void) { if (getenv("SSH_AUTH_SOCK") != NULL) diff --git a/unix/uxnet.c b/unix/uxnet.c index 6e491f69..46959e2f 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -811,16 +811,6 @@ static void sk_tcp_close(Socket sock) sfree(s); } -#define PUT_32BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (char)((value) >> 24), \ - (cp)[1] = (char)((value) >> 16), \ - (cp)[2] = (char)((value) >> 8), \ - (cp)[3] = (char)(value) ) - -#define PUT_16BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (char)((value) >> 8), \ - (cp)[1] = (char)(value) ) - void *sk_getxdmdata(void *sock, int *lenp) { Actual_Socket s = (Actual_Socket) sock; diff --git a/windows/winpgnt.c b/windows/winpgnt.c index 07d59d60..b0cd08bb 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -156,18 +156,6 @@ struct blob { }; static int cmpkeys_ssh2_asymm(void *av, void *bv); -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - #define PASSPHRASE_MAXLEN 512 struct PassphraseProcStruct { diff --git a/windows/winpgntc.c b/windows/winpgntc.c index 3ab81e7b..2259e6a1 100644 --- a/windows/winpgntc.c +++ b/windows/winpgntc.c @@ -10,12 +10,6 @@ #define AGENT_COPYDATA_ID 0x804e50ba /* random goop */ #define AGENT_MAX_MSGLEN 8192 -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - int agent_exists(void) { HWND hwnd; diff --git a/x11fwd.c b/x11fwd.c index 760a80b1..13c6823e 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -11,46 +11,6 @@ #include "ssh.h" #include "tree234.h" -#define GET_32BIT_LSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0]) | \ - ((unsigned long)(unsigned char)(cp)[1] << 8) | \ - ((unsigned long)(unsigned char)(cp)[2] << 16) | \ - ((unsigned long)(unsigned char)(cp)[3] << 24)) - -#define PUT_32BIT_LSB_FIRST(cp, value) ( \ - (cp)[0] = (char)(value), \ - (cp)[1] = (char)((value) >> 8), \ - (cp)[2] = (char)((value) >> 16), \ - (cp)[3] = (char)((value) >> 24) ) - -#define GET_16BIT_LSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0]) | \ - ((unsigned long)(unsigned char)(cp)[1] << 8)) - -#define PUT_16BIT_LSB_FIRST(cp, value) ( \ - (cp)[0] = (char)(value), \ - (cp)[1] = (char)((value) >> 8) ) - -#define GET_32BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (char)((value) >> 24), \ - (cp)[1] = (char)((value) >> 16), \ - (cp)[2] = (char)((value) >> 8), \ - (cp)[3] = (char)(value) ) - -#define GET_16BIT_MSB_FIRST(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 8) | \ - ((unsigned long)(unsigned char)(cp)[1])) - -#define PUT_16BIT_MSB_FIRST(cp, value) ( \ - (cp)[0] = (char)((value) >> 8), \ - (cp)[1] = (char)(value) ) - #define GET_16BIT(endian, cp) \ (endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp)) -- 2.11.0