예제 #1
0
 size_t write(const void *buf, size_t count)
 {
   // Hash, then write
   hash.update(buf, count);
   summed += count;
   return src->write(buf,count);
 }
예제 #2
0
  /* Directly sum an entire stream. The stream is read in increments,
     to avoid loading large files into memory. You can specify the
     buffer size as the second parameter, the default is 16 Kb.

     The algorithm does not depend on size() for non-pointer streams.

     Pointer streams are hashed in one go, and do not advance the file
     pointer.

     Since the position of the file pointer after this operation
     depends on the type of stream given, it is considered undefined.
   */
  static Hash sum(Mangle::Stream::Stream &str, int bufsize = DEFSIZE)
  {
    assert(str.isReadable);

    // Is this a memory stream?
    if(str.hasPtr)
      {
        assert(str.hasSize);

        // Pointer streams makes life easy
        return Hash(str.getPtr(), str.size());
      }

    // No pointers today. Create a buffer and hash in increments.
    char *buf = new char[bufsize];

    Hash result;

    // We do not depend on the stream size, only on eof().
    while(!str.eof())
      {
        size_t num = str.read(buf, bufsize);

        // If we read less than expected, we should be at the
        // end of the stream
        assert(num == bufsize || (num < bufsize && str.eof()));

        // Hash the data
        result.update(buf, num);
      }

    // Clean up and return
    delete[] buf;
    return result.finish();
  }
예제 #3
0
 size_t read(void *buf, size_t count)
 {
   // Read, then hash
   size_t res = src->read(buf, count);
   // And make sure to only hash actual bytes read
   hash.update(buf, res);
   summed += res;
   return res;
 }
예제 #4
0
파일: hmac.hpp 프로젝트: AGWA/batv-tools
		Hmac (const unsigned char* arg_key, size_t arg_key_len =KEY_LENGTH)
		{
			if (arg_key_len > Hash::BLOCK_LENGTH) {
				Hash::compute(key, Hash::BLOCK_LENGTH, arg_key, arg_key_len);
				key_len = Hash::LENGTH;
			} else {
				std::memcpy(key, arg_key, arg_key_len);
				key_len = arg_key_len;
			}

			unsigned char	k_ipad[Hash::BLOCK_LENGTH];
			std::memset(k_ipad, 0, Hash::BLOCK_LENGTH);
			std::memcpy(k_ipad, key, key_len);
			for (size_t i = 0; i < Hash::BLOCK_LENGTH; ++i) {
				k_ipad[i] ^= 0x36;
			}

			hash.update(k_ipad, Hash::BLOCK_LENGTH);
			explicit_memzero(k_ipad, Hash::BLOCK_LENGTH);
		}
예제 #5
0
파일: hmac.hpp 프로젝트: AGWA/batv-tools
		inline void	update (const void* data, size_t len)
		{
			hash.update(data, len);
		}