4b476c3397cd376ce1f4f7bcfe9005ea58e019b2
[trex.git] /
1
2 #include "api.h"
3 #include "crypto_auth_hmacsha512256.h"
4 #include "crypto_auth_hmacsha512.h"
5 #include "crypto_hash_sha512.h"
6 #include "utils.h"
7
8 #include <sys/types.h>
9
10 #include <stdint.h>
11 #include <string.h>
12
13 int
14 crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state,
15                                const unsigned char *key,
16                                size_t keylen)
17 {
18     return crypto_auth_hmacsha512_init((crypto_auth_hmacsha512_state *) state,
19                                        key, keylen);
20 }
21
22 int
23 crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state,
24                                  const unsigned char *in,
25                                  unsigned long long inlen)
26 {
27     return crypto_auth_hmacsha512_update((crypto_auth_hmacsha512_state *) state,
28                                          in, inlen);
29 }
30
31 int
32 crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state,
33                                 unsigned char *out)
34 {
35     unsigned char out0[64];
36
37     crypto_auth_hmacsha512_final((crypto_auth_hmacsha512_state *) state, out0);
38     memcpy(out, out0, 32);
39
40     return 0;
41 }
42
43 int
44 crypto_auth(unsigned char *out, const unsigned char *in,
45             unsigned long long inlen, const unsigned char *k)
46 {
47     crypto_auth_hmacsha512256_state state;
48
49     crypto_auth_hmacsha512256_init(&state, k, crypto_auth_KEYBYTES);
50     crypto_auth_hmacsha512256_update(&state, in, inlen);
51     crypto_auth_hmacsha512256_final(&state, out);
52
53     return 0;
54 }