2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "iv_gen_seq.h"
18 typedef struct private_iv_gen_t private_iv_gen_t
;
21 * Private data of an iv_gen_t object.
23 struct private_iv_gen_t
{
26 * Public iv_gen_t interface.
36 METHOD(iv_gen_t
, get_iv
, bool,
37 private_iv_gen_t
*this, size_t size
, u_int8_t
*buffer
)
39 u_int8_t iv
[sizeof(u_int64_t
)];
42 if (this->seq
== UINT64_MAX
|| len
< sizeof(u_int64_t
))
46 if (len
> sizeof(u_int64_t
))
48 len
= sizeof(u_int64_t
);
49 memset(buffer
, 0, size
- len
);
51 htoun64(iv
, this->seq
++);
52 memcpy(buffer
+ size
- len
, iv
+ sizeof(u_int64_t
) - len
, len
);
56 METHOD(iv_gen_t
, allocate_iv
, bool,
57 private_iv_gen_t
*this, size_t size
, chunk_t
*chunk
)
59 *chunk
= chunk_alloc(size
);
60 if (!get_iv(this, chunk
->len
, chunk
->ptr
))
68 METHOD(iv_gen_t
, destroy
, void,
69 private_iv_gen_t
*this)
74 iv_gen_t
*iv_gen_seq_create()
76 private_iv_gen_t
*this;
81 .allocate_iv
= _allocate_iv
,