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.
19 #include <kripto/cast.h>
20 #include <kripto/memwipe.h>
21 #include <kripto/hash.h>
22 #include <kripto/hash/keccak1600.h>
23 #include <kripto/stream.h>
24 #include <kripto/desc/stream.h>
26 #include <kripto/stream/keccak1600.h>
30 const kripto_stream_desc
*stream
;
34 static kripto_stream
*keccak1600_recreate
44 (void)kripto_hash_recreate(s
->hash
, r
, key_len
);
46 kripto_hash_input(s
->hash
, key
, key_len
);
47 kripto_hash_input(s
->hash
, iv
, iv_len
);
52 static void keccak1600_crypt
64 for(i
= 0, n
= 64; i
< len
; i
++)
69 kripto_hash_output(s
->hash
, buf
, len
- i
);
71 kripto_hash_output(s
->hash
, buf
, 64);
76 U8(out
)[i
] = CU8(in
)[i
] ^ buf
[n
++];
79 kripto_memwipe(buf
, 64);
82 static void keccak1600_prng(kripto_stream
*s
, void *out
, size_t len
)
84 kripto_hash_output(s
->hash
, out
, len
);
87 static kripto_stream
*keccak1600_create
89 const kripto_stream_desc
*desc
,
101 s
= malloc(sizeof(kripto_stream
));
104 s
->stream
= kripto_stream_keccak1600
;
106 s
->hash
= kripto_hash_create(kripto_hash_keccak1600
, r
, key_len
);
113 kripto_hash_input(s
->hash
, key
, key_len
);
114 kripto_hash_input(s
->hash
, iv
, iv_len
);
119 static void keccak1600_destroy(kripto_stream
*s
)
121 kripto_hash_destroy(s
->hash
);
125 static const kripto_stream_desc keccak1600
=
128 &keccak1600_recreate
,
135 UINT_MAX
/* max iv */
138 const kripto_stream_desc
*const kripto_stream_keccak1600
= &keccak1600
;