2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
2005-12-27 11:19:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*@file cost.c
|
|
|
|
*
|
|
|
|
* Determine cost of a given semitrace in sys
|
|
|
|
* Constructed for Arachne results, unreliable otherwise.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "switches.h"
|
2006-03-28 15:45:02 +01:00
|
|
|
#include "system.h"
|
2007-01-06 14:45:29 +00:00
|
|
|
#include "binding.h"
|
|
|
|
#include "error.h"
|
2006-07-06 16:52:13 +01:00
|
|
|
#include <limits.h>
|
2005-12-27 11:19:45 +00:00
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Private methods
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Public methods
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//! Determine cost of an attack
|
|
|
|
/*
|
|
|
|
* This should also work on uncompleted semitraces, and should be monotonous
|
|
|
|
* (i.e. further iterations should increase the cost only) so that it can be
|
|
|
|
* used for branch and bound.
|
|
|
|
*
|
|
|
|
* A lower value (closer to 0) is a more feasible attack.
|
|
|
|
*/
|
2006-01-02 16:07:56 +00:00
|
|
|
int
|
2011-04-26 10:49:05 +01:00
|
|
|
computeAttackCost (const System sys)
|
|
|
|
{
|
|
|
|
// Use nice heuristic cf. work of Gijs Hollestelle. Hand-picked parameters.
|
|
|
|
int cost;
|
|
|
|
|
|
|
|
cost = 0;
|
|
|
|
|
|
|
|
//cost += get_semitrace_length ();
|
|
|
|
|
|
|
|
cost += 10 * selfInitiators (sys);
|
|
|
|
cost += 7 * selfResponders (sys);
|
|
|
|
cost += 10 * sys->num_regular_runs;
|
|
|
|
cost += 3 * countInitiators (sys);
|
|
|
|
cost += 2 * countBindingsDone ();
|
|
|
|
cost += 1 * sys->num_intruder_runs;
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Compute attack cost in different pruning contexts.
|
|
|
|
int
|
2006-01-02 16:07:56 +00:00
|
|
|
attackCost (const System sys)
|
2005-12-27 11:19:45 +00:00
|
|
|
{
|
2006-07-06 16:52:13 +01:00
|
|
|
if (switches.prune == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (switches.prune == 1)
|
2006-07-06 16:54:14 +01:00
|
|
|
{
|
|
|
|
// Select the first attack.
|
|
|
|
// Implied by having the cost of traces after finding an attack to be always higher.
|
|
|
|
//
|
|
|
|
if (sys->current_claim->failed > 0)
|
|
|
|
{
|
|
|
|
// we already have an attack
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// return some value relating to the cost (anything less than int_max will do)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (switches.prune == 2)
|
2006-07-06 16:52:13 +01:00
|
|
|
{
|
2011-04-26 10:49:05 +01:00
|
|
|
return computeAttackCost (sys);
|
2006-07-06 16:52:13 +01:00
|
|
|
}
|
|
|
|
error ("Unknown pruning method (cost function not found)");
|
2007-01-06 14:45:29 +00:00
|
|
|
return 0;
|
2005-12-27 11:19:45 +00:00
|
|
|
}
|