diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index d281c11..04741a7 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -178,7 +178,6 @@ static inline int writev(int sock, struct iovec *iov, int nvecs) typedef struct _LIBSSH2_KEX_METHOD LIBSSH2_KEX_METHOD; typedef struct _LIBSSH2_HOSTKEY_METHOD LIBSSH2_HOSTKEY_METHOD; -typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD; typedef struct _LIBSSH2_CRYPT_METHOD LIBSSH2_CRYPT_METHOD; typedef struct _LIBSSH2_COMP_METHOD LIBSSH2_COMP_METHOD; @@ -310,7 +309,7 @@ struct _LIBSSH2_PACKET /* Where to start reading data from, * used for channel data that's been partially consumed */ - unsigned long data_head; + size_t data_head; }; typedef struct _libssh2_channel_data @@ -319,7 +318,7 @@ typedef struct _libssh2_channel_data uint32_t id; /* Limits and restrictions */ - unsigned long window_size_initial, window_size, packet_size; + uint32_t window_size_initial, window_size, packet_size; /* Set to 1 when CHANNEL_CLOSE / CHANNEL_EOF sent/received */ char close, eof, extended_data_ignore_mode; @@ -340,7 +339,7 @@ struct _LIBSSH2_CHANNEL libssh2_channel_data local, remote; /* Amount of bytes to be refunded to receive window (but not yet sent) */ - unsigned long adjust_queue; + int adjust_queue; LIBSSH2_SESSION *session; @@ -445,8 +444,8 @@ typedef struct _libssh2_endpoint_data const LIBSSH2_CRYPT_METHOD *crypt; void *crypt_abstract; - const LIBSSH2_MAC_METHOD *mac; - unsigned long seqno; + const struct _LIBSSH2_MAC_METHOD *mac; + uint32_t seqno; void *mac_abstract; const LIBSSH2_COMP_METHOD *comp; @@ -499,7 +498,7 @@ struct transportpacket struct _LIBSSH2_PUBLICKEY { LIBSSH2_CHANNEL *channel; - unsigned long version; + uint32_t version; /* State variables used in libssh2_publickey_packet_receive() */ libssh2_nonblocking_states receive_state; @@ -560,7 +559,7 @@ struct _LIBSSH2_SESSION int burn_optimistic_kexinit:1; unsigned char *session_id; - unsigned long session_id_len; + uint32_t session_id_len; /* this is set to TRUE if a blocking API behavior is requested */ int api_block_mode; @@ -573,7 +572,7 @@ struct _LIBSSH2_SESSION * Or read from server in (eg) KEXDH_INIT (for client mode) */ unsigned char *server_hostkey; - unsigned long server_hostkey_len; + uint32_t server_hostkey_len; #if LIBSSH2_MD5 unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH]; #endif /* ! LIBSSH2_MD5 */ @@ -592,7 +591,7 @@ struct _LIBSSH2_SESSION /* Active connection channels */ struct list_head channels; - unsigned long next_channel; + uint32_t next_channel; struct list_head listeners; /* list of LIBSSH2_LISTENER structs */ @@ -720,8 +719,8 @@ struct _LIBSSH2_SESSION /* State variables used in libssh2_channel_forward_listen_ex() */ libssh2_nonblocking_states fwdLstn_state; unsigned char *fwdLstn_packet; - unsigned long fwdLstn_host_len; - unsigned long fwdLstn_packet_len; + uint32_t fwdLstn_host_len; + uint32_t fwdLstn_packet_len; packet_requirev_state_t fwdLstn_packet_requirev_state; /* State variables used in libssh2_publickey_init() */ @@ -759,9 +758,9 @@ struct _LIBSSH2_SESSION /* State variables used in libssh2_scp_recv() */ libssh2_nonblocking_states scpRecv_state; unsigned char *scpRecv_command; - unsigned long scpRecv_command_len; + size_t scpRecv_command_len; unsigned char scpRecv_response[LIBSSH2_SCP_RESPONSE_BUFLEN]; - unsigned long scpRecv_response_len; + size_t scpRecv_response_len; long scpRecv_mode; #if defined(HAVE_LONGLONG) && defined(HAVE_STRTOLL) /* we have the type and we can parse such numbers */ @@ -778,9 +777,9 @@ struct _LIBSSH2_SESSION /* State variables used in libssh2_scp_send_ex() */ libssh2_nonblocking_states scpSend_state; unsigned char *scpSend_command; - unsigned long scpSend_command_len; + size_t scpSend_command_len; unsigned char scpSend_response[LIBSSH2_SCP_RESPONSE_BUFLEN]; - unsigned long scpSend_response_len; + size_t scpSend_response_len; LIBSSH2_CHANNEL *scpSend_channel; /* Keepalive variables used by keepalive.c. */ @@ -886,26 +885,6 @@ struct _LIBSSH2_COMP_METHOD int (*dtor) (LIBSSH2_SESSION * session, int compress, void **abstract); }; -struct _LIBSSH2_MAC_METHOD -{ - const char *name; - - /* The length of a given MAC packet */ - int mac_len; - - /* integrity key length */ - int key_len; - - /* Message Authentication Code Hashing algo */ - int (*init) (LIBSSH2_SESSION * session, unsigned char *key, int *free_key, - void **abstract); - int (*hash) (LIBSSH2_SESSION * session, unsigned char *buf, - unsigned long seqno, const unsigned char *packet, - unsigned long packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract); - int (*dtor) (LIBSSH2_SESSION * session, void **abstract); -}; - #ifdef LIBSSH2DEBUG void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...); diff --git a/src/mac.c b/src/mac.c index 4045910..76894fc 100644 --- a/src/mac.c +++ b/src/mac.c @@ -44,9 +44,9 @@ */ static int mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf, - unsigned long seqno, const unsigned char *packet, - unsigned long packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract) + uint32_t seqno, const unsigned char *packet, + uint32_t packet_len, const unsigned char *addtl, + uint32_t addtl_len, void **abstract) { return 0; } @@ -101,11 +101,11 @@ mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract) */ static int mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session, - unsigned char *buf, unsigned long seqno, + unsigned char *buf, uint32_t seqno, const unsigned char *packet, - unsigned long packet_len, + uint32_t packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract) + uint32_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -141,11 +141,11 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1 = { */ static int mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session, - unsigned char *buf, unsigned long seqno, + unsigned char *buf, uint32_t seqno, const unsigned char *packet, - unsigned long packet_len, + uint32_t packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract) + uint32_t addtl_len, void **abstract) { unsigned char temp[SHA_DIGEST_LENGTH]; @@ -173,11 +173,11 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1_96 = { */ static int mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf, - unsigned long seqno, + uint32_t seqno, const unsigned char *packet, - unsigned long packet_len, + uint32_t packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract) + uint32_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -213,11 +213,11 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_md5 = { */ static int mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session, - unsigned char *buf, unsigned long seqno, + unsigned char *buf, uint32_t seqno, const unsigned char *packet, - unsigned long packet_len, + uint32_t packet_len, const unsigned char *addtl, - unsigned long addtl_len, void **abstract) + uint32_t addtl_len, void **abstract) { unsigned char temp[MD5_DIGEST_LENGTH]; mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, @@ -244,11 +244,11 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_md5_96 = { */ static int mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session, - unsigned char *buf, unsigned long seqno, + unsigned char *buf, uint32_t seqno, const unsigned char *packet, - unsigned long packet_len, + uint32_t packet_len, const unsigned char *addtl, - unsigned long addtl_len, + uint32_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; diff --git a/src/mac.h b/src/mac.h index efccf9d..66d3e61 100644 --- a/src/mac.h +++ b/src/mac.h @@ -1,7 +1,7 @@ #ifndef __LIBSSH2_MAC_H #define __LIBSSH2_MAC_H -/* Copyright (C) 2009 by Daniel Stenberg +/* Copyright (C) 2009-2010 by Daniel Stenberg * * Redistribution and use in source and binary forms, * with or without modification, are permitted provided @@ -40,6 +40,28 @@ #include "libssh2_priv.h" +struct _LIBSSH2_MAC_METHOD +{ + const char *name; + + /* The length of a given MAC packet */ + int mac_len; + + /* integrity key length */ + int key_len; + + /* Message Authentication Code Hashing algo */ + int (*init) (LIBSSH2_SESSION * session, unsigned char *key, int *free_key, + void **abstract); + int (*hash) (LIBSSH2_SESSION * session, unsigned char *buf, + uint32_t seqno, const unsigned char *packet, + uint32_t packet_len, const unsigned char *addtl, + uint32_t addtl_len, void **abstract); + int (*dtor) (LIBSSH2_SESSION * session, void **abstract); +}; + +typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD; + const LIBSSH2_MAC_METHOD **_libssh2_mac_methods(void); #endif /* __LIBSSH2_MAC_H */ diff --git a/src/session.c b/src/session.c index fd852ff..62e5640 100644 --- a/src/session.c +++ b/src/session.c @@ -55,6 +55,7 @@ #include "transport.h" #include "session.h" #include "channel.h" +#include "mac.h" /* libssh2_default_alloc */ diff --git a/src/transport.c b/src/transport.c index a027ff1..cbe49df 100644 --- a/src/transport.c +++ b/src/transport.c @@ -49,6 +49,7 @@ #include #include "transport.h" +#include "mac.h" #define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ #define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */