-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeccakOptAsm.cpp
51 lines (43 loc) · 1.21 KB
/
KeccakOptAsm.cpp
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
/*
* File: KeccakOptAsm.cpp
* Author: ph4r05
*
* Created on June 23, 2014, 2:40 PM
*/
#include "KeccakOptAsm.h"
extern "C" {
#include "sha3/hash_functions/Keccak64_common/KeccakF-1600-interface.h"
#include "sha3/hash_functions/Keccak64_common/KeccakSponge.h"
}
KeccakOptAsm::KeccakOptAsm() : rounds(7) {
}
KeccakOptAsm::~KeccakOptAsm() {
}
int KeccakOptAsm::setNumRounds(int rounds) {
if (rounds!=24 && (rounds<1 || rounds>8)){
return -1;
}
this->rounds=rounds;
return 1;
}
int KeccakOptAsm::evaluate(const unsigned char* input, unsigned char* output) const {
unsigned char ou[128] = {0};
spongeState state;
InitSponge(&state, 1024, 576);
Absorb(&state, input, 32*8, rounds);
Squeeze(&state, ou, 1024, rounds);
memcpy(output, ou, 16);
return 1;
}
int KeccakOptAsm::evaluate(const unsigned char* input, const unsigned char* key, unsigned char* output) const {
unsigned char in[32] = {0};
unsigned char ou[128] = {0};
memcpy(in, input, 16);
memcpy(in+16, key, 16);
spongeState state;
InitSponge(&state, 1024, 576);
Absorb(&state, in, 32*8, rounds);
Squeeze(&state, ou, 1024, rounds);
memcpy(output, ou, 16);
return 1;
}