forked from SideChannelMarvels/Daredevil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpa.cpp
More file actions
52 lines (46 loc) · 2.53 KB
/
cpa.cpp
File metadata and controls
52 lines (46 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ===================================================================== */
/* This file is part of Daredevil */
/* Daredevil is a side-channel analysis tool */
/* Copyright (C) 2016 */
/* Original author: Paul Bottinelli <paulbottinelli@hotmail.com> */
/* Contributors: Joppe Bos <joppe_bos@hotmail.com> */
/* */
/* This program 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 */
/* any later version. */
/* */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* ===================================================================== */
#include <iostream>
#include "cpa.h"
#include "omp.h"
/* Given the messages stored in m, use the bytenum-th byte to construct
* the guesses for round R for algorithm alg and store the guesses in guess.
* des_switch is only used by DES
*/
template <class TypeGuess>
int construct_guess (TypeGuess ***guess, uint32_t alg, Matrix *m, uint32_t n_m, uint32_t bytenum, uint32_t R, uint32_t des_switch, uint16_t * sbox, uint32_t n_keys, int8_t bit) {
int ret;
switch (alg) {
case ALG_AES:
ret = construct_guess_AES (guess, m, n_m, bytenum, R, sbox, n_keys, bit);
if (ret < 0) return -1;
break;
case ALG_DES:
ret = construct_guess_DES (guess, m, n_m, bytenum, R, des_switch, sbox, n_keys, bit);
if (ret < 0) return -1;
break;
default:
fprintf (stderr, "Algorithm is not supported (yet).\n");
return -1;
}
return 1;
}
template int construct_guess (uint8_t ***guess, uint32_t alg, Matrix *m, uint32_t n_m, uint32_t bytenum, uint32_t R, uint32_t des_switch, uint16_t * sbox, uint32_t n_keys, int8_t bit);