diff options
-rw-r--r-- | asn1/cms/packet-cms-template.c | 2 | ||||
-rw-r--r-- | asn1/snmp/packet-snmp-template.c | 192 | ||||
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/crypt/Makefile.common | 6 | ||||
-rw-r--r-- | epan/crypt/airpdcap.c | 10 | ||||
-rw-r--r-- | epan/crypt/airpdcap_sha1.c | 366 | ||||
-rw-r--r-- | epan/crypt/airpdcap_sha1.h | 53 | ||||
-rw-r--r-- | epan/crypt/airpdcap_system.h | 8 | ||||
-rw-r--r-- | epan/crypt/crypt-sha1.c (renamed from epan/sha1.c) | 16 | ||||
-rw-r--r-- | epan/crypt/crypt-sha1.h (renamed from epan/sha1.h) | 6 | ||||
-rw-r--r-- | epan/dissectors/packet-cms.c | 12 | ||||
-rw-r--r-- | epan/dissectors/packet-cms.h | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-snmp.c | 192 | ||||
-rw-r--r-- | epan/sigcomp-udvm.c | 312 |
14 files changed, 375 insertions, 804 deletions
diff --git a/asn1/cms/packet-cms-template.c b/asn1/cms/packet-cms-template.c index 1364a58dbb..678959149d 100644 --- a/asn1/cms/packet-cms-template.c +++ b/asn1/cms/packet-cms-template.c @@ -40,7 +40,7 @@ #include "packet-x509af.h" #include "packet-x509if.h" -#include <epan/sha1.h> +#include <epan/crypt/crypt-sha1.h> #include <epan/crypt/crypt-md5.h> #define PNAME "Cryptographic Message Syntax" diff --git a/asn1/snmp/packet-snmp-template.c b/asn1/snmp/packet-snmp-template.c index ff75710e78..53c188418b 100644 --- a/asn1/snmp/packet-snmp-template.c +++ b/asn1/snmp/packet-snmp-template.c @@ -96,7 +96,7 @@ #include "packet-snmp.h" #include "format-oid.h" -#include <epan/sha1.h> +#include <epan/crypt/crypt-sha1.h> #include <epan/crypt/crypt-md5.h> #include <epan/expert.h> #include <epan/report_err.h> @@ -1067,14 +1067,14 @@ static void renew_ue_cache(void) { localized_ues = NULL; unlocalized_ues = NULL; - + for(a = ue_assocs; a->user.userName.data; a++) { if (a->engine.data) { CACHE_INSERT(localized_ues,a); } else { CACHE_INSERT(unlocalized_ues,a); } - + } } } @@ -1083,10 +1083,10 @@ static void renew_ue_cache(void) { static snmp_ue_assoc_t* localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len ) { snmp_ue_assoc_t* n = se_memdup(o,sizeof(snmp_ue_assoc_t)); guint key_size = n->user.authModel->key_size; - + n->engine.data = se_memdup(engine,engine_len); n->engine.len = engine_len; - + n->user.authKey.data = se_alloc(key_size); n->user.authKey.len = key_size; n->user.authModel->pass2key(n->user.authPassword.data, @@ -1122,22 +1122,22 @@ static snmp_ue_assoc_t* get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb) guint8* given_username; guint given_engine_len; guint8* given_engine; - + if ( ! (localized_ues || unlocalized_ues ) ) return NULL; if (! ( user_tvb && engine_tvb ) ) return NULL; - + given_username_len = tvb_length_remaining(user_tvb,0); given_username = ep_tvb_memdup(user_tvb,0,-1); given_engine_len = tvb_length_remaining(engine_tvb,0); given_engine = ep_tvb_memdup(engine_tvb,0,-1); - + for (a = localized_ues; a; a = a->next) { if ( localized_match(a, given_username, given_username_len, given_engine, given_engine_len) ) { return a; } } - + for (a = unlocalized_ues; a; a = a->next) { if ( unlocalized_match(a, given_username, given_username_len) ) { snmp_ue_assoc_t* n = localize_ue( a, given_engine, given_engine_len ); @@ -1145,21 +1145,21 @@ static snmp_ue_assoc_t* get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb) return n; } } - + return NULL; } static void destroy_ue_assocs(snmp_ue_assoc_t* assocs) { if (assocs) { snmp_ue_assoc_t* a; - + for(a = assocs; a->user.userName.data; a++) { g_free(a->user.userName.data); if (a->user.authKey.data) g_free(a->user.authKey.data); if (a->user.privKey.data) g_free(a->user.privKey.data); if (a->engine.data) g_free(a->engine.data); } - + g_free(ue_assocs); } } @@ -1176,31 +1176,31 @@ gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* ca guint start; guint end; guint i; - + if (!p->auth_tvb) { *error = "No Authenticator"; - return FALSE; + return FALSE; } - + key = p->user_assoc->user.authKey.data; key_len = p->user_assoc->user.authKey.len; - + if (! key ) { *error = "User has no authKey"; return FALSE; } - - + + auth_len = tvb_length_remaining(p->auth_tvb,0); - + if (auth_len != 12) { *error = "Authenticator length wrong"; return FALSE; } - + msg_len = tvb_length_remaining(p->msg_tvb,0); msg = ep_tvb_memdup(p->msg_tvb,0,msg_len); - + auth = ep_tvb_memdup(p->auth_tvb,0,auth_len); @@ -1213,7 +1213,7 @@ gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* ca } md5_hmac(msg, msg_len, key, key_len, calc_auth); - + if (calc_auth_p) *calc_auth_p = calc_auth; if (calc_auth_len_p) *calc_auth_len_p = 12; @@ -1232,47 +1232,47 @@ gboolean snmp_usm_auth_sha1(snmp_usm_params_t* p _U_, guint8** calc_auth_p, guin guint start; guint end; guint i; - + if (!p->auth_tvb) { *error = "No Authenticator"; - return FALSE; + return FALSE; } - + key = p->user_assoc->user.authKey.data; key_len = p->user_assoc->user.authKey.len; - + if (! key ) { *error = "User has no authKey"; return FALSE; } - - + + auth_len = tvb_length_remaining(p->auth_tvb,0); - - + + if (auth_len != 12) { *error = "Authenticator length wrong"; return FALSE; } - + msg_len = tvb_length_remaining(p->msg_tvb,0); msg = ep_tvb_memdup(p->msg_tvb,0,msg_len); auth = ep_tvb_memdup(p->auth_tvb,0,auth_len); - + start = p->auth_offset - p->start_offset; end = start + auth_len; - + /* fill the authenticator with zeros */ for ( i = start ; i < end ; i++ ) { msg[i] = '\0'; } - + sha1_hmac(key, key_len, msg, msg_len, calc_auth); - + if (calc_auth_p) *calc_auth_p = calc_auth; if (calc_auth_len_p) *calc_auth_len_p = 12; - + return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE; } @@ -1280,7 +1280,7 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U #ifdef HAVE_LIBGCRYPT gcry_error_t err; gcry_cipher_hd_t hd = NULL; - + guint8* cleartext; guint8* des_key = p->user_assoc->user.privKey.data; /* first 8 bytes */ guint8* pre_iv = &(p->user_assoc->user.privKey.data[8]); /* last 8 bytes */ @@ -1291,14 +1291,14 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U tvbuff_t* clear_tvb; guint8 iv[8]; guint i; - - + + salt_len = tvb_length_remaining(p->priv_tvb,0); - + if (salt_len != 8) { *error = "decryptionError: msgPrivacyParameters lenght != 8"; return NULL; - } + } salt = ep_tvb_memdup(p->priv_tvb,0,salt_len); @@ -1315,29 +1315,29 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U *error = "decryptionError: the length of the encrypted data is not a mutiple of 8 octets"; return NULL; } - + cryptgrm = ep_tvb_memdup(encryptedData,0,-1); cleartext = ep_alloc(cryptgrm_len); - + err = gcry_cipher_open(&hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_CBC, 0); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setiv(hd, iv, 8); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setkey(hd,des_key,8); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + gcry_cipher_close(hd); - + clear_tvb = tvb_new_real_data(cleartext, cryptgrm_len, cryptgrm_len); - + return clear_tvb; - + on_gcry_error: *error = (void*)gpg_strerror(err); if (hd) gcry_cipher_close(hd); @@ -1352,7 +1352,7 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U #ifdef HAVE_LIBGCRYPT gcry_error_t err; gcry_cipher_hd_t hd = NULL; - + guint8* cleartext; guint8* aes_key = p->user_assoc->user.privKey.data; /* first 16 bytes */ guint8 iv[16]; @@ -1362,12 +1362,12 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U tvbuff_t* clear_tvb; priv_len = tvb_length_remaining(p->priv_tvb,0); - + if (priv_len != 8) { *error = "decryptionError: msgPrivacyParameters lenght != 8"; return NULL; - } - + } + iv[0] = (p->boots & 0xff000000) >> 24; iv[1] = (p->boots & 0x00ff0000) >> 16; iv[2] = (p->boots & 0x0000ff00) >> 8; @@ -1377,30 +1377,30 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U iv[6] = (p->time & 0x0000ff00) >> 8; iv[7] = (p->time & 0x000000ff); tvb_memcpy(p->priv_tvb,&(iv[8]),0,8); - + cryptgrm_len = tvb_length_remaining(encryptedData,0); cryptgrm = ep_tvb_memdup(encryptedData,0,-1); - + cleartext = ep_alloc(cryptgrm_len); - + err = gcry_cipher_open(&hd, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CFB, 0); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setiv(hd, iv, 16); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setkey(hd,aes_key,16); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + gcry_cipher_close(hd); - + clear_tvb = tvb_new_real_data(cleartext, cryptgrm_len, cryptgrm_len); - + return clear_tvb; - + on_gcry_error: *error = (void*)gpg_strerror(err); if (hd) gcry_cipher_close(hd); @@ -1422,29 +1422,29 @@ gboolean check_ScopedPdu(tvbuff_t* tvb) { offset = get_ber_identifier(tvb, 0, &class, &pc, &tag); offset = get_ber_length(NULL, tvb, offset, NULL, NULL); - + if ( ! (((class!=BER_CLASS_APP) && (class!=BER_CLASS_PRI) ) && ( (!pc) || (class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_ENUMERATED) ) )) return FALSE; if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)) return TRUE; - + hoffset = offset; offset = get_ber_identifier(tvb, offset, &class, &pc, &tag); offset = get_ber_length(NULL, tvb, offset, &len, NULL); eoffset = offset + len; - + if (eoffset <= hoffset) return FALSE; - + if ((class!=BER_CLASS_APP)&&(class!=BER_CLASS_PRI)) if( (class!=BER_CLASS_UNI) ||((tag<BER_UNI_TAG_NumericString)&&(tag!=BER_UNI_TAG_OCTETSTRING)&&(tag!=BER_UNI_TAG_UTF8String)) ) return FALSE; - + return TRUE; - + } #include "packet-snmp-fn.c" @@ -1481,7 +1481,7 @@ dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo, usm_p.boots = 0; usm_p.time = 0; usm_p.authOK = FALSE; - + /* * This will throw an exception if we don't have any data left. * That's what we want. (See "tcp_dissect_pdus()", which is @@ -1714,7 +1714,7 @@ dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* MD5 Password to Key Algorithm - from RFC 3414 A.2.1 + from RFC 3414 A.2.1 */ void snmp_usm_password_to_key_md5(const guint8 *password, guint passwordlen, @@ -1727,7 +1727,7 @@ void snmp_usm_password_to_key_md5(const guint8 *password, guint32 count = 0, i; guint8 key1[16]; md5_init(&MD); /* initialize MD5 */ - + /**********************************************/ /* Use while loop until we've done 1 Megabyte */ /**********************************************/ @@ -1744,31 +1744,31 @@ void snmp_usm_password_to_key_md5(const guint8 *password, count += 64; } md5_finish(&MD, key1); /* tell MD5 we're done */ - + /*****************************************************/ /* Now localize the key with the engineID and pass */ /* through MD5 to produce final key */ /* May want to ensure that engineLength <= 32, */ /* otherwise need to use a buffer larger than 64 */ /*****************************************************/ - + md5_init(&MD); md5_append(&MD, key1, 16); md5_append(&MD, engineID, engineLength); md5_append(&MD, key1, 16); md5_finish(&MD, key); - + return; } - - + + /* SHA1 Password to Key Algorithm COPIED from RFC 3414 A.2.2 */ -void snmp_usm_password_to_key_sha1(const guint8 *password, +void snmp_usm_password_to_key_sha1(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, @@ -1777,9 +1777,9 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, guint8 *cp, password_buf[72]; guint32 password_index = 0; guint32 count = 0, i; - + sha1_starts(&SH); /* initialize SHA */ - + /**********************************************/ /* Use while loop until we've done 1 Megabyte */ /**********************************************/ @@ -1796,7 +1796,7 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, count += 64; } sha1_finish(&SH, key); - + /*****************************************************/ /* Now localize the key with the engineID and pass */ /* through SHA to produce final key */ @@ -1806,14 +1806,14 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, memcpy(password_buf, key, 20); memcpy(password_buf+20, engineID, engineLength); memcpy(password_buf+20+engineLength, key, 20); - + sha1_starts(&SH); sha1_update(&SH, password_buf, 40+engineLength); sha1_finish(&SH, key); return; } - + static void process_prefs(void) { @@ -1868,12 +1868,12 @@ process_prefs(void) read_configs(); mibs_loaded = TRUE; #endif /* HAVE_NET_SNMP */ - + if ( g_str_equal(ue_assocs_filename_loaded,ue_assocs_filename) ) return; ue_assocs_filename_loaded = ue_assocs_filename; - + if (ue_assocs) destroy_ue_assocs(ue_assocs); - + if ( *ue_assocs_filename ) { gchar* err = load_snmp_users_file(ue_assocs_filename,&ue_assocs); if (err) report_failure("Error while loading SNMP's users file:\n%s",err); @@ -1881,18 +1881,18 @@ process_prefs(void) ue_assocs = NULL; } } - - - + + + /*--- proto_register_snmp -------------------------------------------*/ -void proto_register_snmp(void) { +void proto_register_snmp(void) { #if defined(_WIN32) && defined(HAVE_NET_SNMP) char *mib_path; int mib_path_len; #define MIB_PATH_APPEND "snmp\\mibs" #endif gchar *tmp_mib_modules; - + /* List of fields */ static hf_register_info hf[] = { { &hf_snmp_v3_flags_auth, @@ -1940,7 +1940,7 @@ void proto_register_snmp(void) { { &hf_snmp_decryptedPDU, { "Decrypted ScopedPDU", "snmp.decrypted_pdu", FT_BYTES, BASE_HEX, NULL, 0, "Decrypted PDU", HFILL }}, - + #include "packet-snmp-hfarr.c" }; @@ -1952,7 +1952,7 @@ void proto_register_snmp(void) { &ett_encryptedPDU, &ett_decrypted, &ett_authParameters, - + #include "packet-snmp-ettarr.c" }; module_t *snmp_module; @@ -2032,11 +2032,11 @@ void proto_register_snmp(void) { "USMuserTable file", "The filename of the user table used for authentication and decryption", &ue_assocs_filename); - + variable_oid_dissector_table = register_dissector_table("snmp.variable_oid", "SNMP Variable OID", FT_STRING, BASE_NONE); - + register_init_routine(renew_ue_cache); } diff --git a/epan/Makefile.common b/epan/Makefile.common index 86cd7b9a6e..3f1e6dd094 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -72,7 +72,6 @@ LIBWIRESHARK_SRC = \ reassemble.c \ reedsolomon.c \ req_resp_hdrs.c \ - sha1.c \ sigcomp_state_hdlr.c \ sigcomp-udvm.c \ sminmpec.c \ @@ -168,7 +167,6 @@ LIBWIRESHARK_INCLUDES = \ req_resp_hdrs.h \ rtp_pt.h \ sctpppids.h \ - sha1.h \ sigcomp_state_hdlr.h \ sigcomp-udvm.h \ slab.h \ diff --git a/epan/crypt/Makefile.common b/epan/crypt/Makefile.common index 38b57476ff..186ee9af2d 100644 --- a/epan/crypt/Makefile.common +++ b/epan/crypt/Makefile.common @@ -28,20 +28,19 @@ LIBAIRPDCAP_SRC = \ airpdcap_ccmp.c \ airpdcap_debug.c \ airpdcap_rijndael.c \ - airpdcap_sha1.c \ airpdcap_tkip.c \ airpdcap_wep.c \ crypt-des.c \ crypt-md4.c \ crypt-md5.c \ - crypt-rc4.c + crypt-rc4.c \ + crypt-sha1.c LIBAIRPDCAP_INCLUDES = \ airpdcap_debug.h \ airpdcap_interop.h \ airpdcap_int.h \ airpdcap_rijndael.h \ - airpdcap_sha1.h \ airpdcap_system.h \ airpdcap_user.h \ airpdcap_ws.h \ @@ -49,4 +48,5 @@ LIBAIRPDCAP_INCLUDES = \ crypt-md4.h \ crypt-md5.h \ crypt-rc4.h \ + crypt-sha1.h \ wep-wpadefs.h diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c index a8cd0c7f35..14b6822971 100644 --- a/epan/crypt/airpdcap.c +++ b/epan/crypt/airpdcap.c @@ -8,7 +8,7 @@ #include "airpdcap_system.h" #include "airpdcap_int.h" -#include "airpdcap_sha1.h" +#include "crypt-sha1.h" #include "crypt-md5.h" #include "airpdcap_debug.h" @@ -985,7 +985,7 @@ INT AirPDcapRsnaMicCheck( md5_hmac(eapol, eapol_len, KCK, AIRPDCAP_WPA_KCK_LEN, c_mic); } else if (key_ver==AIRPDCAP_WPA_KEY_VER_AES_CCMP) { /* use HMAC-SHA1-128 for the EAPOL-Key MIC */ - AirPDcapAlgHmacSha1(KCK, AIRPDCAP_WPA_KCK_LEN, eapol, eapol_len, c_mic); + sha1_hmac(KCK, AIRPDCAP_WPA_KCK_LEN, eapol, eapol_len, c_mic); } else /* key descriptor version not recognized */ return AIRPDCAP_RET_UNSUCCESS; @@ -1226,7 +1226,7 @@ void AirPDcapRsnaPrfX( for(i = 0; i < (x+159)/160; i++) { R[offset] = i; - AirPDcapAlgHmacSha1(pmk, 32, R, 100, ptk + i * 20); + sha1_hmac(pmk, 32, R, 100, ptk + i * 20); } } @@ -1247,13 +1247,13 @@ INT AirPDcapRsnaPwd2PskStep( digest[ssidLength+1] = (UCHAR)((count>>16) & 0xff); digest[ssidLength+2] = (UCHAR)((count>>8) & 0xff); digest[ssidLength+3] = (UCHAR)(count & 0xff); - AirPDcapAlgHmacSha1((UCHAR *)password, strlen(password), digest, ssidLength+4, digest1); + sha1_hmac((UCHAR *)password, strlen(password), digest, ssidLength+4, digest1); /* output = U1 */ memcpy(output, digest1, AIRPDCAP_SHA_DIGEST_LEN); for (i = 1; i < iterations; i++) { /* Un = PRF(P, Un-1) */ - AirPDcapAlgHmacSha1((UCHAR *)password, strlen(password), digest1, AIRPDCAP_SHA_DIGEST_LEN, digest); + sha1_hmac((UCHAR *)password, strlen(password), digest1, AIRPDCAP_SHA_DIGEST_LEN, digest); memcpy(digest1, digest, AIRPDCAP_SHA_DIGEST_LEN); /* output = output xor Un */ diff --git a/epan/crypt/airpdcap_sha1.c b/epan/crypt/airpdcap_sha1.c deleted file mode 100644 index a25c94bc13..0000000000 --- a/epan/crypt/airpdcap_sha1.c +++ /dev/null @@ -1,366 +0,0 @@ -/* airpdcap_sha1.c - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -/******************************************************************************/ -/* File includes */ -/* */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "airpdcap_sha1.h" - -#include "airpdcap_debug.h" -/* */ -/******************************************************************************/ - -#if WORDS_BIGENDIAN == 1 -#define BIG_ENDIAN -#else -#define LITTLE_ENDIAN -#endif - -/******************************************************************************/ -/* Internal definitions */ -/* */ -/* Definition used in HMAC-SHA1 algorithm */ -/* Note: copied from FreeBSD source code, RELENG 6, sys/opencrypto/cryptodev.h*/ -#define HMAC_IPAD_VAL 0x36 -#define HMAC_OPAD_VAL 0x5C - -/* HMAC values */ -#define SHA1_HMAC_BLOCK_LEN (64/8) -#define SHA2_512_HMAC_BLOCK_LEN (128/8) - -/* Maximum HMAC block length */ -#define HMAC_MAX_BLOCK_LEN SHA2_512_HMAC_BLOCK_LEN -/* */ -/******************************************************************************/ - - -/******************************************************************************/ -/* Internal macros */ -/* */ -/* Shortcuts used in HMAC-SHA1 */ -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c */ -#define H(n) (ctxt->h.b32[(n)]) -#define COUNT (ctxt->count) -#define BCOUNT (ctxt->c.b64[0] / 8) -#define W(n) (ctxt->m.b32[(n)]) - -static UINT32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 }; -#define K(t) _K[(t) / 20] - -#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d))) -#define F1(b, c, d) (((b) ^ (c)) ^ (d)) -#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) -#define F3(b, c, d) (((b) ^ (c)) ^ (d)) - -#define S(n, x) (((x) << (n)) | ((x) >> (32 - n))) - -#define PUTPAD(x) { \ - ctxt->m.b8[(COUNT % 64)] = (x); \ - COUNT++; \ - COUNT %= 64; \ - if (COUNT % 64 == 0) \ - sha1_step(ctxt); \ -} -/* */ -/******************************************************************************/ - -/******************************************************************************/ -/* Function prototypes used internally */ -/* */ -void sha1_pad( - SHA1_CONTEXT *ctxt) - ; - -static void sha1_step( - SHA1_CONTEXT *ctxt) - ; - -/* */ -/******************************************************************************/ - -/* TODO: check for little-endian, big-endian */ - -/******************************************************************************/ -/* Function definitions */ -/* */ -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c, 176 */ -void sha1_init( - SHA1_CONTEXT *ctxt) -{ - memset(ctxt, 0, sizeof(SHA1_CONTEXT)); - H(0) = 0x67452301; - H(1) = 0xefcdab89; - H(2) = 0x98badcfe; - H(3) = 0x10325476; - H(4) = 0xc3d2e1f0; -} - -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c, 223 */ -void sha1_loop( - SHA1_CONTEXT *ctxt, - const UCHAR *input, - size_t len) -{ - size_t gaplen; - size_t gapstart; - size_t off; - size_t copysiz; - - off = 0; - - while (off < len) { - gapstart = COUNT % 64; - gaplen = 64 - gapstart; - - copysiz = (gaplen < len - off) ? gaplen : len - off; - memcpy(&ctxt->m.b8[gapstart], input+off, copysiz); - COUNT += copysiz; - COUNT %= 64; - ctxt->c.b64[0] += copysiz * 8; - if (COUNT % 64 == 0) - sha1_step(ctxt); - off += copysiz; - } -} - -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c, 91 */ -static void sha1_step( - SHA1_CONTEXT *ctxt) -{ - UINT32 a, b, c, d, e; - size_t t, s; - UINT32 tmp; -#ifdef LITTLE_ENDIAN - SHA1_CONTEXT tctxt; - memcpy(&tctxt.m.b8[0], &ctxt->m.b8[0], 64); - ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2]; - ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0]; - ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6]; - ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4]; - ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10]; - ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8]; - ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14]; - ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12]; - ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18]; - ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16]; - ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22]; - ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20]; - ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26]; - ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24]; - ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30]; - ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28]; - ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34]; - ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32]; - ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38]; - ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36]; - ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42]; - ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40]; - ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46]; - ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44]; - ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50]; - ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48]; - ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54]; - ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52]; - ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58]; - ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56]; - ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62]; - ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60]; -#else -#warning BIG ENDIAN 1 -#endif - - a = H(0); b = H(1); c = H(2); d = H(3); e = H(4); - - for (t = 0; t < 20; t++) { - s = t & 0x0f; - if (t >= 16) { - W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); - } - tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t); - e = d; d = c; c = S(30, b); b = a; a = tmp; - } - for (t = 20; t < 40; t++) { - s = t & 0x0f; - W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); - tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t); - e = d; d = c; c = S(30, b); b = a; a = tmp; - } - for (t = 40; t < 60; t++) { - s = t & 0x0f; - W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); - tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t); - e = d; d = c; c = S(30, b); b = a; a = tmp; - } - for (t = 60; t < 80; t++) { - s = t & 0x0f; - W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); - tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t); - e = d; d = c; c = S(30, b); b = a; a = tmp; - } - - H(0) = H(0) + a; - H(1) = H(1) + b; - H(2) = H(2) + c; - H(3) = H(3) + d; - H(4) = H(4) + e; - - memset(&ctxt->m.b8[0], 0, 64); -} - -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c, 188 */ -void sha1_pad( - SHA1_CONTEXT *ctxt) -{ - size_t padlen; /*pad length in bytes*/ - size_t padstart; - - PUTPAD(0x80); - - padstart = COUNT % 64; - padlen = 64 - padstart; - if (padlen < 8) { - memset(&ctxt->m.b8[padstart], 0, padlen); - COUNT += padlen; - COUNT %= 64; - sha1_step(ctxt); - padstart = COUNT % 64; /* should be 0 */ - padlen = 64 - padstart; /* should be 64 */ - } - memset(&ctxt->m.b8[padstart], 0, padlen - 8); - COUNT += (padlen - 8); - COUNT %= 64; -#ifdef BIG_ENDIAN -#warning BIG ENDIAN 2 - - PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]); - PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]); - PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]); - PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]); -#else - PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]); - PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]); - PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]); - PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]); -#endif -} - -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.c, 251 */ -void sha1_result( - SHA1_CONTEXT *ctxt, - UCHAR *digest0) -{ - UINT8 *digest; - - digest = (UINT8 *)digest0; - sha1_pad(ctxt); - -#ifdef BIG_ENDIAN -#warning BIG ENDIAN 3 - bcopy(&ctxt->h.b8[0], digest, 20); -#else - digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2]; - digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0]; - digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6]; - digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4]; - digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10]; - digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8]; - digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14]; - digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12]; - digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18]; - digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16]; -#endif -} - -void AirPDcapAlgHmacSha1( - const UCHAR *key_len, - const size_t keylen, - UCHAR *buffer, - const size_t digest_len, - UCHAR digest[20]) -{ - //INT i; - //SHA1_CONTEXT ictx; - //SHA1_CONTEXT octx; - //UCHAR tmpkey[64]; - //UCHAR tmp[HMAC_MAX_BLOCK_LEN]; - - //memset(tmpkey, 0, sizeof(tmpkey)); - //memset(tmp, 0, sizeof(tmp)); - - //memcpy(tmpkey, key_len, keylen); - - //for(i = 0; i<keylen; i++) - // tmpkey[i] ^= HMAC_IPAD_VAL; - - //sha1_init(&ictx); - //sha1_loop(&ictx, tmpkey, keylen); - //sha1_loop(&ictx, tmp, HMAC_MAX_BLOCK_LEN-keylen); - - //for(i = 0; i<keylen; i++) - // tmpkey[i] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL); - - //sha1_init(&octx); - //sha1_loop(&octx, tmpkey, keylen); - //sha1_loop(&octx, tmp, HMAC_MAX_BLOCK_LEN-keylen); - - //for(i = 0; i<keylen; i++) - // tmpkey[i] ^= HMAC_OPAD_VAL; - - //sha1_loop(&ictx, buffer, digest_len); - //sha1_result(&ictx, digest); - //sha1_loop(&octx, digest, 20); - //sha1_result(&octx, digest); - - INT i; - SHA1_CONTEXT ictx, octx; - UCHAR tmpkey[64]; - UCHAR tmp[20]; - - memset(tmpkey, 0, sizeof(tmpkey)); - memcpy(tmpkey, key_len, keylen); - - for(i = 0; i<64; i++) - tmpkey[i] ^= HMAC_IPAD_VAL; - - sha1_init(&ictx); - sha1_loop(&ictx, tmpkey, 64); - - for(i = 0; i<64; i++) - tmpkey[i] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL); - - sha1_init(&octx); - sha1_loop(&octx, tmpkey, 64); - - sha1_loop(&ictx, buffer, digest_len); - sha1_result(&ictx, tmp); - sha1_loop(&octx, tmp, 20); - sha1_result(&octx, digest); - -} -/* */ -/******************************************************************************/ diff --git a/epan/crypt/airpdcap_sha1.h b/epan/crypt/airpdcap_sha1.h deleted file mode 100644 index 6015b525ce..0000000000 --- a/epan/crypt/airpdcap_sha1.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _AIRPDCAP_SHA1 -#define _AIRPDCAP_SHA1 - -/******************************************************************************/ -/* File includes */ -/* */ -#include "airpdcap_interop.h" -/* */ -/* */ -/******************************************************************************/ - -/******************************************************************************/ -/* Definitions */ -/* */ -/* Maximum HMAC block length */ -#define HMAC_MAX_BLOCK_LEN SHA2_512_HMAC_BLOCK_LEN -#define HMAC_IPAD_VAL 0x36 -#define HMAC_OPAD_VAL 0x5C -/* */ -/******************************************************************************/ - -typedef /******************************************************************************/ -/* Type definitions */ -/* */ -/* Note: copied from FreeBSD source code, RELENG 6, sys/crypto/sha1.h, 41 */ -struct _SHA1_CONTEXT { - union { - UCHAR b8[20]; - UINT b32[5]; - } h; - union { - UCHAR b8[8]; - ULONGLONG b64[1]; - } c; - union { - UCHAR b8[64]; - UINT b32[16]; - } m; - size_t count; -} SHA1_CONTEXT; -/* */ -/******************************************************************************/ - -/******************************************************************************/ -/* External function prototypes declarations */ -/* */ -/* */ -/******************************************************************************/ -void sha1_init(SHA1_CONTEXT *ctxt); -void sha1_result(SHA1_CONTEXT *ctxt, UCHAR *digest0); -void sha1_loop(SHA1_CONTEXT *ctxt, const UCHAR *input, size_t len); - -#endif diff --git a/epan/crypt/airpdcap_system.h b/epan/crypt/airpdcap_system.h index 52fc57d3fe..1842f984ca 100644 --- a/epan/crypt/airpdcap_system.h +++ b/epan/crypt/airpdcap_system.h @@ -312,14 +312,6 @@ extern INT AirPDcapTkipDecrypt( UCHAR TA[AIRPDCAP_MAC_LEN], UCHAR TK[AIRPDCAP_TK_LEN]) ; -extern void AirPDcapAlgHmacSha1( - const UCHAR *key_len, - const size_t keylen, - UCHAR *buffer, - const size_t digest_len, - UCHAR digest[20]) - ; - #ifdef __cplusplus } diff --git a/epan/sha1.c b/epan/crypt/crypt-sha1.c index a021386dbc..90e7044dc9 100644 --- a/epan/sha1.c +++ b/epan/crypt/crypt-sha1.c @@ -27,7 +27,7 @@ #include <string.h> #include <glib.h> -#include <epan/sha1.h> +#include <epan/crypt/crypt-sha1.h> #define GET_UINT32(n,b,i) \ { \ @@ -301,28 +301,28 @@ void sha1_hmac( const guint8 *key, guint keylen, const guint8 *buf, guint buflen guint8 k_ipad[64]; guint8 k_opad[64]; guint8 tmpbuf[20]; - + memset( k_ipad, 0x36, 64 ); memset( k_opad, 0x5C, 64 ); - + for( i = 0; i < keylen; i++ ) { if( i >= 64 ) break; - + k_ipad[i] ^= key[i]; k_opad[i] ^= key[i]; } - + sha1_starts( &ctx ); sha1_update( &ctx, k_ipad, 64 ); sha1_update( &ctx, buf, buflen ); sha1_finish( &ctx, tmpbuf ); - + sha1_starts( &ctx ); sha1_update( &ctx, k_opad, 64 ); sha1_update( &ctx, tmpbuf, 20 ); sha1_finish( &ctx, digest ); - + memset( k_ipad, 0, 64 ); memset( k_opad, 0, 64 ); memset( tmpbuf, 0, 20 ); @@ -339,7 +339,7 @@ void sha1_hmac( const guint8 *key, guint keylen, const guint8 *buf, guint buflen * those are the standard FIPS-180-1 test vectors */ -static char *msg[] = +static char *msg[] = { "abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", diff --git a/epan/sha1.h b/epan/crypt/crypt-sha1.h index 5abe259113..0f0e793888 100644 --- a/epan/sha1.h +++ b/epan/crypt/crypt-sha1.h @@ -24,8 +24,8 @@ * References: http://www.ietf.org/rfc/rfc3174.txt?number=3174 */ -#ifndef _SHA1_H -#define _SHA1_H +#ifndef _CRYPT_SHA1_H +#define _CRYPT_SHA1_H typedef struct @@ -42,4 +42,4 @@ void sha1_finish( sha1_context *ctx, guint8 digest[20] ); void sha1_hmac( const guint8 *key, guint keylen, const guint8 *buf, guint buflen, guint8 digest[20] ); -#endif /* sha1.h */ +#endif /* crypt-sha1.h */ diff --git a/epan/dissectors/packet-cms.c b/epan/dissectors/packet-cms.c index a5b6a3bc5f..bf3ee445cf 100644 --- a/epan/dissectors/packet-cms.c +++ b/epan/dissectors/packet-cms.c @@ -1,6 +1,6 @@ /* Do not modify this file. */ /* It is created automatically by the ASN.1 to Wireshark dissector compiler */ -/* .\packet-cms.c */ +/* ./packet-cms.c */ /* ../../tools/asn2wrs.py -b -e -p cms -c cms.cnf -s packet-cms-template CryptographicMessageSyntax.asn */ /* Input file: packet-cms-template.c */ @@ -48,7 +48,7 @@ #include "packet-x509af.h" #include "packet-x509if.h" -#include <epan/sha1.h> +#include <epan/crypt/crypt-sha1.h> #include <epan/crypt/crypt-md5.h> #define PNAME "Cryptographic Message Syntax" @@ -453,7 +453,7 @@ dissect_cms_T_eContent(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, pac pdu_offset = get_ber_identifier(tvb, pdu_offset, &class, &pc, &tag); content_offset = pdu_offset = get_ber_length(tree, tvb, pdu_offset, &len, &ind); pdu_offset = call_ber_oid_callback(object_identifier_id, tvb, pdu_offset, pinfo, top_tree ? top_tree : tree); - + content_tvb = tvb_new_subset(tvb, content_offset, len, -1); @@ -494,7 +494,7 @@ dissect_cms_T_attrType(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, pac if(object_identifier_id) { name = get_oid_str_name(object_identifier_id); - proto_item_append_text(tree, " (%s)", name ? name : object_identifier_id); + proto_item_append_text(tree, " (%s)", name ? name : object_identifier_id); } @@ -1487,14 +1487,14 @@ dissect_cms_MessageDigest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, NULL); - + pi = get_ber_last_created_item(); /* move past TLV */ old_offset = get_ber_identifier(tvb, old_offset, NULL, NULL, NULL); old_offset = get_ber_length(tree, tvb, old_offset, NULL, NULL); - if(content_tvb) + if(content_tvb) cms_verify_msg_digest(pi, content_tvb, x509af_get_last_algorithm_id(), tvb, old_offset); diff --git a/epan/dissectors/packet-cms.h b/epan/dissectors/packet-cms.h index 5e634221e3..c188ad7029 100644 --- a/epan/dissectors/packet-cms.h +++ b/epan/dissectors/packet-cms.h @@ -1,6 +1,6 @@ /* Do not modify this file. */ /* It is created automatically by the ASN.1 to Wireshark dissector compiler */ -/* .\packet-cms.h */ +/* ./packet-cms.h */ /* ../../tools/asn2wrs.py -b -e -p cms -c cms.cnf -s packet-cms-template CryptographicMessageSyntax.asn */ /* Input file: packet-cms-template.h */ diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c index 398034ce77..e4080caf62 100644 --- a/epan/dissectors/packet-snmp.c +++ b/epan/dissectors/packet-snmp.c @@ -104,7 +104,7 @@ #include "packet-snmp.h" #include "format-oid.h" -#include <epan/sha1.h> +#include <epan/crypt/crypt-sha1.h> #include <epan/crypt/crypt-md5.h> #include <epan/expert.h> #include <epan/report_err.h> @@ -1192,14 +1192,14 @@ static void renew_ue_cache(void) { localized_ues = NULL; unlocalized_ues = NULL; - + for(a = ue_assocs; a->user.userName.data; a++) { if (a->engine.data) { CACHE_INSERT(localized_ues,a); } else { CACHE_INSERT(unlocalized_ues,a); } - + } } } @@ -1208,10 +1208,10 @@ static void renew_ue_cache(void) { static snmp_ue_assoc_t* localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len ) { snmp_ue_assoc_t* n = se_memdup(o,sizeof(snmp_ue_assoc_t)); guint key_size = n->user.authModel->key_size; - + n->engine.data = se_memdup(engine,engine_len); n->engine.len = engine_len; - + n->user.authKey.data = se_alloc(key_size); n->user.authKey.len = key_size; n->user.authModel->pass2key(n->user.authPassword.data, @@ -1247,22 +1247,22 @@ static snmp_ue_assoc_t* get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb) guint8* given_username; guint given_engine_len; guint8* given_engine; - + if ( ! (localized_ues || unlocalized_ues ) ) return NULL; if (! ( user_tvb && engine_tvb ) ) return NULL; - + given_username_len = tvb_length_remaining(user_tvb,0); given_username = ep_tvb_memdup(user_tvb,0,-1); given_engine_len = tvb_length_remaining(engine_tvb,0); given_engine = ep_tvb_memdup(engine_tvb,0,-1); - + for (a = localized_ues; a; a = a->next) { if ( localized_match(a, given_username, given_username_len, given_engine, given_engine_len) ) { return a; } } - + for (a = unlocalized_ues; a; a = a->next) { if ( unlocalized_match(a, given_username, given_username_len) ) { snmp_ue_assoc_t* n = localize_ue( a, given_engine, given_engine_len ); @@ -1270,21 +1270,21 @@ static snmp_ue_assoc_t* get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb) return n; } } - + return NULL; } static void destroy_ue_assocs(snmp_ue_assoc_t* assocs) { if (assocs) { snmp_ue_assoc_t* a; - + for(a = assocs; a->user.userName.data; a++) { g_free(a->user.userName.data); if (a->user.authKey.data) g_free(a->user.authKey.data); if (a->user.privKey.data) g_free(a->user.privKey.data); if (a->engine.data) g_free(a->engine.data); } - + g_free(ue_assocs); } } @@ -1301,31 +1301,31 @@ gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* ca guint start; guint end; guint i; - + if (!p->auth_tvb) { *error = "No Authenticator"; - return FALSE; + return FALSE; } - + key = p->user_assoc->user.authKey.data; key_len = p->user_assoc->user.authKey.len; - + if (! key ) { *error = "User has no authKey"; return FALSE; } - - + + auth_len = tvb_length_remaining(p->auth_tvb,0); - + if (auth_len != 12) { *error = "Authenticator length wrong"; return FALSE; } - + msg_len = tvb_length_remaining(p->msg_tvb,0); msg = ep_tvb_memdup(p->msg_tvb,0,msg_len); - + auth = ep_tvb_memdup(p->auth_tvb,0,auth_len); @@ -1338,7 +1338,7 @@ gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* ca } md5_hmac(msg, msg_len, key, key_len, calc_auth); - + if (calc_auth_p) *calc_auth_p = calc_auth; if (calc_auth_len_p) *calc_auth_len_p = 12; @@ -1357,47 +1357,47 @@ gboolean snmp_usm_auth_sha1(snmp_usm_params_t* p _U_, guint8** calc_auth_p, guin guint start; guint end; guint i; - + if (!p->auth_tvb) { *error = "No Authenticator"; - return FALSE; + return FALSE; } - + key = p->user_assoc->user.authKey.data; key_len = p->user_assoc->user.authKey.len; - + if (! key ) { *error = "User has no authKey"; return FALSE; } - - + + auth_len = tvb_length_remaining(p->auth_tvb,0); - - + + if (auth_len != 12) { *error = "Authenticator length wrong"; return FALSE; } - + msg_len = tvb_length_remaining(p->msg_tvb,0); msg = ep_tvb_memdup(p->msg_tvb,0,msg_len); auth = ep_tvb_memdup(p->auth_tvb,0,auth_len); - + start = p->auth_offset - p->start_offset; end = start + auth_len; - + /* fill the authenticator with zeros */ for ( i = start ; i < end ; i++ ) { msg[i] = '\0'; } - + sha1_hmac(key, key_len, msg, msg_len, calc_auth); - + if (calc_auth_p) *calc_auth_p = calc_auth; if (calc_auth_len_p) *calc_auth_len_p = 12; - + return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE; } @@ -1405,7 +1405,7 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U #ifdef HAVE_LIBGCRYPT gcry_error_t err; gcry_cipher_hd_t hd = NULL; - + guint8* cleartext; guint8* des_key = p->user_assoc->user.privKey.data; /* first 8 bytes */ guint8* pre_iv = &(p->user_assoc->user.privKey.data[8]); /* last 8 bytes */ @@ -1416,14 +1416,14 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U tvbuff_t* clear_tvb; guint8 iv[8]; guint i; - - + + salt_len = tvb_length_remaining(p->priv_tvb,0); - + if (salt_len != 8) { *error = "decryptionError: msgPrivacyParameters lenght != 8"; return NULL; - } + } salt = ep_tvb_memdup(p->priv_tvb,0,salt_len); @@ -1440,29 +1440,29 @@ tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U *error = "decryptionError: the length of the encrypted data is not a mutiple of 8 octets"; return NULL; } - + cryptgrm = ep_tvb_memdup(encryptedData,0,-1); cleartext = ep_alloc(cryptgrm_len); - + err = gcry_cipher_open(&hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_CBC, 0); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setiv(hd, iv, 8); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setkey(hd,des_key,8); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + gcry_cipher_close(hd); - + clear_tvb = tvb_new_real_data(cleartext, cryptgrm_len, cryptgrm_len); - + return clear_tvb; - + on_gcry_error: *error = (void*)gpg_strerror(err); if (hd) gcry_cipher_close(hd); @@ -1477,7 +1477,7 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U #ifdef HAVE_LIBGCRYPT gcry_error_t err; gcry_cipher_hd_t hd = NULL; - + guint8* cleartext; guint8* aes_key = p->user_assoc->user.privKey.data; /* first 16 bytes */ guint8 iv[16]; @@ -1487,12 +1487,12 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U tvbuff_t* clear_tvb; priv_len = tvb_length_remaining(p->priv_tvb,0); - + if (priv_len != 8) { *error = "decryptionError: msgPrivacyParameters lenght != 8"; return NULL; - } - + } + iv[0] = (p->boots & 0xff000000) >> 24; iv[1] = (p->boots & 0x00ff0000) >> 16; iv[2] = (p->boots & 0x0000ff00) >> 8; @@ -1502,30 +1502,30 @@ tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U iv[6] = (p->time & 0x0000ff00) >> 8; iv[7] = (p->time & 0x000000ff); tvb_memcpy(p->priv_tvb,&(iv[8]),0,8); - + cryptgrm_len = tvb_length_remaining(encryptedData,0); cryptgrm = ep_tvb_memdup(encryptedData,0,-1); - + cleartext = ep_alloc(cryptgrm_len); - + err = gcry_cipher_open(&hd, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CFB, 0); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setiv(hd, iv, 16); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_setkey(hd,aes_key,16); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len); if (err != GPG_ERR_NO_ERROR) goto on_gcry_error; - + gcry_cipher_close(hd); - + clear_tvb = tvb_new_real_data(cleartext, cryptgrm_len, cryptgrm_len); - + return clear_tvb; - + on_gcry_error: *error = (void*)gpg_strerror(err); if (hd) gcry_cipher_close(hd); @@ -1547,29 +1547,29 @@ gboolean check_ScopedPdu(tvbuff_t* tvb) { offset = get_ber_identifier(tvb, 0, &class, &pc, &tag); offset = get_ber_length(NULL, tvb, offset, NULL, NULL); - + if ( ! (((class!=BER_CLASS_APP) && (class!=BER_CLASS_PRI) ) && ( (!pc) || (class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_ENUMERATED) ) )) return FALSE; if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)) return TRUE; - + hoffset = offset; offset = get_ber_identifier(tvb, offset, &class, &pc, &tag); offset = get_ber_length(NULL, tvb, offset, &len, NULL); eoffset = offset + len; - + if (eoffset <= hoffset) return FALSE; - + if ((class!=BER_CLASS_APP)&&(class!=BER_CLASS_PRI)) if( (class!=BER_CLASS_UNI) ||((tag<BER_UNI_TAG_NumericString)&&(tag!=BER_UNI_TAG_OCTETSTRING)&&(tag!=BER_UNI_TAG_UTF8String)) ) return FALSE; - + return TRUE; - + } @@ -3238,7 +3238,7 @@ dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo, usm_p.boots = 0; usm_p.time = 0; usm_p.authOK = FALSE; - + /* * This will throw an exception if we don't have any data left. * That's what we want. (See "tcp_dissect_pdus()", which is @@ -3471,7 +3471,7 @@ dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* MD5 Password to Key Algorithm - from RFC 3414 A.2.1 + from RFC 3414 A.2.1 */ void snmp_usm_password_to_key_md5(const guint8 *password, guint passwordlen, @@ -3484,7 +3484,7 @@ void snmp_usm_password_to_key_md5(const guint8 *password, guint32 count = 0, i; guint8 key1[16]; md5_init(&MD); /* initialize MD5 */ - + /**********************************************/ /* Use while loop until we've done 1 Megabyte */ /**********************************************/ @@ -3501,31 +3501,31 @@ void snmp_usm_password_to_key_md5(const guint8 *password, count += 64; } md5_finish(&MD, key1); /* tell MD5 we're done */ - + /*****************************************************/ /* Now localize the key with the engineID and pass */ /* through MD5 to produce final key */ /* May want to ensure that engineLength <= 32, */ /* otherwise need to use a buffer larger than 64 */ /*****************************************************/ - + md5_init(&MD); md5_append(&MD, key1, 16); md5_append(&MD, engineID, engineLength); md5_append(&MD, key1, 16); md5_finish(&MD, key); - + return; } - - + + /* SHA1 Password to Key Algorithm COPIED from RFC 3414 A.2.2 */ -void snmp_usm_password_to_key_sha1(const guint8 *password, +void snmp_usm_password_to_key_sha1(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, @@ -3534,9 +3534,9 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, guint8 *cp, password_buf[72]; guint32 password_index = 0; guint32 count = 0, i; - + sha1_starts(&SH); /* initialize SHA */ - + /**********************************************/ /* Use while loop until we've done 1 Megabyte */ /**********************************************/ @@ -3553,7 +3553,7 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, count += 64; } sha1_finish(&SH, key); - + /*****************************************************/ /* Now localize the key with the engineID and pass */ /* through SHA to produce final key */ @@ -3563,14 +3563,14 @@ void snmp_usm_password_to_key_sha1(const guint8 *password, memcpy(password_buf, key, 20); memcpy(password_buf+20, engineID, engineLength); memcpy(password_buf+20+engineLength, key, 20); - + sha1_starts(&SH); sha1_update(&SH, password_buf, 40+engineLength); sha1_finish(&SH, key); return; } - + static void process_prefs(void) { @@ -3625,12 +3625,12 @@ process_prefs(void) read_configs(); mibs_loaded = TRUE; #endif /* HAVE_NET_SNMP */ - + if ( g_str_equal(ue_assocs_filename_loaded,ue_assocs_filename) ) return; ue_assocs_filename_loaded = ue_assocs_filename; - + if (ue_assocs) destroy_ue_assocs(ue_assocs); - + if ( *ue_assocs_filename ) { gchar* err = load_snmp_users_file(ue_assocs_filename,&ue_assocs); if (err) report_failure("Error while loading SNMP's users file:\n%s",err); @@ -3638,18 +3638,18 @@ process_prefs(void) ue_assocs = NULL; } } - - - + + + /*--- proto_register_snmp -------------------------------------------*/ -void proto_register_snmp(void) { +void proto_register_snmp(void) { #if defined(_WIN32) && defined(HAVE_NET_SNMP) char *mib_path; int mib_path_len; #define MIB_PATH_APPEND "snmp\\mibs" #endif gchar *tmp_mib_modules; - + /* List of fields */ static hf_register_info hf[] = { { &hf_snmp_v3_flags_auth, @@ -3697,7 +3697,7 @@ void proto_register_snmp(void) { { &hf_snmp_decryptedPDU, { "Decrypted ScopedPDU", "snmp.decrypted_pdu", FT_BYTES, BASE_HEX, NULL, 0, "Decrypted PDU", HFILL }}, - + /*--- Included file: packet-snmp-hfarr.c ---*/ #line 1 "packet-snmp-hfarr.c" @@ -4046,7 +4046,7 @@ void proto_register_snmp(void) { &ett_encryptedPDU, &ett_decrypted, &ett_authParameters, - + /*--- Included file: packet-snmp-ettarr.c ---*/ #line 1 "packet-snmp-ettarr.c" @@ -4155,11 +4155,11 @@ void proto_register_snmp(void) { "USMuserTable file", "The filename of the user table used for authentication and decryption", &ue_assocs_filename); - + variable_oid_dissector_table = register_dissector_table("snmp.variable_oid", "SNMP Variable OID", FT_STRING, BASE_NONE); - + register_init_routine(renew_ue_cache); } diff --git a/epan/sigcomp-udvm.c b/epan/sigcomp-udvm.c index ce29f2bc40..d1d0259e59 100644 --- a/epan/sigcomp-udvm.c +++ b/epan/sigcomp-udvm.c @@ -13,12 +13,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -43,7 +43,7 @@ #include "strutil.h" #include "sigcomp-udvm.h" #include "sigcomp_state_hdlr.h" -#include "sha1.h" +#include "crypt/crypt-sha1.h" #include "crc16.h" #include "except.h" @@ -117,14 +117,14 @@ static int decode_udvm_literal_operand(guint8 *buff,guint operand_address, guint static int dissect_udvm_reference_operand(guint8 *buff,guint operand_address, guint16 *value, guint *result_dest); static int decode_udvm_multitype_operand(guint8 *buff,guint operand_address,guint16 *value); static int decode_udvm_address_operand(guint8 *buff,guint operand_address, guint16 *value,guint current_address); -static int decomp_dispatch_get_bits(tvbuff_t *message_tvb,proto_tree *udvm_tree,guint8 bit_order, +static int decomp_dispatch_get_bits(tvbuff_t *message_tvb,proto_tree *udvm_tree,guint8 bit_order, guint8 *buff,guint16 *old_input_bit_order, guint16 *remaining_bits, guint16 *input_bits, guint *input_address, guint16 length, guint16 *result_code,guint msg_end); tvbuff_t* decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet_info *pinfo, - proto_tree *udvm_tree, gint udvm_mem_dest, + proto_tree *udvm_tree, gint udvm_mem_dest, gint print_flags, gint hf_id, gint header_len, gint byte_code_state_len, gint byte_code_id_len, @@ -257,7 +257,7 @@ decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet /* UDVM memory must be initialised to zero */ memset(buff, 0, UDVM_MEMORY_SIZE); - /* Set initial UDVM data + /* Set initial UDVM data * The first 32 bytes of UDVM memory are then initialized to special * values as illustrated in Figure 5. * @@ -300,7 +300,7 @@ decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet cycles_per_bit = buff[2] << 8; cycles_per_bit = cycles_per_bit | buff[3]; - /* + /* * maximum_UDVM_cycles = (8 * n + 1000) * cycles_per_bit */ maximum_UDVM_cycles = (( 8 * (header_len + msg_end) ) + 1000) * cycles_per_bit; @@ -328,7 +328,7 @@ decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet current_address = udvm_start_ip; input_address = 0; operand_address = 0; - + proto_tree_add_text(udvm_tree, bytecode_tvb, offset, 1,"UDVM EXECUTION STARTED at Address: %u Message size %u", current_address, msg_end); @@ -354,12 +354,12 @@ execute_next_instruction: /* At least something got decompressed, show it */ decomp_tvb = tvb_new_real_data(out_buff,output_address,output_address); /* Arrange that the allocated packet data copy be freed when the - * tvbuff is freed. + * tvbuff is freed. */ tvb_set_free_cb( decomp_tvb, g_free ); /* Add the tvbuff to the list of tvbuffs to which the tvbuff we * were handed refers, so it'll get cleaned up when that tvbuff - * is cleaned up. + * is cleaned up. */ tvb_set_child_real_data_tvbuff(message_tvb,decomp_tvb); add_new_data_source(pinfo, decomp_tvb, "Decompressed SigComp message(Incomplete)"); @@ -384,7 +384,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -400,14 +400,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 & operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -426,7 +426,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -442,14 +442,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 | operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -477,14 +477,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 ^ 0xffff; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -502,7 +502,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -518,14 +518,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 << operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -543,7 +543,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -559,14 +559,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 >> operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; case SIGCOMP_INSTR_ADD: /* 6 ADD ($operand_1, %operand_2) */ @@ -583,7 +583,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -599,14 +599,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 + operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; case SIGCOMP_INSTR_SUBTRACT: /* 7 SUBTRACT ($operand_1, %operand_2) */ @@ -623,7 +623,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -639,14 +639,14 @@ execute_next_instruction: /* execute the instruction */ result = operand_1 - operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -664,7 +664,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -677,7 +677,7 @@ execute_next_instruction: "Addr: %u ## MULTIPLY (operand_1=%u, operand_2=%u)", current_address, operand_1, operand_2); } - /* + /* * execute the instruction * MULTIPLY (m, n) := m * n (modulo 2^16) */ @@ -687,14 +687,14 @@ execute_next_instruction: } result = operand_1 * operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -712,7 +712,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -725,7 +725,7 @@ execute_next_instruction: "Addr: %u ## DIVIDE (operand_1=%u, operand_2=%u)", current_address, operand_1, operand_2); } - /* + /* * execute the instruction * DIVIDE (m, n) := floor(m / n) * Decompression failure occurs if a DIVIDE or REMAINDER instruction @@ -737,14 +737,14 @@ execute_next_instruction: } result = operand_1 / operand_2; lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; @@ -762,7 +762,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u operand_1 %u", operand_address, operand_1); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %operand_2*/ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &operand_2); if (show_instr_detail_level == 2 ){ @@ -775,7 +775,7 @@ execute_next_instruction: "Addr: %u ## REMAINDER (operand_1=%u, operand_2=%u)", current_address, operand_1, operand_2); } - /* + /* * execute the instruction * REMAINDER (m, n) := m - n * floor(m / n) * Decompression failure occurs if a DIVIDE or REMAINDER instruction @@ -787,14 +787,14 @@ execute_next_instruction: } result = operand_1 - operand_2 * (operand_1 / operand_2); lsb = result & 0xff; - msb = result >> 8; + msb = result >> 8; buff[result_dest] = msb; buff[result_dest+1] = lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1," Loading result %u at %u", result, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; goto execute_next_instruction; break; case SIGCOMP_INSTR_SORT_ASCENDING: /* 11 SORT-ASCENDING (%start, %n, %k) */ @@ -838,7 +838,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u position %u", operand_address, position); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -854,7 +854,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u $destination %u", operand_address, ref_destination); } - current_address = next_operand_address; + current_address = next_operand_address; used_udvm_cycles = used_udvm_cycles + 1 + length; n = 0; @@ -892,7 +892,7 @@ execute_next_instruction: sha1_finish( &ctx, sha1_digest_buf ); - k = ref_destination; + k = ref_destination; for ( n=0; n< STATE_BUFFER_SIZE; n++ ) { @@ -929,7 +929,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u Address %u", operand_address, address); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %value */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &value); if (show_instr_detail_level == 1) @@ -973,7 +973,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u Address %u", operand_address, address); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* #n */ next_operand_address = decode_udvm_literal_operand(buff,operand_address, &n); @@ -987,7 +987,7 @@ execute_next_instruction: "Addr: %u ## MULTILOAD (%%address=%u, #n=%u, value_0, ..., value_%d)", current_address, address, n, n-1); } - operand_address = next_operand_address; + operand_address = next_operand_address; used_udvm_cycles = used_udvm_cycles + 1 + n; while ( n > 0) { n = n - 1; @@ -1010,13 +1010,13 @@ execute_next_instruction: operand_address, value, address, value, value); } address = address + 2; - operand_address = next_operand_address; + operand_address = next_operand_address; } current_address = next_operand_address; goto execute_next_instruction; break; - + case SIGCOMP_INSTR_PUSH: /* 16 PUSH (%value) */ if (show_instr_detail_level == 2){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1, @@ -1036,11 +1036,11 @@ execute_next_instruction: "Addr: %u ## PUSH (value=%u)", current_address, value); } - current_address = next_operand_address; + current_address = next_operand_address; - /* Push the value address onto the stack */ + /* Push the value address onto the stack */ stack_location = (buff[70] << 8) | buff[71]; - stack_fill = (buff[stack_location] << 8) + stack_fill = (buff[stack_location] << 8) | buff[(stack_location+1) & 0xFFFF]; address = (stack_location + stack_fill * 2 + 2) & 0xFFFF; @@ -1052,7 +1052,7 @@ execute_next_instruction: if (stack_location >= UDVM_MEMORY_SIZE - 1) goto decompression_failure; - + stack_fill = (stack_fill + 1) & 0xFFFF; buff[stack_location] = (stack_fill >> 8) & 0x00FF; buff[(stack_location+1) & 0xFFFF] = stack_fill & 0x00FF; @@ -1081,11 +1081,11 @@ execute_next_instruction: "Addr: %u ## POP (address=%u)", current_address, destination); } - current_address = next_operand_address; + current_address = next_operand_address; - /* Pop value from the top of the stack */ + /* Pop value from the top of the stack */ stack_location = (buff[70] << 8) | buff[71]; - stack_fill = (buff[stack_location] << 8) + stack_fill = (buff[stack_location] << 8) | buff[(stack_location+1) & 0xFFFF]; if (stack_fill == 0) { @@ -1105,7 +1105,7 @@ execute_next_instruction: if (address >= UDVM_MEMORY_SIZE - 1) goto decompression_failure; - value = (buff[address] << 8) + value = (buff[address] << 8) | buff[(address+1) & 0xFFFF]; /* ... and store the popped value. */ @@ -1132,7 +1132,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u position %u", operand_address, position); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -1166,10 +1166,10 @@ execute_next_instruction: * Set k := m + 1 (modulo 2^16) * If k = byte_copy_right then set n := byte_copy_left, else set n := k * - */ + */ n = 0; - k = destination; + k = destination; byte_copy_right = buff[66] << 8; byte_copy_right = byte_copy_right | buff[67]; byte_copy_left = buff[64] << 8; @@ -1219,7 +1219,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u position %u", operand_address, position); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -1242,7 +1242,7 @@ execute_next_instruction: "Addr: %u ## COPY-LITERAL (position=%u, length=%u, $destination=%u)", current_address, position, length, destination); } - current_address = next_operand_address; + current_address = next_operand_address; /* @@ -1256,10 +1256,10 @@ execute_next_instruction: * Set k := m + 1 (modulo 2^16) * If k = byte_copy_right then set n := byte_copy_left, else set n := k * - */ + */ n = 0; - k = ref_destination; + k = ref_destination; byte_copy_right = buff[66] << 8; byte_copy_right = byte_copy_right | buff[67]; byte_copy_left = buff[64] << 8; @@ -1273,7 +1273,7 @@ execute_next_instruction: buff[k] = buff[position]; if (print_level_2 ){ proto_tree_add_text(udvm_tree, message_tvb, input_address, 1, - " Copying value: %u (0x%x) to Addr: %u", + " Copying value: %u (0x%x) to Addr: %u", buff[position], buff[position], k); } position = ( position + 1 ) & 0xffff; @@ -1299,7 +1299,7 @@ execute_next_instruction: used_udvm_cycles = used_udvm_cycles + 1 + length; goto execute_next_instruction; break; - + case SIGCOMP_INSTR_COPY_OFFSET: /* 20 COPY-OFFSET (%offset, %length, $destination) */ if (show_instr_detail_level == 2 ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1, @@ -1313,7 +1313,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u offset %u", operand_address, multy_offset); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -1337,13 +1337,13 @@ execute_next_instruction: "Addr: %u ## COPY-OFFSET (offset=%u, length=%u, $destination=%u)", current_address, multy_offset, length, result_dest); } - current_address = next_operand_address; + current_address = next_operand_address; /* Execute the instruction: * To derive the value of the position operand, starting at the memory * address specified by destination, the UDVM counts backwards a total * of offset memory addresses. - * + * * If the memory address specified in byte_copy_left is reached, the * next memory address is taken to be (byte_copy_right - 1) modulo 2^16. */ @@ -1392,10 +1392,10 @@ execute_next_instruction: * Set k := m + 1 (modulo 2^16) * If k = byte_copy_right then set n := byte_copy_left, else set n := k * - */ + */ n = 0; - k = ref_destination; + k = ref_destination; if (print_level_2 ){ proto_tree_add_text(udvm_tree, message_tvb, input_address, 1, " byte_copy_left = %u byte_copy_right = %u", byte_copy_left, byte_copy_right); @@ -1444,7 +1444,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u Address %u", operand_address, address); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length, */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -1459,7 +1459,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u start_value %u", operand_address, start_value); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %offset */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &multy_offset); @@ -1473,15 +1473,15 @@ execute_next_instruction: "Addr: %u ## MEMSET (address=%u, length=%u, start_value=%u, offset=%u)", current_address, address, length, start_value, multy_offset); } - current_address = next_operand_address; + current_address = next_operand_address; /* exetute the instruction * The sequence of values used by the MEMSET instruction is specified by * the following formula: - * + * * Seq[n] := (start_value + n * offset) modulo 256 */ n = 0; - k = address; + k = address; byte_copy_right = buff[66] << 8; byte_copy_right = byte_copy_right | buff[67]; byte_copy_left = buff[64] << 8; @@ -1629,18 +1629,18 @@ execute_next_instruction: "Addr: %u ## CALL (@address=%u)", current_address, at_address); } - current_address = next_operand_address; + current_address = next_operand_address; - /* Push the current address onto the stack */ + /* Push the current address onto the stack */ stack_location = (buff[70] << 8) | buff[71]; - stack_fill = (buff[stack_location] << 8) + stack_fill = (buff[stack_location] << 8) | buff[(stack_location+1) & 0xFFFF]; address = (stack_location + stack_fill * 2 + 2) & 0xFFFF; if (address >= UDVM_MEMORY_SIZE - 1) goto decompression_failure; buff[address] = (current_address >> 8) & 0x00FF; buff[(address+1) & 0xFFFF] = current_address & 0x00FF; - + stack_fill = (stack_fill + 1) & 0xFFFF; if (stack_location >= UDVM_MEMORY_SIZE - 1) goto decompression_failure; @@ -1662,9 +1662,9 @@ execute_next_instruction: current_address); } - /* Pop value from the top of the stack */ + /* Pop value from the top of the stack */ stack_location = (buff[70] << 8) | buff[71]; - stack_fill = (buff[stack_location] << 8) + stack_fill = (buff[stack_location] << 8) | buff[(stack_location+1) & 0xFFFF]; if (stack_fill == 0) { @@ -1679,7 +1679,7 @@ execute_next_instruction: buff[(stack_location+1) & 0xFFFF] = stack_fill & 0x00FF; address = (stack_location + stack_fill * 2 + 2) & 0xFFFF; - at_address = (buff[address] << 8) + at_address = (buff[address] << 8) | buff[(address+1) & 0xFFFF]; /* ... and set the PC to the popped value */ @@ -1695,7 +1695,7 @@ execute_next_instruction: * When a SWITCH instruction is encountered the UDVM reads the value of * j. It then continues instruction execution at the address specified * by address j. - * + * * Decompression failure occurs if j specifies a value of n or more, or * if the address lies beyond the overall UDVM memory size. */ @@ -1706,7 +1706,7 @@ execute_next_instruction: current_address); } operand_address = current_address + 1; - /* #n + /* #n * Number of addresses in the instruction */ next_operand_address = decode_udvm_literal_operand(buff,operand_address, &n); @@ -1714,7 +1714,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u n %u", operand_address, n); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %j */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &j); if (print_level_1 ){ @@ -1767,7 +1767,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u Value %u", operand_address, value); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %position */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &position); @@ -1775,7 +1775,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u position %u", operand_address, position); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &length); @@ -1794,7 +1794,7 @@ execute_next_instruction: } /* operand_value = (memory_address_of_instruction + D) modulo 2^16 */ used_udvm_cycles = used_udvm_cycles + 1 + length; - + n = 0; k = position; byte_copy_right = buff[66] << 8; @@ -1880,7 +1880,7 @@ execute_next_instruction: "Addr: %u ## INPUT-BYTES length=%u, destination=%u, @address=%u)", current_address, length, destination, at_address); } - /* execute the instruction TODO insert checks + /* execute the instruction TODO insert checks * RFC 3320 : * * 0 7 8 15 @@ -1893,7 +1893,7 @@ execute_next_instruction: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | stack_location | 70 - 71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * + * * Figure 7: Memory addresses of the UDVM registers * : * 8.4. Byte copying @@ -1906,10 +1906,10 @@ execute_next_instruction: * Set k := m + 1 (modulo 2^16) * If k = byte_copy_right then set n := byte_copy_left, else set n := k * - */ + */ n = 0; - k = destination; + k = destination; byte_copy_right = buff[66] << 8; byte_copy_right = byte_copy_right | buff[67]; byte_copy_left = buff[64] << 8; @@ -1945,7 +1945,7 @@ execute_next_instruction: * execution to the address specified by the address operand. */ - + k = ( k + 1 ) & 0xffff; n++; } @@ -1958,7 +1958,7 @@ execute_next_instruction: * The length operand indicates the requested number of bits. * Decompression failure occurs if this operand does not lie between 0 * and 16 inclusive. - * + * * The destination operand specifies the memory address to which the * compressed data should be copied. Note that the requested bits are * interpreted as a 2-byte integer ranging from 0 to 2^length - 1, as @@ -2009,7 +2009,7 @@ execute_next_instruction: /* * Execute actual instr. * The input_bit_order register contains the following three flags: - * + * * 0 7 8 15 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved |F|H|P| 68 - 69 @@ -2032,11 +2032,11 @@ execute_next_instruction: goto decompression_failure; } - /* - * Transfer F bit to bit_order to tell decomp dispatcher which bit order to use + /* + * Transfer F bit to bit_order to tell decomp dispatcher which bit order to use */ bit_order = ( input_bit_order & 0x0004 ) >> 2; - value = decomp_dispatch_get_bits( message_tvb, udvm_tree, bit_order, + value = decomp_dispatch_get_bits( message_tvb, udvm_tree, bit_order, buff, &old_input_bit_order, &remaining_bits, &input_bits, &input_address, length, &result_code, msg_end); if ( result_code == 11 ){ @@ -2094,7 +2094,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u n %u", operand_address, n); } - operand_address = next_operand_address; + operand_address = next_operand_address; if (show_instr_detail_level == 1) { proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1, @@ -2108,38 +2108,38 @@ execute_next_instruction: * Note that if n = 0 then the INPUT-HUFFMAN instruction is ignored and * program execution resumes at the following instruction. * Decompression failure occurs if (bits_1 + ... + bits_n) > 16. - * + * * In all other cases, the behavior of the INPUT-HUFFMAN instruction is * defined below: - * + * * 1. Set j := 1 and set H := 0. - * + * * 2. Request bits_j compressed bits. Interpret the returned bits as an * integer k from 0 to 2^bits_j - 1, as explained in Section 8.2. - * + * * 3. Set H := H * 2^bits_j + k. - * + * * 4. If data is requested that lies beyond the end of the SigComp * message, terminate the INPUT-HUFFMAN instruction and move program * execution to the memory address specified by the address operand. - * + * * 5. If (H < lower_bound_j) or (H > upper_bound_j) then set j := j + 1. * Then go back to Step 2, unless j > n in which case decompression * failure occurs. - * + * * 6. Copy (H + uncompressed_j - lower_bound_j) modulo 2^16 to the * memory address specified by the destination operand. - * + * */ /* * The input_bit_order register contains the following three flags: - * + * * 0 7 8 15 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved |F|H|P| 68 - 69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * - * Transfer H bit to bit_order to tell decomp dispatcher which bit order to use + * Transfer H bit to bit_order to tell decomp dispatcher which bit order to use */ input_bit_order = buff[68] << 8; input_bit_order = input_bit_order | buff[69]; @@ -2157,7 +2157,7 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u bits_n %u", operand_address, bits_n); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %lower_bound_n */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &lower_bound_n); @@ -2165,14 +2165,14 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u lower_bound_n %u", operand_address, lower_bound_n); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %upper_bound_n */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &upper_bound_n); if (print_in_loop ){ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"Addr: %u upper_bound_n %u", operand_address, upper_bound_n); } - operand_address = next_operand_address; + operand_address = next_operand_address; /* %uncompressed_n */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &uncompressed_n); if (print_in_loop ){ @@ -2186,7 +2186,7 @@ execute_next_instruction: * 2. Request bits_j compressed bits. Interpret the returned bits as an * integer k from 0 to 2^bits_j - 1, as explained in Section 8.2. */ - k = decomp_dispatch_get_bits( message_tvb, udvm_tree, bit_order, + k = decomp_dispatch_get_bits( message_tvb, udvm_tree, bit_order, buff, &old_input_bit_order, &remaining_bits, &input_bits, &input_address, bits_n, &result_code, msg_end); if ( result_code == 11 ){ @@ -2199,7 +2199,7 @@ execute_next_instruction: goto execute_next_instruction; } - /* + /* * 3. Set H := H * 2^bits_j + k. * [In practice is a shift+OR operation.] */ @@ -2238,10 +2238,10 @@ execute_next_instruction: buff[destination + 1]=lsb; if (print_level_1 ){ proto_tree_add_text(udvm_tree, message_tvb, input_address, 1, - " Loading H: %u (0x%x) at Addr: %u,j = %u remaining_bits: %u", + " Loading H: %u (0x%x) at Addr: %u,j = %u remaining_bits: %u", H, H, destination,( n - m + 1 ), remaining_bits); } - + } @@ -2268,7 +2268,7 @@ execute_next_instruction: } operand_address = current_address + 1; - /* + /* * %partial_identifier_start */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &p_id_start); @@ -2339,10 +2339,10 @@ execute_next_instruction: " byte_copy_right = %u, byte_copy_left = %u", byte_copy_right,byte_copy_left); } - result_code = udvm_state_access(message_tvb, udvm_tree, buff, p_id_start, p_id_length, state_begin, &state_length, + result_code = udvm_state_access(message_tvb, udvm_tree, buff, p_id_start, p_id_length, state_begin, &state_length, &state_address, &state_instruction, hf_id); if ( result_code != 0 ){ - goto decompression_failure; + goto decompression_failure; } used_udvm_cycles = used_udvm_cycles + 1 + state_length; goto execute_next_instruction; @@ -2431,15 +2431,15 @@ execute_next_instruction: no_of_state_create++; if ( no_of_state_create > 4 ){ result_code = 12; - goto decompression_failure; + goto decompression_failure; } if (( minimum_access_length < 6 ) || ( minimum_access_length > STATE_BUFFER_SIZE )){ result_code = 1; - goto decompression_failure; + goto decompression_failure; } if ( state_retention_priority == 65535 ){ result_code = 13; - goto decompression_failure; + goto decompression_failure; } state_length_buff[no_of_state_create] = state_length; state_address_buff[no_of_state_create] = state_address; @@ -2482,7 +2482,7 @@ execute_next_instruction: current_address); } operand_address = current_address + 1; - /* + /* * %partial_identifier_start */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &p_id_start); @@ -2524,7 +2524,7 @@ execute_next_instruction: current_address); } operand_address = current_address + 1; - /* + /* * %output_start */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &output_start); @@ -2533,7 +2533,7 @@ execute_next_instruction: operand_address, output_start); } operand_address = next_operand_address; - /* + /* * %output_length */ next_operand_address = decode_udvm_multitype_operand(buff, operand_address, &output_length); @@ -2549,8 +2549,8 @@ execute_next_instruction: } current_address = next_operand_address; - /* - * Execute instruction + /* + * Execute instruction * 8.4. Byte copying * : * The string of bytes is copied in ascending order of memory address, @@ -2561,10 +2561,10 @@ execute_next_instruction: * Set k := m + 1 (modulo 2^16) * If k = byte_copy_right then set n := byte_copy_left, else set n := k * - */ + */ n = 0; - k = output_start; + k = output_start; byte_copy_right = buff[66] << 8; byte_copy_right = byte_copy_right | buff[67]; byte_copy_left = buff[64] << 8; @@ -2679,7 +2679,7 @@ execute_next_instruction: no_of_state_create++; if ( no_of_state_create > 4 ){ result_code = 12; - goto decompression_failure; + goto decompression_failure; } state_length_buff[no_of_state_create] = state_length; state_address_buff[no_of_state_create] = state_address; @@ -2687,7 +2687,7 @@ execute_next_instruction: /* Not used ? */ state_minimum_access_length_buff[no_of_state_create] = minimum_access_length; state_state_retention_priority_buff[no_of_state_create] = state_retention_priority; - + /* Execute the instruction */ proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"no_of_state_create %u",no_of_state_create); @@ -2705,7 +2705,7 @@ execute_next_instruction: sha1buff[2] = state_address_buff[n] >> 8; sha1buff[3] = state_address_buff[n] & 0xff; sha1buff[4] = state_instruction_buff[n] >> 8; - sha1buff[5] = state_instruction_buff[n] & 0xff; + sha1buff[5] = state_instruction_buff[n] & 0xff; sha1buff[6] = state_minimum_access_length_buff[n] >> 8; sha1buff[7] = state_minimum_access_length_buff[n] & 0xff; if (print_level_3 ){ @@ -2731,12 +2731,12 @@ execute_next_instruction: proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"SHA1 digest %s",bytes_to_str(sha1_digest_buf, STATE_BUFFER_SIZE)); } -/* begin partial state-id change cco@iptel.org */ +/* begin partial state-id change cco@iptel.org */ #if 0 udvm_state_create(sha1buff, sha1_digest_buf, state_minimum_access_length_buff[n]); -#endif +#endif udvm_state_create(sha1buff, sha1_digest_buf, STATE_MIN_ACCESS_LEN); -/* end partial state-id change cco@iptel.org */ +/* end partial state-id change cco@iptel.org */ proto_tree_add_text(udvm_tree,bytecode_tvb, 0, -1,"### Creating state ###"); proto_tree_add_string(udvm_tree,hf_id, bytecode_tvb, 0, 0, bytes_to_str(sha1_digest_buf, state_minimum_access_length_buff[n])); @@ -2750,7 +2750,7 @@ execute_next_instruction: /* At least something got decompressed, show it */ decomp_tvb = tvb_new_real_data(out_buff,output_address,output_address); /* Arrange that the allocated packet data copy be freed when the - * tvbuff is freed. + * tvbuff is freed. */ tvb_set_free_cb( decomp_tvb, g_free ); @@ -2758,7 +2758,7 @@ execute_next_instruction: add_new_data_source(pinfo, decomp_tvb, "Decompressed SigComp message"); /* proto_tree_add_text(udvm_tree, decomp_tvb, 0, -1,"SigComp message Decompressed"); - */ + */ used_udvm_cycles = used_udvm_cycles + 1 + state_length; proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"maximum_UDVM_cycles %u used_udvm_cycles %u", maximum_UDVM_cycles, used_udvm_cycles); @@ -2773,7 +2773,7 @@ execute_next_instruction: g_free(out_buff); return NULL; decompression_failure: - + proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"DECOMPRESSION FAILURE: %s", val_to_str(result_code, result_code_vals,"Unknown (%u)")); THROW(ReportedBoundsError); @@ -2781,7 +2781,7 @@ decompression_failure: return NULL; } - + /* The simplest operand type is the literal (#), which encodes a * constant integer from 0 to 65535 inclusive. A literal operand may * require between 1 and 3 bytes depending on its value. @@ -2794,7 +2794,7 @@ decompression_failure: * */ static int -decode_udvm_literal_operand(guint8 *buff,guint operand_address, guint16 *value) +decode_udvm_literal_operand(guint8 *buff,guint operand_address, guint16 *value) { guint bytecode; guint16 operand; @@ -2858,7 +2858,7 @@ decode_udvm_literal_operand(guint8 *buff,guint operand_address, guint16 *value) * Figure 9: Bytecode for a reference ($) operand */ static int -dissect_udvm_reference_operand(guint8 *buff,guint operand_address, guint16 *value,guint *result_dest) +dissect_udvm_reference_operand(guint8 *buff,guint operand_address, guint16 *value,guint *result_dest) { guint bytecode; guint16 operand; @@ -2924,7 +2924,7 @@ dissect_udvm_reference_operand(guint8 *buff,guint operand_address, guint16 *valu * Bytecode: Operand value: Range: HEX val * 00nnnnnn N 0 - 63 0x00 * 01nnnnnn memory[2 * N] 0 - 65535 0x40 - * 1000011n 2 ^ (N + 6) 64 , 128 0x86 + * 1000011n 2 ^ (N + 6) 64 , 128 0x86 * 10001nnn 2 ^ (N + 8) 256 , ... , 32768 0x88 * 111nnnnn N + 65504 65504 - 65535 0xe0 * 1001nnnn nnnnnnnn N + 61440 61440 - 65535 0x90 @@ -2949,7 +2949,7 @@ decode_udvm_multitype_operand(guint8 *buff,guint operand_address, guint16 *value test_bits = ( bytecode & 0xc0 ) >> 6; switch (test_bits ){ case 0: - /* + /* * 00nnnnnn N 0 - 63 */ operand = buff[operand_address]; @@ -2960,7 +2960,7 @@ decode_udvm_multitype_operand(guint8 *buff,guint operand_address, guint16 *value offset ++; break; case 1: - /* + /* * 01nnnnnn memory[2 * N] 0 - 65535 */ memmory_addr = ( bytecode & 0x3f) * 2; @@ -3061,12 +3061,12 @@ decode_udvm_multitype_operand(guint8 *buff,guint operand_address, guint16 *value temp_data16 = buff[memmory_addr] << 8; temp_data16 = temp_data16 | buff[memmory_addr+1]; *value = temp_data16; - /* debug + /* debug * g_warning("Reading 0x%x From address %u",temp_data16,memmory_addr); */ offset = offset +2; } - + default : break; } @@ -3146,13 +3146,13 @@ static int decomp_dispatch_get_bits( tvbuff_t *message_tvb, proto_tree *udvm_tree, - guint8 bit_order, + guint8 bit_order, guint8 *buff, - guint16 *old_input_bit_order, + guint16 *old_input_bit_order, guint16 *remaining_bits, - guint16 *input_bits, - guint *input_address, - guint16 length, + guint16 *input_bits, + guint *input_address, + guint16 length, guint16 *result_code, guint msg_end) { @@ -3191,11 +3191,11 @@ decomp_dispatch_get_bits( return 0xfbad; } - /* Note: This is never called with length > 16, so the following loop + /* Note: This is never called with length > 16, so the following loop * never loops more than three time. */ while (bits_still_required > 0) { - /* + /* * We only put anything into input_bits if we know we will remove * at least one bit. That ensures we can simply discard the spare * bits if the P-bit changes. @@ -3224,7 +3224,7 @@ decomp_dispatch_get_bits( *input_bits <<= bits_to_use; /* Shift bits into MSByte */ value = (value << bits_to_use) /* Then add to the accumulated value */ | ((*input_bits >> 8) & 0xFF); - *remaining_bits -= bits_to_use; + *remaining_bits -= bits_to_use; *input_bits &= 0x00FF; /* Leave just the remaining bits */ } |