• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • libbytearraychecksum
  • algorithm
modsum64bytearraychecksumalgorithm.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "modsum64bytearraychecksumalgorithm.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 // Qt
30 #include <QtCore/QtEndian>
31 
32 
33 ModSum64ByteArrayChecksumAlgorithm::ModSum64ByteArrayChecksumAlgorithm()
34  : AbstractByteArrayChecksumAlgorithm(
35  i18nc("name of the checksum algorithm", "Modular sum 64-bit") )
36 {}
37 
38 AbstractByteArrayChecksumParameterSet* ModSum64ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; }
39 
40 bool ModSum64ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
41  const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
42 {
43  const bool useLittleEndian = ( mParameterSet.endianness() == LittleEndian );
44  quint64 modSum = useLittleEndian ?
45  calculateModSumWithLittleEndian( model, range ) :
46  calculateModSumWithBigEndian( model, range );
47 
48  modSum = ~modSum + 1;
49 
50  if( useLittleEndian )
51  modSum = qbswap( modSum );
52 
53  *result = QString::fromLatin1("%1").arg( modSum, 16, 16, QChar::fromLatin1('0') );
54  return true;
55 }
56 
57 quint64 ModSum64ByteArrayChecksumAlgorithm::calculateModSumWithBigEndian( const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
58 {
59  quint64 modSum = 0x00000000;
60  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
61 
62  // TODO: move padding checks into extra code before and after loop
63  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
64  {
65  quint64 value = (quint64)( (quint8)(model->byte( i )) ) << 56;
66  ++i;
67  if( i<=range.end() )
68  {
69  value |= (quint64)( (quint8)(model->byte( i )) ) << 48;
70  ++i;
71  if( i<=range.end() )
72  {
73  value |= (quint64)( (quint8)(model->byte( i )) ) << 40;
74  ++i;
75  if( i<=range.end() )
76  {
77  value |= (quint64)( (quint8)(model->byte( i )) ) << 32;
78  ++i;
79  if( i<=range.end() )
80  {
81  value |= (quint64)( (quint8)(model->byte( i )) ) << 24;
82  ++i;
83  if( i<=range.end() )
84  {
85  value |= (quint64)( (quint8)(model->byte( i )) ) << 16;
86  ++i;
87  if( i<=range.end() )
88  {
89  value |= (quint64)( (quint8)(model->byte( i )) ) << 8;
90  ++i;
91  if( i<=range.end() )
92  value |= (quint64)( (quint8)(model->byte( i )) );
93  }
94  }
95  }
96  }
97  }
98  }
99 
100  modSum += value;
101 #if 0
102  const uchar value = (crcBits & 0xFF) + model->byte( i );
103  crcBits >>= 8;
104  crcBits ^= lookupTable[value];
105 #endif
106  if( i >= nextBlockEnd )
107  {
108  nextBlockEnd += CalculatedByteCountSignalLimit;
109  emit calculatedBytes( range.localIndex(i)+1 );
110  }
111  }
112 
113  return modSum;
114 }
115 
116 quint64 ModSum64ByteArrayChecksumAlgorithm::calculateModSumWithLittleEndian( const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
117 {
118  quint64 modSum = 0x00000000;
119  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
120 
121  // TODO: move padding checks into extra code before and after loop
122  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
123  {
124  quint64 value = (quint8)( model->byte(i) );
125  ++i;
126  if( i<=range.end() )
127  {
128  value |= (quint64)( (quint8)(model->byte( i )) ) << 8;
129  ++i;
130  if( i<=range.end() )
131  {
132  value |= (quint64)( (quint8)(model->byte( i )) ) << 16;
133  ++i;
134  if( i<=range.end() )
135  {
136  value |= (quint64)( (quint8)(model->byte( i )) ) << 24;
137  ++i;
138  if( i<=range.end() )
139  {
140  value |= (quint64)( (quint8)(model->byte( i )) ) << 32;
141  ++i;
142  if( i<=range.end() )
143  {
144  value |= (quint64)( (quint8)(model->byte( i )) ) << 40;
145  ++i;
146  if( i<=range.end() )
147  {
148  value |= (quint64)( (quint8)(model->byte( i )) ) << 48;
149  ++i;
150  if( i<=range.end() )
151  value |= (quint64)( (quint8)(model->byte( i )) ) << 56;
152  }
153  }
154  }
155  }
156  }
157  }
158 
159  modSum += value;
160 #if 0
161  const uchar value = (crcBits & 0xFF) + model->byte( i );
162  crcBits >>= 8;
163  crcBits ^= lookupTable[value];
164 #endif
165  if( i >= nextBlockEnd )
166  {
167  nextBlockEnd += CalculatedByteCountSignalLimit;
168  emit calculatedBytes( range.localIndex(i)+1 );
169  }
170  }
171 
172  return modSum;
173 }
174 
175 ModSum64ByteArrayChecksumAlgorithm::~ModSum64ByteArrayChecksumAlgorithm() {}
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
AbstractByteArrayChecksumAlgorithm
Definition: abstractbytearraychecksumalgorithm.h:38
ModSum64ByteArrayChecksumAlgorithm::~ModSum64ByteArrayChecksumAlgorithm
virtual ~ModSum64ByteArrayChecksumAlgorithm()
Definition: modsum64bytearraychecksumalgorithm.cpp:175
modsum64bytearraychecksumalgorithm.h
KDE::NumberRange< Address, Size >
ModSum64ByteArrayChecksumAlgorithm::calculateModSumWithBigEndian
quint64 calculateModSumWithBigEndian(const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum64bytearraychecksumalgorithm.cpp:57
KDE::Range::start
T start() const
Definition: range.h:86
AbstractByteArrayChecksumAlgorithm::CalculatedByteCountSignalLimit
static const int CalculatedByteCountSignalLimit
Definition: abstractbytearraychecksumalgorithm.h:43
ModSum64ByteArrayChecksumAlgorithm::ModSum64ByteArrayChecksumAlgorithm
ModSum64ByteArrayChecksumAlgorithm()
Definition: modsum64bytearraychecksumalgorithm.cpp:33
KDE::NumberRange::localIndex
N localIndex(N index) const
Definition: numberrange.h:199
KDE::Range::end
T end() const
Definition: range.h:88
ModSum64ByteArrayChecksumAlgorithm::calculateModSumWithLittleEndian
quint64 calculateModSumWithLittleEndian(const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum64bytearraychecksumalgorithm.cpp:116
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
ModSum64ByteArrayChecksumAlgorithm::calculateChecksum
virtual bool calculateChecksum(QString *result, const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum64bytearraychecksumalgorithm.cpp:40
ModSum64ByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: modsum64bytearraychecksumalgorithm.cpp:38
ModSum64ByteArrayChecksumAlgorithm::mParameterSet
ModSumByteArrayChecksumParameterSet mParameterSet
Definition: modsum64bytearraychecksumalgorithm.h:47
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
ModSumByteArrayChecksumParameterSet::endianness
Endianness endianness() const
Definition: modsumbytearraychecksumparameterset.cpp:32
LittleEndian
Definition: endianness.h:32
AbstractByteArrayChecksumAlgorithm::calculatedBytes
void calculatedBytes(int bytes) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal