- Huge code documentation effort.

This commit is contained in:
ccremers 2006-01-02 21:06:08 +00:00
parent 6676266f4a
commit da75862d82
24 changed files with 127 additions and 94 deletions

View File

@ -43,34 +43,34 @@ extern int *graph;
extern int nodes; extern int nodes;
extern int graph_uordblks; extern int graph_uordblks;
static System sys; static System sys; //!< local buffer for the system pointer
int attack_length; int attack_length; //!< length of the attack
int attack_leastcost; int attack_leastcost; //!< cost of the best attack sofar \sa cost.c
Protocol INTRUDER; // Pointers, to be set by the Init Protocol INTRUDER; //!< intruder protocol
Role I_M; // Same here. Role I_M; //!< Initial knowledge role of the intruder
Role I_RRS; Role I_RRS; //!< Encrypt role of the intruder
Role I_RRSD; Role I_RRSD; //!< Decrypt role of the intruder
int proofDepth; int proofDepth; //!< Current depth of the proof
int max_encryption_level; int max_encryption_level; //!< Maximum encryption level of any term
int num_regular_runs; int num_regular_runs; //!< Current number of regular runs
int num_intruder_runs; int num_intruder_runs; //!< Current number of intruder runs
static int indentDepth; static int indentDepth;
static int prevIndentDepth; static int prevIndentDepth;
static int indentDepthChanges; static int indentDepthChanges;
static FILE *attack_stream; static FILE *attack_stream;
/** /*
* Forward declarations * Forward declarations
*/ */
int iterate (); int iterate ();
void printSemiState (); void printSemiState ();
/** /*
* Program code * Program code
*/ */
@ -151,14 +151,12 @@ arachneDone ()
// Detail // Detail
//------------------------------------------------------------------------ //------------------------------------------------------------------------
/* //! Just a defined integer for invalid
* runs[rid].step is now the number of 'valid' events within the run, but we
* call it 'length' here.
*/
#define INVALID -1 #define INVALID -1
//! can this roledef constitute a read Goal?
#define isGoal(rd) (rd->type == READ && !rd->internal) #define isGoal(rd) (rd->type == READ && !rd->internal)
//! is this roledef already bound?
#define isBound(rd) (rd->bound) #define isBound(rd) (rd->bound)
#define length step
//! Indent prefix print //! Indent prefix print
void void
@ -303,7 +301,7 @@ semiRunCreate (const Protocol p, const Role r)
num_regular_runs++; num_regular_runs++;
roleInstance (sys, p, r, NULL, NULL); roleInstance (sys, p, r, NULL, NULL);
run = sys->maxruns - 1; run = sys->maxruns - 1;
sys->runs[run].length = 0; sys->runs[run].height = 0;
return run; return run;
} }
@ -359,7 +357,7 @@ fixAgentKeylevels (void)
//! After a role instance, or an extension of a run, we might need to add some goals //! After a role instance, or an extension of a run, we might need to add some goals
/** /**
* From old to new. Sets the new length to new. * From old to new. Sets the new height to new.
*@returns The number of goals added (for destructions) *@returns The number of goals added (for destructions)
*/ */
int int
@ -369,7 +367,7 @@ add_read_goals (const int run, const int old, const int new)
int i; int i;
Roledef rd; Roledef rd;
sys->runs[run].length = new; sys->runs[run].height = new;
i = old; i = old;
rd = roledef_shift (sys->runs[run].start, i); rd = roledef_shift (sys->runs[run].start, i);
count = 0; count = 0;
@ -465,7 +463,7 @@ get_semitrace_length ()
{ {
// Non-intruder run: count length // Non-intruder run: count length
// Subtract 'firstReal' to ignore chooses. // Subtract 'firstReal' to ignore chooses.
length = length + sys->runs[run].length - sys->runs[run].firstReal; length = length + sys->runs[run].height - sys->runs[run].firstReal;
} }
run++; run++;
} }
@ -674,6 +672,7 @@ iterate_role_sends (int (*func) ())
* Note that this does not add any bindings for the reads. * Note that this does not add any bindings for the reads.
* *
*@param term The term to be decrypted (implies decryption key) *@param term The term to be decrypted (implies decryption key)
*@param key The key that is needed to decrypt the term
* *
*@returns The run id of the decryptor instance *@returns The run id of the decryptor instance
*/ */
@ -691,7 +690,7 @@ create_decryptor (const Term term, const Term key)
rd->message = termDuplicateUV (term); rd->message = termDuplicateUV (term);
rd->next->message = termDuplicateUV (key); rd->next->message = termDuplicateUV (key);
rd->next->next->message = termDuplicateUV (TermOp (term)); rd->next->next->message = termDuplicateUV (TermOp (term));
sys->runs[run].step = 3; sys->runs[run].height = 3;
proof_suppose_run (run, 0, 3); proof_suppose_run (run, 0, 3);
return run; return run;
@ -739,7 +738,9 @@ getPriorityOfNeededKey (const System sys, const Term keyneeded)
* needed keys, but simply the path throught the term. This would enable * needed keys, but simply the path throught the term. This would enable
* reconstruction of the keys anyway. TODO * reconstruction of the keys anyway. TODO
* *
*@param subterm determines whether it is a subterm unification or not. *@param b binding to fix (bind), destination filled in
*@param run run of binding start
*@param index index in run of binding start
*/ */
int int
bind_existing_to_goal (const Binding b, const int run, const int index) bind_existing_to_goal (const Binding b, const int run, const int index)
@ -914,7 +915,7 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
rd = roledef_shift (sys->runs[run].start, index); rd = roledef_shift (sys->runs[run].start, index);
// Fix length // Fix length
old_length = sys->runs[run].length; old_length = sys->runs[run].height;
if ((index + 1) > old_length) if ((index + 1) > old_length)
newgoals = add_read_goals (run, old_length, index + 1); newgoals = add_read_goals (run, old_length, index + 1);
else else
@ -935,7 +936,7 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
} }
// Reset length // Reset length
goal_remove_last (newgoals); goal_remove_last (newgoals);
sys->runs[run].length = old_length; sys->runs[run].height = old_length;
return flag; return flag;
} }
@ -1055,7 +1056,7 @@ printSemiState ()
index = 0; index = 0;
rd = sys->runs[run].start; rd = sys->runs[run].start;
while (index < sys->runs[run].length) while (index < sys->runs[run].height)
{ {
indentPrint (); indentPrint ();
eprintf ("!! %i ", index); eprintf ("!! %i ", index);
@ -1110,7 +1111,6 @@ bind_old_goal (const Binding b_new)
} }
//! Create a new intruder run to generate knowledge from m0 //! Create a new intruder run to generate knowledge from m0
int int
bind_goal_new_m0 (const Binding b) bind_goal_new_m0 (const Binding b)
{ {
@ -1137,7 +1137,7 @@ bind_goal_new_m0 (const Binding b)
I_M->roledef->message = m0t; I_M->roledef->message = m0t;
run = semiRunCreate (INTRUDER, I_M); run = semiRunCreate (INTRUDER, I_M);
proof_suppose_run (run, 0, 1); proof_suppose_run (run, 0, 1);
sys->runs[run].length = 1; sys->runs[run].height = 1;
{ {
indentDepth++; indentDepth++;
if (goal_bind (b, run, 0)) if (goal_bind (b, run, 0))
@ -1394,7 +1394,7 @@ bind_goal_regular_run (const Binding b)
} }
// Bind to all possible sends of intruder runs //! Bind to all possible sends of intruder runs
int int
bind_goal_old_intruder_run (Binding b) bind_goal_old_intruder_run (Binding b)
{ {
@ -1413,7 +1413,7 @@ bind_goal_old_intruder_run (Binding b)
rd = sys->runs[run].start; rd = sys->runs[run].start;
ev = 0; ev = 0;
while (ev < sys->runs[run].length) while (ev < sys->runs[run].height)
{ {
if (rd->type == SEND) if (rd->type == SEND)
{ {
@ -2207,19 +2207,19 @@ knowledgeAtArachne (const System sys, const int myrun, const int myindex,
while (run < sys->maxruns) while (run < sys->maxruns)
{ {
int index; int index;
int maxstep; int maxheight;
Roledef rd; Roledef rd;
index = 0; index = 0;
rd = sys->runs[run].start; rd = sys->runs[run].start;
maxstep = sys->runs[run].step; maxheight = sys->runs[run].height;
if (run == myrun && myindex > maxstep) if (run == myrun && myindex > maxheight)
{ {
// local run index can override real step // local run index can override real step
maxstep = myindex; maxheight = myindex;
} }
while (rd != NULL && index < maxstep) while (rd != NULL && index < maxheight)
{ {
// Check whether this event precedes myevent // Check whether this event precedes myevent
if (aftercomplete || isOrderedBefore (run, index, myrun, myindex)) if (aftercomplete || isOrderedBefore (run, index, myrun, myindex))

View File

@ -13,13 +13,17 @@ int isTriviallyKnownAtArachne (const System sys, const Term t, const int run,
int isTriviallyKnownAfterArachne (const System sys, const Term t, int isTriviallyKnownAfterArachne (const System sys, const Term t,
const int run, const int index); const int run, const int index);
//! Goal structure
/**
* Signals a read event or claim event to which a term has to be bound.
*/
struct goalstruct struct goalstruct
{ {
int run; int run; //!< run of goal
int index; int index; //!< index of goal in the run
Roledef rd; Roledef rd; //!< pointer to the role definition
}; };
typedef struct goalstruct Goal; typedef struct goalstruct Goal; //!< pointer to goal structure
#endif #endif

View File

@ -16,13 +16,13 @@
#include "switches.h" #include "switches.h"
#include <malloc.h> #include <malloc.h>
static System sys; static System sys; //!< local storage of system pointer
int *graph = NULL; int *graph = NULL; //!< graph data
int nodes = 0; int nodes = 0; //!< number of nodes in the graph
int graph_uordblks = 0; int graph_uordblks = 0;
extern Protocol INTRUDER; // The intruder protocol extern Protocol INTRUDER; //!< The intruder protocol
extern Role I_M; // special role; precedes all other events always extern Role I_M; //!< special role; precedes all other events always
/* /*
* Forward declarations * Forward declarations

View File

@ -5,6 +5,7 @@
#include "termmap.h" #include "termmap.h"
#include "system.h" #include "system.h"
//! Binding structure
/* /*
* Idea is the ev_from *has to* precede the ev_to * Idea is the ev_from *has to* precede the ev_to
*/ */
@ -13,20 +14,17 @@ struct binding
int done; //!< Iff true, it is bound int done; //!< Iff true, it is bound
int blocked; //!< Iff true, ignore it int blocked; //!< Iff true, ignore it
int run_from; int run_from; //!< origination run
int ev_from; int ev_from; //!< step in origination run
int run_to; int run_to; //!< destination run
int ev_to; int ev_to; //!< step in destination run
int *graph; Term term; //!< Binding term
int nodes; int level; //!< ???
Term term;
int level;
}; };
typedef struct binding *Binding; typedef struct binding *Binding; //!< pointer to binding structure
void bindingInit (const System mysys); void bindingInit (const System mysys);

View File

@ -19,12 +19,18 @@
#include "switches.h" #include "switches.h"
#include "memory.h" #include "memory.h"
//! When none of the runs match
#define MATCH_NONE 0 #define MATCH_NONE 0
//! When the order matches
#define MATCH_ORDER 1 #define MATCH_ORDER 1
//! When the order is reversed
#define MATCH_REVERSE 2 #define MATCH_REVERSE 2
//! When the content matches
#define MATCH_CONTENT 3 #define MATCH_CONTENT 3
//! This label is fixed
#define LABEL_GOOD -3 #define LABEL_GOOD -3
//! This label still needs to be done
#define LABEL_TODO -2 #define LABEL_TODO -2
extern int globalError; extern int globalError;

View File

@ -8,12 +8,18 @@
#include <stdio.h> #include <stdio.h>
#include "switches.h" #include "switches.h"
//! Substitution string for --plain output
char *empty = ""; char *empty = "";
//! Reset colors
char *COLOR_Reset = ""; char *COLOR_Reset = "";
//! Red
char *COLOR_Red = ""; char *COLOR_Red = "";
//! Green
char *COLOR_Green = ""; char *COLOR_Green = "";
//! Bold
char *COLOR_Bold = ""; char *COLOR_Bold = "";
//! Init colors
void void
colorInit (void) colorInit (void)
{ {
@ -26,6 +32,7 @@ colorInit (void)
} }
} }
//! Exit colors
void void
colorDone (void) colorDone (void)
{ {

View File

@ -12,6 +12,7 @@
// Private methods // Private methods
//************************************************************************ //************************************************************************
//! determine whether a run is a so-called self-initiator
int int
selfInitiator (const System sys, const int run) selfInitiator (const System sys, const int run)
{ {

View File

@ -6,7 +6,7 @@
void void
error_die (void) error_die (void)
{ {
exit (1); exit (EXIT_ERROR);
} }
//! Print error message header //! Print error message header
@ -34,7 +34,7 @@ error_post (char *fmt, ...)
vfprintf (stderr, fmt, args); vfprintf (stderr, fmt, args);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
va_end (args); va_end (args);
exit (1); exit (EXIT_ERROR);
} }
//! Print error message and die. //! Print error message and die.

View File

@ -1,6 +1,10 @@
#ifndef ERROR #ifndef ERROR
#define ERROR #define ERROR
//! Types of exit codes
enum exittypes
{ EXIT_NOATTACK = 0, EXIT_ERROR = 1, EXIT_NOCLAIM = 2, EXIT_ATTACK = 3 };
void error_die (void); void error_die (void);
void error_pre (void); void error_pre (void);
void error_post (char *fmt, ...); void error_post (char *fmt, ...);

View File

@ -13,8 +13,6 @@
#include "specialterm.h" #include "specialterm.h"
#include "switches.h" #include "switches.h"
#define length step
//! Check whether a binding (goal) is selectable //! Check whether a binding (goal) is selectable
int int
is_goal_selectable (const Binding b) is_goal_selectable (const Binding b)
@ -99,7 +97,7 @@ termBindConsequences (const System sys, Term t)
rd = sys->runs[run].start; rd = sys->runs[run].start;
step = 0; step = 0;
while (step < sys->runs[run].length) while (step < sys->runs[run].height)
{ {
Termlist tl; Termlist tl;

View File

@ -14,6 +14,7 @@ struct knowledge
Termlist basic; Termlist basic;
//! A list of terms encrypted, such that the inverse is not in the knowledge set. //! A list of terms encrypted, such that the inverse is not in the knowledge set.
Termlist encrypt; Termlist encrypt;
//! List of inverse pairs (thus length of list is even)
Termlist inverses; Termlist inverses;
//! List of open variables in the knowledge set. //! List of open variables in the knowledge set.
/** /**

View File

@ -1,14 +1,15 @@
#ifndef GENERICLIST #ifndef GENERICLIST
#define GENERICLIST #define GENERICLIST
//! generic list structure node
struct list_struct struct list_struct
{ {
struct list_struct *next; struct list_struct *next; //!< pointer to next node
struct list_struct *prev; struct list_struct *prev; //!< pointer to previous node
void *data; void *data; //!< pointer to the actual data element (should be typecast)
}; };
typedef struct list_struct *List; typedef struct list_struct *List; //!< pointer to generic list node
List list_create (const void *data); List list_create (const void *data);
List list_rewind (List list); List list_rewind (List list);

View File

@ -37,9 +37,6 @@
* be done for any style using the GNU indent program. * be done for any style using the GNU indent program.
*/ */
enum exittypes
{ EXIT_NOATTACK = 0, EXIT_ERROR = 1, EXIT_NOCLAIM = 2, EXIT_ATTACK = 3 };
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
@ -61,11 +58,14 @@ enum exittypes
#include "switches.h" #include "switches.h"
#include "specialterm.h" #include "specialterm.h"
#include "color.h" #include "color.h"
#include "error.h"
// The global system state //! The global system state pointer
System sys; System sys;
//! Pointer to the tac node container
extern struct tacnode *spdltac; extern struct tacnode *spdltac;
//! Match mode
extern int mgu_match; extern int mgu_match;
void scanner_cleanup (void); void scanner_cleanup (void);

View File

@ -1,5 +1,5 @@
/** /**
* @file roles.c * @file role.c
* \brief role related logic. * \brief role related logic.
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -108,12 +108,14 @@ roledefPrintGeneric (Roledef rd, int print_actor)
eprintf ("$"); eprintf ("$");
} }
//! Print a roledef
void void
roledefPrint (Roledef rd) roledefPrint (Roledef rd)
{ {
roledefPrintGeneric (rd, 1); roledefPrintGeneric (rd, 1);
} }
//! Print a roledef, but shorten it
void void
roledefPrintShort (Roledef rd) roledefPrintShort (Roledef rd)
{ {

View File

@ -103,7 +103,7 @@ struct roledef
/* /*
* Bindings for Arachne engine * Bindings for Arachne engine
*/ */
int bound; int bound; //!< determines whether it is already bound
/* evt runid for synchronisation, but that is implied in the /* evt runid for synchronisation, but that is implied in the
base array */ base array */

View File

@ -5,21 +5,23 @@
#include "knowledge.h" #include "knowledge.h"
#include "system.h" #include "system.h"
//! substitution structure
struct substitution struct substitution
{ {
Term from; Term from;
Term to; Term to;
}; };
typedef struct substitution *Substitution; typedef struct substitution *Substitution; //!< substitution structure
//! substitution list
struct substitutionlist struct substitutionlist
{ {
Substitution subst; Substitution subst;
struct substitutionlist *next; struct substitutionlist *next;
}; };
typedef struct substitutionlist *Substitutionlist; typedef struct substitutionlist *Substitutionlist; //!< substitution list structure
Substitution makeSubstitution (Term from, Term to); Substitution makeSubstitution (Term from, Term to);

View File

@ -79,6 +79,6 @@ struct switchdata
int latex; int latex;
}; };
extern struct switchdata switches; extern struct switchdata switches; //!< pointer to switchdata structure
#endif #endif

View File

@ -13,6 +13,7 @@ enum symboltypes
#define EOS 0 #define EOS 0
//! Symbol structure
struct symbol struct symbol
{ {
//! Type of symbol. //! Type of symbol.
@ -32,7 +33,7 @@ struct symbol
struct symbol *allocnext; struct symbol *allocnext;
}; };
typedef struct symbol *Symbol; typedef struct symbol *Symbol; //!< pointer to symbol structure
void symbolsInit (void); void symbolsInit (void);
void symbolsDone (void); void symbolsDone (void);

View File

@ -207,4 +207,11 @@ int isAgentTrusted (const System sys, Term agent);
int isAgentlistTrusted (const System sys, Termlist agents); int isAgentlistTrusted (const System sys, Termlist agents);
int isRunTrusted (const System sys, const int run); int isRunTrusted (const System sys, const int run);
//! Equality for run structure naming
/**
* For the modelchecker, there was an index called step. In Strand Space
* terminology, something like that is the height of the strand.
*/
#define height step
#endif #endif

View File

@ -31,13 +31,14 @@ enum tactypes
TAC_USERTYPE TAC_USERTYPE
}; };
//! Structure to hold the compilation tree nodes
struct tacnode struct tacnode
{ {
struct tacnode *next; struct tacnode *next; //!< pointer to previous node
struct tacnode *prev; struct tacnode *prev; //!< pointer to next node
struct tacnode *allnext; struct tacnode *allnext;
int op; int op; //!< operator for this node
int lineno; int lineno; //!< line number of parser location in the input file
union union
{ {
Symbol sym; Symbol sym;

View File

@ -1,4 +1,4 @@
/** @file terms.c \brief Term related base functions. /** @file term.c \brief Term related base functions.
* *
* Intended to be a standalone file, however during development it turned out * Intended to be a standalone file, however during development it turned out
* that a termlist structure was needed to define term types, so there is now a * that a termlist structure was needed to define term types, so there is now a
@ -7,7 +7,7 @@
* Until now, symbols were unique and never deleted. The same holds for basic * Until now, symbols were unique and never deleted. The same holds for basic
* terms; leaves are equal when their pointers are equal. We are looking to * terms; leaves are equal when their pointers are equal. We are looking to
* extend this to whole terms. At that point, term equality is be reduced to * extend this to whole terms. At that point, term equality is be reduced to
* pointer comparison, which is what we want. However, for comparison of terms * pointer comparison, which is what we want.
*/ */
#include <string.h> #include <string.h>
@ -34,6 +34,7 @@ void indent (void);
/* useful macros */ /* useful macros */
//! Undefined run identifier in a term
#define RID_UNDEF MIN_INT #define RID_UNDEF MIN_INT
/* main code */ /* main code */
@ -507,7 +508,6 @@ termDuplicateDeep (const Term term)
* Remove all instantiated variables on the way down. * Remove all instantiated variables on the way down.
*\sa termDuplicate() *\sa termDuplicate()
*/ */
Term Term
termDuplicateUV (Term term) termDuplicateUV (Term term)
{ {
@ -534,14 +534,7 @@ termDuplicateUV (Term term)
return newterm; return newterm;
} }
/* //! Make a deep copy of a term, also of leaves
realTermDuplicate
make a deep copy of a term, also of leaves.
*/
Term Term
realTermDuplicate (const Term term) realTermDuplicate (const Term term)
{ {
@ -1149,7 +1142,7 @@ term_encryption_level (const Term term)
//! Determine 'constrained factor' of a term //! Determine 'constrained factor' of a term
/** /**
* Actually this is (#vars/structure). * Actually this is (number of vars/structure).
* Thus, 0 means very constrained, no variables. * Thus, 0 means very constrained, no variables.
* Everything else has higher float, but always <=1. In fact, only a single variable has a level 1. * Everything else has higher float, but always <=1. In fact, only a single variable has a level 1.
*/ */

View File

@ -30,7 +30,7 @@ struct term
//! Data Type termlist (e.g. agent or nonce) //! Data Type termlist (e.g. agent or nonce)
/** Only for leaves. */ /** Only for leaves. */
void *stype; // list of types void *stype; // list of types
int roleVar; // only for leaf, arachne engine: role variable flag int roleVar; //!< only for leaf, arachne engine: role variable flag
//! Substitution term. //! Substitution term.
/** /**
@ -41,15 +41,17 @@ struct term
union union
{ {
//! Pointer to the symbol for leaves
Symbol symb; Symbol symb;
//! Encrypted subterm. //! Encrypted subterm.
struct term *op; struct term *op;
//! Left-hand side of tuple pair. //! Left-hand side of tuple pair.
struct term *op1; struct term *op1;
struct term *next; // for alternative memory management struct term *next; //!< for alternative memory management
} left; } left;
union union
{ {
//! run identifier for leaves
int runid; int runid;
//! Key used to encrypt subterm. //! Key used to encrypt subterm.
struct term *key; struct term *key;

View File

@ -5,14 +5,14 @@
#include "debug.h" #include "debug.h"
#include "memory.h" #include "memory.h"
/** /*
* Shared stuff * Shared stuff
*/ */
//! Termlist error thing (for global use) //! Termlist error thing (for global use)
Termlist TERMLISTERROR; Termlist TERMLISTERROR;
/** /*
* Forward declarations * Forward declarations
*/ */

View File

@ -1,11 +1,16 @@
/** /**
*@file warshall.c
*
* Warshall's algorithm for transitive closure computation. * Warshall's algorithm for transitive closure computation.
*
* Currently this is the slow integer-instead-of-bit olde slowe version.
*/ */
#include <limits.h> #include <limits.h>
#include "warshall.h" #include "warshall.h"
#include "debug.h" #include "debug.h"
//! fill the graph with some value
void void
graph_fill (int *graph, int nodes, int value) graph_fill (int *graph, int nodes, int value)
{ {