tools/qcryptographichash.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2static int SHA224_256AddLength(SHA256Context *context, unsigned int length); -
3static int SHA384_512AddLength(SHA512Context *context, unsigned int length); -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length) -
18{ -
19 ::quint32 addTemp; -
20 return (addTemp = (context)->Length_Low, (context)->Corrupted = (((context)->Length_Low += (length)) < addTemp) && (++(context)->Length_High == 0) ? shaInputTooLong : (context)->Corrupted );
executed: return (addTemp = (context)->Length_Low, (context)->Corrupted = (((context)->Length_Low += (length)) < addTemp) && (++(context)->Length_High == 0) ? shaInputTooLong : (context)->Corrupted );
Execution Count:24
24
21} -
22static inline int SHA384_512AddLength(SHA512Context *context, unsigned int length) -
23{ -
24 ::quint64 addTemp; -
25 return (addTemp = context->Length_Low, context->Corrupted = ((context->Length_Low += length) < addTemp) && (++context->Length_High == 0) ? shaInputTooLong : (context)->Corrupted);
executed: return (addTemp = context->Length_Low, context->Corrupted = ((context->Length_Low += length) < addTemp) && (++context->Length_High == 0) ? shaInputTooLong : (context)->Corrupted);
Execution Count:24
24
26} -
27 -
28 -
29 -
30class QCryptographicHashPrivate -
31{ -
32public: -
33 QCryptographicHash::Algorithm method; -
34 union { -
35 MD5Context md5Context; -
36 md4_context md4Context; -
37 Sha1State sha1Context; -
38 SHA224Context sha224Context; -
39 SHA256Context sha256Context; -
40 SHA384Context sha384Context; -
41 SHA512Context sha512Context; -
42 }; -
43 QByteArray result; -
44}; -
45QCryptographicHash::QCryptographicHash(Algorithm method) -
46 : d(new QCryptographicHashPrivate) -
47{ -
48 d->method = method; -
49 reset(); -
50}
executed: }
Execution Count:2421
2421
51 -
52 -
53 -
54 -
55QCryptographicHash::~QCryptographicHash() -
56{ -
57 delete d; -
58}
executed: }
Execution Count:2421
2421
59 -
60 -
61 -
62 -
63void QCryptographicHash::reset() -
64{ -
65 switch (d->method) { -
66 case Md4: -
67 md4_init(&d->md4Context); -
68 break;
executed: break;
Execution Count:4
4
69 case Md5: -
70 MD5Init(&d->md5Context); -
71 break;
executed: break;
Execution Count:2120
2120
72 case Sha1: -
73 sha1InitState(&d->sha1Context); -
74 break;
executed: break;
Execution Count:361
361
75 case Sha224: -
76 SHA224Reset(&d->sha224Context); -
77 break;
executed: break;
Execution Count:4
4
78 case Sha256: -
79 SHA256Reset(&d->sha256Context); -
80 break;
executed: break;
Execution Count:4
4
81 case Sha384: -
82 SHA384Reset(&d->sha384Context); -
83 break;
executed: break;
Execution Count:4
4
84 case Sha512: -
85 SHA512Reset(&d->sha512Context); -
86 break;
executed: break;
Execution Count:4
4
87 } -
88 d->result.clear(); -
89}
executed: }
Execution Count:2501
2501
90 -
91 -
92 -
93 -
94 -
95void QCryptographicHash::addData(const char *data, int length) -
96{ -
97 switch (d->method) { -
98 case Md4: -
99 md4_update(&d->md4Context, (const unsigned char *)data, length); -
100 break;
executed: break;
Execution Count:4
4
101 case Md5: -
102 MD5Update(&d->md5Context, (const unsigned char *)data, length); -
103 break;
executed: break;
Execution Count:2657
2657
104 case Sha1: -
105 sha1Update(&d->sha1Context, (const unsigned char *)data, length); -
106 break;
executed: break;
Execution Count:363
363
107 case Sha224: -
108 SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length); -
109 break;
executed: break;
Execution Count:4
4
110 case Sha256: -
111 SHA256Input(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length); -
112 break;
executed: break;
Execution Count:4
4
113 case Sha384: -
114 SHA384Input(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length); -
115 break;
executed: break;
Execution Count:4
4
116 case Sha512: -
117 SHA512Input(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length); -
118 break;
executed: break;
Execution Count:4
4
119 } -
120 d->result.clear(); -
121}
executed: }
Execution Count:3040
3040
122 -
123 -
124 -
125 -
126void QCryptographicHash::addData(const QByteArray &data) -
127{ -
128 addData(data.constData(), data.length()); -
129}
executed: }
Execution Count:2767
2767
130 -
131 -
132 -
133 -
134 -
135 -
136bool QCryptographicHash::addData(QIODevice* device) -
137{ -
138 if (!device->isReadable())
evaluated: !device->isReadable()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
139 return false;
executed: return false;
Execution Count:2
2
140 -
141 if (!device->isOpen())
partially evaluated: !device->isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
142 return false;
never executed: return false;
0
143 -
144 char buffer[1024]; -
145 int length; -
146 -
147 while ((length = device->read(buffer,sizeof(buffer))) > 0)
evaluated: (length = device->read(buffer,sizeof(buffer))) > 0
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:2
2-9
148 addData(buffer,length);
executed: addData(buffer,length);
Execution Count:9
9
149 -
150 return device->atEnd();
executed: return device->atEnd();
Execution Count:2
2
151} -
152 -
153 -
154 -
155 -
156 -
157 -
158 -
159QByteArray QCryptographicHash::result() const -
160{ -
161 if (!d->result.isEmpty())
evaluated: !d->result.isEmpty()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2501
14-2501
162 return d->result;
executed: return d->result;
Execution Count:14
14
163 -
164 switch (d->method) { -
165 case Md4: { -
166 md4_context copy = d->md4Context; -
167 d->result.resize((128/8)); -
168 md4_final(&copy, (unsigned char *)d->result.data()); -
169 break;
executed: break;
Execution Count:4
4
170 } -
171 case Md5: { -
172 MD5Context copy = d->md5Context; -
173 d->result.resize(16); -
174 MD5Final(&copy, (unsigned char *)d->result.data()); -
175 break;
executed: break;
Execution Count:2120
2120
176 } -
177 case Sha1: { -
178 Sha1State copy = d->sha1Context; -
179 d->result.resize(20); -
180 sha1FinalizeState(&copy); -
181 sha1ToHash(&copy, (unsigned char *)d->result.data()); -
182 break;
executed: break;
Execution Count:361
361
183 } -
184 case Sha224: { -
185 SHA224Context copy = d->sha224Context; -
186 d->result.resize(SHA224HashSize); -
187 SHA224Result(&copy, reinterpret_cast<unsigned char *>(d->result.data())); -
188 break;
executed: break;
Execution Count:4
4
189 } -
190 case Sha256:{ -
191 SHA256Context copy = d->sha256Context; -
192 d->result.resize(SHA256HashSize); -
193 SHA256Result(&copy, reinterpret_cast<unsigned char *>(d->result.data())); -
194 break;
executed: break;
Execution Count:4
4
195 } -
196 case Sha384:{ -
197 SHA384Context copy = d->sha384Context; -
198 d->result.resize(SHA384HashSize); -
199 SHA384Result(&copy, reinterpret_cast<unsigned char *>(d->result.data())); -
200 break;
executed: break;
Execution Count:4
4
201 } -
202 case Sha512:{ -
203 SHA512Context copy = d->sha512Context; -
204 d->result.resize(SHA512HashSize); -
205 SHA512Result(&copy, reinterpret_cast<unsigned char *>(d->result.data())); -
206 break;
executed: break;
Execution Count:4
4
207 } -
208 } -
209 return d->result;
executed: return d->result;
Execution Count:2501
2501
210} -
211 -
212 -
213 -
214 -
215QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method) -
216{ -
217 QCryptographicHash hash(method); -
218 hash.addData(data); -
219 return hash.result();
executed: return hash.result();
Execution Count:2066
2066
220} -
221 -
222 -
223 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial