install.sh and uninstall.sh
[rofl0r-kripto.git] / lib / block.c
blob3409ef9e08e3677e69c361011a6e2d6a2286277b
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/block.h>
18 #include <kripto/block.h>
20 struct kripto_block
22 const kripto_block_desc *desc;
25 kripto_block *kripto_block_create
27 const kripto_block_desc *desc,
28 unsigned int rounds,
29 const void *key,
30 unsigned int key_len
33 assert(desc);
34 assert(desc->create);
36 assert(key);
37 assert(key_len);
38 assert(key_len <= kripto_block_maxkey(desc));
40 return desc->create(rounds, key, key_len);
43 kripto_block *kripto_block_recreate
45 kripto_block *s,
46 unsigned int rounds,
47 const void *key,
48 unsigned int key_len
51 assert(s);
52 assert(s->desc);
53 assert(s->desc->recreate);
55 assert(key);
56 assert(key_len);
57 assert(key_len <= kripto_block_maxkey(s->desc));
59 return s->desc->recreate(s, rounds, key, key_len);
62 void kripto_block_tweak
64 kripto_block *s,
65 const void *tweak,
66 unsigned int len
69 assert(s);
70 assert(s->desc);
71 assert(s->desc->tweak);
73 assert(tweak);
74 assert(len);
76 s->desc->tweak(s, tweak, len);
79 void kripto_block_encrypt
81 const kripto_block *s,
82 const void *pt,
83 void *ct
86 assert(s);
87 assert(s->desc);
88 assert(s->desc->encrypt);
89 assert(pt);
90 assert(ct);
92 s->desc->encrypt(s, pt, ct);
95 void kripto_block_decrypt
97 const kripto_block *s,
98 const void *ct,
99 void *pt
102 assert(s);
103 assert(s->desc);
104 assert(s->desc->decrypt);
105 assert(ct);
106 assert(pt);
108 s->desc->decrypt(s, ct, pt);
111 void kripto_block_destroy(kripto_block *s)
113 assert(s);
114 assert(s->desc);
115 assert(s->desc->destroy);
117 s->desc->destroy(s);
120 const kripto_block_desc *kripto_block_getdesc(const kripto_block *s)
122 assert(s);
123 assert(s->desc);
125 return s->desc;
128 unsigned int kripto_block_size(const kripto_block_desc *desc)
130 assert(desc);
131 assert(desc->blocksize);
133 return desc->blocksize;
136 unsigned int kripto_block_maxkey(const kripto_block_desc *desc)
138 assert(desc);
139 assert(desc->maxkey);
141 return desc->maxkey;