aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2011-10-09 19:50:29 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2011-10-14 23:04:29 +0100
commitd73045dd1c1dd9c11e8a1ae6890137df9f9b3c7c (patch)
tree10f2589eaa7fbc91929bae9eb59350bb70849b50
parent69295f04a92ba99d4c2b210c77e80ab48e4be621 (diff)
downloadpaludis-d73045dd1c1dd9c11e8a1ae6890137df9f9b3c7c.tar.gz
paludis-d73045dd1c1dd9c11e8a1ae6890137df9f9b3c7c.tar.xz
Move to/from_bigendian to byte_swap.hh
-rw-r--r--paludis/util/byte_swap.hh30
-rw-r--r--paludis/util/sha1.cc30
2 files changed, 33 insertions, 27 deletions
diff --git a/paludis/util/byte_swap.hh b/paludis/util/byte_swap.hh
index b19fce3..2ba7786 100644
--- a/paludis/util/byte_swap.hh
+++ b/paludis/util/byte_swap.hh
@@ -75,6 +75,36 @@ namespace paludis
{
return byte_swap_internals::ByteSwap<sizeof(T_), T_>::swap(x);
}
+
+#ifdef PALUDIS_BIG_ENDIAN
+ template <typename T_>
+ inline T_
+ from_bigendian(T_ x)
+ {
+ return x;
+ }
+
+ template <typename T_>
+ inline T_
+ to_bigendian(T_ x)
+ {
+ return x;
+ }
+#else
+ template <typename T_>
+ inline T_
+ from_bigendian(T_ x)
+ {
+ return byte_swap(x);
+ }
+
+ template <typename T_>
+ inline T_
+ to_bigendian(T_ x)
+ {
+ return byte_swap(x);
+ }
+#endif
}
#endif
diff --git a/paludis/util/sha1.cc b/paludis/util/sha1.cc
index 135f111..5bf816b 100644
--- a/paludis/util/sha1.cc
+++ b/paludis/util/sha1.cc
@@ -17,8 +17,6 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "config.h"
-
#include <paludis/util/sha1.hh>
#include <paludis/util/byte_swap.hh>
#include <paludis/util/digest_registry.hh>
@@ -35,28 +33,6 @@ using namespace paludis;
namespace
{
-#ifdef PALUDIS_BIG_ENDIAN
- inline uint32_t from_bigendian(uint32_t x)
- {
- return x;
- }
-
- inline uint32_t to_bigendian(uint32_t x)
- {
- return x;
- }
-#else
- inline uint32_t from_bigendian(uint32_t x)
- {
- return byte_swap(x);
- }
-
- inline uint32_t to_bigendian(uint32_t x)
- {
- return byte_swap(x);
- }
-#endif
-
template <int n_>
inline uint32_t s(uint32_t x)
{
@@ -137,7 +113,7 @@ SHA1::process_block(uint32_t * w)
{
uint32_t a(h0), b(h1), c(h2), d(h3), e(h4);
- std::transform(&w[0], &w[16], &w[0], from_bigendian);
+ std::transform(&w[0], &w[16], &w[0], from_bigendian<uint32_t>);
for (int t = 16; t < 80; ++t)
w[t] = s<1>(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
@@ -189,8 +165,8 @@ SHA1::SHA1(std::istream & s) :
}
std::fill(&block.m[block_size], &block.m[56], 0);
- block.w[14] = to_bigendian((size >> 32) & 0xFFFFFFFFU);
- block.w[15] = to_bigendian(size & 0xFFFFFFFFU);
+ block.w[14] = to_bigendian<uint32_t>((size >> 32) & 0xFFFFFFFFU);
+ block.w[15] = to_bigendian<uint32_t>(size & 0xFFFFFFFFU);
}
process_block(block.w);