[nordugrid-arc/el5] Backport fixes for endian independent md5 checksum
Mattias Ellert
ellert at fedoraproject.org
Sun Oct 23 23:57:32 UTC 2011
commit eb608dd493aa2c4d09866ba6bc1176810871a6d6
Author: Mattias Ellert <mattias.ellert at fysast.uu.se>
Date: Mon Oct 24 01:56:21 2011 +0200
Backport fixes for endian independent md5 checksum
nordugrid-arc-md5.patch | 155 +++++++++++++++++++++++++++++++++++++++++++++++
nordugrid-arc.spec | 7 ++-
2 files changed, 161 insertions(+), 1 deletions(-)
---
diff --git a/nordugrid-arc-md5.patch b/nordugrid-arc-md5.patch
new file mode 100644
index 0000000..cebda5b
--- /dev/null
+++ b/nordugrid-arc-md5.patch
@@ -0,0 +1,155 @@
+Index: arc1/trunk/src/hed/libs/common/CheckSum.cpp
+===================================================================
+--- arc1/trunk/src/hed/libs/common/CheckSum.cpp (revision 22836)
++++ arc1/trunk/src/hed/libs/common/CheckSum.cpp (revision 23053)
+@@ -170,5 +170,5 @@
+
+ // ----------------------------------------------------------------------------
+- // This is MD5 implementation for LOW-ENDIAN machines derived directly from RFC
++ // This is MD5 implementation derived directly from RFC
+ // ----------------------------------------------------------------------------
+
+@@ -235,4 +235,5 @@
+ count = 0;
+ Xlen = 0;
++ memset(X,0,sizeof(X));
+ computed = false;
+ }
+@@ -241,16 +242,15 @@
+ u_char *buf_ = (u_char*)buf;
+ for (; len;) {
+- if (Xlen < 64) { // 16 words = 64 bytes
+- u_int l = 64 - Xlen;
+- if (len < l)
+- l = len;
+- memcpy(((u_char*)X) + Xlen, buf_, l);
+- Xlen += l;
+- count += l;
+- len -= l;
+- buf_ += l;
++ for(;Xlen < 64;) { // 16 words = 64 bytes
++ if(!len) break;
++ u_int Xi = Xlen >> 2;
++ u_int Xs = (Xlen & 3) << 3;
++ X[Xi] |= ((uint32_t)(*buf_)) << Xs;
++ ++Xlen;
++ ++count;
++ --len;
++ ++buf_;
+ }
+- if (Xlen < 64)
+- return;
++ if (Xlen < 64) return;
+
+ uint32_t AA = A;
+@@ -349,10 +349,10 @@
+ D += DD;
+ Xlen = 0;
++ memset(X,0,sizeof(X));
+ }
+ }
+
+ void MD5Sum::end(void) {
+- if (computed)
+- return;
++ if (computed) return;
+ // pad
+ uint64_t l = 8 * count; // number of bits
+@@ -360,7 +360,14 @@
+ add(&c, 1);
+ c = 0;
+- for (; Xlen != 56;)
+- add(&c, 1);
+- add(&l, 8);
++ for (; Xlen != 56;) add(&c, 1);
++ //add(&l, 8);
++ c = (u_char)(l>>0); add(&c, 1);
++ c = (u_char)(l>>8); add(&c, 1);
++ c = (u_char)(l>>16); add(&c, 1);
++ c = (u_char)(l>>24); add(&c, 1);
++ c = (u_char)(l>>32); add(&c, 1);
++ c = (u_char)(l>>40); add(&c, 1);
++ c = (u_char)(l>>48); add(&c, 1);
++ c = (u_char)(l>>56); add(&c, 1);
+ computed = true;
+ }
+@@ -368,31 +375,31 @@
+ int MD5Sum::print(char *buf, int len) const {
+ if (!computed) {
+- if (len > 0)
+- buf[0] = 0;
++ if (len > 0) buf[0] = 0;
+ return 0;
+ }
+ return snprintf(buf, len,
+ "md5:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+- ((u_char*)&A)[0], ((u_char*)&A)[1], ((u_char*)&A)[2], ((u_char*)&A)[3],
+- ((u_char*)&B)[0], ((u_char*)&B)[1], ((u_char*)&B)[2], ((u_char*)&B)[3],
+- ((u_char*)&C)[0], ((u_char*)&C)[1], ((u_char*)&C)[2], ((u_char*)&C)[3],
+- ((u_char*)&D)[0], ((u_char*)&D)[1], ((u_char*)&D)[2], ((u_char*)&D)[3]
++ (u_char)(A>>0), (u_char)(A>>8), (u_char)(A>>16), (u_char)(A>>24),
++ (u_char)(B>>0), (u_char)(B>>8), (u_char)(B>>16), (u_char)(B>>24),
++ (u_char)(C>>0), (u_char)(C>>8), (u_char)(C>>16), (u_char)(C>>24),
++ (u_char)(D>>0), (u_char)(D>>8), (u_char)(D>>16), (u_char)(D>>24)
+ );
+ }
+
+ void MD5Sum::scan(const char *buf) {
++ u_char A0, A1, A2, A3, B0, B1, B2, B3, C0, C1, C2, C3, D0, D1, D2, D3;
+ computed = false;
+- if (strncasecmp("md5:", buf, 4) != 0)
+- return;
++ if (strncasecmp("md5:", buf, 4) != 0) return;
+ int l = sscanf(buf + 4,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
+- ((u_char*)&A) + 0, ((u_char*)&A) + 1, ((u_char*)&A) + 2, ((u_char*)&A) + 3,
+- ((u_char*)&B) + 0, ((u_char*)&B) + 1, ((u_char*)&B) + 2, ((u_char*)&B) + 3,
+- ((u_char*)&C) + 0, ((u_char*)&C) + 1, ((u_char*)&C) + 2, ((u_char*)&C) + 3,
+- ((u_char*)&D) + 0, ((u_char*)&D) + 1, ((u_char*)&D) + 2, ((u_char*)&D) + 3
++ &A0, &A1, &A2, &A3, &B0, &B1, &B2, &B3,
++ &C0, &C1, &C2, &C3, &D0, &D1, &D2, &D3
+ );
+- if (l != 16)
+- return;
++ A = (((uint32_t)A0)<<0) | (((uint32_t)A1)<<8) | (((uint32_t)A2)<<16) | (((uint32_t)A3)<<24);
++ B = (((uint32_t)B0)<<0) | (((uint32_t)B1)<<8) | (((uint32_t)B2)<<16) | (((uint32_t)B3)<<24);
++ C = (((uint32_t)C0)<<0) | (((uint32_t)C1)<<8) | (((uint32_t)C2)<<16) | (((uint32_t)C3)<<24);
++ D = (((uint32_t)D0)<<0) | (((uint32_t)D1)<<8) | (((uint32_t)D2)<<16) | (((uint32_t)D3)<<24);
++ if (l != 16) return;
+ computed = true;
+ return;
+Index: arc1/trunk/src/hed/libs/common/test/CheckSumTest.cpp
+===================================================================
+--- arc1/trunk/src/hed/libs/common/test/CheckSumTest.cpp (revision 22394)
++++ arc1/trunk/src/hed/libs/common/test/CheckSumTest.cpp (revision 23053)
+@@ -47,4 +47,9 @@
+ CPPUNIT_ASSERT_EQUAL((std::string)"acb7ca96", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1K.data", Arc::CheckSumAny::cksum));
+ CPPUNIT_ASSERT_EQUAL((std::string)"53a57307", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1M.data", Arc::CheckSumAny::cksum));
++ char buf[64];
++ Arc::CheckSumAny ck(Arc::CheckSumAny::cksum);
++ ck.scan("cksum:53a57307");
++ ck.print(buf,sizeof(buf));
++ CPPUNIT_ASSERT_EQUAL((std::string)"cksum:53a57307", (std::string)buf);
+ }
+
+@@ -52,4 +57,9 @@
+ CPPUNIT_ASSERT_EQUAL((std::string)"88bb69a5d5e02ec7af5f68d82feb1f1d", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1K.data"));
+ CPPUNIT_ASSERT_EQUAL((std::string)"2f54d66538c094bf229e89ed0667b6fd", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1M.data"));
++ char buf[64];
++ Arc::CheckSumAny ck(Arc::CheckSumAny::md5);
++ ck.scan("md5:2f54d66538c094bf229e89ed0667b6fd");
++ ck.print(buf,sizeof(buf));
++ CPPUNIT_ASSERT_EQUAL((std::string)"md5:2f54d66538c094bf229e89ed0667b6fd", (std::string)buf);
+ }
+
+@@ -57,4 +67,9 @@
+ CPPUNIT_ASSERT_EQUAL((std::string)"ad1abb81", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1K.data", Arc::CheckSumAny::adler32));
+ CPPUNIT_ASSERT_EQUAL((std::string)"471b96e5", Arc::CheckSumAny::FileChecksum("CheckSumTest.f1M.data", Arc::CheckSumAny::adler32));
++ //char buf[64];
++ //Arc::CheckSumAny ck(Arc::CheckSumAny::adler32);
++ //ck.scan("adler32:471b96e5");
++ //ck.print(buf,sizeof(buf));
++ //CPPUNIT_ASSERT_EQUAL((std::string)"adler32:471b96e5", (std::string)buf);
+ }
+
diff --git a/nordugrid-arc.spec b/nordugrid-arc.spec
index 0bb1984..98a372f 100644
--- a/nordugrid-arc.spec
+++ b/nordugrid-arc.spec
@@ -47,12 +47,13 @@
Name: nordugrid-arc
Version: 1.1.0
-Release: 1%{?dist}
+Release: 2%{?dist}
Summary: Advanced Resource Connector Grid Middleware
Group: System Environment/Daemons
License: ASL 2.0
URL: http://www.nordugrid.org/
Source: http://download.nordugrid.org/packages/%{name}/releases/%{version}/src/%{name}-%{version}.tar.gz
+Patch0: %{name}-md5.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: cppunit-devel
@@ -566,6 +567,7 @@ fetch-crl tool in the fetch-crl package.
%prep
%setup -q
+%patch0 -p2
%if %{?fedora}%{!?fedora:0} <= 9 && %{?rhel}%{!?rhel:0} <= 5
# Older versions of SELinux does not have policy for open
@@ -1192,6 +1194,9 @@ service fetch-crl-cron start > /dev/null 2>&1
%defattr(-,root,root,-)
%changelog
+* Mon Oct 24 2011 Mattias Ellert <mattias.ellert at fysast.uu.se> - 1.1.0-2
+- Backport fixes for endian independent md5 checksum
+
* Mon Oct 03 2011 Mattias Ellert <mattias.ellert at fysast.uu.se> - 1.1.0-1
- 1.1.0 Final Release
- Drop patches accepted upstream: nordugrid-arc-perl-switch.patch and
More information about the scm-commits
mailing list