|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61743 - in sandbox/hash: boost/hash libs/hash/example libs/hash/test
From: me22.ca+boost_at_[hidden]
Date: 2010-05-03 10:44:30
Author: smcmurray
Date: 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
New Revision: 61743
URL: http://svn.boost.org/trac/boost/changeset/61743
Log:
hash: move everything (but some pack internals) to iterator-based interfaces (instead of pointer-based); factor the pack code better to need less code in the change-dependant code; update the hashsum example to use streambuf more efficiently so it's no longer more than twice as slow as memory mapping
Text files modified:
sandbox/hash/boost/hash/compute_digest.hpp | 17 ++--
sandbox/hash/boost/hash/pack.hpp | 153 +++++++++++++++++++++++----------------
sandbox/hash/boost/hash/stream_preprocessor.hpp | 61 +++++++++++----
sandbox/hash/libs/hash/example/hashsum.cpp | 17 +++
sandbox/hash/libs/hash/test/cubehash.cpp | 8 +-
sandbox/hash/libs/hash/test/md.cpp | 8 +-
sandbox/hash/libs/hash/test/sha.cpp | 30 +++---
sandbox/hash/libs/hash/test/sha2.cpp | 26 +++---
sandbox/hash/libs/hash/test/shacal.cpp | 8 +-
9 files changed, 196 insertions(+), 132 deletions(-)
Modified: sandbox/hash/boost/hash/compute_digest.hpp
==============================================================================
--- sandbox/hash/boost/hash/compute_digest.hpp (original)
+++ sandbox/hash/boost/hash/compute_digest.hpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -30,28 +30,29 @@
typedef typename hash_T::template stream_hash<value_bits>::type
stream_hash_type;
stream_hash_type sh;
- while (b != e) sh.update(*b++);
+ sh.update(b, e);
return sh.end_message();
}
-template <typename hash_T, typename value_T>
+template <typename hash_T, typename iter_T>
typename hash_T::digest_type
-compute_digest(value_T const *p, size_t n) {
- BOOST_STATIC_ASSERT(std::numeric_limits<value_T>::is_specialized);
+compute_digest_n(iter_T b, size_t n) {
+ typedef typename std::iterator_traits<iter_T>::value_type value_type;
+ BOOST_STATIC_ASSERT(std::numeric_limits<value_type>::is_specialized);
unsigned const value_bits =
- std::numeric_limits<value_T>::digits +
- std::numeric_limits<value_T>::is_signed;
+ std::numeric_limits<value_type>::digits +
+ std::numeric_limits<value_type>::is_signed;
typedef typename hash_T::template stream_hash<value_bits>::type
stream_hash_type;
stream_hash_type sh;
- sh.update_n(p, n);
+ sh.update_n(b, n);
return sh.end_message();
}
template <typename hash_T>
typename hash_T::digest_type
compute_digest(char const *p) {
- return compute_digest<hash_T>(p, std::strlen(p));
+ return compute_digest_n<hash_T>(p, std::strlen(p));
}
} // namespace hash
Modified: sandbox/hash/boost/hash/pack.hpp
==============================================================================
--- sandbox/hash/boost/hash/pack.hpp (original)
+++ sandbox/hash/boost/hash/pack.hpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -35,24 +35,17 @@
false, false> {
template <typename InputType, typename OutputType>
- static void pack_array(InputType const &in, OutputType &out) {
- BOOST_STATIC_ASSERT(OutputType::static_size == InputType::static_size);
- unsigned i = 0;
- for (unsigned j = 0; j < InputType::static_size; ++j) {
- out[i++] = in[j];
- }
- BOOST_ASSERT(i == OutputType::static_size);
- }
-
- template <typename InputType, typename OutputType>
static void pack_n(InputType const *in, size_t in_n,
- OutputType *out, size_t out_n) {
- BOOST_ASSERT(in_n == out_n);
+ OutputType *out) {
unsigned i = 0;
for (unsigned j = 0; j < in_n; ++j) {
out[i++] = in[j];
}
- BOOST_ASSERT(i == out_n);
+ }
+
+ template <typename IterT1, typename IterT2>
+ void pack(IterT1 b1, IterT1 e1, IterT2 b2) {
+ while (b1 != e1) *b2++ = *b1++;
}
};
@@ -66,27 +59,13 @@
BOOST_STATIC_ASSERT(InputBits % OutputBits == 0);
template <typename InputType, typename OutputType>
- static void pack_array(InputType const &in, OutputType &out) {
- BOOST_STATIC_ASSERT(OutputType::static_size*OutputBits ==
- InputType::static_size*InputBits);
- unsigned i = 0;
- for (unsigned j = 0; j < InputType::static_size; ++j) {
- detail::exploder<Endianness, InputBits, OutputBits>
- ::explode1_array(out, i, in[j]);
- }
- BOOST_ASSERT(i == OutputType::static_size);
- }
-
- template <typename InputType, typename OutputType>
static void pack_n(InputType const *in, size_t in_n,
- OutputType *out, size_t out_n) {
- BOOST_ASSERT(InputBits*in_n == OutputBits*out_n);
+ OutputType *out) {
unsigned i = 0;
for (unsigned j = 0; j < in_n; ++j) {
detail::exploder<Endianness, InputBits, OutputBits>
::explode1_array(out, i, in[j]);
}
- BOOST_ASSERT(i == out_n);
}
};
@@ -100,27 +79,14 @@
BOOST_STATIC_ASSERT(OutputBits % InputBits == 0);
template <typename InputType, typename OutputType>
- static void pack_array(InputType const &in, OutputType &out) {
- BOOST_STATIC_ASSERT(OutputType::static_size*OutputBits ==
- InputType::static_size*InputBits);
- unsigned i = 0;
- for (unsigned j = 0; j < OutputType::static_size; ++j) {
- detail::imploder<Endianness, InputBits, OutputBits>
- ::implode1_array(in, i, out[j] = 0);
- }
- BOOST_ASSERT(i == InputType::static_size);
- }
-
- template <typename InputType, typename OutputType>
static void pack_n(InputType const *in, size_t in_n,
- OutputType *out, size_t out_n) {
- BOOST_ASSERT(InputBits*in_n == OutputBits*out_n);
+ OutputType *out) {
+ size_t out_n = in_n/(OutputBits/InputBits);
unsigned i = 0;
for (unsigned j = 0; j < out_n; ++j) {
detail::imploder<Endianness, InputBits, OutputBits>
::implode1_array(in, i, out[j] = 0);
}
- BOOST_ASSERT(i == in_n);
}
};
@@ -134,17 +100,11 @@
!(OutputBits % UnitBits));
template <typename InputType, typename OutputType>
- static void pack_array(InputType const &in, OutputType &out) {
- BOOST_STATIC_ASSERT(OutputType::static_size*OutputBits ==
- InputType::static_size*InputBits);
- std::memcpy(&out[0], &in[0], InputType::static_size*InputBits/CHAR_BIT);
- }
-
- template <typename InputType, typename OutputType>
static void pack_n(InputType const *in, size_t in_n,
- OutputType *out, size_t out_n) {
- BOOST_ASSERT(sizeof(InputType)*in_n == sizeof(OutputType)*out_n);
- BOOST_ASSERT(InputBits*in_n == OutputBits*out_n);
+ OutputType *out) {
+ // FIXME: Bad assumption
+ BOOST_ASSERT(sizeof(InputType)*OutputBits ==
+ sizeof(OutputType)*InputBits);
std::memcpy(&out[0], &in[0], InputBits*in_n/CHAR_BIT);
}
@@ -164,7 +124,6 @@
InputBits, OutputBits,
true, true> {};
-// Forward if nothing better matches
template <typename Endianness,
int InputBits, int OutputBits,
bool BytesOnly = !(InputBits % CHAR_BIT) && !(OutputBits % CHAR_BIT)>
@@ -215,19 +174,85 @@
#endif
template <typename Endianness,
- int InBits, int OutBits,
- typename T1, typename T2>
-void pack(T1 const &in, T2 &out) {
- typedef packer<Endianness, InBits, OutBits> packer_type;
- packer_type::pack_array(in, out);
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack_n(IterT1 in, size_t in_n,
+ IterT2 out) {
+ typedef packer<Endianness, InValueBits, OutValueBits> packer_type;
+ packer_type::pack_n(in, in_n, out);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack_n(IterT1 in, size_t in_n,
+ IterT2 out, size_t out_n) {
+ BOOST_ASSERT(in_n*InValueBits == out_n*OutValueBits);
+ pack_n<Endianness, InValueBits, OutValueBits>(in, in_n, out);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack(IterT1 b1, IterT1 e1, std::random_access_iterator_tag,
+ IterT2 b2) {
+ pack_n<Endianness, InValueBits, OutValueBits>(b1, e1-b1, b2);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename CatT1,
+ typename IterT2>
+void pack(IterT1 b1, IterT1 e1, CatT1,
+ IterT2 b2) {
+ typedef packer<Endianness, InValueBits, OutValueBits> packer_type;
+ packer_type::pack(b1, e1, b2);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack(IterT1 b1, IterT1 e1,
+ IterT2 b2) {
+ typedef typename std::iterator_traits<IterT1>::iterator_category cat1;
+ pack<Endianness, InValueBits, OutValueBits>(b1, e1, cat1(), b2);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack(IterT1 b1, IterT1 e1, std::random_access_iterator_tag,
+ IterT2 b2, IterT2 e2, std::random_access_iterator_tag) {
+ pack_n<Endianness, InValueBits, OutValueBits>(b1, e1-b1, b2, e2-b2);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename CatT1,
+ typename IterT2, typename CatT2>
+void pack(IterT1 b1, IterT1 e1, CatT1,
+ IterT2 b2, IterT2, CatT2) {
+ pack<Endianness, InValueBits, OutValueBits>(b1, e1, b2);
+}
+
+template <typename Endianness,
+ int InValueBits, int OutValueBits,
+ typename IterT1, typename IterT2>
+void pack(IterT1 b1, IterT1 e1,
+ IterT2 b2, IterT2 e2) {
+ typedef typename std::iterator_traits<IterT1>::iterator_category cat1;
+ typedef typename std::iterator_traits<IterT2>::iterator_category cat2;
+ pack<Endianness, InValueBits, OutValueBits>(b1, e1, cat1(), b2, e2, cat2());
}
template <typename Endianness,
- int InBits, int OutBits,
- typename T1, typename T2>
-void pack(T1 const *in, size_t in_n, T2 *out, size_t out_n) {
- typedef packer<Endianness, InBits, OutBits> packer_type;
- packer_type::pack_n(in, in_n, out, out_n);
+ int InValueBits, int OutValueBits,
+ typename InputType, typename OutputType>
+void pack(InputType const &in, OutputType &out) {
+ BOOST_STATIC_ASSERT(InputType::static_size*InValueBits ==
+ OutputType::static_size*OutValueBits);
+ pack_n<Endianness, InValueBits, OutValueBits>(&in[0], in.size(),
+ &out[0], out.size());
}
} // namespace hash
Modified: sandbox/hash/boost/hash/stream_preprocessor.hpp
==============================================================================
--- sandbox/hash/boost/hash/stream_preprocessor.hpp (original)
+++ sandbox/hash/boost/hash/stream_preprocessor.hpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -15,6 +15,8 @@
#include <boost/static_assert.hpp>
#include <boost/utility/enable_if.hpp>
+#include <iterator>
+
namespace boost {
namespace hash {
@@ -63,7 +65,8 @@
BOOST_STATIC_ASSERT(!length_bits || value_bits <= length_bits);
private:
- void process_block() {
+ void
+ process_block() {
// Convert the input into words
block_type block;
pack<endian, value_bits, word_bits>(value_array, block);
@@ -98,7 +101,8 @@
// No appending requested, so nothing to do
}
public:
- stream_preprocessor &update(value_type value) {
+ stream_preprocessor &
+ update_one(value_type value) {
unsigned i = seen % block_bits;
unsigned j = i / value_bits;
value_array[j] = value;
@@ -109,20 +113,19 @@
}
return *this;
}
- template <typename T>
- stream_preprocessor &update_n(T const *p_, size_t n) {
- BOOST_STATIC_ASSERT(sizeof(T) == sizeof(value_type));
- value_type const *p = reinterpret_cast<value_type const *>(p_);
+ template <typename IterT>
+ stream_preprocessor &
+ update_n(IterT p, size_t n) {
#ifndef BOOST_HASH_NO_OPTIMIZATION
for ( ; n && (seen % block_bits); --n, ++p) {
- update(*p);
+ update_one(*p);
}
for ( ; n >= block_values; n -= block_values, p += block_values) {
// Convert the input into words
block_type block;
- pack<endian, value_bits, word_bits>(p, block_values,
- &block[0], block_words);
-
+ pack_n<endian, value_bits, word_bits>(p, block_values,
+ &block[0], block_words);
+
// Process the block
block_hash.update(block);
seen += block_bits;
@@ -130,13 +133,36 @@
// Reset seen if we don't need to track the length
if (!length_bits) seen = 0;
}
-#endif
+#endif
for ( ; n; --n, ++p) {
- update(*p);
+ update_one(*p);
}
return *this;
}
- digest_type end_message() {
+ template <typename IterT>
+ stream_preprocessor &
+ update(IterT b, IterT e, std::random_access_iterator_tag) {
+ return update_n(b, e-b);
+ }
+ template <typename IterT, typename Category>
+ stream_preprocessor &
+ update(IterT b, IterT e, Category) {
+ while (b != e) update_one(*b++);
+ return *this;
+ }
+ template <typename IterT>
+ stream_preprocessor &
+ update(IterT b, IterT e) {
+ typedef typename std::iterator_traits<IterT>::iterator_category cat;
+ return update(b, e, cat());
+ }
+ template <typename ContainerT>
+ stream_preprocessor &
+ update(ContainerT const &c) {
+ return update(c.begin(), c.end());
+ }
+ digest_type
+ end_message() {
length_type length = seen;
// Add a 1 bit
@@ -144,16 +170,16 @@
array<bool, value_bits> padding_bits = {{1}};
array<value_type, 1> padding_values;
pack<endian, 1, value_bits>(padding_bits, padding_values);
- update(padding_values[0]);
+ update_one(padding_values[0]);
#else
value_type pad = 0;
detail::imploder<endian, 1, value_bits>::step(1, pad);
- update(pad);
+ update_one(pad);
#endif
// Pad with 0 bits
while ((seen + length_bits) % block_bits != 0) {
- update(value_type());
+ update_one(value_type());
}
// Append length
@@ -171,7 +197,8 @@
public:
stream_preprocessor() : value_array(), block_hash(), seen() {}
- void reset() {
+ void
+ reset() {
seen = 0;
block_hash.reset();
}
Modified: sandbox/hash/libs/hash/example/hashsum.cpp
==============================================================================
--- sandbox/hash/libs/hash/example/hashsum.cpp (original)
+++ sandbox/hash/libs/hash/example/hashsum.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -21,16 +21,27 @@
typedef boost::hash::HASH hash_policy;
hash_policy::digest_type
-hash_streambuf(std::streambuf *buf) {
+hash_streambuf(std::streambuf *sbuf) {
+#ifdef BOOST_HASH_NO_OPTIMIZATION
return boost::hash::compute_digest<hash_policy>(
- std::istreambuf_iterator<char>(buf),
+ std::istreambuf_iterator<char>(sbuf),
std::istreambuf_iterator<char>()
);
+#else
+ hash_policy::stream_hash<8>::type hash;
+ for (;;) {
+ boost::array<char, 8*1024> buf;
+ std::streamsize n = sbuf->sgetn(&buf[0], buf.size());
+ if (!n) break;
+ hash.update_n(buf.begin(), n);
+ }
+ return hash.end_message();
+#endif
}
hash_policy::digest_type
hash_memory(void *buf, size_t n) {
- return boost::hash::compute_digest<hash_policy>((char*)buf, n);
+ return boost::hash::compute_digest_n<hash_policy>((char*)buf, n);
}
std::ostream &
Modified: sandbox/hash/libs/hash/test/cubehash.cpp
==============================================================================
--- sandbox/hash/libs/hash/test/cubehash.cpp (original)
+++ sandbox/hash/libs/hash/test/cubehash.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -103,7 +103,7 @@
"b271bb1349a4a17b6dd065bde8f1dfc1" == d);
#ifndef BOOST_HASH_SHOW_PROGRESS
- for (unsigned i = 0; i < 1000000; ++i) sh.update('a');
+ for (unsigned i = 0; i < 1000000; ++i) sh.update_one('a');
d = sh.end_message();
printf("%s\n", d.cstring().data());
assert("b2255396660eb6d08cdfd5f391ff522a"
@@ -112,7 +112,7 @@
"00bfff4ad4b107aa71419c84ae30814e" == d);
#ifndef QUICK
- for (unsigned i = 0; i < 1000000000; ++i) sh.update('a');
+ for (unsigned i = 0; i < 1000000000; ++i) sh.update_one('a');
d = sh.end_message();
printf("%s\n", d.cstring().data());
assert("cad33236b5a4810ea619e069bb2beff1"
@@ -167,14 +167,14 @@
"cfed5b69ecde8a0aee0766d879e13e7b" == d);
#ifndef BOOST_HASH_SHOW_PROGRESS
- for (unsigned i = 0; i < 1000000; ++i) sh.update('a');
+ for (unsigned i = 0; i < 1000000; ++i) sh.update_one('a');
d = sh.end_message();
printf("%s\n", d.cstring().data());
assert("bdaaff72d49f8d5a66e4760fc54c2587"
"d909bd21811473d252e8589d30b34352" == d);
#ifndef QUICK
- for (unsigned i = 0; i < 1000000000; ++i) sh.update('a');
+ for (unsigned i = 0; i < 1000000000; ++i) sh.update_one('a');
d = sh.end_message();
printf("%s\n", d.cstring().data());
assert("7ed524f063da37f9e38e5ad9bbb4db9f"
Modified: sandbox/hash/libs/hash/test/md.cpp
==============================================================================
--- sandbox/hash/libs/hash/test/md.cpp (original)
+++ sandbox/hash/libs/hash/test/md.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -97,7 +97,7 @@
{
md4::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
assert(h.digest() == h.digest());
md4::block_hash_type::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -108,7 +108,7 @@
{
md4::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
md4::block_hash_type::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -128,7 +128,7 @@
{
md5::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
assert(!(h.digest() != h.digest()));
md5::block_hash_type::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -140,7 +140,7 @@
// perl -e 'for (1..1000000) { print "a"; }' | md5sum
md5::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
md5::block_hash_type::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
Modified: sandbox/hash/libs/hash/test/sha.cpp
==============================================================================
--- sandbox/hash/libs/hash/test/sha.cpp (original)
+++ sandbox/hash/libs/hash/test/sha.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -67,9 +67,9 @@
assert(sizeof(fic1) == sizeof(fic2));
- sha::digest_type h1 = compute_digest<sha>(fic1, bitlength/32);
+ sha::digest_type h1 = compute_digest_n<sha>(fic1, bitlength/32);
printf("%s\n", h1.cstring().data());
- sha::digest_type h2 = compute_digest<sha>(fic2, bitlength/32);
+ sha::digest_type h2 = compute_digest_n<sha>(fic2, bitlength/32);
printf("%s\n", h2.cstring().data());
assert(h1 == h2);
@@ -89,9 +89,9 @@
{
// echo -n "abc" | sha1sum
sha1::stream_hash<4>::type h;
- h.update(0x6).update(0x1)
- .update(0x6).update(0x2)
- .update(0x6).update(0x3);
+ h.update_one(0x6).update_one(0x1)
+ .update_one(0x6).update_one(0x2)
+ .update_one(0x6).update_one(0x3);
sha1::digest_type d = h.end_message();
assert(!strcmp("a9993e364706816aba3e25717850c26c9cd0d89d",
d.cstring().data()));
@@ -102,7 +102,7 @@
{
// A.1/1
bool a[] = {1, 0, 0, 1, 1};
- sha1::digest_type d = compute_digest<sha1>(a, sizeof(a)/sizeof(*a));
+ sha1::digest_type d = compute_digest_n<sha1>(a, sizeof(a)/sizeof(*a));
std::printf("%s\n", d.cstring().data());
assert(!strcmp("29826b003b906e660eff4027ce98af3531ac75ba",
d.cstring().data()));
@@ -112,9 +112,9 @@
// A.1/2
bool a[] = {0, 1, 0, 1,
1, 1, 1, 0};
- sha1::digest_type d = compute_digest<sha1>(a, sizeof(a)/sizeof(*a));
+ sha1::digest_type d = compute_digest_n<sha1>(a, sizeof(a)/sizeof(*a));
std::printf("%s\n", d.cstring().data());
- assert(d == compute_digest<sha1>("\x5e", 1));
+ assert(d == compute_digest_n<sha1>("\x5e", 1));
}
#define B0 0, 0, 0, 0
@@ -141,7 +141,7 @@
B5, B9, B4, BB, BB, BE, B3, BA,
B3, BB, B1, B1, B7, B5, B4, B2,
BD, B9, B4, BA, BC, B8, B8};
- sha1::digest_type d = compute_digest<sha1>(a, n);
+ sha1::digest_type d = compute_digest_n<sha1>(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("6239781e03729919c01955b3ffa8acb60b988340",
d.cstring().data()));
@@ -172,7 +172,7 @@
B1, B1, BA, B1, BB, B3, B2, BA,
BE
};
- sha1::digest_type d = compute_digest<sha1>(a, n);
+ sha1::digest_type d = compute_digest_n<sha1>(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("8c5b2a5ddae5a97fc7f9d85661c672adbf7933d4",
d.cstring().data()));
@@ -186,7 +186,7 @@
};
sha1::stream_hash<4>::type h;
for (unsigned i = 0; i < n; i += 4) {
- h.update((a[i/32] >> (32-4-i%32)) % 0x10);
+ h.update_one((a[i/32] >> (32-4-i%32)) % 0x10);
}
sha1::digest_type d = h.end_message();
std::printf("%s\n", d.cstring().data());
@@ -208,7 +208,7 @@
};
sha1::stream_hash<4>::type h;
for (unsigned i = 0; i < n; i += 4) {
- h.update((a[i/32] >> (32-4-i%32)) % 0x10);
+ h.update_one((a[i/32] >> (32-4-i%32)) % 0x10);
}
sha1::digest_type d = h.end_message();
std::printf("%s\n", d.cstring().data());
@@ -303,7 +303,7 @@
{
// Example from Appendix A.1
sha1::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
sha1::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
assert(!strcmp("a9993e364706816aba3e25717850c26c9cd0d89d",
@@ -315,7 +315,7 @@
// Example from Appendix A.3
sha1::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
sha1::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -339,7 +339,7 @@
}
{
- sha1::digest_type h = compute_digest<sha0>("abc", 3);
+ sha1::digest_type h = compute_digest_n<sha0>("abc", 3);
std::printf("%s\n", h.cstring().data());
assert(!strcmp("0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
h.cstring().data()));
Modified: sandbox/hash/libs/hash/test/sha2.cpp
==============================================================================
--- sandbox/hash/libs/hash/test/sha2.cpp (original)
+++ sandbox/hash/libs/hash/test/sha2.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -26,7 +26,7 @@
// B.1/1
unsigned n = 5;
bool a[] = {0, 1, 1, 0, 1};
- sha2<224>::digest_type d = compute_digest<sha2<224> >(a, n);
+ sha2<224>::digest_type d = compute_digest_n<sha2<224> >(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("e3b048552c3c387bcab37f6eb06bb79b"
"96a4aee5ff27f51531a9551c",
@@ -37,7 +37,7 @@
// C.1/1
unsigned n = 5;
bool a[] = {0, 1, 1, 0, 1};
- sha2<256>::digest_type d = compute_digest<sha2<256> >(a, n);
+ sha2<256>::digest_type d = compute_digest_n<sha2<256> >(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("d6d3e02a31a84a8caa9718ed6c2057be"
"09db45e7823eb5079ce7a573a3760f95",
@@ -48,7 +48,7 @@
// D.1/1
unsigned n = 5;
bool a[] = {0, 0, 0, 1, 0};
- sha2<384>::digest_type d = compute_digest<sha2<384> >(a, n);
+ sha2<384>::digest_type d = compute_digest_n<sha2<384> >(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("8d17be79e32b6718e07d8a603eb84ba0478f7fcfd1bb9399"
"5f7d1149e09143ac1ffcfc56820e469f3878d957a15a3fe4",
@@ -59,7 +59,7 @@
// E.1/1
unsigned n = 5;
bool a[] = {1, 0, 1, 1, 0};
- sha2<512>::digest_type d = compute_digest<sha2<512> >(a, n);
+ sha2<512>::digest_type d = compute_digest_n<sha2<512> >(a, n);
std::printf("%s\n", d.cstring().data());
assert(!strcmp("d4ee29a9e90985446b913cf1d1376c836f4be2c1cf3cada0"
"720a6bf4857d886a7ecb3c4e4c0fa8c7f95214e41dc1b0d2"
@@ -302,7 +302,7 @@
{
// Example from Appendix B.1
HASH::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
assert("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" == s);
@@ -313,7 +313,7 @@
// Example from Appendix B.3
HASH::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -336,7 +336,7 @@
{
// Example from Appendix D.1
HASH::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
assert("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded163"
@@ -348,7 +348,7 @@
// Example from Appendix D.3
HASH::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -372,7 +372,7 @@
{
// Example from Appendix C.1
HASH::stream_hash<8>::type h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
assert("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
@@ -384,7 +384,7 @@
// Example from Appendix C.3
HASH::stream_hash<8>::type h;
for (unsigned i = 0; i < 1000000; ++i) {
- h.update('a');
+ h.update_one('a');
}
HASH::digest_type s = h.end_message();
std::printf("%s\n", s.cstring().data());
@@ -406,7 +406,7 @@
test_preprocessor_sha512();
{
- sha2<224>::digest_type h = compute_digest<sha2<224> >("abc", 3);
+ sha2<224>::digest_type h = compute_digest_n<sha2<224> >("abc", 3);
std::printf("%s\n", h.cstring().data());
assert(!strcmp("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
h.cstring().data()));
@@ -415,7 +415,7 @@
{
sha2<512>::stream_hash<16>::type pp;
for (unsigned i = 0; i < 1000000/2; ++i) {
- pp.update(('a'<<8) | 'a');
+ pp.update_one(('a'<<8) | 'a');
}
sha2<512>::digest_type h = pp.end_message();
std::printf("%s\n", h.cstring().data());
@@ -427,7 +427,7 @@
{
sha2<512>::stream_hash<32>::type pp;
for (unsigned i = 0; i < 1000000/4; ++i) {
- pp.update(('a'<<24) | ('a'<<16) | ('a'<<8) | 'a');
+ pp.update_one(('a'<<24) | ('a'<<16) | ('a'<<8) | 'a');
}
sha2<512>::digest_type h = pp.end_message();
std::printf("%s\n", h.cstring().data());
Modified: sandbox/hash/libs/hash/test/shacal.cpp
==============================================================================
--- sandbox/hash/libs/hash/test/shacal.cpp (original)
+++ sandbox/hash/libs/hash/test/shacal.cpp 2010-05-03 10:44:25 EDT (Mon, 03 May 2010)
@@ -235,7 +235,7 @@
{
sha512_octet_hash h;
- h.update('a').update('b').update('c');
+ h.update_one('a').update_one('b').update_one('c');
digest_type d = h.end_message();
printf("%s\n", d.cstring().data());
char const *ed = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
@@ -248,7 +248,7 @@
char const *m = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
for (char const *p = m; *p; ++p) {
- h.update(*p);
+ h.update_one(*p);
}
digest_type d = h.end_message();
printf("%s\n", d.cstring().data());
@@ -260,7 +260,7 @@
#ifndef BOOST_HASH_SHOW_PROGRESS
{
sha512_octet_hash h;
- for (unsigned n = 1000000; n--; ) h.update('a');
+ for (unsigned n = 1000000; n--; ) h.update_one('a');
digest_type d = h.end_message();
printf("%s\n", d.cstring().data());
char const *ed = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"
@@ -272,7 +272,7 @@
{
// perl -e 'for ($x = 1000000000; $x--;) {print "a";}' | sha512sum
sha512_octet_hash h;
- for (unsigned n = 1000000000; n--; ) h.update('a');
+ for (unsigned n = 1000000000; n--; ) h.update_one('a');
digest_type d = h.end_message();
printf("%s\n", d.cstring().data());
char const *ed = "7cc86d7e06edc6a2029b8c0fa0e3ffb013888fd360f8faf681c7cffd08eacffb"
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk