-rw-r--r-- 4980 cryptattacktester-20231020/isd0_params.cpp raw
#include <cassert>
#include "selection.h"
#include "isd0_params.h"
using namespace std;
bool isd0_params_valid(const vector<bigint> ¶ms,const vector<bigint> &attackparams)
{
bigint N = params.at(0);
bigint K_orig = params.at(1);
bigint W = params.at(2);
bigint pos = 0;
bigint ITERS = attackparams.at(pos++);
bigint RESET = attackparams.at(pos++);
bigint X = attackparams.at(pos++);
bigint YX = attackparams.at(pos++); auto Y = X+YX;
bigint P = attackparams.at(pos++);
bigint L = attackparams.at(pos++);
bigint Z = attackparams.at(pos++);
bigint QUEUE_SIZE = attackparams.at(pos++);
bigint QF = attackparams.at(pos++); auto PERIOD = QF*QUEUE_SIZE;
bigint FW = attackparams.at(pos++);
if (attackparams.size() != pos) return 0;
bigint K = K_orig-FW;
if (ITERS < 1) return 0;
if (RESET < 1) return 0;
if (ITERS%RESET != 0) return 0;
if (P < 0) return 0;
if (P > W) return 0;
if (L < 0) return 0;
if (L > N-K-(W-P)) return 0;
if (X < 1) return 0;
if (X > N-K-L) return 0;
if (Y < X) return 0;
if (Y > K+L) return 0;
if (Z < 0) return 0;
if (Z > K+L-P) return 0;
if (QUEUE_SIZE < 1) return 0;
if (PERIOD < 1) return 0;
if (P > 0 && L > 0 && QF*QUEUE_SIZE >= 2*binomial(K+L-Z,P)) return 0;
if (FW < 0) return 0;
if (FW > 1) return 0;
return 1;
}
void isd0_params(const vector<bigint> ¶ms,map<string,string> &S,int (*callback)(const vector<bigint> &))
{
bigint N = params.at(0);
bigint K_orig = params.at(1);
bigint W = params.at(2);
bigint FWmin = 0;
bigint FWmax = 1;
selection_constrain(S,"FW",FWmin,FWmax);
for (bigint FW = 0;FW <= 1;++FW) {
if (FW < FWmin) continue;
if (FW > FWmax) continue;
bigint K = K_orig-FW;
bigint Pmin = 1;
bigint Pmax = 3;
selection_constrain(S,"P",Pmin,Pmax);
for (bigint P = Pmin;P <= Pmax;++P) {
if (P < 0) continue;
if (P > W) continue;
bigint Lmin = 10;
bigint Lmax = 20;
selection_constrain(S,"L",Lmin,Lmax);
for (bigint L = Lmin;L <= Lmax;++L) {
if (L < 0) continue;
if (L > N-K-(W-P)) continue;
bigint ITERSmin = 1;
bigint ITERSmax = (16*binomial(N,W))/(binomial(K,P)*binomial(N-K-L,W-P));
if (ITERSmax > 1024) ITERSmax = 1024;
selection_constrain(S,"I",ITERSmin,ITERSmax);
if (ITERSmin < 1) continue;
for (bigint ITERS = ITERSmin;ITERS <= ITERSmax;ITERS *= 2) {
if (ITERS < 1) break;
bigint Zmin = 0;
bigint Zmax = L;
selection_constrain(S,"Z",Zmin,Zmax);
for (bigint Z = Zmin;Z <= Zmax;Z += (L > 0 ? L : bigint(1))) {
if (Z < 0) continue;
if (Z > K+L-P) continue;
bigint Xmin = 1;
bigint Xmax = 8;
selection_constrain(S,"X",Xmin,Xmax);
if (Xmin < 1) continue;
for (bigint X = Xmin;X <= Xmax;X *= 2) {
if (X < 1) break;
if (X > N-K-L) continue;
bigint RESETmin = 1;
bigint RESETmax = 1024;
if (X > 1) RESETmin = 2;
selection_constrain(S,"RE",RESETmin,RESETmax);
if (RESETmin < 1) continue;
for (bigint RESET = RESETmin;RESET <= RESETmax;RESET *= 2) {
if (RESET < 1) break;
if (ITERS%RESET != 0) continue;
bigint YXdiffmin = 1;
while ((RESET>>YXdiffmin) > 0) ++YXdiffmin;
bigint YXdiffmax = YXdiffmin+5;
if (RESET == 1) YXdiffmin = YXdiffmax = 1;
selection_constrain(S,"YX",YXdiffmin,YXdiffmax);
if (YXdiffmin < 0) continue;
for (bigint YXdiff = YXdiffmin;YXdiff <= YXdiffmax;++YXdiff) {
bigint Y = X+YXdiff;
if (Y < X) continue;
if (Y > K+L) continue;
bigint QFmin = 1;
bigint QFmax = 1024;
if (P == 0 || L == 0) QFmax = 1;
selection_constrain(S,"QF",QFmin,QFmax);
if (QFmin < 1) continue;
for (bigint QF = QFmin;QF <= QFmax;QF *= 2) {
if (QF < 1) break;
bigint QUEUE_SIZEmin = 1;
bigint QUEUE_SIZEmax = 8;
if (P == 0 || L == 0) QUEUE_SIZEmax = 1;
selection_constrain(S,"QU",QUEUE_SIZEmin,QUEUE_SIZEmax);
if (QUEUE_SIZEmin < 1) continue;
for (bigint QUEUE_SIZE = QUEUE_SIZEmin;QUEUE_SIZE <= QUEUE_SIZEmax;QUEUE_SIZE *= 2) {
if (QUEUE_SIZE < 1) break;
if (P > 0 && L > 0 && QF*QUEUE_SIZE >= 2*binomial(K+L-Z,P)) continue;
vector<bigint> Q{ITERS,RESET,X,Y-X,P,L,Z,QUEUE_SIZE,QF,FW};
if (callback(Q) < 0) return;
}
}
}
}
}
}
}
}
}
}
}