-rw-r--r-- 5331 cryptattacktester-20231020/isd1_params.cpp raw
#include <cassert>
#include "selection.h"
#include "isd1_params.h"
using namespace std;
bool isd1_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 PI = 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 WINDOW = attackparams.at(pos++);
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 (PI < 1) return 0;
if (2*PI > W) return 0;
if (L < 0) return 0;
if (L > N-K-(W-2*PI)) 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-2*PI) return 0;
// now PI <= (K+L-Z)/2
if (QUEUE_SIZE < 1) return 0;
if (PERIOD < 1) return 0;
if (WINDOW < 1) return 0;
if (FW < 0) return 0;
if (FW > 1) return 0;
return 1;
}
void isd1_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 PImin = 1;
bigint PImax = 3;
selection_constrain(S,"PI",PImin,PImax);
for (bigint PI = PImin;PI <= PImax;++PI) {
if (PI < 1) continue;
if (2*PI > W) continue;
if (PI > K/2) continue;
bigint Lmin = 0;
bigint Lmax = 10;
selection_constrain(S,"L",Lmin,Lmax);
for (bigint L = Lmin;L <= Lmax;++L) {
if (L < 0) continue;
if (L > N-K-(W-2*PI)) continue;
bigint ITERSmin = 1;
bigint ITERSmax = (16*binomial(N,W))/(binomial(K/2,PI)*binomial(K-K/2,PI)*binomial(N-K-L,W-PI*2));
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-2*PI) continue;
bigint listsize0 = binomial((K+L-Z)/2,PI);
bigint listsize1 = binomial(K+L-Z-(K+L-Z)/2,PI);
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;
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;
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;
bigint WINDOWmin = 1;
bigint WINDOWmax = 3;
selection_constrain(S,"WI",WINDOWmin,WINDOWmax);
for (bigint WINDOW = WINDOWmin;WINDOW <= WINDOWmax;++WINDOW) {
if (WINDOW < 1) continue;
vector<bigint> Q{ITERS,RESET,X,Y-X,PI,L,Z,QUEUE_SIZE,QF,WINDOW,FW};
if (callback(Q) < 0) return;
}
}
}
}
}
}
}
}
}
}
}
}