ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
macSkein.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2015 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 
21 void 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 
34 void 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 
51 void* 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 
61 void 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 
71 void 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 
85 void freeSkeinMacContext(void* ctx)
86 {
87  if (ctx)
88  free(ctx);
89 }
void skeinReset(SkeinCtx_t *ctx)
Resets a Skein context for furter use.
void macSkein(uint8_t *key, int32_t key_length, const uint8_t *data, uint32_t data_length, uint8_t *mac, int32_t mac_length, SkeinSize_t skeinSize)
Compute Skein MAC.
Definition: macSkein.cpp:21
int skeinUpdate(SkeinCtx_t *ctx, const uint8_t *msg, size_t msgByteCnt)
Update Skein with the next part of the message.
void macSkeinCtx(void *ctx, const uint8_t *data, uint32_t data_length, uint8_t *mac)
Compute Skein MAC.
Definition: macSkein.cpp:61
int skeinFinal(SkeinCtx_t *ctx, uint8_t *hash)
Finalize Skein and return the hash.
void freeSkeinMacContext(void *ctx)
Free Skein MAC context.
Definition: macSkein.cpp:85
void * createSkeinMacContext(uint8_t *key, int32_t key_length, int32_t mac_length, SkeinSize_t skeinSize)
Create and initialize a Skein MAC context.
Definition: macSkein.cpp:51
int skeinMacInit(SkeinCtx_t *ctx, const uint8_t *key, size_t keyLen, size_t hashBitLen)
Initializes or reuses a Skein context for MAC usage.
Context for Skein.
Definition: skeinApi.h:118
Function that provide Skein MAC support.
int skeinCtxPrepare(SkeinCtx_t *ctx, SkeinSize_t size)
Prepare a Skein context.
enum SkeinSize SkeinSize_t
Which Skein size to use.