Topic: bitwise_op function objects in <functional>


Author: "=?iso-8859-1?q?Pedro_Lamar=E3o?=" <pedro.lamarao@gmail.com>
Date: Thu, 30 Nov 2006 11:19:50 CST
Raw View
Has there ever been a proposal to add bitwise operation function
objects in <functional> ?

I'm implementing the algorithms given in PKCS #5 [1] and I've found an
opportunity of using std::accumulate in the implementation of the
following function:

"the function F is defined as the exclusive-or sum of the first c
iterates of the
underlying pseudorandom function PRF applied to the password P and the
concatenation of the salt S and the block index i"

Like this:

        template <typename PRF, typename Size>
        std::string
        F (std::string const& P, std::string const& S, Size c, Size i)
{
            std::vector<std::string> U;
            U.push_back(PRF(P, S + Int(i)));
            for (Size j = 1; j < (c - 1); ++j) {
                U.push_back(PRF(P, U.back()));
            }
            return std::accumulate(U.begin(), U.end(),
bitwise_xor<std::string>());
        }

with:

        template <typename T>
        struct bitwise_xor : public std::binary_function<T, T, T>
        {
            T
            operator() (T t1, T t2) const {
                return t1 ^ t2;
            }
        };

        template <>
        struct bitwise_xor<std::string>
        : public std::binary_function<std::string, std::string,
std::string>
        {
            std::string
            operator() (std::string const& t1, std::string const& t2)
const {
                std::string result;
                std::transform(
                    t1.begin(),
                    t1.end(),
                    t2.begin(),
                    std::back_inserter(result),
                    bitwise_xor<char>()
                );
                return result;
            }
        };

I actually expected to find bitwise_xor in <functional> and ended up
writing my own.

Is there an interest in such a proposal?

--
 Pedro Lamar   o


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "=?iso-8859-1?q?Pedro_Lamar=E3o?=" <pedro.lamarao@gmail.com>
Date: Thu, 30 Nov 2006 11:26:33 CST
Raw View
Has there ever been a proposal to add bitwise operation function
objects in <functional> ?

I'm implementing the algorithms given in PKCS #5 [1] and I've found an
opportunity of using std::accumulate in the implementation of the
following function:

"the function F is defined as the exclusive-or sum of the first c
iterates of the
underlying pseudorandom function PRF applied to the password P and the
concatenation of the salt S and the block index i"

Like this:

        template <typename PRF, typename Size>
        std::string
        F (std::string const& P, std::string const& S, Size c, Size i)
{
            std::vector<std::string> U;
            U.push_back(PRF(P, S + Int(i)));
            for (Size j = 1; j < (c - 1); ++j) {
                U.push_back(PRF(P, U.back()));
            }
            return std::accumulate(U.begin(), U.end(),
bitwise_xor<std::string>());
        }

with:

        template <typename T>
        struct bitwise_xor : public std::binary_function<T, T, T>
        {
            T
            operator() (T t1, T t2) const {
                return t1 ^ t2;
            }
        };

        template <>
        struct bitwise_xor<std::string>
        : public std::binary_function<std::string, std::string,
std::string>
        {
            std::string
            operator() (std::string const& t1, std::string const& t2)
const {
                std::string result;
                std::transform(
                    t1.begin(),
                    t1.end(),
                    t2.begin(),
                    std::back_inserter(result),
                    bitwise_xor<char>()
                );
                return result;
            }
        };

I actually expected to find bitwise_xor in <functional> and ended up
writing my own.

Is there an interest in such a proposal?

[1] http://www.rsasecurity.com/rsalabs/node.asp?id=2127

--
 Pedro Lamar   o


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]