-
Notifications
You must be signed in to change notification settings - Fork 5
/
owf.c
63 lines (55 loc) · 1.89 KB
/
owf.c
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
52
53
54
55
56
57
58
59
60
61
62
63
/*
* SPDX-License-Identifier: MIT
*/
#if defined(HAVE_CONFIG_H)
#include <config.h>
#endif
#include "owf.h"
#include "aes.h"
bool owf_128(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
int ret = aes128_init_round_keys(&round_keys, key);
ret |= aes128_encrypt_block(&round_keys, input, output);
return ret == 0;
}
bool owf_192(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
int ret = aes192_init_round_keys(&round_keys, key);
ret |= aes192_encrypt_block(&round_keys, input, output);
ret |= aes192_encrypt_block(&round_keys, input + 16, output + 16);
return ret == 0;
}
bool owf_256(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
int ret = aes256_init_round_keys(&round_keys, key);
ret |= aes256_encrypt_block(&round_keys, input, output);
ret |= aes256_encrypt_block(&round_keys, input + 16, output + 16);
return ret == 0;
}
bool owf_em_128(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
aes128_init_round_keys(&round_keys, input);
int ret = aes128_encrypt_block(&round_keys, key, output);
for (unsigned int i = 0; i != 16; ++i) {
output[i] ^= key[i];
}
return ret == 0;
}
bool owf_em_192(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
rijndael192_init_round_keys(&round_keys, input);
int ret = rijndael192_encrypt_block(&round_keys, key, output);
for (unsigned int i = 0; i != 24; ++i) {
output[i] ^= key[i];
}
return ret == 0;
}
bool owf_em_256(const uint8_t* key, const uint8_t* input, uint8_t* output) {
aes_round_keys_t round_keys;
rijndael256_init_round_keys(&round_keys, input);
int ret = rijndael256_encrypt_block(&round_keys, key, output);
for (unsigned int i = 0; i != 32; ++i) {
output[i] ^= key[i];
}
return ret == 0;
}