// rdhash.cpp // // Functions for generating and verifying hashes. // // (C) Copyright 2017-2025 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // 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 General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // #include #include #include #include #include #include #include #include "rdhash.h" QString __RDSha1Hash_MakePasswordHash(const QString &secret,const QString &salt) { QByteArray bytes; EVP_MD_CTX *ctx; unsigned char *digest=NULL; unsigned int digest_len=EVP_MD_size(EVP_sha1()); ctx=EVP_MD_CTX_new(); EVP_DigestInit_ex(ctx,EVP_sha1(),NULL); bytes=salt.toUtf8(); EVP_DigestUpdate(ctx,bytes,bytes.size()); bytes=secret.toUtf8(); EVP_DigestUpdate(ctx,bytes,bytes.size()); digest=(unsigned char *)OPENSSL_malloc(digest_len); EVP_DigestFinal_ex(ctx,digest,&digest_len); EVP_MD_CTX_free(ctx); QString ret=salt; for(unsigned i=0;i=0) { ctx=EVP_MD_CTX_new(); EVP_DigestInit_ex(ctx,EVP_sha1(),NULL); while((n=read(fd,buffer,1024))>0) { EVP_DigestUpdate(ctx,buffer,n); } if(n<0) { // read() returned an error! fprintf(stderr,"RDSha1HashFile() read error: %s\n",strerror(errno)); } digest=(unsigned char *)OPENSSL_malloc(digest_len); EVP_DigestFinal_ex(ctx,digest,&digest_len); EVP_MD_CTX_free(ctx); QString ret; for(unsigned i=0;i