2018-05-28 22:03:39 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/pqi: pqihash.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2008-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-11-11 23:45:22 +00:00
|
|
|
#ifndef PQI_HASH_
|
|
|
|
#define PQI_HASH_
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
#include <retroshare/rsids.h>
|
2008-01-25 06:36:40 +00:00
|
|
|
#include <openssl/sha.h>
|
|
|
|
#include <string>
|
|
|
|
#include <iomanip>
|
2013-09-26 23:53:06 +00:00
|
|
|
#include <string.h>
|
2012-04-14 22:38:24 +00:00
|
|
|
#include "util/rsstring.h"
|
2013-09-05 19:28:10 +00:00
|
|
|
#include "retroshare/rstypes.h"
|
2012-10-02 19:15:24 +00:00
|
|
|
#include <inttypes.h>
|
2008-01-25 06:36:40 +00:00
|
|
|
|
|
|
|
class pqihash
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pqihash()
|
|
|
|
{
|
|
|
|
|
|
|
|
sha_hash = new uint8_t[SHA_DIGEST_LENGTH];
|
2010-02-23 21:55:29 +00:00
|
|
|
memset(sha_hash,0,SHA_DIGEST_LENGTH*sizeof(uint8_t)) ;
|
2008-01-25 06:36:40 +00:00
|
|
|
sha_ctx = new SHA_CTX;
|
|
|
|
SHA1_Init(sha_ctx);
|
|
|
|
doHash = true;
|
|
|
|
}
|
|
|
|
|
2008-04-02 13:55:45 +00:00
|
|
|
~pqihash()
|
|
|
|
{
|
|
|
|
delete[] sha_hash;
|
|
|
|
delete sha_ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 21:00:43 +00:00
|
|
|
void addData(const void *data, uint32_t len)
|
2008-01-25 06:36:40 +00:00
|
|
|
{
|
|
|
|
if (doHash)
|
|
|
|
{
|
|
|
|
SHA1_Update(sha_ctx, data, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
void Complete(RsFileHash &hash)
|
2008-01-25 06:36:40 +00:00
|
|
|
{
|
|
|
|
if (!doHash)
|
|
|
|
{
|
|
|
|
hash = endHash;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHA1_Final(sha_hash, sha_ctx);
|
|
|
|
|
2012-04-14 22:38:24 +00:00
|
|
|
endHash.clear();
|
2014-03-17 20:56:06 +00:00
|
|
|
endHash = hash = Sha1CheckSum(sha_hash);
|
2013-09-05 19:28:10 +00:00
|
|
|
|
|
|
|
// for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
|
|
|
// {
|
|
|
|
// rs_sprintf_append(endHash, "%02x", (unsigned int) (sha_hash[i]));
|
|
|
|
// }
|
|
|
|
// hash = endHash;
|
2008-01-25 06:36:40 +00:00
|
|
|
doHash = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool doHash;
|
2014-03-17 20:56:06 +00:00
|
|
|
RsFileHash endHash;
|
2008-01-25 06:36:40 +00:00
|
|
|
uint8_t *sha_hash;
|
|
|
|
SHA_CTX *sha_ctx;
|
|
|
|
};
|
|
|
|
|
2012-11-11 23:45:22 +00:00
|
|
|
#endif
|