From 9c247e83bd2241caddcffac926c4775d5b143940 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Thu, 18 Feb 2016 17:25:11 +0000 Subject: KuznechikCrypt: initial commit git-svn-id: http://svn.miranda-ng.org/main/trunk@16305 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Kuzne4ikCrypt/src/utils.cpp | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 plugins/Kuzne4ikCrypt/src/utils.cpp (limited to 'plugins/Kuzne4ikCrypt/src/utils.cpp') diff --git a/plugins/Kuzne4ikCrypt/src/utils.cpp b/plugins/Kuzne4ikCrypt/src/utils.cpp new file mode 100644 index 0000000000..a669540320 --- /dev/null +++ b/plugins/Kuzne4ikCrypt/src/utils.cpp @@ -0,0 +1,55 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-16 Miranda NG project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +bool getRandomBytes(BYTE *buf, size_t bufLen) +{ + // try to use Intel hardware randomizer first + HCRYPTPROV hProvider = NULL; + if (::CryptAcquireContext(&hProvider, NULL, _T("Intel Hardware Cryptographic Service Provider"), PROV_INTEL_SEC, 0) || + ::CryptAcquireContext(&hProvider, NULL, MS_STRONG_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) || + ::CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + { + ::CryptGenRandom(hProvider, DWORD(bufLen), buf); + ::CryptReleaseContext(hProvider, 0); + } + // no luck? try to use Windows NT RTL + else { + typedef BOOL(WINAPI *pfnGetRandom)(PVOID RandomBuffer, ULONG RandomBufferLength); + pfnGetRandom fnGetRandom = (pfnGetRandom)GetProcAddress(GetModuleHandleA("advapi32.dll"), "SystemFunction036"); + if (fnGetRandom == NULL) + return false; + + fnGetRandom(buf, DWORD(bufLen)); + } + return true; +} + +void slow_hash(const void *buf, size_t bufLen, BYTE* tmpHash) +{ + mir_sha256_hash(buf, bufLen, tmpHash); + + for (int i = 0; i < 50000; i++) + mir_sha256_hash(tmpHash, 32, tmpHash); +} -- cgit v1.2.3