hmac fixed for new API
[rofl0r-kripto.git] / lib / mac.c
blobf96758019aab0b93f6e46975d433941810bbf642
1 /*
2 * Copyright (C) 2013 Gregor Pintar <grpintar@gmail.com>
4 * Permission is granted to deal in this work without any restriction,
5 * including unlimited rights to use, publicly perform, publish,
6 * reproduce, relicence, modify, merge, and/or distribute in any form,
7 * for any purpose, with or without fee, and by any means.
9 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind,
10 * to the utmost extent permitted by applicable law. In no event
11 * shall a licensor, author or contributor be held liable for any
12 * issues arising in any way out of dealing in the work.
15 #include <assert.h>
17 #include <kripto/mac_desc.h>
19 #include <kripto/mac.h>
21 struct kripto_mac
23 const kripto_mac_desc *desc;
26 kripto_mac *kripto_mac_create
28 const kripto_mac_desc *desc,
29 unsigned int rounds,
30 const void *key,
31 unsigned int key_len,
32 unsigned int tag_len
35 assert(desc);
36 assert(desc->create);
38 assert(key);
39 assert(key_len);
41 return desc->create(desc, rounds, key, key_len, tag_len);
44 kripto_mac *kripto_mac_recreate
46 kripto_mac *s,
47 unsigned int rounds,
48 const void *key,
49 unsigned int key_len,
50 unsigned int tag_len
53 assert(s);
54 assert(s->desc);
55 assert(s->desc->recreate);
57 assert(key);
58 assert(key_len);
60 return s->desc->recreate(s, rounds, key, key_len, tag_len);
63 void kripto_mac_input(kripto_mac *s, const void *in, size_t len)
65 assert(s);
66 assert(s->desc);
67 assert(s->desc->input);
69 s->desc->input(s, in, len);
72 void kripto_mac_tag(kripto_mac *s, void *tag, unsigned int len)
74 assert(s);
75 assert(s->desc);
76 assert(s->desc->tag);
78 s->desc->tag(s, tag, len);
81 void kripto_mac_destroy(kripto_mac *s)
83 assert(s);
84 assert(s->desc);
85 assert(s->desc->destroy);
87 s->desc->destroy(s);
90 int kripto_mac_all
92 const kripto_mac_desc *desc,
93 unsigned int rounds,
94 const void *key,
95 unsigned int key_len,
96 const void *in,
97 unsigned int in_len,
98 void *tag,
99 unsigned int tag_len
102 kripto_mac *s;
104 assert(desc);
106 s = kripto_mac_create(desc, rounds, key, key_len, tag_len);
107 if(!s) return -1;
109 kripto_mac_input(s, in, in_len);
110 kripto_mac_tag(s, tag, tag_len);
112 kripto_mac_destroy(s);
114 return 0;
117 const kripto_mac_desc *kripto_mac_getdesc(const kripto_mac *s)
119 assert(s);
120 assert(s->desc);
122 return s->desc;
125 unsigned int kripto_mac_maxtag(const kripto_mac_desc *desc)
127 assert(desc);
129 return desc->maxtag;