Updated GNU Wget binary to v1.18 (2016-06-09) with HTTPS support.
[LameXP.git] / src / FileHash.cpp
blobf3ed1507f24a5ded400f0258239fdbd9b644ebf2
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "FileHash.h"
25 //MUtils
26 #include <MUtils/Hash_Keccak.h>
27 #include <MUtils/Exception.h>
29 static const char *g_blnk = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
30 static const char *g_seed = "c375d83b4388329408dfcbb4d9a065b6e06d28272f25ef299c70b506e26600af79fd2f866ae24602daf38f25c9d4b7e1";
31 static const char *g_salt = "ee9f7bdabc170763d2200a7e3030045aafe380011aefc1730e547e9244c62308aac42a976feeca224ba553de0c4bb883";
33 QByteArray FileHash::computeHash(QFile &file)
35 QByteArray hash = QByteArray::fromHex(g_blnk).toHex();
37 if(file.isOpen() && file.reset())
39 MUtils::Hash::Keccak keccak;
40 const QByteArray data = file.readAll();
41 if (data.size() >= 16)
43 const QByteArray seed = QByteArray::fromHex(g_seed);
44 const QByteArray salt = QByteArray::fromHex(g_salt);
45 if (keccak.init(MUtils::Hash::Keccak::hb384))
47 bool ok = true;
48 ok = ok && keccak.addData(seed);
49 ok = ok && keccak.addData(data);
50 ok = ok && keccak.addData(salt);
51 if (ok)
53 const QByteArray digest = keccak.finalize();
54 if (!digest.isEmpty()) hash = digest.toHex();
60 return hash;
63 void FileHash::selfTest(void)
65 if(!MUtils::Hash::Keccak::selfTest())
67 MUTILS_THROW("QKeccakHash self-test has failed!");