/* Copyright (c) 2002 Redshift Software, Inc. All Rights Reserved. */ #ifndef com_redshift_software_libraries_algorithm_onewayaccumulator_h #define com_redshift_software_libraries_algorithm_onewayaccumulator_h #include #include #include com_redshift_software_libraries_algorithm_p { /** A class that implements a one way accumulator. This resembles a hash function except that the inputs generate the same result no matter what order they are calculated. See the paper by Benaloh and de Mare "One Way Accumulators: A decentralized alternative to digital signatures" for an actual explanation of one way accumulators and their uses. */ class OneWayValue { public: OneWayValue(); OneWayValue(Pointer,UInt); OneWayValue(const OneWayValue & aValue); OneWayValue & operator =(const OneWayValue & aValue); virtual ~OneWayValue(); UInt getSize(); void setSize(UInt); std::wstring getString(); std::string getAsciiString(); com::redshift_software::UString getUString(); Pointer getBytes(); void set(Pointer,UInt); void set(const std::wstring &); void set(const std::string &); void set(const UString &); void set(const char *); struct Data; Data & getData(); private: UInt mSize; AutoPointer mData; }; class OneWayAccumulator { public: //! OneWayAccumulator(); //! virtual ~OneWayAccumulator(); /** This creates a random large modulus for the accumulation function. @return true, if successful */ bool generateModulus(UInt32 aSize); //! Sets the internal base primes of the modulus. bool setModulus(OneWayValue & aP, OneWayValue & aQ); bool setModulus(OneWayValue & aM); //! Copies the base primes of the modules. OneWayValue getModulusP(); OneWayValue getModulusQ(); OneWayValue getModulus(); //! Set the total accumulation for verification. void setAccumulation(OneWayValue & aAccumulation); //! Get the initial prime value. OneWayValue getInitial(); //! Set the initial prime value. bool setInitial(OneWayValue & aInitial); //! Verify that the member accumulation is part of the total accumulation. bool verify(OneWayValue & aPartialAccumulation, OneWayValue & aMember); //! Compute phase one residue for members of an accumuation set. OneWayValue residue(OneWayValue & aX); //! Compute phase one residue for members of an accumuation set. OneWayValue residue(OneWayValue & aU, OneWayValue & aW); //! Accumulate subsets for members of accumulation. OneWayValue accumulate(OneWayValue & aBase, OneWayValue & aResidue); //! Accumulate subsets for members of accumulation, base is fixed as initial. OneWayValue accumulate(OneWayValue & aResidue); protected: //! struct Data; //! AutoPointer mData; //! bool mModulusSet; //! bool mInitialSet; }; } p_com_redshift_software_libraries_algorithm #endif