blob: 2cf10625ec34fc09f66a0b8964c478e9cd50e5ea [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "crypto/capi_util.h"
6
7#include "base/basictypes.h"
8#include "base/memory/singleton.h"
9#include "base/synchronization/lock.h"
10
11namespace {
12
13class CAPIUtilSingleton {
14 public:
15 static CAPIUtilSingleton* GetInstance() {
16 return Singleton<CAPIUtilSingleton>::get();
17 }
18
19 // Returns a lock to guard calls to CryptAcquireContext with
20 // CRYPT_DELETEKEYSET or CRYPT_NEWKEYSET.
21 base::Lock& acquire_context_lock() {
22 return acquire_context_lock_;
23 }
24
25 private:
26 friend class Singleton<CAPIUtilSingleton>;
27 friend struct DefaultSingletonTraits<CAPIUtilSingleton>;
28
29 CAPIUtilSingleton() {}
30
31 base::Lock acquire_context_lock_;
32
33 DISALLOW_COPY_AND_ASSIGN(CAPIUtilSingleton);
34};
35
36} // namespace
37
38namespace crypto {
39
40BOOL CryptAcquireContextLocked(HCRYPTPROV* prov,
41 LPCWSTR container,
42 LPCWSTR provider,
43 DWORD prov_type,
44 DWORD flags) {
45 base::AutoLock lock(CAPIUtilSingleton::GetInstance()->acquire_context_lock());
46 return CryptAcquireContext(prov, container, provider, prov_type, flags);
47}
48
49void* WINAPI CryptAlloc(size_t size) {
50 return malloc(size);
51}
52
53void WINAPI CryptFree(void* p) {
54 free(p);
55}
56
57} // namespace crypto