/*
- * Copyright (C) 2011-2013 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
{
int i;
- fprintf(stderr, "%s (%u bytes): ", msg, len);
+ fprintf(stderr, "%s (%d bytes): ", msg, len);
for (i = 0; i < len; i++)
fprintf(stderr, "%02x ", buf[i]);
fprintf(stderr, "\n");
{
gcry_error_t gret;
gcry_md_hd_t handle;
- size_t n;;
+ size_t n;
unsigned char *md;
unsigned char octet_string[4], *rp = result, *end = rp + result_len;
gcry_cipher_hd_t handle;
};
-struct stream_cipher *sc_new(const unsigned char *data, int len)
+struct stream_cipher *sc_new(const unsigned char *data, int len,
+ bool use_aes)
{
gcry_error_t gret;
-
struct stream_cipher *sc = para_malloc(sizeof(*sc));
+
+ if (use_aes) {
+ assert(len >= 2 * AES_CRT128_BLOCK_SIZE);
+ gret = gcry_cipher_open(&sc->handle, GCRY_CIPHER_AES128,
+ GCRY_CIPHER_MODE_CTR, 0);
+ assert(gret == 0);
+ gret = gcry_cipher_setkey(sc->handle, data,
+ AES_CRT128_BLOCK_SIZE);
+ assert(gret == 0);
+ gret = gcry_cipher_setctr(sc->handle,
+ data + AES_CRT128_BLOCK_SIZE, AES_CRT128_BLOCK_SIZE);
+ assert(gret == 0);
+ return sc;
+ }
gret = gcry_cipher_open(&sc->handle, GCRY_CIPHER_ARCFOUR,
GCRY_CIPHER_MODE_STREAM, 0);
if (gret) {