install.sh and uninstall.sh
[rofl0r-kripto.git] / lib / hash.c
blob673a64772a9ab3d0d13c05463b09bc6a0293c6c9
1 /*
2 * Written in 2013 by Gregor Pintar <grpintar@gmail.com>
4 * To the extent possible under law, the author(s) have dedicated
5 * all copyright and related and neighboring rights to this software
6 * to the public domain worldwide.
7 *
8 * This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication.
11 * If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
14 #include <assert.h>
16 #include <kripto/desc/hash.h>
18 #include <kripto/hash.h>
20 struct kripto_hash
22 const kripto_hash_desc *desc;
25 kripto_hash *kripto_hash_create
27 const kripto_hash_desc *desc,
28 unsigned int rounds,
29 size_t len
32 assert(desc);
33 assert(desc->create);
34 assert(len <= kripto_hash_maxout(desc));
36 return desc->create(rounds, len);
39 kripto_hash *kripto_hash_recreate
41 kripto_hash *s,
42 unsigned int rounds,
43 size_t len
46 assert(s);
47 assert(s->desc);
48 assert(s->desc->recreate);
49 assert(len <= kripto_hash_maxout(s->desc));
51 return s->desc->recreate(s, rounds, len);
54 void kripto_hash_input(kripto_hash *s, const void *in, size_t len)
56 assert(s);
57 assert(s->desc);
58 assert(s->desc->input);
60 s->desc->input(s, in, len);
63 void kripto_hash_output(kripto_hash *s, void *out, size_t len)
65 assert(s);
66 assert(s->desc);
67 assert(s->desc->output);
68 assert(len <= kripto_hash_maxout(s->desc));
70 s->desc->output(s, out, len);
73 void kripto_hash_destroy(kripto_hash *s)
75 assert(s);
76 assert(s->desc);
77 assert(s->desc->destroy);
79 s->desc->destroy(s);
82 int kripto_hash_all
84 const kripto_hash_desc *desc,
85 unsigned int rounds,
86 const void *in,
87 size_t in_len,
88 void *out,
89 size_t out_len
92 assert(desc);
93 assert(desc->hash_all);
94 assert(out_len <= kripto_hash_maxout(desc));
96 return desc->hash_all(rounds, in, in_len, out, out_len);
99 const kripto_hash_desc *kripto_hash_getdesc(const kripto_hash *s)
101 assert(s);
102 assert(s->desc);
104 return s->desc;
107 size_t kripto_hash_maxout(const kripto_hash_desc *desc)
109 assert(desc);
110 assert(desc->maxout);
112 return desc->maxout;
115 unsigned int kripto_hash_blocksize(const kripto_hash_desc *desc)
117 assert(desc);
118 assert(desc->blocksize);
120 return desc->blocksize;