scyther/src/knowledge.h

97 lines
3.2 KiB
C
Raw Normal View History

/*
* Scyther : An automatic verifier for security protocols.
2013-10-05 23:56:12 +01:00
* Copyright (C) 2007-2013 Cas Cremers
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2004-04-23 11:58:43 +01:00
#ifndef KNOWLEDGE
#define KNOWLEDGE
#include "term.h"
#include "termlist.h"
2004-04-23 11:58:43 +01:00
2004-05-15 13:33:01 +01:00
//! Knowledge structure.
/**
* Contains a miminal representation of a knowledge set.
*/
2004-04-23 11:58:43 +01:00
struct knowledge
{
2004-05-15 13:33:01 +01:00
//! A list of non-encrypted terms.
2004-04-23 11:58:43 +01:00
Termlist basic;
2004-05-15 13:33:01 +01:00
//! A list of terms encrypted, such that the inverse is not in the knowledge set.
2004-04-23 11:58:43 +01:00
Termlist encrypt;
//! List of inverse pairs (thus length of list is even) (add,sub)
Termlist inversekeys;
//! List of inverse pairs (thus length of list is even) (pk,sk)
Termlist inversekeyfunctions;
2004-05-26 09:42:34 +01:00
//! List of open variables in the knowledge set.
/**
* This list is used to determine whether the knowledge needs to be rewritten.
* If a new substitution is done, one of the elements of this list will become closed,
* and we need to reconstruct the knowledge set.
*/
Termlist vars; // special: denotes unsubstituted variables
//! A list of hash functions
Termlist publicfunctions;
2004-04-23 11:58:43 +01:00
};
2004-05-15 13:33:01 +01:00
//! Shorthand for knowledge pointer.
2004-04-23 11:58:43 +01:00
typedef struct knowledge *Knowledge;
void knowledgeInit (void);
void knowledgeDone (void);
Knowledge makeKnowledge ();
Knowledge emptyKnowledge ();
Knowledge knowledgeDuplicate (Knowledge know);
void knowledgeDelete (Knowledge know);
void knowledgeDestroy (Knowledge know);
int knowledgeAddTerm (Knowledge know, Term term);
int knowledgeAddTermlist (Knowledge know, Termlist tl);
void knowledgeAddInverseKeys (Knowledge know, Term t1, Term t2);
void knowledgeAddInverseKeyFunctions (Knowledge know, Term t1, Term t2);
int inKnowledgeSet (const Knowledge know, Term t);
2004-04-23 11:58:43 +01:00
void knowledgeSimplify (Knowledge know, Term decryptkey);
int inKnowledge (const Knowledge know, Term term);
void knowledgePrint (Knowledge know);
void knowledgePrintShort (const Knowledge know);
2004-07-20 10:07:43 +01:00
Termlist knowledgeSet (const Knowledge know);
2004-04-23 11:58:43 +01:00
int knowledgeSubstNeeded (const Knowledge know);
Knowledge knowledgeSubstDo (const Knowledge know);
void knowledgeAddPublicFunction (const Knowledge know, const Term f);
int isKnowledgePublicFunction (const Knowledge know, const Term f);
Term inverseKey (Knowledge know, Term key);
2004-04-23 11:58:43 +01:00
2004-05-15 13:33:01 +01:00
//! Harnass macro for recursive procedures.
2004-04-23 11:58:43 +01:00
#define mindwipe(k,recurse) \
2004-05-26 10:34:08 +01:00
Termlist tl; \
int flag; \
2004-04-23 11:58:43 +01:00
if (k != NULL && k->vars != NULL) { \
2004-05-26 10:34:08 +01:00
tl = k->vars; \
2004-04-23 11:58:43 +01:00
while (tl != NULL) { \
if (tl->term->subst != NULL) { \
Term oldsubst = tl->term->subst; \
tl->term->subst = NULL; \
2004-05-26 10:34:08 +01:00
flag = recurse; \
2004-04-23 11:58:43 +01:00
tl->term->subst = oldsubst; \
return flag; \
} \
tl = tl->next; \
} \
} \
#endif