summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Crypto/WindowsCryptoProvider.cpp')
-rw-r--r--Swiften/Crypto/WindowsCryptoProvider.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Swiften/Crypto/WindowsCryptoProvider.cpp b/Swiften/Crypto/WindowsCryptoProvider.cpp
index 513941f..c784283 100644
--- a/Swiften/Crypto/WindowsCryptoProvider.cpp
+++ b/Swiften/Crypto/WindowsCryptoProvider.cpp
@@ -1,80 +1,80 @@
/*
- * Copyright (c) 2012-2016 Isode Limited.
+ * Copyright (c) 2012-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
/*
* Copyright (c) 2013 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Crypto/WindowsCryptoProvider.h>
#include <Windows.h>
#define SECURITY_WIN32
#include <security.h>
#include <Wincrypt.h>
#include <cassert>
#include <memory>
#include <Swiften/Crypto/Hash.h>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/WindowsRegistry.h>
using namespace Swift;
struct WindowsCryptoProvider::Private {
HCRYPTPROV context;
};
namespace {
class WindowsHash : public Hash {
public:
WindowsHash(HCRYPTPROV context, ALG_ID algorithm) : hash(NULL) {
if (!CryptCreateHash(context, algorithm, 0, 0, &hash)) {
assert(false);
}
}
virtual ~WindowsHash() {
CryptDestroyHash(hash);
}
- virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const ByteArray& data) override {
return updateInternal(data);
}
- virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const SafeByteArray& data) override {
return updateInternal(data);
}
virtual std::vector<unsigned char> getHash() {
std::vector<unsigned char> result;
DWORD hashLength = sizeof(DWORD);
DWORD hashSize;
CryptGetHashParam(hash, HP_HASHSIZE, reinterpret_cast<BYTE*>(&hashSize), &hashLength, 0);
result.resize(static_cast<size_t>(hashSize));
if (!CryptGetHashParam(hash, HP_HASHVAL, vecptr(result), &hashSize, 0)) {
assert(false);
}
result.resize(static_cast<size_t>(hashSize));
return result;
}
private:
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
if (!CryptHashData(hash, const_cast<BYTE*>(vecptr(data)), data.size(), 0)) {
assert(false);
}
return *this;
}
private:
HCRYPTHASH hash;
};
#if 0 // NOT YET DONE
@@ -96,65 +96,65 @@ namespace {
template<typename T>
HMACHash(HCRYPTPROV context, const T& rawKey) : hash(NULL) {
// Import raw key
T blobData(sizeof(PlainTextKeyBlob) + rawKey.size());
PlainTextKeyBlob* blob = reinterpret_cast<PlainTextKeyBlob*>(vecptr(blobData));
blob->hdr.bType = PLAINTEXTKEYBLOB;
blob->hdr.bVersion = CUR_BLOB_VERSION;
blob->hdr.reserved = 0;
blob->hdr.aiKeyAlg = CALG_RC2;
blob->dwKeySize = rawKey.size();
std::copy(rawKey.begin(), rawKey.end(), blobData.begin() + sizeof(PlainTextKeyBlob));
HCRYPTKEY key;
if (!CryptImportKey(context, vecptr(blobData), blobData.size(), 0, CRYPT_IPSEC_HMAC_KEY, &key)) {
assert(false);
return;
}
// Create hash
if (!CryptCreateHash(context, CALG_HMAC, key, 0, &hash)) {
assert(false);
return;
}
ZeroMemory(&info, sizeof(info));
info.HashAlgid = CALG_SHA1;
}
~HMACHash() {
CryptDestroyHash(hash);
}
- virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const ByteArray& data) override {
return updateInternal(data);
}
- virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE {
+ virtual Hash& update(const SafeByteArray& data) override {
return updateInternal(data);
}
virtual std::vector<unsigned char> getHash() {
std::vector<unsigned char> result;
DWORD hashLength = sizeof(DWORD);
DWORD hashSize;
CryptGetHashParam(hash, HP_HASHSIZE, reinterpret_cast<BYTE*>(&hashSize), &hashLength, 0);
result.resize(static_cast<size_t>(hashSize));
if (!CryptGetHashParam(hash, HP_HASHVAL, vecptr(result), &hashSize, 0)) {
assert(false);
}
result.resize(static_cast<size_t>(hashSize));
return result;
}
private:
template<typename ContainerType>
Hash& updateInternal(const ContainerType& data) {
if (!CryptHashData(hash, const_cast<BYTE*>(vecptr(data)), data.size(), 0)) {
assert(false);
}
return *this;
}
private:
HCRYPTHASH hash;
HMAC_INFO info;
};
#endif