Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qmessageauthenticationcode.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | static int qt_hash_block_size(QCryptographicHash::Algorithm method) | - | ||||||
10 | { | - | ||||||
11 | switch (method) { | - | ||||||
12 | case never executed: QCryptographicHash::Md4:case QCryptographicHash::Md4: never executed: case QCryptographicHash::Md4: | 0 | ||||||
13 | return never executed: 64;return 64; never executed: return 64; | 0 | ||||||
14 | case executed 20 times by 1 test: QCryptographicHash::Md5:case QCryptographicHash::Md5: Executed by:
executed 20 times by 1 test: case QCryptographicHash::Md5: Executed by:
| 20 | ||||||
15 | return executed 20 times by 1 test: 64;return 64; Executed by:
executed 20 times by 1 test: return 64; Executed by:
| 20 | ||||||
16 | case executed 8 times by 1 test: QCryptographicHash::Sha1:case QCryptographicHash::Sha1: Executed by:
executed 8 times by 1 test: case QCryptographicHash::Sha1: Executed by:
| 8 | ||||||
17 | return executed 8 times by 1 test: SHA1_Message_Block_Size;return SHA1_Message_Block_Size; Executed by:
executed 8 times by 1 test: return SHA1_Message_Block_Size; Executed by:
| 8 | ||||||
18 | case never executed: QCryptographicHash::Sha224:case QCryptographicHash::Sha224: never executed: case QCryptographicHash::Sha224: | 0 | ||||||
19 | return never executed: SHA224_Message_Block_Size;return SHA224_Message_Block_Size; never executed: return SHA224_Message_Block_Size; | 0 | ||||||
20 | case executed 8 times by 1 test: QCryptographicHash::Sha256:case QCryptographicHash::Sha256: Executed by:
executed 8 times by 1 test: case QCryptographicHash::Sha256: Executed by:
| 8 | ||||||
21 | return executed 8 times by 1 test: SHA256_Message_Block_Size;return SHA256_Message_Block_Size; Executed by:
executed 8 times by 1 test: return SHA256_Message_Block_Size; Executed by:
| 8 | ||||||
22 | case never executed: QCryptographicHash::Sha384:case QCryptographicHash::Sha384: never executed: case QCryptographicHash::Sha384: | 0 | ||||||
23 | return never executed: SHA384_Message_Block_Size;return SHA384_Message_Block_Size; never executed: return SHA384_Message_Block_Size; | 0 | ||||||
24 | case never executed: QCryptographicHash::Sha512:case QCryptographicHash::Sha512: never executed: case QCryptographicHash::Sha512: | 0 | ||||||
25 | return never executed: SHA512_Message_Block_Size;return SHA512_Message_Block_Size; never executed: return SHA512_Message_Block_Size; | 0 | ||||||
26 | case never executed: QCryptographicHash::Sha3_224:case QCryptographicHash::Sha3_224: never executed: case QCryptographicHash::Sha3_224: | 0 | ||||||
27 | return never executed: 144;return 144; never executed: return 144; | 0 | ||||||
28 | case never executed: QCryptographicHash::Sha3_256:case QCryptographicHash::Sha3_256: never executed: case QCryptographicHash::Sha3_256: | 0 | ||||||
29 | return never executed: 136;return 136; never executed: return 136; | 0 | ||||||
30 | case never executed: QCryptographicHash::Sha3_384:case QCryptographicHash::Sha3_384: never executed: case QCryptographicHash::Sha3_384: | 0 | ||||||
31 | return never executed: 104;return 104; never executed: return 104; | 0 | ||||||
32 | case never executed: QCryptographicHash::Sha3_512:case QCryptographicHash::Sha3_512: never executed: case QCryptographicHash::Sha3_512: | 0 | ||||||
33 | return never executed: 72;return 72; never executed: return 72; | 0 | ||||||
34 | } | - | ||||||
35 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
36 | } | - | ||||||
37 | - | |||||||
38 | class QMessageAuthenticationCodePrivate | - | ||||||
39 | { | - | ||||||
40 | public: | - | ||||||
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:
| 18 | ||||||
45 | - | |||||||
46 | QByteArray key; | - | ||||||
47 | QByteArray result; | - | ||||||
48 | QCryptographicHash messageHash; | - | ||||||
49 | QCryptographicHash::Algorithm method; | - | ||||||
50 | bool messageHashInited; | - | ||||||
51 | - | |||||||
52 | void initMessageHash(); | - | ||||||
53 | }; | - | ||||||
54 | - | |||||||
55 | void QMessageAuthenticationCodePrivate::initMessageHash() | - | ||||||
56 | { | - | ||||||
57 | if (messageHashInited
| 18-27 | ||||||
58 | return; executed 27 times by 1 test: return; Executed by:
| 27 | ||||||
59 | messageHashInited = true; | - | ||||||
60 | - | |||||||
61 | const int blockSize = qt_hash_block_size(method); | - | ||||||
62 | - | |||||||
63 | if (key.size() > blockSize
| 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
| 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:
| 18 | ||||||
75 | - | |||||||
76 | QVarLengthArray<char> iKeyPad(blockSize); | - | ||||||
77 | const char * const keyData = key.constData(); | - | ||||||
78 | - | |||||||
79 | for (int i = 0; i < blockSize
| 18-1152 | ||||||
80 | iKeyPad[i] = keyData[i] ^ 0x36; executed 1152 times by 1 test: iKeyPad[i] = keyData[i] ^ 0x36; Executed by:
| 1152 | ||||||
81 | - | |||||||
82 | messageHash.addData(iKeyPad.data(), iKeyPad.size()); | - | ||||||
83 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||
84 | QMessageAuthenticationCode::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:
| 18 | ||||||
90 | - | |||||||
91 | - | |||||||
92 | - | |||||||
93 | - | |||||||
94 | QMessageAuthenticationCode::~QMessageAuthenticationCode() | - | ||||||
95 | { | - | ||||||
96 | delete d; | - | ||||||
97 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||
98 | - | |||||||
99 | - | |||||||
100 | - | |||||||
101 | - | |||||||
102 | void 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:
| 18 | ||||||
108 | - | |||||||
109 | - | |||||||
110 | - | |||||||
111 | - | |||||||
112 | void QMessageAuthenticationCode::setKey(const QByteArray &key) | - | ||||||
113 | { | - | ||||||
114 | reset(); | - | ||||||
115 | d->key = key; | - | ||||||
116 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||
117 | - | |||||||
118 | - | |||||||
119 | - | |||||||
120 | - | |||||||
121 | void 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 | - | |||||||
130 | void 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:
| 27 | ||||||
135 | - | |||||||
136 | - | |||||||
137 | - | |||||||
138 | - | |||||||
139 | - | |||||||
140 | - | |||||||
141 | - | |||||||
142 | bool QMessageAuthenticationCode::addData(QIODevice *device) | - | ||||||
143 | { | - | ||||||
144 | d->initMessageHash(); | - | ||||||
145 | return never executed: d->messageHash.addData(device);return d->messageHash.addData(device); never executed: return d->messageHash.addData(device); | 0 | ||||||
146 | } | - | ||||||
147 | - | |||||||
148 | - | |||||||
149 | - | |||||||
150 | - | |||||||
151 | - | |||||||
152 | - | |||||||
153 | QByteArray QMessageAuthenticationCode::result() const | - | ||||||
154 | { | - | ||||||
155 | if (!d->result.isEmpty()
| 0-18 | ||||||
156 | return never executed: d->result;return 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
| 18-1152 | ||||||
168 | oKeyPad[i] = keyData[i] ^ 0x5c; executed 1152 times by 1 test: oKeyPad[i] = keyData[i] ^ 0x5c; Executed by:
| 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: d->result;return d->result; Executed by:
executed 18 times by 1 test: return d->result; Executed by:
| 18 | ||||||
176 | } | - | ||||||
177 | - | |||||||
178 | - | |||||||
179 | - | |||||||
180 | - | |||||||
181 | - | |||||||
182 | QByteArray 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: mac.result();return mac.result(); never executed: return mac.result(); | 0 | ||||||
189 | } | - | ||||||
190 | - | |||||||
191 | - | |||||||
Switch to Source code | Preprocessed file |