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.
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/>.
17 #include <kripto/stream.h>
18 #include <kripto/desc/stream.h>
22 const kripto_stream_desc
*desc
;
26 kripto_stream
*kripto_stream_create
28 const kripto_stream_desc
*desc
,
41 assert(key_len
<= kripto_stream_maxkey(desc
));
42 assert(iv_len
<= kripto_stream_maxiv(desc
));
43 if(iv_len
) assert(iv
);
45 return desc
->create(desc
, rounds
, key
, key_len
, iv
, iv_len
);
48 kripto_stream
*kripto_stream_recreate
60 assert(s
->desc
->recreate
);
64 assert(key_len
<= kripto_stream_maxkey(s
->desc
));
65 assert(iv_len
<= kripto_stream_maxiv(s
->desc
));
66 if(iv_len
) assert(iv
);
68 return s
->desc
->recreate(s
, rounds
, key
, key_len
, iv
, iv_len
);
71 void kripto_stream_encrypt
81 assert(s
->desc
->encrypt
);
82 assert(len
% kripto_stream_multof(s
) == 0);
84 s
->desc
->encrypt(s
, pt
, ct
, len
);
87 void kripto_stream_decrypt
97 assert(s
->desc
->decrypt
);
98 assert(len
% kripto_stream_multof(s
) == 0);
100 s
->desc
->decrypt(s
, ct
, pt
, len
);
103 void kripto_stream_prng
112 assert(s
->desc
->prng
);
114 s
->desc
->prng(s
, out
, len
);
117 void kripto_stream_destroy(kripto_stream
*s
)
121 assert(s
->desc
->destroy
);
126 unsigned int kripto_stream_multof(const kripto_stream
*s
)
134 const kripto_stream_desc
*kripto_stream_getdesc(const kripto_stream
*s
)
142 unsigned int kripto_stream_maxkey(const kripto_stream_desc
*desc
)
145 assert(desc
->maxkey
);
150 unsigned int kripto_stream_maxiv(const kripto_stream_desc
*desc
)