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:
objectRepresent 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 thePropertyobject.Note that arithmetic with properties is not supported. For example, two
Propertyobjectsd1andd2cannot be XORed, i.e.,d1 ^ d2. This can be done instead by performing the arithmetic with the property values and converting the resultingTermto 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,LinearMaskorValue.- xreplace(rule)[source]
Replace occurrences of properties within the expression.
The argument
ruleis a dict-like object representing the replacement rule.This method is similar to SymPy xreplace but with the restriction that only
Propertyobjects are allowed inrule.
- vrepr()[source]
Return an executable string representation.
This method returns a string so that the relation
eval(self.vrepr()) == selfholds.
- 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
Valueproperty 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
Differenceproperty 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
LinearMaskproperty, 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
Operationopany 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 aPropertyobject. Otherwise, this method returns theabstractproperty.opmodel.OpModelof the operationopwith the given input propertyinput_prop.Note
Operations
opwith scalar operands are not supported, but these operands can be removed withmake_partial_operationand partial operations are supported by this method.
- class cascada.abstractproperty.property.PropConcat(**kwargs)[source]
Bases:
cascada.bitvector.operation.ConcatSubclass of
Concatthat propagates properties naturally.The only difference between
ConcatandPropConcatis that the latter one propagates (seeProperty.propagate) an inputPropertylistp0, p1asProperty(Concat(p0.val, p1.val)).
- class cascada.abstractproperty.property.PropExtract(**kwargs)[source]
Bases:
cascada.bitvector.operation.ExtractSubclass of
Extractthat propagates properties naturally.The only difference between
ExtractandPropExtractis that the latter one (with fixed operands) propagates (seeProperty.propagate) an inputPropertypasProperty(Extract_{·, i, j}(p0.val)), wherei, jare the fixed operands.
- cascada.abstractproperty.property.make_partial_propextract(i, j)[source]
Return a
PartialOperationofPropExtractthat propagates properties naturally.