Bump version.
[LameXP.git] / src / FileHash.cpp
blob596a7f4621be4533cdd5dda8db539e9e6edef80a
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2019 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.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 result;
37 if(file.isOpen() && file.reset())
39 QScopedPointer<MUtils::Hash::Hash> hash(MUtils::Hash::create(MUtils::Hash::HASH_KECCAK_384));
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);
46 bool okay[3];
47 okay[0] = hash->update(seed);
48 okay[1] = hash->update(data);
49 okay[2] = hash->update(salt);
51 if (okay[0] && okay[1] && okay[2])
53 result = hash->digest(true);
58 return result.isEmpty() ? QByteArray::fromHex(g_blnk).toHex() : result;