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/authstream.h>
20 #include <kripto/authstream.h>
22 struct kripto_authstream
24 const kripto_authstream_desc
*desc
;
28 kripto_authstream
*kripto_authstream_create
30 const kripto_authstream_desc
*desc
,
44 assert(key_len
<= kripto_authstream_maxkey(desc
));
45 assert(iv_len
<= kripto_authstream_maxiv(desc
));
46 if(iv_len
) assert(iv
);
47 assert(tag_len
<= kripto_authstream_maxtag(desc
));
49 return desc
->create(desc
, rounds
, key
, key_len
, iv
, iv_len
, tag_len
);
52 kripto_authstream
*kripto_authstream_recreate
65 assert(s
->desc
->recreate
);
69 assert(key_len
<= kripto_authstream_maxkey(s
->desc
));
70 assert(iv_len
<= kripto_authstream_maxiv(s
->desc
));
71 if(iv_len
) assert(iv
);
72 assert(tag_len
<= kripto_authstream_maxtag(s
->desc
));
74 return s
->desc
->recreate(s
, rounds
, key
, key_len
, iv
, iv_len
, tag_len
);
77 void kripto_authstream_encrypt
87 assert(s
->desc
->encrypt
);
88 assert(len
% kripto_authstream_multof(s
->desc
) == 0);
90 s
->desc
->encrypt(s
, pt
, ct
, len
);
93 void kripto_authstream_decrypt
103 assert(s
->desc
->decrypt
);
104 assert(len
% kripto_authstream_multof(s
->desc
) == 0);
106 s
->desc
->decrypt(s
, ct
, pt
, len
);
109 void kripto_authstream_header
111 kripto_authstream
*s
,
118 assert(s
->desc
->header
);
120 s
->desc
->header(s
, header
, len
);
123 void kripto_authstream_tag
125 kripto_authstream
*s
,
132 assert(s
->desc
->tag
);
134 s
->desc
->tag(s
, tag
, len
);
137 void kripto_authstream_destroy(kripto_authstream
*s
)
141 assert(s
->desc
->destroy
);
146 unsigned int kripto_authstream_multof(const kripto_authstream
*s
)
154 const kripto_authstream_desc
*kripto_authstream_getdesc(const kripto_authstream
*s
)
162 unsigned int kripto_authstream_maxkey(const kripto_authstream_desc
*desc
)
165 assert(desc
->maxkey
);
170 unsigned int kripto_authstream_maxiv(const kripto_authstream_desc
*desc
)
177 unsigned int kripto_authstream_maxtag(const kripto_authstream_desc
*desc
)