RC5 added
[rofl0r-kripto.git] / lib / hash.c
blob5e3a5762607eeee90ae9294410bf2c42b6920109
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/desc/hash.h>
19 #include <kripto/hash.h>
21 struct kripto_hash
23 const kripto_hash_desc *desc;
26 kripto_hash *kripto_hash_create
28 const kripto_hash_desc *desc,
29 unsigned int rounds,
30 size_t len
33 assert(desc);
34 assert(desc->create);
35 assert(len <= kripto_hash_maxout(desc));
37 return desc->create(rounds, len);
40 kripto_hash *kripto_hash_recreate
42 kripto_hash *s,
43 unsigned int rounds,
44 size_t len
47 assert(s);
48 assert(s->desc);
49 assert(s->desc->recreate);
50 assert(len <= kripto_hash_maxout(s->desc));
52 return s->desc->recreate(s, rounds, len);
55 void kripto_hash_input(kripto_hash *s, const void *in, size_t len)
57 assert(s);
58 assert(s->desc);
59 assert(s->desc->input);
61 s->desc->input(s, in, len);
64 void kripto_hash_output(kripto_hash *s, void *out, size_t len)
66 assert(s);
67 assert(s->desc);
68 assert(s->desc->output);
69 assert(len <= kripto_hash_maxout(s->desc));
71 s->desc->output(s, out, len);
74 void kripto_hash_destroy(kripto_hash *s)
76 assert(s);
77 assert(s->desc);
78 assert(s->desc->destroy);
80 s->desc->destroy(s);
83 int kripto_hash_all
85 const kripto_hash_desc *desc,
86 unsigned int rounds,
87 const void *in,
88 size_t in_len,
89 void *out,
90 size_t out_len
93 assert(desc);
94 assert(desc->hash_all);
95 assert(out_len <= kripto_hash_maxout(desc));
97 return desc->hash_all(rounds, in, in_len, out, out_len);
100 const kripto_hash_desc *kripto_hash_getdesc(const kripto_hash *s)
102 assert(s);
103 assert(s->desc);
105 return s->desc;
108 size_t kripto_hash_maxout(const kripto_hash_desc *desc)
110 assert(desc);
111 assert(desc->maxout);
113 return desc->maxout;
116 unsigned int kripto_hash_blocksize(const kripto_hash_desc *desc)
118 assert(desc);
119 assert(desc->blocksize);
121 return desc->blocksize;