Diff for /libaitio/src/crypt.c between versions 1.8 and 1.9

version 1.8, 2012/08/02 00:47:47 version 1.9, 2013/03/13 14:54:39
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, 2011, 2012Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
         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 51  SUCH DAMAGE. Line 51  SUCH DAMAGE.
  *   *
  * @pInput = input buffer   * @pInput = input buffer
  * @inLen = input buffer len   * @inLen = input buffer len
 * @ppOutput = output allocated buffe, must be io_free after use * @ppOutput = output allocated buffe, must be e_free after use
  * @Cipher = cipher engine, like EVP_bf_cbc() or etc...   * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
  * @pKey = key   * @pKey = key
  * @pIV = IV, salt (8 bytes)   * @pIV = IV, salt (8 bytes)
Line 68  ioCipher(u_char *pInput, int inLen, u_char **ppOutput, Line 68  ioCipher(u_char *pInput, int inLen, u_char **ppOutput,
   
         if (!pInput || !inLen || !ppOutput || nMode & 0xFFFFFFFE)          if (!pInput || !inLen || !ppOutput || nMode & 0xFFFFFFFE)
                 return 0;                  return 0;
        buf = io_malloc(inLen + EVP_MAX_BLOCK_LENGTH);        buf = e_malloc(inLen + EVP_MAX_BLOCK_LENGTH);
         if (!buf) {          if (!buf) {
                 LOGERR;                  LOGERR;
                 goto end;                  goto end;
Line 84  ioCipher(u_char *pInput, int inLen, u_char **ppOutput, Line 84  ioCipher(u_char *pInput, int inLen, u_char **ppOutput,
                 if (!EVP_CipherUpdate(&ctx, buf + outlen, &buflen, pos, chunk)) {                  if (!EVP_CipherUpdate(&ctx, buf + outlen, &buflen, pos, chunk)) {
                         EVP_CIPHER_CTX_cleanup(&ctx);                          EVP_CIPHER_CTX_cleanup(&ctx);
                         outlen = 0;                          outlen = 0;
                        io_free(buf);                        e_free(buf);
                         buf = NULL;                          buf = NULL;
                         goto end;                          goto end;
                 } else {                  } else {
Line 97  ioCipher(u_char *pInput, int inLen, u_char **ppOutput, Line 97  ioCipher(u_char *pInput, int inLen, u_char **ppOutput,
         }          }
         if (!EVP_CipherFinal_ex(&ctx, buf + outlen, &buflen)) {          if (!EVP_CipherFinal_ex(&ctx, buf + outlen, &buflen)) {
                 outlen = 0;                  outlen = 0;
                io_free(buf);                e_free(buf);
                 buf = NULL;                  buf = NULL;
         } else          } else
                 outlen += buflen;                  outlen += buflen;
Line 113  end: Line 113  end:
  *   *
  * @pInput = input buffer   * @pInput = input buffer
  * @inLen = input buffer len   * @inLen = input buffer len
 * @ppOutput = output allocated buffe, must be io_free after use * @ppOutput = output allocated buffe, must be e_free after use
  * @pKey = key   * @pKey = key
  * @pIV = IV, salt (8 bytes)   * @pIV = IV, salt (8 bytes)
  * @nMode = Mode 0 - decrypting or 1 - encrypting   * @nMode = Mode 0 - decrypting or 1 - encrypting
Line 132  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp Line 132  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp
   
         if (nMode) {          if (nMode) {
                 len = strlen((char*) pInput);                  len = strlen((char*) pInput);
                str = io_strdup((char*) pInput);                str = e_strdup((char*) pInput);
         } else {          } else {
                 len = strlen((char*) pInput) / 2;                  len = strlen((char*) pInput) / 2;
                str = io_malloc(len + 1);                str = e_malloc(len + 1);
                 if (!str) {                  if (!str) {
                         LOGERR;                          LOGERR;
                         return 0;                          return 0;
Line 149  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp Line 149  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp
         }          }
   
         ret = len = ioCipher((u_char*) str, len, &buf, EVP_bf_cbc(), pKey, pIV, nMode);          ret = len = ioCipher((u_char*) str, len, &buf, EVP_bf_cbc(), pKey, pIV, nMode);
        io_free(str);        e_free(str);
   
         if (nMode) {          if (nMode) {
                 ret *= 2;                  ret *= 2;
                *ppOutput = io_malloc(ret + 1);                *ppOutput = e_malloc(ret + 1);
                 if (!*ppOutput) {                  if (!*ppOutput) {
                         LOGERR;                          LOGERR;
                         return 0;                          return 0;
Line 167  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp Line 167  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp
                 }                  }
         } else          } else
                 if (ret && buf)                  if (ret && buf)
                        *ppOutput = (u_char*) io_strdup((char*) buf);                        *ppOutput = (u_char*) e_strdup((char*) buf);
   
         return ret;          return ret;
 }  }
Line 177  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp Line 177  io_Blowfish(u_char *pInput, int inLen, u_char **ppOutp
  *   *
  * @pInput = Input buffer with ASCII   * @pInput = Input buffer with ASCII
  * @inLen = Input buffer data length   * @inLen = Input buffer data length
 * @ppOutput = Output buffer with cipher data, must be io_free after use * @ppOutput = Output buffer with cipher data, must be e_free after use
  * @pKey = Key   * @pKey = Key
  * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!   * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
  * return: -1 error or >-1 how many cipher blocks proceeded   * return: -1 error or >-1 how many cipher blocks proceeded
Line 193  io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutpu Line 193  io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutpu
         if (!pInput || !inLen || !ppOutput)          if (!pInput || !inLen || !ppOutput)
                 return -1;                  return -1;
   
        *ppOutput = io_malloc(inLen);        *ppOutput = e_malloc(inLen);
         if (!*ppOutput) {          if (!*ppOutput) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
Line 209  io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutpu Line 209  io_ctr_AES(u_char *pInput, int inLen, u_char **ppOutpu
                                 (inLen / (AES_BLOCK_SIZE - 1)) ? (AES_BLOCK_SIZE - 1) : inLen,                                   (inLen / (AES_BLOCK_SIZE - 1)) ? (AES_BLOCK_SIZE - 1) : inLen, 
                                 &key, IV, ecount_buf, &num);                                  &key, IV, ecount_buf, &num);
                 if (num < 1) {                  if (num < 1) {
                        io_free(*ppOutput);                        e_free(*ppOutput);
                         *ppOutput = NULL;                          *ppOutput = NULL;
                         total = -1;                          total = -1;
                         break;                          break;

Removed from v.1.8  
changed lines
  Added in v.1.9


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