Text   |  XML   |  ReML   |   Visible Warnings:

Unused Value  at packet-zbee-security.c:952

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

zbee_sec_hash

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-zbee-security.c)expand/collapse
Show more  
 883  zbee_sec_hash(guint8 *input, guint input_len, guint8 *output)
 884  {
 885      guint8              cipher_in[ZBEE_SEC_CONST_BLOCKSIZE];
 886      guint               i, j;
 887      /* Cipher Instance. */
 888      gcry_cipher_hd_t    cipher_hd;
 889   
 890      /* Clear the first hash block (Hash0). */
 891      memset(output, 0, ZBEE_SEC_CONST_BLOCKSIZE);
 892      /* Create the cipher instance in ECB mode. */
 893      if (gcry_cipher_open(&cipher_hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0)) {
 894          return; /* Failed. */
 895      }
 896      /* Create the subsequent hash blocks using the formula: Hash[i] = E(Hash[i-1], M[i]) XOR M[i]
 897       *
 898       * because we can't garauntee that M will be exactly a multiple of the
 899       * block size, we will need to copy it into local buffers and pad it.
 900       *
 901       * Note that we check for the next cipher block at the end of the loop 
 902       * rather than the start. This is so that if the input happens to end
 903       * on a block boundary, the next cipher block will be generated for the 
 904       * start of the padding to be placed into.
 905       */
 906      i = 0;
 907      j = 0;
 908      while (i<input_len) {
 909          /* Copy data into the cipher input. */
 910          cipher_in[j++] = input[i++];
 911          /* Check if this cipher block is done. */
 912          if (j >= ZBEE_SEC_CONST_BLOCKSIZE) {
 913              /* We have reached the end of this block. Process it with the
 914               * cipher, note that the Key input to the cipher is actually
 915               * the previous hash block, which we are keeping in output.
 916               */
 917              (void)gcry_cipher_setkey(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE);
 918              (void)gcry_cipher_encrypt(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE, cipher_in, ZBEE_SEC_CONST_BLOCKSIZE);
 919              /* Now we have to XOR the input into the hash block. */
 920              for (j=0;j<ZBEE_SEC_CONST_BLOCKSIZE;j++) output[j] ^= cipher_in[j];
 921              /* Reset j to start again at the beginning at the next block. */
 922              j = 0;
 923          }
 924      } /* for */
 925      /* Need to append the bit '1', followed by '0' padding long enough to end 
 926       * the hash input on a block boundary. However, because 'n' is 16, and 'l'
 927       * will be a multiple of 8, the padding will be >= 7-bits, and we can just
 928       * append the byte 0x80.
 929       */
 930      cipher_in[j++] = 0x80;
 931      /* Pad with '0' until the the current block is exactly 'n' bits from the 
 932       * end.
 933       */
 934      while (j!=(ZBEE_SEC_CONST_BLOCKSIZE-2)) {
 935          if (j >= ZBEE_SEC_CONST_BLOCKSIZE) {
 936              /* We have reached the end of this block. Process it with the
 937               * cipher, note that the Key input to the cipher is actually
 938               * the previous hash block, which we are keeping in output.
 939               */
 940              (void)gcry_cipher_setkey(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE);
 941              (void)gcry_cipher_encrypt(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE, cipher_in, ZBEE_SEC_CONST_BLOCKSIZE);
 942              /* Now we have to XOR the input into the hash block. */
 943              for (j=0;j<ZBEE_SEC_CONST_BLOCKSIZE;j++) output[j] ^= cipher_in[j];
 944              /* Reset j to start again at the beginning at the next block. */
 945              j = 0;
 946          }
 947          /* Pad the input with 0. */
 948          cipher_in[j++] = 0x00;
 949      } /* while */
 950      /* Add the 'n'-bit representation of 'l' to the end of the block. */
 951      cipher_in[j++] = ((input_len * 8) >> 8) & 0xff;
 952      cipher_in[j++] = ((input_len * 8) >> 0) & 0xff;
 953      /* Process the last cipher block. */
 954      (void)gcry_cipher_setkey(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE);
 955      (void)gcry_cipher_encrypt(cipher_hd, output, ZBEE_SEC_CONST_BLOCKSIZE, cipher_in, ZBEE_SEC_CONST_BLOCKSIZE);
 956      /* XOR the last input block back into the cipher output to get the hash. */
 957      for (j=0;j<ZBEE_SEC_CONST_BLOCKSIZE;j++) output[j] ^= cipher_in[j];
 958      /* Cleanup the cipher. */
 959      gcry_cipher_close(cipher_hd);
 960      /* Done */
 961  } /* zbee_sec_hash */
Show more  




Change Warning 3089.29650 : Unused Value

Priority:
State:
Finding:
Owner:
Note: