OpenCoverage

qmessageauthenticationcode.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qmessageauthenticationcode.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static int qt_hash_block_size(QCryptographicHash::Algorithm method)-
10{-
11 switch (method) {-
12 case
never executed: case QCryptographicHash::Md4:
QCryptographicHash::Md4:
never executed: case QCryptographicHash::Md4:
0
13 return
never executed: return 64;
64;
never executed: return 64;
0
14 case
executed 20 times by 1 test: case QCryptographicHash::Md5:
Executed by:
  • tst_QMessageAuthenticationCode
QCryptographicHash::Md5:
executed 20 times by 1 test: case QCryptographicHash::Md5:
Executed by:
  • tst_QMessageAuthenticationCode
20
15 return
executed 20 times by 1 test: return 64;
Executed by:
  • tst_QMessageAuthenticationCode
64;
executed 20 times by 1 test: return 64;
Executed by:
  • tst_QMessageAuthenticationCode
20
16 case
executed 8 times by 1 test: case QCryptographicHash::Sha1:
Executed by:
  • tst_QMessageAuthenticationCode
QCryptographicHash::Sha1:
executed 8 times by 1 test: case QCryptographicHash::Sha1:
Executed by:
  • tst_QMessageAuthenticationCode
8
17 return
executed 8 times by 1 test: return SHA1_Message_Block_Size;
Executed by:
  • tst_QMessageAuthenticationCode
SHA1_Message_Block_Size;
executed 8 times by 1 test: return SHA1_Message_Block_Size;
Executed by:
  • tst_QMessageAuthenticationCode
8
18 case
never executed: case QCryptographicHash::Sha224:
QCryptographicHash::Sha224:
never executed: case QCryptographicHash::Sha224:
0
19 return
never executed: return SHA224_Message_Block_Size;
SHA224_Message_Block_Size;
never executed: return SHA224_Message_Block_Size;
0
20 case
executed 8 times by 1 test: case QCryptographicHash::Sha256:
Executed by:
  • tst_QMessageAuthenticationCode
QCryptographicHash::Sha256:
executed 8 times by 1 test: case QCryptographicHash::Sha256:
Executed by:
  • tst_QMessageAuthenticationCode
8
21 return
executed 8 times by 1 test: return SHA256_Message_Block_Size;
Executed by:
  • tst_QMessageAuthenticationCode
SHA256_Message_Block_Size;
executed 8 times by 1 test: return SHA256_Message_Block_Size;
Executed by:
  • tst_QMessageAuthenticationCode
8
22 case
never executed: case QCryptographicHash::Sha384:
QCryptographicHash::Sha384:
never executed: case QCryptographicHash::Sha384:
0
23 return
never executed: return SHA384_Message_Block_Size;
SHA384_Message_Block_Size;
never executed: return SHA384_Message_Block_Size;
0
24 case
never executed: case QCryptographicHash::Sha512:
QCryptographicHash::Sha512:
never executed: case QCryptographicHash::Sha512:
0
25 return
never executed: return SHA512_Message_Block_Size;
SHA512_Message_Block_Size;
never executed: return SHA512_Message_Block_Size;
0
26 case
never executed: case QCryptographicHash::Sha3_224:
QCryptographicHash::Sha3_224:
never executed: case QCryptographicHash::Sha3_224:
0
27 return
never executed: return 144;
144;
never executed: return 144;
0
28 case
never executed: case QCryptographicHash::Sha3_256:
QCryptographicHash::Sha3_256:
never executed: case QCryptographicHash::Sha3_256:
0
29 return
never executed: return 136;
136;
never executed: return 136;
0
30 case
never executed: case QCryptographicHash::Sha3_384:
QCryptographicHash::Sha3_384:
never executed: case QCryptographicHash::Sha3_384:
0
31 return
never executed: return 104;
104;
never executed: return 104;
0
32 case
never executed: case QCryptographicHash::Sha3_512:
QCryptographicHash::Sha3_512:
never executed: case QCryptographicHash::Sha3_512:
0
33 return
never executed: return 72;
72;
never executed: return 72;
0
34 }-
35 return
never executed: return 0;
0;
never executed: return 0;
0
36}-
37-
38class QMessageAuthenticationCodePrivate-
39{-
40public:-
41 QMessageAuthenticationCodePrivate(QCryptographicHash::Algorithm m)-
42 : messageHash(m), method(m), messageHashInited(false)-
43 {-
44 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
45-
46 QByteArray key;-
47 QByteArray result;-
48 QCryptographicHash messageHash;-
49 QCryptographicHash::Algorithm method;-
50 bool messageHashInited;-
51-
52 void initMessageHash();-
53};-
54-
55void QMessageAuthenticationCodePrivate::initMessageHash()-
56{-
57 if (messageHashInited
messageHashInitedDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
)
18-27
58 return;
executed 27 times by 1 test: return;
Executed by:
  • tst_QMessageAuthenticationCode
27
59 messageHashInited = true;-
60-
61 const int blockSize = qt_hash_block_size(method);-
62-
63 if (key.size() > blockSize
key.size() > blockSizeDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
) {
0-18
64 QCryptographicHash hash(method);-
65 hash.addData(key);-
66 key = hash.result();-
67 hash.reset();-
68 }
never executed: end of block
0
69-
70 if (key.size() < blockSize
key.size() < blockSizeDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
FALSEnever evaluated
) {
0-18
71 const int size = key.size();-
72 key.resize(blockSize);-
73 memset(key.data() + size, 0, blockSize - size);-
74 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
75-
76 QVarLengthArray<char> iKeyPad(blockSize);-
77 const char * const keyData = key.constData();-
78-
79 for (int i = 0; i < blockSize
i < blockSizeDescription
TRUEevaluated 1152 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
; ++i)
18-1152
80 iKeyPad[i] = keyData[i] ^ 0x36;
executed 1152 times by 1 test: iKeyPad[i] = keyData[i] ^ 0x36;
Executed by:
  • tst_QMessageAuthenticationCode
1152
81-
82 messageHash.addData(iKeyPad.data(), iKeyPad.size());-
83}
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
84QMessageAuthenticationCode::QMessageAuthenticationCode(QCryptographicHash::Algorithm method,-
85 const QByteArray &key)-
86 : d(new QMessageAuthenticationCodePrivate(method))-
87{-
88 d->key = key;-
89}
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
90-
91-
92-
93-
94QMessageAuthenticationCode::~QMessageAuthenticationCode()-
95{-
96 delete d;-
97}
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
98-
99-
100-
101-
102void QMessageAuthenticationCode::reset()-
103{-
104 d->result.clear();-
105 d->messageHash.reset();-
106 d->messageHashInited = false;-
107}
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
108-
109-
110-
111-
112void QMessageAuthenticationCode::setKey(const QByteArray &key)-
113{-
114 reset();-
115 d->key = key;-
116}
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
18
117-
118-
119-
120-
121void QMessageAuthenticationCode::addData(const char *data, int length)-
122{-
123 d->initMessageHash();-
124 d->messageHash.addData(data, length);-
125}
never executed: end of block
0
126-
127-
128-
129-
130void QMessageAuthenticationCode::addData(const QByteArray &data)-
131{-
132 d->initMessageHash();-
133 d->messageHash.addData(data);-
134}
executed 27 times by 1 test: end of block
Executed by:
  • tst_QMessageAuthenticationCode
27
135-
136-
137-
138-
139-
140-
141-
142bool QMessageAuthenticationCode::addData(QIODevice *device)-
143{-
144 d->initMessageHash();-
145 return
never executed: return d->messageHash.addData(device);
d->messageHash.addData(device);
never executed: return d->messageHash.addData(device);
0
146}-
147-
148-
149-
150-
151-
152-
153QByteArray QMessageAuthenticationCode::result() const-
154{-
155 if (!d->result.isEmpty()
!d->result.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
)
0-18
156 return
never executed: return d->result;
d->result;
never executed: return d->result;
0
157-
158 d->initMessageHash();-
159-
160 const int blockSize = qt_hash_block_size(d->method);-
161-
162 QByteArray hashedMessage = d->messageHash.result();-
163-
164 QVarLengthArray<char> oKeyPad(blockSize);-
165 const char * const keyData = d->key.constData();-
166-
167 for (int i = 0; i < blockSize
i < blockSizeDescription
TRUEevaluated 1152 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMessageAuthenticationCode
; ++i)
18-1152
168 oKeyPad[i] = keyData[i] ^ 0x5c;
executed 1152 times by 1 test: oKeyPad[i] = keyData[i] ^ 0x5c;
Executed by:
  • tst_QMessageAuthenticationCode
1152
169-
170 QCryptographicHash hash(d->method);-
171 hash.addData(oKeyPad.data(), oKeyPad.size());-
172 hash.addData(hashedMessage);-
173-
174 d->result = hash.result();-
175 return
executed 18 times by 1 test: return d->result;
Executed by:
  • tst_QMessageAuthenticationCode
d->result;
executed 18 times by 1 test: return d->result;
Executed by:
  • tst_QMessageAuthenticationCode
18
176}-
177-
178-
179-
180-
181-
182QByteArray QMessageAuthenticationCode::hash(const QByteArray &message, const QByteArray &key,-
183 QCryptographicHash::Algorithm method)-
184{-
185 QMessageAuthenticationCode mac(method);-
186 mac.setKey(key);-
187 mac.addData(message);-
188 return
never executed: return mac.result();
mac.result();
never executed: return mac.result();
0
189}-
190-
191-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9