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.
18 #include <kripto/desc/stream.h>
20 #include <kripto/stream.h>
24 const kripto_stream_desc
*desc
;
28 kripto_stream
*kripto_stream_create
30 const kripto_stream_desc
*desc
,
43 assert(key_len
<= kripto_stream_maxkey(desc
));
44 assert(iv_len
<= kripto_stream_maxiv(desc
));
45 if(iv_len
) assert(iv
);
47 return desc
->create(desc
, rounds
, key
, key_len
, iv
, iv_len
);
50 kripto_stream
*kripto_stream_recreate
62 assert(s
->desc
->recreate
);
66 assert(key_len
<= kripto_stream_maxkey(s
->desc
));
67 assert(iv_len
<= kripto_stream_maxiv(s
->desc
));
68 if(iv_len
) assert(iv
);
70 return s
->desc
->recreate(s
, rounds
, key
, key_len
, iv
, iv_len
);
73 void kripto_stream_encrypt
83 assert(s
->desc
->encrypt
);
84 assert(len
% kripto_stream_multof(s
->desc
) == 0);
86 s
->desc
->encrypt(s
, pt
, ct
, len
);
89 void kripto_stream_decrypt
99 assert(s
->desc
->decrypt
);
100 assert(len
% kripto_stream_multof(s
->desc
) == 0);
102 s
->desc
->decrypt(s
, ct
, pt
, len
);
105 void kripto_stream_prng
114 assert(s
->desc
->prng
);
116 s
->desc
->prng(s
, out
, len
);
119 void kripto_stream_destroy(kripto_stream
*s
)
123 assert(s
->desc
->destroy
);
128 unsigned int kripto_stream_multof(const kripto_stream
*s
)
136 const kripto_stream_desc
*kripto_stream_getdesc(const kripto_stream
*s
)
144 unsigned int kripto_stream_maxkey(const kripto_stream_desc
*desc
)
147 assert(desc
->maxkey
);
152 unsigned int kripto_stream_maxiv(const kripto_stream_desc
*desc
)