blob: ba4c260a862f2c7fa5f9acbd20e1fa96e0af8ccb [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
2 Copyright (C) 2010 Werner Dittmann
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <crypto/macSkein.h>
19#include <stdlib.h>
20
21void macSkein(uint8_t* key, int32_t key_length,
22 const uint8_t* data, uint32_t data_length,
23 uint8_t* mac, int32_t mac_length, SkeinSize_t skeinSize)
24{
25 SkeinCtx_t ctx;
26
27 skeinCtxPrepare(&ctx, skeinSize);
28
29 skeinMacInit(&ctx, key, key_length, mac_length);
30 skeinUpdate(&ctx, data, data_length);
31 skeinFinal(&ctx, mac);
32}
33
34void macSkein(uint8_t* key, int32_t key_length,
35 const uint8_t* data[], uint32_t data_length[],
36 uint8_t* mac, int32_t mac_length, SkeinSize_t skeinSize)
37{
38 SkeinCtx_t ctx;
39
40 skeinCtxPrepare(&ctx, skeinSize);
41
42 skeinMacInit(&ctx, key, key_length, mac_length);
43 while (*data) {
44 skeinUpdate(&ctx, *data, *data_length);
45 data++;
46 data_length ++;
47 }
48 skeinFinal(&ctx, mac);
49}
50
51void* createSkeinMacContext(uint8_t* key, int32_t key_length,
52 int32_t mac_length, SkeinSize_t skeinSize)
53{
54 SkeinCtx_t* ctx = (SkeinCtx_t*)malloc(sizeof(SkeinCtx_t));
55
56 skeinCtxPrepare(ctx, skeinSize);
57 skeinMacInit(ctx, key, key_length, mac_length);
58 return ctx;
59}
60
61void macSkeinCtx(void* ctx, const uint8_t* data, uint32_t data_length,
62 uint8_t* mac)
63{
64 SkeinCtx_t* pctx = (SkeinCtx_t*)ctx;
65
66 skeinUpdate(pctx, data, data_length);
67 skeinFinal(pctx, mac);
68 skeinReset(pctx);
69}
70
71void macSkeinCtx(void* ctx, const uint8_t* data[], uint32_t data_length[],
72 uint8_t* mac)
73{
74 SkeinCtx_t* pctx = (SkeinCtx_t*)ctx;
75
76 while (*data) {
77 skeinUpdate(pctx, *data, *data_length);
78 data++;
79 data_length++;
80 }
81 skeinFinal(pctx, mac);
82 skeinReset(pctx);
83}
84
85void freeSkeinMacContext(void* ctx)
86{
87 if (ctx)
88 free(ctx);
89}