lazart.analysis.attack_redundancy module¶
The module lazart.analysis.attack_redundancy contains definitions for attack equivalence-redundancy analysis.
Fixing non-redundant attacks should fix corresponding relative attacks (or at least make them harder), depending on the chosen definition and fault model.
- since
3.0
- author
Etienne Boespflug
- class lazart.analysis.attack_redundancy.AttackRedundancyNode(trace_name: str)¶
Bases:
object
AttackRedundancyNode represents a node of the attack redundancy graph.
It holds the set of trace-nodes redundant to its trace.
Each node is associated to an attack trace, identified by name.
__init__ (ctor): Constructs a AttackRedundancyNode for the trace identified by trace_name.
- Parameters
trace_name (str) – the name of the trace corresponding to this node.
- redundant¶
Determines if the trace is redundant from at least another one.
- Type
bool
- equivalents¶
The set of all trace that are equivalent with this node.
- Type
List[AttackRedundancyNode]
- _trace_name¶
The name of the trace corresponding to this node.
- Type
str
- get_trace(analysis: lazart.core.analysis.Analysis) lazart.core.traces.Trace ¶
Returns the trace corresponding to the node, cached on first request.
- trace_name() str ¶
The name of the trace corresponding to this node.
- Returns
the name of the associated trace.
- Return type
str
- add_edge(redundant) bool ¶
Adds a node corresponding to a redundant attack to the set of edges (redundant attacks).
- Parameters
redundant (AttackRedundancyNode) – The node corresponding to the redundant trace.
- Returns
Returns True if the edge was added, False otherwise (duplicate).
- Return type
bool
- have_edge(node) bool ¶
Check if this node is in the list of redundant traces.
- Parameters
node (AttackRedundancyNode) – the node to be checked.
- Returns
Returns True if this node is in the list of redundant traces, False otherwise.
- Return type
bool
- class lazart.analysis.attack_redundancy.AttackRedundancyGraph¶
Bases:
object
The AttackRedundancyGraph class represents a graph of redundancy and equivalence for attack traces.
It contains a set of
AttackRedundancyNode
containing list of redundant (edge) trace nodes and the associated equivalence class.__init__ (ctor): Constructs a new empty redundancy graph.
- _equivalence_classes¶
list of equivalence classes, containing list of equivalent nodes.
- Type
List[AttackRedundancyNode]
- add_node(trace_name: str, node: lazart.analysis.attack_redundancy.AttackRedundancyNode)¶
Adds a node to the graph with the specified trace_name.
- Parameters
trace_name (str) – the name of the trace corresponding to the node.
node (AttackRedundancyNode) – the node object to add.
- node(trace_name: str) lazart.analysis.attack_redundancy.AttackRedundancyNode ¶
Returns the node corresponding to the trace name. Returns None if the node doesn’t exist.
- Parameters
trace_name (str) – the name of the trace of the node.
- Returns
the node corresponding to the trace name, None other wise.
- Return type
- make_or_get(trace_name: str) lazart.analysis.attack_redundancy.AttackRedundancyNode ¶
Returns the node corresponding to the trace name if it exists, otherwise creates and returns a new node for this trace name.
- Parameters
trace_name (str) – the name of the trace of the node.
- Returns
the node corresponding to the trace name.
- Return type
- add_edge(base: lazart.analysis.attack_redundancy.AttackRedundancyNode, redundant: lazart.analysis.attack_redundancy.AttackRedundancyNode)¶
Adds a edge in the base node for the redundant trace node.
- Parameters
base (AttackRedundancyNode) – the node corresponding to the trace to which redundant is redundant.
redundant (AttackRedundancyNode) – the node corresponding to the trace which is redundant to base.
- equivalent(a: lazart.analysis.attack_redundancy.AttackRedundancyNode, b: lazart.analysis.attack_redundancy.AttackRedundancyNode) List[lazart.analysis.attack_redundancy.AttackRedundancyNode] ¶
Set a and b as equivalent traces, creating a new equivalent class if required.
- Parameters
a (AttackRedundancyNode) – the first attack node.
b (AttackRedundancyNode) – the second attack node.
- Returns
the equivalence class of attacks as a list of nodes.
- Return type
List[AttackRedundancyNode]
- redundant_by(node: lazart.analysis.attack_redundancy.AttackRedundancyNode) List[lazart.analysis.attack_redundancy.AttackRedundancyNode] ¶
Returns the list of redundant trace nodes for the specified node.
O(n) complexity, as it need to search among all node wich one contains node as edge.
- Parameters
node (AttackRedundancyNode) – the node for which the redundant nodes will be searched.
- Returns
the list of all nodes redundant to node.
- Return type
List[AttackRedundancyNode]
- lazart.analysis.attack_redundancy.prefix_rule(a: lazart.core.traces.Trace, b: lazart.core.traces.Trace)¶
Verifies if the trace b is redundant to a with respect to “SubWord” definition.
Prefix redundancy definition: an attack A2 is redundant to an attack A1 if the the ordered set of fault of A2 is a prefix of the ordered set of faults of A1.
example: {A1 = [F1, F2, F3], A2 = [F1, F2]}.
- lazart.analysis.attack_redundancy.sub_word_rule(a: lazart.core.traces.Trace, b: lazart.core.traces.Trace)¶
Verifies if the trace b is redundant to a with respect to “SubWord” definition. SubWord redundancy definition: an attack A2 is redundant to an attack A1 if the ordered set of faults of A2 is a sub-word of the ordered set of faults of A1.
This definition includes
Prefix
definition. Longer to compute.examples: {A1: [F1, F2, F3, F4], A2 = [F2, F4]} ; {A1 = [F1, F2, F3], A2 = [F1, F2]}
- lazart.analysis.attack_redundancy.feq_rule(a: lazart.core.traces.Trace, b: lazart.core.traces.Trace) bool ¶
Verifies if the attacks b and to a are fault-equivalent. Fault-equivalence: two attacks A1 and A2 are equivalent if their sequence of fault IPs are equal.
- lazart.analysis.attack_redundancy.eq_rule(a: lazart.core.traces.Trace, b: lazart.core.traces.Trace) bool ¶
Verifies if the attacks b and to a are equivalent. Equivalence: two attacks A1 and A2 are equivalent if their sequences of transitions (faults, detections and CF) are equal.
- class lazart.analysis.attack_redundancy.AttackRedundancyResults(analysis: lazart.core.analysis.Analysis, graph: lazart.analysis.attack_redundancy.AttackRedundancyGraph, duration: float)¶
Bases:
object
The AttackRedundancyResults class holds results of the attacks redundancy analysis.
It holds the graph of equivalence and redundancy.
__init__ (ctor): Constructs a new AttackRedundancyResults object with an analysis, the equivalence/redundancy graph and the duration information.
- Parameters
analysis (Analysis) – the Analysis object from which the traces will be read.
graph (AttackRedundancyGraph) – Hotspot data for each injection point for each order.
duration (float) – duration of the analysis computing in millisecond.
- _graph¶
The redundancy graph of the analysis.
- _duration¶
The duration of the attack redundancy analysis.
- Type
float
- lazy_count¶
The number of lazy nodes.
- Type
int
- graph() lazart.analysis.attack_redundancy.AttackRedundancyGraph ¶
Returns the redundancy graph.
- Returns
the redundancy graph.
- Return type
- representatives(predicate: Callable[[lazart.core.traces.Trace], bool] = <function AttackRedundancyResults.<lambda>>, minimals_only=False) List[lazart.core.traces.Trace] ¶
Returns the list of a representative traces for each equivalence class in the graph, if the trace’s representative verify predicate.
- Parameters
- Returns
the list of representative traces for specified orders.
- Return type
List[Trace]
- duration() float ¶
Returns the duration in second of the attacks redundancy analysis computations.
- Returns
duration of the analysis computing in second.
- Return type
float
- table(**kwargs) lazart.results.formats.Table ¶
Returns the table of attack for each order, including redundant attacks.
- Parameters
title (str, optional) – title of the table, defaults to None
- Returns
the table corresponding to equivalence and redundancy results.
- Return type
_type_
- lazart.analysis.attack_redundancy.eq_red_analysis(analysis: lazart.core.analysis.Analysis, **kwargs) lazart.analysis.attack_redundancy.AttackRedundancyResults ¶
Returns an AttackRedundancyResults from an analysis object performing Attacks Redundancy Analysis.
Requires that the traces parsing step (see
traces_results()
) has been computed for this analysis. This function uses log to display progress, reduce verbosity level to reduce output.- Kwargs:
eq_rule (Callable[[Trace, Trace], bool]): binary predicate determining if two attacks are equivalent. default: feq_rule (fault-equivalence).
red_rule (Callable[[Trace, Trace], bool]): binary predicate determining if an attack ‘b’ is redundant to an attack ‘a’. default: prefix_rule.
lazy (bool): boolean predicate determining if the complete graph should be computed. Otherwise, only the minimal attacks are researched. default: False.
satisfies_fct (Callable[[Trace], bool]): boolean predicate determining if a trace should be considered. default: lambda trace: trace.satisfies().
eq_range (List[int]): two elements list ([min, max]) limit in which the equivalence analysis will be performed. default: [1, max_order].
red_range (List[int]): two elements list ([min, max]) limit in which the redundancy analysis will be performed. default: [1, max_order].
- eq_mode (str): name of the mode of equivalence comparison to be performed (“0”, “1+”, “N+”), default: “0”:
“0”: indicates that each trace will be compared to other same order traces only.
“0+”: indicates that each trace will be compared to other traces of order greater or equal than itself.
“1+”: indicates that each trace will be compared to other traces of order strictly greater than itself.
*note:* equivalence and fault-equivalence require that “0” mode is used. However, this option can be used if a custom `eq_rule` is provided and required specific comparison mode.
- red_mode (str): name of the mode of equivalence comparison to be performed (“0”, “1+”, “N+”), default: “1+”:
“0”: indicates that each trace will be compared to other same order traces only.
“0+”: indicates that each trace will be compared to other traces of order greater or equal than itself.
“1+”: indicates that each trace will be compared to other traces of order strictly greater than itself.
*note:* prefix and sub-word definitions require that “1+” mode is used. However, this option can be used if a custom `red_rule` is provided and required specific comparison mode.
- Parameters
analysis (Analysis) – the analysis for which the equivalence-redundancy analysis will be performed.
- Returns
the computed attacks equivalence and redundancy results.
- Return type
- class lazart.analysis.attack_redundancy.AttacksRedundancyStep(analysis)¶
Bases:
lazart._internal_.extensions.AnalysisStep
Subclass of AnalysisStep for the equivalence and redundancy analysis, see
lazart._internal_.extensions.AnalysisStep
.__init__ (ctor): Constructs a new AttacksRedundancyStep object associated to the specified analysis.
- Parameters
analysis (Analysis) – the analysis of the step.
- execute(**kwargs)¶
- init()¶
- save_disk()¶
- clean()¶
- lazart.analysis.attack_redundancy.attacks_redundancy_results(analysis: lazart.core.analysis.Analysis, **kwargs) lazart.analysis.attack_redundancy.AttackRedundancyResults ¶
Returns an AttackRedundancyResults from an analysis object performing Attacks Redundancy Analysis.
Requires that the traces has been computed for this analysis.
Uses extension system (attack_redundancy_ext, see
AttacksRedundancyStep
) to reuse disk/RAM cache if available. This function uses log to display progress, reduce verbosity level to reduce output.- Kwargs:
eq_rule (Callable[[Trace, Trace], bool]): binary predicate determining if two attacks are equivalent. default: feq_rule (fault-equivalence).
red_rule (Callable[[Trace, Trace], bool]): binary predicate determining if an attack ‘b’ is redundant to an attack ‘a’. default: prefix_rule.
lazy (bool): boolean predicate determining if the complete graph should be computed. Otherwise, only the minimal attacks are researched. default: False.
satisfies_fct (Callable[[Trace], bool]): boolean predicate determining if a trace should be considered. default: lambda trace: trace.satisfies().
eq_range (List[int]): two elements list ([min, max]) limit in which the equivalence analysis will be performed. default: [1, max_order].
red_range (List[int]): two elements list ([min, max]) limit in which the redundancy analysis will be performed. default: [1, max_order].
- eq_mode (str): name of the mode of equivalence comparison to be performed (“0”, “1+”, “N+”), default: “0”:
“0”: indicates that each trace will be compared to other same order traces only.
“0+”: indicates that each trace will be compared to other traces of order greater or equal than itself.
“1+”: indicates that each trace will be compared to other traces of order strictly greater than itself.
*note:* equivalence and fault-equivalence require that “0” mode is used. However, this option can be used if a custom `eq_rule` is provided and required specific comparison mode.
- red_mode (str): name of the mode of equivalence comparison to be performed (“0”, “1+”, “N+”), default: “1+”:
“0”: indicates that each trace will be compared to other same order traces only.
“0+”: indicates that each trace will be compared to other traces of order greater or equal than itself.
“1+”: indicates that each trace will be compared to other traces of order strictly greater than itself.
*note:* prefix and sub-word definitions require that “1+” mode is used. However, this option can be used if a custom `red_rule` is provided and required specific comparison mode.
- Parameters
analysis (Analysis) – the Analysis object from which the traces will be read.
- Returns
the computed attacks equivalence and redundancy results.
- Return type
- lazart.analysis.attack_redundancy.representatives(analysis: lazart.core.analysis.Analysis, predicate: Callable[[lazart.core.traces.Trace], bool] = <function <lambda>>) List[lazart.core.traces.Trace] ¶
Returns the list of minimal attacks matching the specified predicate. One representative per equivalence class is kept.
- lazart.analysis.attack_redundancy.minimals(analysis: lazart.core.analysis.Analysis, predicate: Callable[[lazart.core.traces.Trace, lazart.analysis.attack_redundancy.AttackRedundancyNode], bool] = <function <lambda>>) List[lazart.core.traces.Trace] ¶
Returns the list of minimal attacks matching the specified predicate. One representative per equivalence class is kept.