Diff for /libaitio/src/crypt.c between versions 1.3 and 1.6

version 1.3, 2011/04/20 22:56:32 version 1.6, 2012/05/14 12:49:21
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 47  SUCH DAMAGE. Line 47  SUCH DAMAGE.
   
   
 /*  /*
 * ioCipher() Cipher wrapper for all supported crypto algorythms * ioCipher() - Cipher wrapper for all supported crypto algorythms
  *
  * @pInput = input buffer   * @pInput = input buffer
  * @inLen = input buffer len   * @inLen = input buffer len
  * @ppOutput = output allocated buffe, must be free after use   * @ppOutput = output allocated buffe, must be free after use
Line 108  end: Line 109  end:
 }  }
   
 /*  /*
 * io_Blowfish() Blowfish cipher algorythm, work with ASCII hex strings * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
  *
  * @pInput = input buffer   * @pInput = input buffer
  * @inLen = input buffer len   * @inLen = input buffer len
  * @ppOutput = output allocated buffe, must be free after use   * @ppOutput = output allocated buffe, must be free after use
Line 168  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp Line 170  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp
                         *ppOutput = (u_char*) strdup((char*) buf);                          *ppOutput = (u_char*) strdup((char*) buf);
   
         return ret;          return ret;
   }
   
   /*
    * 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, u_char IV[AES_BLOCK_SIZE])
   {
           u_int num;
           AES_KEY key;
           u_char ecount_buf[AES_BLOCK_SIZE] = { 0 };
           int total = 0;
   
           if (!pInput || !inLen || !ppOutput)
                   return -1;
   
           *ppOutput = malloc(inLen);
           if (!*ppOutput) {
                   LOGERR;
                   return -1;
           } else
                   memset(*ppOutput, 0, inLen);
   
           AES_set_encrypt_key(pKey, 128, &key);
   
           while (inLen) {
                   num = 0;
                   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, IV, ecount_buf, &num);
                   if (num < 1) {
                           free(*ppOutput);
                           *ppOutput = NULL;
                           total = -1;
                           break;
                   } else {
                           total += num;
                           inLen -= num;
                   }
           }
   
           return total;
 }  }

Removed from v.1.3  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>