// Copyright (c) The University of Cincinnati. All rights reserved. // UC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF // THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE, OR NON-INFRINGEMENT. UC SHALL NOT BE LIABLE // FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, // RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS // DERIVATIVES. // By using or copying this Software, Licensee agrees to abide by the // intellectual property laws, and all other applicable laws of the // U.S., and the terms of this license. // Author : Antarpreet Singh // #include #include #include #include using namespace std; typedef vector double_vector; typedef vector bool_vector; void DPA_HW(vector*, vector&, int, vector*, int); int HW(vector&); void TEST1(vector *, vector *, vector *); bool DPA_HW_DOM(int no_of_output_bits, int max_key_comb, int vectors, vector &ptext, vector ¤t_data, vector &diffwf, int *final_key, vector &kg, double *max, int clock_posedge_time_min, int clock_posedge_time_max, int correct_key, ofstream &fplog,string testname, string algorithm) { vector ctext; vector ctext_temp; vector diffwf_temp; int i,j,k; double absmax; bool done; int keyvalue; int ctext_size; int hamming_weight_cut_off = ceil(no_of_output_bits/2); for(j=0;j ctext_size) { cout<<" All the vectors are exhausted. Unable to find key"<<"\n"; fplog<<" All the vectors are exhausted. Unable to find key"<<"\n"; exit(1); } //Perform DPA DPA_HW(¤t_data,ctext,hamming_weight_cut_off,&diffwf_temp,vectors); diffwf.push_back(diffwf_temp); diffwf_temp.clear(); ctext.clear(); } for(j=0;j max[j]) { *(max+j) = diffwf[j][i]; } } } absmax = *max; keyvalue = 0; for(j=1;j absmax) { absmax = *(max+j); keyvalue = j; } } cout<<"Key Guess is : "< ctext_size) { cout<<"Found Incorrect key\n"; fplog<<"Found Incorrect key\n"; exit(2); } else { cout<<"Peak Value For Correct key : "< *current_data, vector &ctext, int bit, vector *diffwf1, int vectors) { vector wf0; vector wf1; vector :: iterator iter_cd_i = current_data->begin(); vector :: iterator iter_cd_j = iter_cd_i->begin(); int i,j; //Power Model for DPA for(i=0; i < vectors; i++) { if(HW(ctext[i]) < bit) { wf0.push_back((*iter_cd_i)); } else if (HW(ctext[i]) >= bit) { wf1.push_back((*iter_cd_i)); } iter_cd_i++; } int no_of_samples_x = (*current_data)[0].size(); int no_of_samples_y = current_data->size()-1; DPA_DOM(no_of_samples_x,wf0,wf1,diffwf1); } /******************************************************************/ int HW(vector &ctext) { int i,HW=0; int size = ctext.size(); for(i=0;i