scyther/src/runs.h

269 lines
6.8 KiB
C
Raw Normal View History

2004-04-23 11:58:43 +01:00
#ifndef RUNS
#define RUNS
#include "terms.h"
#include "termlists.h"
#include "knowledge.h"
#include "constraints.h"
#define READ 1
#define SEND 2
#define CLAIM 3
#define runPointerGet(sys,run) sys->runs[run].index
#define runPointerSet(sys,run,newp) sys->runs[run].index = newp
2004-05-15 13:33:01 +01:00
//! Structure for a role event node or list.
/**
*\sa role
*/
2004-04-23 11:58:43 +01:00
struct roledef
{
2004-05-15 13:33:01 +01:00
//! flag for internal actions.
/**
* Typically, this is true to signify internal reads (e.g. variable choices)
* as opposed to a normal read.
*/
2004-04-23 11:58:43 +01:00
int internal;
2004-05-15 13:33:01 +01:00
//! Type of event.
/**
*\sa READ, SEND, CLAIM
*/
2004-04-23 11:58:43 +01:00
int type;
2004-05-15 13:33:01 +01:00
//! Event label.
2004-04-23 11:58:43 +01:00
Term label;
2004-05-15 13:33:01 +01:00
//! Event sender.
2004-04-23 11:58:43 +01:00
Term from;
2004-05-15 13:33:01 +01:00
//! Event target.
2004-04-23 11:58:43 +01:00
Term to;
2004-05-15 13:33:01 +01:00
//! Event message.
2004-04-23 11:58:43 +01:00
Term message;
2004-05-15 13:33:01 +01:00
//! Pointer to next roledef node.
2004-04-23 11:58:43 +01:00
struct roledef *next;
2004-05-15 13:33:01 +01:00
//! Illegal injections for this event.
2004-04-23 11:58:43 +01:00
Knowledge forbidden;
2004-05-15 13:33:01 +01:00
//! knowledge transitions counter.
2004-04-23 11:58:43 +01:00
int knowPhase;
/* evt runid for synchronisation, but that is implied in the
base array */
};
2004-05-15 13:33:01 +01:00
//! Shorthand for roledef pointer.
2004-04-23 11:58:43 +01:00
typedef struct roledef *Roledef;
2004-05-15 13:33:01 +01:00
//! Role definition.
/**
*\sa roledef
*/
2004-04-23 11:58:43 +01:00
struct role
{
2004-05-15 13:33:01 +01:00
//! Name of the role 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 events.
2004-04-23 11:58:43 +01:00
Roledef roledef;
2004-05-15 13:33:01 +01:00
//! Local constants for this role.
2004-04-23 11:58:43 +01:00
Termlist locals;
2004-05-15 13:33:01 +01:00
//! Pointer to next role definition.
2004-04-23 11:58:43 +01:00
struct role *next;
};
2004-05-15 13:33:01 +01:00
//! Shorthand for role pointer.
2004-04-23 11:58:43 +01:00
typedef struct role *Role;
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
{
2004-05-15 13:33:01 +01:00
//! Protocol of this run.
2004-04-23 11:58:43 +01:00
Protocol protocol;
2004-05-15 13:33:01 +01:00
//! Role of this run.
2004-04-23 11:58:43 +01:00
Role role;
2004-05-15 13:33:01 +01:00
//! Agents involved in this run.
2004-04-23 11:58:43 +01:00
Termlist agents;
2004-05-15 13:33:01 +01:00
//! Current execution point in the run.
2004-04-23 11:58:43 +01:00
Roledef index;
2004-05-15 13:33:01 +01:00
//! Head of the run definition.
2004-04-23 11:58:43 +01:00
Roledef start;
2004-05-15 13:33:01 +01:00
//! Current knowledge of the run.
2004-04-23 11:58:43 +01:00
Knowledge know;
2004-05-15 13:33:01 +01:00
//! Locals of the run.
Termlist locals;
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.
2004-04-23 11:58:43 +01:00
Termlist from;
2004-05-15 13:33:01 +01:00
//! List of terms to which the closed variables are bound.
2004-04-23 11:58:43 +01:00
Termlist to;
2004-05-15 13:33:01 +01:00
//! List of open variables.
2004-04-23 11:58:43 +01:00
Termlist empty;
};
2004-05-15 13:33:01 +01:00
//! Shorthand for varbuf pointer.
2004-04-23 11:58:43 +01:00
typedef struct varbuf *Varbuf;
2004-05-15 13:33:01 +01:00
//! Trace buffer.
2004-04-23 11:58:43 +01:00
struct tracebuf
{
2004-05-15 13:33:01 +01:00
//! Length of trace.
2004-04-23 11:58:43 +01:00
int length;
2004-05-15 13:33:01 +01:00
//! Length of trace minus the redundant events.
2004-04-23 11:58:43 +01:00
int reallength;
2004-05-15 13:33:01 +01:00
//! Array of events.
2004-04-23 11:58:43 +01:00
Roledef *event;
2004-05-15 13:33:01 +01:00
//! Array of run identifiers for each event.
2004-04-23 11:58:43 +01:00
int *run;
2004-05-15 13:33:01 +01:00
//! Array of status flags for each event.
/**
*\sa S_OKE, S_RED, S_TOD, S_UNK
*/
2004-04-23 11:58:43 +01:00
int *status;
2004-05-15 13:33:01 +01:00
//! Array for matching sends to reads.
2004-04-23 11:58:43 +01:00
int *link;
2004-05-15 13:33:01 +01:00
//! Index of violated claim in trace.
int violatedclaim;
//! Array of knowledge sets for each event.
2004-04-23 11:58:43 +01:00
Knowledge *know;
2004-05-15 13:33:01 +01:00
//! List of terms required to be in the final knowledge.
2004-04-23 11:58:43 +01:00
Termlist requiredterms;
2004-05-15 13:33:01 +01:00
//! List of variables in the system.
2004-04-23 11:58:43 +01:00
Varbuf variables;
};
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.
int shortestattack; //!< Length of shortest attack trace.
2004-04-23 11:58:43 +01:00
/* switches */
int report;
2004-05-15 13:33:01 +01:00
int prune; //!< Type of pruning.
int switch_maxtracelength; //!< Helps to remember the length of the last trace.
int maxtracelength; //!< helps to remember the length of the last trace.
int switchM; //!< Memory display switch.
int switchT; //!< Time display switch.
int switchS; //!< Progress display switch. (traversed states)
int porparam; //!< A multi-purpose integer parameter, passed to the partial order reduction method selected.
//! Latex output switch.
/**
* Obsolete. Use globalLatex instead.
*\sa globalLatex
*/
int latex;
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 */
unsigned long int statesLow;
unsigned long int statesHigh;
2004-05-15 13:33:01 +01:00
unsigned long int claims; //!< Number of claims encountered.
unsigned long int failed; //!< Number of claims failed.
2004-04-23 11:58:43 +01:00
/* matching */
2004-05-15 13:33:01 +01:00
int match; //!< Matching type.
int clp; //!< Do we use clp?
2004-04-23 11:58:43 +01:00
/* protocol definition */
Protocol protocols;
Termlist locals;
Termlist variables;
Termlist untrusted;
/* constructed trace pointers, static */
Roledef *traceEvent; // MaxRuns * maxRoledef
int *traceRun; // MaxRuns * maxRoledef
Knowledge *traceKnow; // Maxruns * maxRoledef
/* POR reduction assistance */
int PORphase; // -1: init (all sends), 0...: recurse reads
int PORdone; // simple bit to denote something was done.
int knowPhase; // which knowPhase have we already explored?
Constraintlist constraints; // only needed for CLP match
2004-05-15 13:33:01 +01:00
//! Shortest attack storage.
2004-04-23 11:58:43 +01:00
struct tracebuf* attack;
};
typedef struct system *System;
System systemInit ();
void systemReset (const System sys);
System systemDuplicate (System fromsys);
void statesPrint (System sys);
void statesPrintShort (System sys);
void systemDestroy (System sys);
void systemDone (System sys);
void ensureValidRun (System sys, int run);
void runAdd (System sys, int run, int type, Term label, Term from, Term to,
Term msg);
void roledefPrint (Roledef rd);
void runPrint (Roledef rd);
void runsPrint (System sys);
Term agentOfRunRole (const System sys, const int run, const Term role);
Term agentOfRun (const System sys, const int run);
Roledef roledefDuplicate1 (const Roledef rd);
Roledef roledefDuplicate (Roledef rd);
void roledefDelete (Roledef rd);
void roledefDestroy (Roledef rd);
void roleInstance (const System sys, const Protocol protocol, const Role role,
const Termlist tolist);
Roledef roledefInit (int type, Term label, Term from, Term to, Term msg);
Roledef roledefAdd (Roledef rd, int type, Term label, Term from, Term to,
Term msg);
void systemStart (System sys);
void indentActivate ();
void indentSet (int i);
void indent ();
Protocol protocolCreate (Term nameterm);
Role roleCreate (Term nameterm);
void locVarPrint (Termlist tl);
void protocolPrint (Protocol p);
void protocolsPrint (Protocol p);
void rolePrint (Role r);
void rolesPrint (Role r);
int untrustedAgent (System sys, Termlist agents);
int getMaxTraceLength (const System sys);
void agentsOfRunPrint (const System sys, const int run);
void violatedClaimPrint (const System sys, int i);
int attackLength(struct tracebuf* tb);
#endif