Expunge CVS cruft.
[tripe] / ethereal / packet-tripe.c
index 93f1e0e..afeb1bc 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: packet-tripe.c,v 1.1 2003/10/15 09:30:19 mdw Exp $
+ * $Id: packet-tripe.c,v 1.4 2004/04/18 18:08:11 mdw Exp $
  *
  * TrIPE protocol dissector for Ethereal
  *
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: packet-tripe.c,v $
- * Revision 1.1  2003/10/15 09:30:19  mdw
- * Add support for Ethereal protocol analysis.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include "config.h"
@@ -47,6 +39,7 @@
 #include <glib.h>
 #include <gmodule.h>
 #include <epan/packet.h>
+#include <prefs.h>
 
 #ifdef ETHEREAL_BUGGERED
 #  define plugin_address_table_t void
 
 static int proto_tripe = -1;
 
-typedef struct hfmp { int hf, hf_len, hf_val, tt; } hfmp;
+static guint hashsz = 20, tagsz = 10, ivsz = 8;
+
+typedef struct hfmp {
+  int hf, hf_len, hf_val, tt;
+} hfmp;
+typedef struct hfge {
+  int hf, hf_len, hf_val, hfx_len, hfx_val, hfy_len, hfy_val, tt;
+} hfge;
 
 static int hf_tripe_cat = -1;
 static int hf_tripe_packet_type = -1;
 static int hf_tripe_ct = -1;
 static int hf_tripe_ct_seq = -1;
 static int hf_tripe_ct_iv = -1;
-static int hf_tripe_ct_cbc = -1;
-static int hf_tripe_ct_mac = -1;
+static int hf_tripe_ct_ct = -1;
+static int hf_tripe_ct_tag = -1;
 static int hf_tripe_kx_type = -1;
-static hfmp hf_tripe_kx_mychal = { -1, -1, -1, -1 };
+static hfge hf_tripe_kx_mychal = { -1, -1, -1, -1, -1, -1, -1, -1 };
 static int hf_tripe_kx_mycookie = -1;
 static int hf_tripe_kx_yourcookie = -1;
 static hfmp hf_tripe_kx_check = { -1, -1, -1, -1 };
@@ -84,10 +84,12 @@ G_MODULE_EXPORT const gchar version[] = VERSION;
 
 /*----- Main code ---------------------------------------------------------*/
 
+static void prefcb(void) { }
+
 static gint gethash(proto_tree *tt, int hf, tvbuff_t *b, gint off)
 {
-  proto_tree_add_item(tt, hf, b, off, 20, FALSE);
-  return (off + 20); 
+  proto_tree_add_item(tt, hf, b, off, hashsz, FALSE);
+  return (off + hashsz); 
 }
 
 static gint getmp(proto_tree *tt, const hfmp *hf, tvbuff_t *b, gint off)
@@ -100,6 +102,31 @@ static gint getmp(proto_tree *tt, const hfmp *hf, tvbuff_t *b, gint off)
   return (off + 2 + len);
 }
 
+static gint getge(proto_tree *tt, const hfge *hf, tvbuff_t *b, gint off)
+{
+  guint16 len = tvb_get_ntohs(b, off), len2;
+  guint r;
+  proto_item *ti;
+  r = tvb_length_remaining(b, off);
+  if (r < 4 + len ||
+      (len2 = tvb_get_ntohs(b, off + 2 + len), r < 4 + len + len2)) {
+    ti = proto_tree_add_item(tt, hf->hf, b, off, len + 2, FALSE);
+    tt = proto_item_add_subtree(ti, hf->tt);
+    proto_tree_add_item(tt, hf->hf_len, b, off, 2, FALSE);
+    proto_tree_add_item(tt, hf->hf_val, b, off + 2, len, FALSE);
+    r = off + len + 2;
+  } else {
+    ti = proto_tree_add_item(tt, hf->hf, b, off, len + len2 + 4, FALSE);
+    tt = proto_item_add_subtree(ti, hf->tt);
+    proto_tree_add_item(tt, hf->hfx_len, b, off, 2, FALSE);
+    proto_tree_add_item(tt, hf->hfx_val, b, off + 2, len, FALSE);
+    proto_tree_add_item(tt, hf->hfy_len, b, off + 2 + len, 2, FALSE);
+    proto_tree_add_item(tt, hf->hfy_val, b, off + 4 + len, len2, FALSE);
+    r = off + len + len2 + 4;
+  }    
+  return (r);
+}
+
 static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
 {
   proto_item *ti;
@@ -186,14 +213,14 @@ static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
        proto_tree_add_item(tt, hf_tripe_kx_type, b, 0, 1, FALSE);
        switch (ty & MSG_TYPEMASK) {
          case KX_PRECHAL:
-           off = getmp(tt, &hf_tripe_kx_mychal, b, off);
+           off = getge(tt, &hf_tripe_kx_mychal, b, off);
            goto tail;
          case KX_COOKIE:
-           off = getmp(tt, &hf_tripe_kx_mychal, b, off);
+           off = getge(tt, &hf_tripe_kx_mychal, b, off);
            off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
            goto tail;
          case KX_CHAL:
-           off = getmp(tt, &hf_tripe_kx_mychal, b, off);
+           off = getge(tt, &hf_tripe_kx_mychal, b, off);
            off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
            off = getmp(tt, &hf_tripe_kx_check, b, off);
            goto tail;
@@ -224,17 +251,21 @@ static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
     goto done;
   ct:
     ti = proto_tree_add_item(tt, hf_tripe_ct, b, off, -1, FALSE);
-    seq = tvb_get_ntohl(b, off + 10);
+    seq = tvb_get_ntohl(b, off + tagsz);
     proto_item_set_text(ti, "Encrypted ciphertext (sequence number %lu)",
                        (unsigned long)seq);
     tt = proto_item_add_subtree(ti, tt_tripe_ct);
-    proto_tree_add_item(tt, hf_tripe_ct_mac, b, off, 10, FALSE);
-    off += 10;
+    if (tagsz) {
+      proto_tree_add_item(tt, hf_tripe_ct_tag, b, off, tagsz, FALSE);
+      off += tagsz;
+    }
     proto_tree_add_item(tt, hf_tripe_ct_seq, b, off, 4, FALSE);
     off += 4;
-    proto_tree_add_item(tt, hf_tripe_ct_iv, b, off, 8, FALSE);
-    off += 8;
-    proto_tree_add_item(ti, hf_tripe_ct_cbc, b, off, -1, FALSE);
+    if (ivsz) {
+      proto_tree_add_item(tt, hf_tripe_ct_iv, b, off, ivsz, FALSE);
+      off += ivsz;
+    }
+    proto_tree_add_item(ti, hf_tripe_ct_ct, b, off, -1, FALSE);
     goto done;
   done:;
   }  
@@ -242,6 +273,8 @@ static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
 
 void proto_register_tripe(void)
 {
+  module_t *mod;
+
   static value_string vs_kxtype[] = {
     { KX_PRECHAL,      "KX_PRECHAL (prechallenge)" },
     { KX_COOKIE,       "KX_COOKIE (cookie)" },
@@ -277,15 +310,15 @@ void proto_register_tripe(void)
       FT_BYTES, BASE_NONE, 0, 0,
       "This is the initialization vector used for the actual encryption."
     },
-    &hf_tripe_ct_cbc, {
-      "CBC-encrypted data", "tripe.ct.cbc",
+    &hf_tripe_ct_ct, {
+      "Actual encrypted data", "tripe.ct.ct",
       FT_BYTES, BASE_NONE, 0, 0,
-      "This is the CBC-encrypted message.  Reading it ought to be hard."
+      "This is the encrypted message.  Reading it ought to be hard."
     },
-    &hf_tripe_ct_mac, {
-      "Message authentication code", "tripe.ct.mac",
+    &hf_tripe_ct_tag, {
+      "Message authentication code", "tripe.ct.tag",
       FT_BYTES, BASE_NONE, 0, 0,
-      "This is the message authentication code for the ciphertext."
+      "This is the message authentication code tag for the ciphertext."
     },
     &hf_tripe_kx_type, {
       "Key-exchange message type", "tripe.kx.type",
@@ -295,17 +328,37 @@ void proto_register_tripe(void)
     &hf_tripe_kx_mychal.hf, {
       "Sender's challenge data", "tripe.kx.mychal",
       FT_BYTES, BASE_NONE, 0, 0,
-      "This is the sender's challenge value."
+      "This is the sender's challenge."
     },
     &hf_tripe_kx_mychal.hf_len, {
       "Challenge length", "tripe.kx.mychal.len",
       FT_UINT16, BASE_DEC, 0, 0,
-      "This is the length of the sender's challenge value."
+      "This is the length of the sender's challenge."
     },
     &hf_tripe_kx_mychal.hf_val, {
-      "Challenge value", "tripe.kx.mychal.val",
+      "Challenge", "tripe.kx.mychal.val",
+      FT_BYTES, BASE_NONE, 0, 0,
+      "This is the value of the sender's challenge."
+    },
+    &hf_tripe_kx_mychal.hfx_len, {
+      "Challenge x length", "tripe.kx.mychal.x.len",
+      FT_UINT16, BASE_DEC, 0, 0,
+      "This is the length of the sender's challenge x-coordinate."
+    },
+    &hf_tripe_kx_mychal.hfy_val, {
+      "Challenge x value", "tripe.kx.mychal.x.val",
       FT_BYTES, BASE_NONE, 0, 0,
-      "This is the value of the sender's challenge value."
+      "This is the value of the sender's challenge x-coordinate."
+    },
+    &hf_tripe_kx_mychal.hfy_len, {
+      "Challenge y length", "tripe.kx.mychal.y.len",
+      FT_UINT16, BASE_DEC, 0, 0,
+      "This is the length of the sender's challenge x-coordinate."
+    },
+    &hf_tripe_kx_mychal.hfx_val, {
+      "Challenge y value", "tripe.kx.mychal.y.val",
+      FT_BYTES, BASE_NONE, 0, 0,
+      "This is the value of the sender's challenge x-coordinate."
     },
     &hf_tripe_kx_mycookie, {
       "Sender's hashed cookie", "tripe.kx.mycookie",
@@ -350,6 +403,17 @@ void proto_register_tripe(void)
   proto_tripe = proto_register_protocol("TrIPE", "TrIPE", "tripe");
   proto_register_field_array(proto_tripe, hfs, array_length(hfs));
   proto_register_subtree_array(tts, array_length(tts));
+
+  mod = prefs_register_protocol(proto_tripe, prefcb);
+  prefs_register_uint_preference(mod, "hashsz", "Hash length",
+                                "hash function output length (in octets)",
+                                10, &hashsz);
+  prefs_register_uint_preference(mod, "tagsz", "MAC tag length",
+                                "MAC tag length (in octets)", 10, &tagsz);
+  prefs_register_uint_preference(mod, "ivsz", "IV length",
+                                "block cipher initialization vector length"
+                                " (in octets)",
+                                10, &ivsz);
 }
 
 void proto_reg_handoff_tripe(void)