-rw-r--r-- 1567 cryptattacktester-20230614/subset.h raw
#ifndef SUBSET_H
#define SUBSET_H
#include "bigint.h"
#include "bit_vector.h"
static inline void subset(vector<vector<bit>> &L_sum,
vector<vector<vector<bit>>> &L_set,
bigint m, bigint n, const bigint idx_bits,
const vector<bit> &s,
const vector<vector<bit>> &H,
vector<bigint> prefix = vector<bigint>(0),
vector<vector<bit>> precomputed = vector<vector<bit>>(0))
{
if (precomputed.size() == 0)
{
precomputed.push_back(H.at(0));
for (bigint i = 1; i < n; i++)
precomputed.push_back(bit_vector_xor(H.at(i), precomputed.at(i-1)));
}
if (n == 0 || n == m)
{
// computing subset set at the LE positions
vector<bigint> set = prefix;
vector<bit> s_new = s;
if (n == m)
{
if (n) bit_vector_ixor(s_new, precomputed.at(n-1));
for (bigint i = n-1; i >= 0; i--)
{
set.push_back(i);
// bit_vector_ixor(s_new, H.at(i));
}
}
vector<vector<bit>> v_set(0);
for (bigint i = 0; i < set.size(); i++)
v_set.push_back(bit_vector_from_integer(set.at(i), idx_bits));
L_sum.push_back(s_new);
L_set.push_back(v_set);
return;
}
vector<bit> s_new = s;
subset(L_sum, L_set, n, n, idx_bits, s_new, H, prefix, precomputed);
for (bigint i = n; i < m; i++)
{
vector<bigint> prefix_new = prefix;
prefix_new.push_back(i);
vector<bit> s_new = bit_vector_xor(s, H.at(i));
subset(L_sum, L_set, i, n-1, idx_bits, s_new, H, prefix_new, precomputed);
}
}
#endif