mirror of
				https://github.com/libssh2/libssh2.git
				synced 2025-11-03 22:13:11 +03:00 
			
		
		
		
	More cleaning up converting libssh2_ to _libssh2_ for internal functions and
removing libssh2_ from static functions. Added mac.h.
This commit is contained in:
		@@ -1,9 +1,9 @@
 | 
				
			|||||||
# $Id: Makefile.am,v 1.18 2009/03/26 22:09:35 bagder Exp $
 | 
					# $Id: Makefile.am,v 1.19 2009/03/26 22:25:23 bagder Exp $
 | 
				
			||||||
AUTOMAKE_OPTIONS = foreign nostdinc
 | 
					AUTOMAKE_OPTIONS = foreign nostdinc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
libssh2_la_SOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \
 | 
					libssh2_la_SOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c     \
 | 
				
			||||||
packet.c publickey.c scp.c session.c sftp.c userauth.c libssh2_priv.h	   \
 | 
					packet.c publickey.c scp.c session.c sftp.c userauth.c libssh2_priv.h	       \
 | 
				
			||||||
openssl.h libgcrypt.h transport.c version.c transport.h channel.h comp.h
 | 
					openssl.h libgcrypt.h transport.c version.c transport.h channel.h comp.h mac.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if LIBGCRYPT
 | 
					if LIBGCRYPT
 | 
				
			||||||
libssh2_la_SOURCES += libgcrypt.c pem.c
 | 
					libssh2_la_SOURCES += libgcrypt.c pem.c
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,5 +42,4 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const LIBSSH2_COMP_METHOD **_libssh2_comp_methods(void);
 | 
					const LIBSSH2_COMP_METHOD **_libssh2_comp_methods(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __LIBSSH2_COMP_H */
 | 
					#endif /* __LIBSSH2_COMP_H */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								src/kex.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/kex.c
									
									
									
									
									
								
							@@ -39,6 +39,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "transport.h"
 | 
					#include "transport.h"
 | 
				
			||||||
#include "comp.h"
 | 
					#include "comp.h"
 | 
				
			||||||
 | 
					#include "mac.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* TODO: Switch this to an inline and handle alloc() failures */
 | 
					/* TODO: Switch this to an inline and handle alloc() failures */
 | 
				
			||||||
/* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */
 | 
					/* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */
 | 
				
			||||||
@@ -1037,10 +1038,10 @@ static int kexinit(LIBSSH2_SESSION * session)
 | 
				
			|||||||
                                     libssh2_crypt_methods());
 | 
					                                     libssh2_crypt_methods());
 | 
				
			||||||
        mac_cs_len =
 | 
					        mac_cs_len =
 | 
				
			||||||
            LIBSSH2_METHOD_PREFS_LEN(session->local.mac_prefs,
 | 
					            LIBSSH2_METHOD_PREFS_LEN(session->local.mac_prefs,
 | 
				
			||||||
                                     libssh2_mac_methods());
 | 
					                                     _libssh2_mac_methods());
 | 
				
			||||||
        mac_sc_len =
 | 
					        mac_sc_len =
 | 
				
			||||||
            LIBSSH2_METHOD_PREFS_LEN(session->remote.mac_prefs,
 | 
					            LIBSSH2_METHOD_PREFS_LEN(session->remote.mac_prefs,
 | 
				
			||||||
                                     libssh2_mac_methods());
 | 
					                                     _libssh2_mac_methods());
 | 
				
			||||||
        comp_cs_len =
 | 
					        comp_cs_len =
 | 
				
			||||||
            LIBSSH2_METHOD_PREFS_LEN(session->local.comp_prefs,
 | 
					            LIBSSH2_METHOD_PREFS_LEN(session->local.comp_prefs,
 | 
				
			||||||
                                     _libssh2_comp_methods());
 | 
					                                     _libssh2_comp_methods());
 | 
				
			||||||
@@ -1080,9 +1081,9 @@ static int kexinit(LIBSSH2_SESSION * session)
 | 
				
			|||||||
        LIBSSH2_METHOD_PREFS_STR(s, crypt_sc_len, session->remote.crypt_prefs,
 | 
					        LIBSSH2_METHOD_PREFS_STR(s, crypt_sc_len, session->remote.crypt_prefs,
 | 
				
			||||||
                                 libssh2_crypt_methods());
 | 
					                                 libssh2_crypt_methods());
 | 
				
			||||||
        LIBSSH2_METHOD_PREFS_STR(s, mac_cs_len, session->local.mac_prefs,
 | 
					        LIBSSH2_METHOD_PREFS_STR(s, mac_cs_len, session->local.mac_prefs,
 | 
				
			||||||
                                 libssh2_mac_methods());
 | 
					                                 _libssh2_mac_methods());
 | 
				
			||||||
        LIBSSH2_METHOD_PREFS_STR(s, mac_sc_len, session->remote.mac_prefs,
 | 
					        LIBSSH2_METHOD_PREFS_STR(s, mac_sc_len, session->remote.mac_prefs,
 | 
				
			||||||
                                 libssh2_mac_methods());
 | 
					                                 _libssh2_mac_methods());
 | 
				
			||||||
        LIBSSH2_METHOD_PREFS_STR(s, comp_cs_len, session->local.comp_prefs,
 | 
					        LIBSSH2_METHOD_PREFS_STR(s, comp_cs_len, session->local.comp_prefs,
 | 
				
			||||||
                                 _libssh2_comp_methods());
 | 
					                                 _libssh2_comp_methods());
 | 
				
			||||||
        LIBSSH2_METHOD_PREFS_STR(s, comp_sc_len, session->remote.comp_prefs,
 | 
					        LIBSSH2_METHOD_PREFS_STR(s, comp_sc_len, session->remote.comp_prefs,
 | 
				
			||||||
@@ -1441,7 +1442,7 @@ static int kex_agree_mac(LIBSSH2_SESSION * session,
 | 
				
			|||||||
                         libssh2_endpoint_data * endpoint, unsigned char *mac,
 | 
					                         libssh2_endpoint_data * endpoint, unsigned char *mac,
 | 
				
			||||||
                         unsigned long mac_len)
 | 
					                         unsigned long mac_len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const LIBSSH2_MAC_METHOD **macp = libssh2_mac_methods();
 | 
					    const LIBSSH2_MAC_METHOD **macp = _libssh2_mac_methods();
 | 
				
			||||||
    unsigned char *s;
 | 
					    unsigned char *s;
 | 
				
			||||||
    (void) session;
 | 
					    (void) session;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1832,12 +1833,12 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    case LIBSSH2_METHOD_MAC_CS:
 | 
					    case LIBSSH2_METHOD_MAC_CS:
 | 
				
			||||||
        prefvar = &session->local.mac_prefs;
 | 
					        prefvar = &session->local.mac_prefs;
 | 
				
			||||||
        mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_mac_methods();
 | 
					        mlist = (const LIBSSH2_COMMON_METHOD **) _libssh2_mac_methods();
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case LIBSSH2_METHOD_MAC_SC:
 | 
					    case LIBSSH2_METHOD_MAC_SC:
 | 
				
			||||||
        prefvar = &session->remote.mac_prefs;
 | 
					        prefvar = &session->remote.mac_prefs;
 | 
				
			||||||
        mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_mac_methods();
 | 
					        mlist = (const LIBSSH2_COMMON_METHOD **) _libssh2_mac_methods();
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case LIBSSH2_METHOD_COMP_CS:
 | 
					    case LIBSSH2_METHOD_COMP_CS:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1210,11 +1210,9 @@ unsigned long _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
 | 
				
			|||||||
/* this is the lib-internal set blocking function */
 | 
					/* this is the lib-internal set blocking function */
 | 
				
			||||||
int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking);
 | 
					int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Let crypt.c/hostkey.c/comp.c/mac.c expose their method structs */
 | 
					/* Let crypt.c/hostkey.c expose their method structs */
 | 
				
			||||||
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void);
 | 
					const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void);
 | 
				
			||||||
const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void);
 | 
					const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void);
 | 
				
			||||||
const LIBSSH2_COMP_METHOD **libssh2_comp_methods(void);
 | 
					 | 
				
			||||||
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Language API doesn't exist yet.  Just act like we've agreed on a language */
 | 
					/* Language API doesn't exist yet.  Just act like we've agreed on a language */
 | 
				
			||||||
#define libssh2_kex_agree_lang(session, endpoint, str, str_len) 0
 | 
					#define libssh2_kex_agree_lang(session, endpoint, str, str_len) 0
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										191
									
								
								src/mac.c
									
									
									
									
									
								
							
							
						
						
									
										191
									
								
								src/mac.c
									
									
									
									
									
								
							@@ -36,39 +36,40 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "libssh2_priv.h"
 | 
					#include "libssh2_priv.h"
 | 
				
			||||||
 | 
					#include "mac.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef LIBSSH2_MAC_NONE
 | 
					#ifdef LIBSSH2_MAC_NONE
 | 
				
			||||||
/* {{{ libssh2_mac_none_MAC
 | 
					/* mac_none_MAC
 | 
				
			||||||
 * Minimalist MAC: No MAC
 | 
					 * Minimalist MAC: No MAC
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf,
 | 
					mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf,
 | 
				
			||||||
                     unsigned long seqno, const unsigned char *packet,
 | 
					             unsigned long seqno, const unsigned char *packet,
 | 
				
			||||||
                     unsigned long packet_len, const unsigned char *addtl,
 | 
					             unsigned long packet_len, const unsigned char *addtl,
 | 
				
			||||||
                     unsigned long addtl_len, void **abstract)
 | 
					             unsigned long addtl_len, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static LIBSSH2_MAC_METHOD libssh2_mac_method_none = {
 | 
					
 | 
				
			||||||
 | 
					static LIBSSH2_MAC_METHOD mac_method_none = {
 | 
				
			||||||
    "none",
 | 
					    "none",
 | 
				
			||||||
    0,
 | 
					    0,
 | 
				
			||||||
    0,
 | 
					    0,
 | 
				
			||||||
    NULL,
 | 
					    NULL,
 | 
				
			||||||
    libssh2_mac_none_MAC,
 | 
					    mac_none_MAC,
 | 
				
			||||||
    NULL
 | 
					    NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif /* LIBSSH2_MAC_NONE */
 | 
					#endif /* LIBSSH2_MAC_NONE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_common_init
 | 
					/* mac_method_common_init
 | 
				
			||||||
 * Initialize simple mac methods
 | 
					 * Initialize simple mac methods
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_common_init(LIBSSH2_SESSION * session, unsigned char *key,
 | 
					mac_method_common_init(LIBSSH2_SESSION * session, unsigned char *key,
 | 
				
			||||||
                               int *free_key, void **abstract)
 | 
					                       int *free_key, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    *abstract = key;
 | 
					    *abstract = key;
 | 
				
			||||||
    *free_key = 0;
 | 
					    *free_key = 0;
 | 
				
			||||||
@@ -77,13 +78,13 @@ libssh2_mac_method_common_init(LIBSSH2_SESSION * session, unsigned char *key,
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_common_dtor
 | 
					
 | 
				
			||||||
 | 
					/* mac_method_common_dtor
 | 
				
			||||||
 * Cleanup simple mac methods
 | 
					 * Cleanup simple mac methods
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract)
 | 
					mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (*abstract) {
 | 
					    if (*abstract) {
 | 
				
			||||||
        LIBSSH2_FREE(session, *abstract);
 | 
					        LIBSSH2_FREE(session, *abstract);
 | 
				
			||||||
@@ -93,18 +94,18 @@ libssh2_mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract)
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_hmac_sha1_hash
 | 
					
 | 
				
			||||||
 | 
					/* mac_method_hmac_sha1_hash
 | 
				
			||||||
 * Calculate hash using full sha1 value
 | 
					 * Calculate hash using full sha1 value
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
 | 
					mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
 | 
				
			||||||
                                  unsigned char *buf, unsigned long seqno,
 | 
					                          unsigned char *buf, unsigned long seqno,
 | 
				
			||||||
                                  const unsigned char *packet,
 | 
					                          const unsigned char *packet,
 | 
				
			||||||
                                  unsigned long packet_len,
 | 
					                          unsigned long packet_len,
 | 
				
			||||||
                                  const unsigned char *addtl,
 | 
					                          const unsigned char *addtl,
 | 
				
			||||||
                                  unsigned long addtl_len, void **abstract)
 | 
					                          unsigned long addtl_len, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    libssh2_hmac_ctx ctx;
 | 
					    libssh2_hmac_ctx ctx;
 | 
				
			||||||
    unsigned char seqno_buf[4];
 | 
					    unsigned char seqno_buf[4];
 | 
				
			||||||
@@ -124,58 +125,58 @@ libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
 | 
					
 | 
				
			||||||
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1 = {
 | 
				
			||||||
    "hmac-sha1",
 | 
					    "hmac-sha1",
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_sha1_hash,
 | 
					    mac_method_hmac_sha1_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_hmac_sha1_96_hash
 | 
					/* mac_method_hmac_sha1_96_hash
 | 
				
			||||||
 * Calculate hash using first 96 bits of sha1 value
 | 
					 * Calculate hash using first 96 bits of sha1 value
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session,
 | 
					mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session,
 | 
				
			||||||
                                     unsigned char *buf, unsigned long seqno,
 | 
					                             unsigned char *buf, unsigned long seqno,
 | 
				
			||||||
                                     const unsigned char *packet,
 | 
					                             const unsigned char *packet,
 | 
				
			||||||
                                     unsigned long packet_len,
 | 
					                             unsigned long packet_len,
 | 
				
			||||||
                                     const unsigned char *addtl,
 | 
					                             const unsigned char *addtl,
 | 
				
			||||||
                                     unsigned long addtl_len, void **abstract)
 | 
					                             unsigned long addtl_len, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned char temp[SHA_DIGEST_LENGTH];
 | 
					    unsigned char temp[SHA_DIGEST_LENGTH];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    libssh2_mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len,
 | 
					    mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len,
 | 
				
			||||||
                                      addtl, addtl_len, abstract);
 | 
					                              addtl, addtl_len, abstract);
 | 
				
			||||||
    memcpy(buf, (char *) temp, 96 / 8);
 | 
					    memcpy(buf, (char *) temp, 96 / 8);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
 | 
					
 | 
				
			||||||
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1_96 = {
 | 
				
			||||||
    "hmac-sha1-96",
 | 
					    "hmac-sha1-96",
 | 
				
			||||||
    12,
 | 
					    12,
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_sha1_96_hash,
 | 
					    mac_method_hmac_sha1_96_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_hmac_md5_hash
 | 
					/* mac_method_hmac_md5_hash
 | 
				
			||||||
 * Calculate hash using full md5 value
 | 
					 * Calculate hash using full md5 value
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
 | 
					mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
 | 
				
			||||||
                                 unsigned long seqno,
 | 
					                         unsigned long seqno,
 | 
				
			||||||
                                 const unsigned char *packet,
 | 
					                         const unsigned char *packet,
 | 
				
			||||||
                                 unsigned long packet_len,
 | 
					                         unsigned long packet_len,
 | 
				
			||||||
                                 const unsigned char *addtl,
 | 
					                         const unsigned char *addtl,
 | 
				
			||||||
                                 unsigned long addtl_len, void **abstract)
 | 
					                         unsigned long addtl_len, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    libssh2_hmac_ctx ctx;
 | 
					    libssh2_hmac_ctx ctx;
 | 
				
			||||||
    unsigned char seqno_buf[4];
 | 
					    unsigned char seqno_buf[4];
 | 
				
			||||||
@@ -195,60 +196,58 @@ libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
 | 
					
 | 
				
			||||||
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_md5 = {
 | 
				
			||||||
    "hmac-md5",
 | 
					    "hmac-md5",
 | 
				
			||||||
    16,
 | 
					    16,
 | 
				
			||||||
    16,
 | 
					    16,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_md5_hash,
 | 
					    mac_method_hmac_md5_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* {{{ libssh2_mac_method_hmac_md5_96_hash
 | 
					/* mac_method_hmac_md5_96_hash
 | 
				
			||||||
 * Calculate hash using first 96 bits of md5 value
 | 
					 * Calculate hash using first 96 bits of md5 value
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session,
 | 
					mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session,
 | 
				
			||||||
                                    unsigned char *buf, unsigned long seqno,
 | 
					                            unsigned char *buf, unsigned long seqno,
 | 
				
			||||||
                                    const unsigned char *packet,
 | 
					                            const unsigned char *packet,
 | 
				
			||||||
                                    unsigned long packet_len,
 | 
					                            unsigned long packet_len,
 | 
				
			||||||
                                    const unsigned char *addtl,
 | 
					                            const unsigned char *addtl,
 | 
				
			||||||
                                    unsigned long addtl_len, void **abstract)
 | 
					                            unsigned long addtl_len, void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned char temp[MD5_DIGEST_LENGTH];
 | 
					    unsigned char temp[MD5_DIGEST_LENGTH];
 | 
				
			||||||
 | 
					    mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len,
 | 
				
			||||||
    libssh2_mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len,
 | 
					                             addtl, addtl_len, abstract);
 | 
				
			||||||
                                     addtl, addtl_len, abstract);
 | 
					 | 
				
			||||||
    memcpy(buf, (char *) temp, 96 / 8);
 | 
					    memcpy(buf, (char *) temp, 96 / 8);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
 | 
					
 | 
				
			||||||
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_md5_96 = {
 | 
				
			||||||
    "hmac-md5-96",
 | 
					    "hmac-md5-96",
 | 
				
			||||||
    12,
 | 
					    12,
 | 
				
			||||||
    16,
 | 
					    16,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_md5_96_hash,
 | 
					    mac_method_hmac_md5_96_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if LIBSSH2_HMAC_RIPEMD
 | 
					#if LIBSSH2_HMAC_RIPEMD
 | 
				
			||||||
/* {{{ libssh2_mac_method_hmac_ripemd160_hash
 | 
					/* mac_method_hmac_ripemd160_hash
 | 
				
			||||||
 * Calculate hash using ripemd160 value
 | 
					 * Calculate hash using ripemd160 value
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
 | 
					mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
 | 
				
			||||||
                                       unsigned char *buf, unsigned long seqno,
 | 
					                               unsigned char *buf, unsigned long seqno,
 | 
				
			||||||
                                       const unsigned char *packet,
 | 
					                               const unsigned char *packet,
 | 
				
			||||||
                                       unsigned long packet_len,
 | 
					                               unsigned long packet_len,
 | 
				
			||||||
                                       const unsigned char *addtl,
 | 
					                               const unsigned char *addtl,
 | 
				
			||||||
                                       unsigned long addtl_len,
 | 
					                               unsigned long addtl_len,
 | 
				
			||||||
                                       void **abstract)
 | 
					                               void **abstract)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    libssh2_hmac_ctx ctx;
 | 
					    libssh2_hmac_ctx ctx;
 | 
				
			||||||
    unsigned char seqno_buf[4];
 | 
					    unsigned char seqno_buf[4];
 | 
				
			||||||
@@ -268,44 +267,44 @@ libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160 = {
 | 
					
 | 
				
			||||||
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160 = {
 | 
				
			||||||
    "hmac-ripemd160",
 | 
					    "hmac-ripemd160",
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_ripemd160_hash,
 | 
					    mac_method_hmac_ripemd160_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160_openssh_com = {
 | 
					static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160_openssh_com = {
 | 
				
			||||||
    "hmac-ripemd160@openssh.com",
 | 
					    "hmac-ripemd160@openssh.com",
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    20,
 | 
					    20,
 | 
				
			||||||
    libssh2_mac_method_common_init,
 | 
					    mac_method_common_init,
 | 
				
			||||||
    libssh2_mac_method_hmac_ripemd160_hash,
 | 
					    mac_method_hmac_ripemd160_hash,
 | 
				
			||||||
    libssh2_mac_method_common_dtor,
 | 
					    mac_method_common_dtor,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif /* LIBSSH2_HMAC_RIPEMD */
 | 
					#endif /* LIBSSH2_HMAC_RIPEMD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const LIBSSH2_MAC_METHOD *_libssh2_mac_methods[] = {
 | 
					static const LIBSSH2_MAC_METHOD *mac_methods[] = {
 | 
				
			||||||
    &libssh2_mac_method_hmac_sha1,
 | 
					    &mac_method_hmac_sha1,
 | 
				
			||||||
    &libssh2_mac_method_hmac_sha1_96,
 | 
					    &mac_method_hmac_sha1_96,
 | 
				
			||||||
    &libssh2_mac_method_hmac_md5,
 | 
					    &mac_method_hmac_md5,
 | 
				
			||||||
    &libssh2_mac_method_hmac_md5_96,
 | 
					    &mac_method_hmac_md5_96,
 | 
				
			||||||
#if LIBSSH2_HMAC_RIPEMD
 | 
					#if LIBSSH2_HMAC_RIPEMD
 | 
				
			||||||
    &libssh2_mac_method_hmac_ripemd160,
 | 
					    &mac_method_hmac_ripemd160,
 | 
				
			||||||
    &libssh2_mac_method_hmac_ripemd160_openssh_com,
 | 
					    &mac_method_hmac_ripemd160_openssh_com,
 | 
				
			||||||
#endif /* LIBSSH2_HMAC_RIPEMD */
 | 
					#endif /* LIBSSH2_HMAC_RIPEMD */
 | 
				
			||||||
#ifdef LIBSSH2_MAC_NONE
 | 
					#ifdef LIBSSH2_MAC_NONE
 | 
				
			||||||
    &libssh2_mac_method_none,
 | 
					    &mac_method_none,
 | 
				
			||||||
#endif /* LIBSSH2_MAC_NONE */
 | 
					#endif /* LIBSSH2_MAC_NONE */
 | 
				
			||||||
    NULL
 | 
					    NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const LIBSSH2_MAC_METHOD **
 | 
					const LIBSSH2_MAC_METHOD **
 | 
				
			||||||
libssh2_mac_methods(void)
 | 
					_libssh2_mac_methods(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return _libssh2_mac_methods;
 | 
					    return mac_methods;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										45
									
								
								src/mac.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/mac.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					#ifndef __LIBSSH2_MAC_H
 | 
				
			||||||
 | 
					#define __LIBSSH2_MAC_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Copyright (C) 2009 by Daniel Stenberg
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms,
 | 
				
			||||||
 | 
					 * with or without modification, are permitted provided
 | 
				
			||||||
 | 
					 * that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *   Redistributions of source code must retain the above
 | 
				
			||||||
 | 
					 *   copyright notice, this list of conditions and the
 | 
				
			||||||
 | 
					 *   following disclaimer.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *   Redistributions in binary form must reproduce the above
 | 
				
			||||||
 | 
					 *   copyright notice, this list of conditions and the following
 | 
				
			||||||
 | 
					 *   disclaimer in the documentation and/or other materials
 | 
				
			||||||
 | 
					 *   provided with the distribution.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *   Neither the name of the copyright holder nor the names
 | 
				
			||||||
 | 
					 *   of any other contributors may be used to endorse or
 | 
				
			||||||
 | 
					 *   promote products derived from this software without
 | 
				
			||||||
 | 
					 *   specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 | 
				
			||||||
 | 
					 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
				
			||||||
 | 
					 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
				
			||||||
 | 
					 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 | 
				
			||||||
 | 
					 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
				
			||||||
 | 
					 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 | 
				
			||||||
 | 
					 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 | 
				
			||||||
 | 
					 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 | 
				
			||||||
 | 
					 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 | 
				
			||||||
 | 
					 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "libssh2_priv.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const LIBSSH2_MAC_METHOD **_libssh2_mac_methods(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __LIBSSH2_MAC_H */
 | 
				
			||||||
		Reference in New Issue
	
	Block a user