--- libaitio/src/crypt.c 2011/10/07 09:14:41 1.3.8.1 +++ libaitio/src/crypt.c 2012/03/29 01:31:34 1.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: crypt.c,v 1.3.8.1 2011/10/07 09:14:41 misho Exp $ +* $Id: crypt.c,v 1.5 2012/03/29 01:31:34 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ SUCH DAMAGE. /* * ioCipher() Cipher wrapper for all supported crypto algorythms + * * @pInput = input buffer * @inLen = input buffer len * @ppOutput = output allocated buffe, must be free after use @@ -109,6 +110,7 @@ end: /* * io_Blowfish() Blowfish cipher algorythm, work with ASCII hex strings + * * @pInput = input buffer * @inLen = input buffer len * @ppOutput = output allocated buffe, must be free after use @@ -172,18 +174,20 @@ io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp /* * io_ctr_AES() Encrypt/Decrypt stream cipher CTR_AES + * * @pInput = Input buffer with ASCII * @inLen = Input buffer data length * @ppOutput = Output buffer with cipher data, must be free after use * @pKey = Key + * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!! * return: -1 error or >-1 how many cipher blocks proceeded */ int -io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutput, u_char *pKey) +io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutput, u_char *pKey, u_char IV[AES_BLOCK_SIZE]) { u_int num; AES_KEY key; - u_char ivec[AES_BLOCK_SIZE] = { 0 }, ecount_buf[AES_BLOCK_SIZE] = { 0 }; + u_char ecount_buf[AES_BLOCK_SIZE] = { 0 }; int total = 0; if (!pInput || !inLen || !ppOutput) @@ -203,7 +207,7 @@ io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutpu memset(ecount_buf, 0, sizeof ecount_buf); AES_ctr128_encrypt(pInput + total, (*ppOutput) + total, (inLen / (AES_BLOCK_SIZE - 1)) ? (AES_BLOCK_SIZE - 1) : inLen, - &key, ivec, ecount_buf, &num); + &key, IV, ecount_buf, &num); if (num < 1) { free(*ppOutput); *ppOutput = NULL;