Key combination

CryptoSideChannel.TemplateAttacks.LikelyKeyType
struct LikelyKey
    keylist::Vector{Vector{Integer}}
end

This struct merges different key bytes for which probabilities are known to a whole key, by iterating first over keys that are more likely.

Keys are stored as lists of lists, where the outer lists represent the respective key byte (i.e. the first list represents the first key byte). The inner lists must be sorted according to the probability of a specific byte occuring.

Example

julia> k = LikelyKey([[1, 2, 3], [4, 5, 6]])
julia> for x = k
         print(x); print(" ")
       end
[1, 4] [2, 4] [1, 5] [3, 4] [2, 5] [1, 6] [3, 5] [2, 6] [3, 6]
source
CryptoSideChannel.TemplateAttacks.increase!Function
function increase!(s::Stack{Int}, size::Int)

Modifies the stack to the next larger state. All stacks that contain n elements will be seen before any stack containing n + 1 elements. No element in the stack will be greater than size.

If results from this method are used with iterate, all lists will be iterated.

Internals

If s has n elements, and there is a lexicographically larger stack with n elements, return a lexicographically larger stack corresponding to a new list (as described in Base.iterate).

Otherwise, returns the lexicographically smallest stack with n+1 elements.

source

Iteration interface

Base.iterateMethod
Base.iterate(k::LikelyKey)
Base.iterate(k::LikelyKey, state::Stack{Int})

Iterate over a LikelyKey. Keys that are more likely by the internal sorting of k will be seen first.

Internally, the current status of the iteration is represented by a stack. The contents of this stack are indices of the outer list. An occurence of a list index means that at this position in the key the next likely value should be tried. For example, a stack containing the following values: [1, 1, 1, 3, 3, 4, 4, 5] would be interpreted as follows:

  • For the first key byte, take the fourth most likely (since there are three 1s in our stack, we take the 3+1th most likely element)
  • The second key byte is the most likely (since there is no 2 in our stack)
  • The third key byte is the third most likely (there are two 3s in our stack)
  • Same for the fourth key byte: Take the third most likely
  • For the fifth key byte, take the second most likely (there is one 5 in our stack)

With this system, stacks with less entries will always correspond to more likely lists than stacks containing more entries.

source
Base.lengthMethod
Base.length(k::LikelyKey)

Returns the length of this iterator, which is the product of the length of all lists.

source
Base.eltypeMethod
Base.eltype(k::LikelyKey)

Returns the type of the elements that are iterated over. This is always a vector of key parts.

source