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.
31 METHOD(iv_gen_t
, get_iv
, bool,
32 private_iv_gen_t
*this, u_int64_t seq
, size_t size
, u_int8_t
*buffer
)
34 u_int8_t iv
[sizeof(u_int64_t
)];
37 if (len
> sizeof(u_int64_t
))
39 len
= sizeof(u_int64_t
);
40 memset(buffer
, 0, size
- len
);
43 memcpy(buffer
+ size
- len
, iv
+ sizeof(u_int64_t
) - len
, len
);
47 METHOD(iv_gen_t
, allocate_iv
, bool,
48 private_iv_gen_t
*this, u_int64_t seq
, size_t size
, chunk_t
*chunk
)
50 *chunk
= chunk_alloc(size
);
51 if (!get_iv(this, seq
, chunk
->len
, chunk
->ptr
))
59 METHOD(iv_gen_t
, destroy
, void,
60 private_iv_gen_t
*this)
65 iv_gen_t
*iv_gen_seq_create()
67 private_iv_gen_t
*this;
72 .allocate_iv
= _allocate_iv
,