/*****************************************************************************
 *
 * Copyright (c) 2018-19, Eduard Gerlits, Paula Herber, Josef Treus
 * Westfälische Wilhelms-Universität Münster, AG Embedded Systems 
 * All rights reserved.
 *
 * This file is part of SysCSec
 *
 * SysCSec is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * SysCSec is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SysCSec.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 *  Please report any problems or bugs to: sysc.sec@uni-muenster.de
 *
 ****************************************************************************/

#include <systemc.h>
#include "ecc_domain_parameters.h"
#include <string.h>
#include "System.h"
#include "RessourceHandler.cpp"
#include <iostream>
#include <random>
#include <chrono>

int sc_main(int argc, char* argv[]){

	#define __TIMEOUT__ 15000000
	// intitialize power trace timeline
	bool useUAF = false;
	if(argc == 3 && !strcmp(argv[2], "UAF")){
			useUAF = true;
	}

	if(argc==1) {
		SystemModule system("system", useUAF, _STD_ECC_PARAM_A_, _STD_ECC_PARAM_B_, _STD_ECC_PARAM_M_, _STD_ECC_PARAM_G_X_, _STD_ECC_PARAM_G_Y_, _STD_ECC_PARAM_N_);
		sc_start(__TIMEOUT__, SC_NS);
	}
	else {
		
		char * param = new char[ strlen( argv[1] ) ];
		strcpy( param, argv[1] );

		if(!strcmp(param,"standard")){
			SystemModule system("system", useUAF, _STD_ECC_PARAM_A_, _STD_ECC_PARAM_B_, _STD_ECC_PARAM_M_, _STD_ECC_PARAM_G_X_, _STD_ECC_PARAM_G_Y_, _STD_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);
		}
		else if(!strcmp(param,"standard2")){
			SystemModule system("system", useUAF, _STD2_ECC_PARAM_A_, _STD2_ECC_PARAM_B_, _STD2_ECC_PARAM_M_, _STD2_ECC_PARAM_G_X_, _STD2_ECC_PARAM_G_Y_, _STD2_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);
		}
		else if(!strcmp(param,"standard3")){
			SystemModule system("system", useUAF, _STD3_ECC_PARAM_A_, _STD3_ECC_PARAM_B_, _STD3_ECC_PARAM_M_, _STD3_ECC_PARAM_G_X_, _STD3_ECC_PARAM_G_Y_, _STD3_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);
		}
		else if(!strcmp(param,"secp128r1")){
			SystemModule system("system", useUAF, _SECP128R1_ECC_PARAM_A_, _SECP128R1_ECC_PARAM_B_, _SECP128R1_ECC_PARAM_M_, _SECP128R1_ECC_PARAM_G_X_, _SECP128R1_ECC_PARAM_G_Y_, _SECP128R1_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);
		}
		else if(!strcmp(param,"secp128r2")){
			SystemModule system("system", useUAF, _SECP128R2_ECC_PARAM_A_, _SECP128R2_ECC_PARAM_B_, _SECP128R2_ECC_PARAM_M_, _SECP128R2_ECC_PARAM_G_X_, _SECP128R2_ECC_PARAM_G_Y_, _SECP128R2_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);
		}

		else if(!strcmp(param,"userdefined")){
			SystemModule system("system", useUAF, argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
			sc_start(__TIMEOUT__, SC_NS);
		}

		else {
			SystemModule system("system", useUAF, _STD_ECC_PARAM_A_, _STD_ECC_PARAM_B_, _STD_ECC_PARAM_M_, _STD_ECC_PARAM_G_X_, _STD_ECC_PARAM_G_Y_, _STD_ECC_PARAM_N_);
			sc_start(__TIMEOUT__, SC_NS);		
		}
		delete param;
	}

	RessourceHandler::getInstance()->logToFile();
	
	return 0;
}
