cascada.abstractproperty.property module
Provide a base class for properties like Difference
, LinearMask
or Value
.
Represent bit-vector properties. |
|
Subclass of |
|
Subclass of |
|
Return a |
- class cascada.abstractproperty.property.Property(value)[source]
Bases:
object
Represent bit-vector properties.
A (bit-vector) property pair, or simply a property, over a function \(f\) is a pair of bit-vectors \((\alpha, \beta)\) with an associated propagation probability \(PP_f(\alpha, \beta)\). In this case, we also say that the input property \(\alpha\) propagates to the output property \(\beta\) with probability \(PP_f(\alpha, \beta)\).
Each instance of this class represents an input or output property; the underlying bit-vector value of the input or output property is stored in the attribute
val
, but the associated function \(f\) is not stored within theProperty
object.Note that arithmetic with properties is not supported. For example, two
Property
objectsd1
andd2
cannot be XORed, i.e.,d1 ^ d2
. This can be done instead by performing the arithmetic with the property values and converting the resultingTerm
to a property, that is,Property(d1.val ^ d2.val)
This class is not meant to be instantiated but to provide a base class to define bit-vector properties such as
Difference
,LinearMask
orValue
.- xreplace(rule)[source]
Replace occurrences of properties within the expression.
The argument
rule
is a dict-like object representing the replacement rule.This method is similar to SymPy xreplace but with the restriction that only
Property
objects are allowed inrule
.
- vrepr()[source]
Return an executable string representation.
This method returns a string so that the relation
eval(self.vrepr()) == self
holds.
- classmethod propagate(op, input_prop)[source]
Propagate the given input property through the given operation.
Given a function \(y = f(x)\), an input property \(p_x\) propagates (over \(f\)) to an output property \(p_y\) if the propagation probability \(PP_f(\alpha, \beta)\) is not zero.
Note that if \(f\) has \(t\) operands, the input property is actually a list of \(t\) properties, that is, \(p_x = (p_{x_0}, p_{x_1}, \dots, p_{x_{t-1}})\), and similar for \(p_y\).
For some functions, any input property propagates to a unique output property with probability 1, and the output property can be easily computed from the input property.
Examples of probability-one propagations are the following:
For the
Value
property type, for any operation \(f\) and any input property \(p_x\), the output property \(p_y\) is uniquely determined and its bit-vector value isf(p_x.val)
.For the
Difference
property type with difference operation \(-\) (e.g., XOR), for any linear (over \(-\)) operation \(f\) and any input property \(p_x\), the output property \(p_y\) is uniquely determined and its bit-vector value isf(p_x.val)
.For the
LinearMask
property, for any XOR-linear operation \(f\) and any input property \(p_x\), the output property \(p_y\) is uniquely determined and its bit-vector value satisfiesp_x.val == M(p_y.val)
, where \(M\) is the transpose of the binary matrix representing \(f\).
If for the given
Operation
op
any input property propagates to a unique output property with probability 1 and the output property can be easily computed from the input property, this method returns the corresponding output property (for the given input propertyinput_prop
) as aProperty
object. Otherwise, this method returns theabstractproperty.opmodel.OpModel
of the operationop
with the given input propertyinput_prop
.Note
Operations
op
with scalar operands are not supported, but these operands can be removed withmake_partial_operation
and partial operations are supported by this method.
- class cascada.abstractproperty.property.PropConcat(**kwargs)[source]
Bases:
cascada.bitvector.operation.Concat
Subclass of
Concat
that propagates properties naturally.The only difference between
Concat
andPropConcat
is that the latter one propagates (seeProperty.propagate
) an inputProperty
listp0, p1
asProperty(Concat(p0.val, p1.val))
.
- class cascada.abstractproperty.property.PropExtract(**kwargs)[source]
Bases:
cascada.bitvector.operation.Extract
Subclass of
Extract
that propagates properties naturally.The only difference between
Extract
andPropExtract
is that the latter one (with fixed operands) propagates (seeProperty.propagate
) an inputProperty
p
asProperty(Extract_{·, i, j}(p0.val))
, wherei, j
are the fixed operands.
- cascada.abstractproperty.property.make_partial_propextract(i, j)[source]
Return a
PartialOperation
ofPropExtract
that propagates properties naturally.