scyther/src/system.h

207 lines
7.0 KiB
C
Raw Normal View History

#ifndef SYSTEM
#define SYSTEM
2004-04-23 11:58:43 +01:00
#include "term.h"
#include "termmap.h"
#include "termlist.h"
2004-04-23 11:58:43 +01:00
#include "knowledge.h"
#include "states.h"
#include "role.h"
2004-08-15 12:55:22 +01:00
#include "list.h"
2004-04-23 11:58:43 +01:00
#define runPointerGet(sys,run) sys->runs[run].index
#define runPointerSet(sys,run,newp) sys->runs[run].index = newp
enum outputs
{ EMPTY, ATTACK, STATESPACE, SCENARIOS, SUMMARY, PROOF };
enum engines
{ POR_ENGINE, ARACHNE_ENGINE };
2004-05-15 13:33:01 +01:00
//! Protocol definition.
2004-04-23 11:58:43 +01:00
struct protocol
{
2004-05-15 13:33:01 +01:00
//! Name of the protocol encoded in a term.
2004-04-23 11:58:43 +01:00
Term nameterm;
2004-05-15 13:33:01 +01:00
//! List of role definitions.
2004-04-23 11:58:43 +01:00
Role roles;
2004-05-15 13:33:01 +01:00
//! List of role names.
2004-04-23 11:58:43 +01:00
Termlist rolenames;
2004-05-15 13:33:01 +01:00
//! List of local terms for this protocol.
2004-04-23 11:58:43 +01:00
Termlist locals;
2004-05-15 13:33:01 +01:00
//! Pointer to next protocol.
2004-04-23 11:58:43 +01:00
struct protocol *next;
};
2004-05-15 13:33:01 +01:00
//! Shorthand for protocol pointer.
2004-04-23 11:58:43 +01:00
typedef struct protocol *Protocol;
2004-05-15 13:33:01 +01:00
//! Run container.
2004-04-23 11:58:43 +01:00
struct run
{
Protocol protocol; //!< Protocol of this run.
Role role; //!< Role of this run.
Termlist agents; //!< Agents involved in this run.
int step; //!< Current execution point in the run (integer)
int rolelength; //!< Length of role
Roledef index; //!< Current execution point in the run (roledef pointer)
Roledef start; //!< Head of the run definition.
Knowledge know; //!< Current knowledge of the run.
Termlist locals; //!< Locals of the run.
Termlist artefacts; //!< Stuff created especially for this run.
Termlist substitutions; //!< The substitutions as they came from the roledef unifier
int prevSymmRun; //!< Used for symmetry reduction. Either -1, or the previous run with the same role def and at least a single parameter.
int firstNonAgentRead; //!< Used for symmetry reductions for equal agents runs; -1 if there is no candidate.
int firstReal; //!< 1 if a choose was inserted, otherwise 0
2004-04-23 11:58:43 +01:00
};
2004-05-15 13:33:01 +01:00
//! Shorthand for run pointer.
2004-04-23 11:58:43 +01:00
typedef struct run *Run;
2004-05-15 13:33:01 +01:00
//! Buffer for variables substitution state.
2004-04-23 11:58:43 +01:00
struct varbuf
{
2004-05-15 13:33:01 +01:00
//! List of closed variables.
Termlist from;
2004-05-15 13:33:01 +01:00
//! List of terms to which the closed variables are bound.
Termlist to;
2004-05-15 13:33:01 +01:00
//! List of open variables.
Termlist empty;
2004-04-23 11:58:43 +01:00
};
2004-05-15 13:33:01 +01:00
//! Shorthand for varbuf pointer.
2004-04-23 11:58:43 +01:00
typedef struct varbuf *Varbuf;
//! Structure for information on special terms (cacheing)
struct hiddenterm
{
Term term;
unsigned int hideminimum;
unsigned int hideprotocol;
unsigned int hideknowledge;
struct hiddenterm *next;
};
//! Pointer shorthand
typedef struct hiddenterm *Hiddenterm;
2004-05-15 13:33:01 +01:00
//! The main state structure.
2004-04-23 11:58:43 +01:00
struct system
{
2004-05-15 13:33:01 +01:00
int step; //!< Step in trace during exploration. Can be managed globally
Knowledge know; //!< Knowledge in currect step of system.
2004-04-23 11:58:43 +01:00
struct parameters *parameters; // misc
/* static run info, maxruns */
Run runs;
/* global */
2004-05-15 13:33:01 +01:00
int maxruns; //!< Number of runs in the system.
2004-04-23 11:58:43 +01:00
/* properties */
2004-05-15 13:33:01 +01:00
Termlist secrets; //!< Integrate secrets list into system.
Termlist synchronising_labels; //!< List of labels that might synchronise.
2004-05-15 13:33:01 +01:00
int shortestattack; //!< Length of shortest attack trace.
int maxtracelength; //!< helps to remember the length of the last trace.
2004-04-23 11:58:43 +01:00
/* traversal */
2004-05-15 13:33:01 +01:00
int traverse; //!< Traversal method.
int explore; //!< Boolean: explore states after actions or not.
2004-04-23 11:58:43 +01:00
/* counters */
states_t states; //!< States traversed
states_t statesScenario; //!< States traversed that are within the scenario, not the prefix
states_t interval; //!< Used to update state printing at certain intervals
states_t claims; //!< Number of claims encountered.
states_t failed; //!< Number of claims failed.
int attackid; //!< Global counter of attacks (used for assigning identifiers) within this Scyther call.
int countScenario; //!< Number of scenarios skipped.
2004-04-23 11:58:43 +01:00
/* protocol definition */
Protocol protocols; //!< List of protocols in the system
Termlist locals; //!< List of local terms
Termlist variables; //!< List of all variables
Termlist untrusted; //!< List of untrusted agent names
Termlist globalconstants; //!< List of global constants
Hiddenterm hidden; //!< List of hiddenterm constructs for Hidelevel lemma
2004-04-23 11:58:43 +01:00
/* protocol preprocessing */
int rolecount; //!< Number of roles in the system
int roleeventmax; //!< Maximum number of events in a single role
int lastChooseRun; //!< Last run with a choose event
Claimlist claimlist; //!< List of claims in the system, with occurrence counts
List labellist; //!< List of labelinfo stuff
2004-04-23 11:58:43 +01:00
/* constructed trace pointers, static */
Roledef *traceEvent; //!< Trace roledefs: MaxRuns * maxRoledef
int *traceRun; //!< Trace run ids: MaxRuns * maxRoledef
Knowledge *traceKnow; //!< Trace intruder knowledge: Maxruns * maxRoledef
states_t *traceNode; //!< Trace node traversal: Maxruns * maxRoledef
2004-04-23 11:58:43 +01:00
2004-08-15 12:55:22 +01:00
/* Arachne assistance */
List bindings; //!< List of bindings
2005-05-02 14:38:45 +01:00
Claimlist current_claim; //!< The claim under current investigation
2004-04-23 11:58:43 +01:00
};
typedef struct system *System;
2004-04-23 11:58:43 +01:00
System systemInit ();
void systemReset (const System sys);
void systemRuns (const System sys);
System systemDuplicate (const System fromsys);
void statesPrint (const System sys);
void statesPrintShort (const System sys);
void systemDestroy (const System sys);
void systemDone (const System sys);
void ensureValidRun (const System sys, int run);
2004-04-23 11:58:43 +01:00
void runPrint (Roledef rd);
void runsPrint (const System sys);
2004-04-23 11:58:43 +01:00
Term agentOfRunRole (const System sys, const int run, const Term role);
Term agentOfRun (const System sys, const int run);
void roleInstance (const System sys, const Protocol protocol, const Role role,
const Termlist paramlist, Termlist substlist);
void roleInstanceDestroy (const System sys);
void systemStart (const System sys);
2004-04-23 11:58:43 +01:00
void indentActivate ();
void indentSet (int i);
void indent ();
Protocol protocolCreate (Term nameterm);
void locVarPrint (Termlist tl);
void protocolPrint (Protocol p);
void protocolsPrint (Protocol p);
int untrustedAgent (const System sys, Termlist agents);
2004-04-23 11:58:43 +01:00
int getMaxTraceLength (const System sys);
void agentsOfRunPrint (const System sys, const int run);
void violatedClaimPrint (const System sys, int i);
void commandlinePrint (FILE * stream);
2004-04-23 11:58:43 +01:00
int compute_rolecount (const System sys);
int compute_roleeventmax (const System sys);
void scenarioPrint (const System sys);
int system_iterate_roles (const System sys, int (*func) ());
2005-07-01 14:25:54 +01:00
int isAgentTrusted (const System sys, Term agent);
int isAgentlistTrusted (const System sys, Termlist agents);
int isRunTrusted (const System sys, const int run);
int iterateRuns (const System sys, int (*callback) (int r));
int iterateRegularRuns (const System sys, int (*callback) (int r));
int iterateEvents (const System sys, const int run,
int (*callback) (Roledef rd, int ev));
int iterateEventsType (const System sys, const int run, const int evtype,
int (*callback) (Roledef rd, int ev));
int iterateLocalToOther (const System sys, const int myrun,
int (*callback) (Term t));
int firstOccurrence (const System sys, const int r, Term t, int evtype);
2006-01-02 21:06:08 +00:00
//! 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
2004-04-23 11:58:43 +01:00
#endif