• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CRYPTO_UNEXPORTABLE_KEY_METRICS_H_
6 #define CRYPTO_UNEXPORTABLE_KEY_METRICS_H_
7 
8 #include <string>
9 
10 #include "crypto/crypto_export.h"
11 #include "crypto/unexportable_key.h"
12 
13 namespace crypto {
14 
15 enum class TPMOperation {
16   kMessageSigning,
17   kMessageVerify,
18   kWrappedKeyCreation,
19   kNewKeyCreation,
20 };
21 
22 // Converts the given `operation` to a string representation.
23 CRYPTO_EXPORT std::string OperationToString(TPMOperation operation);
24 
25 // Converts the given `algorithm` to a string representation.
26 CRYPTO_EXPORT std::string AlgorithmToString(
27     SignatureVerifier::SignatureAlgorithm algorithm);
28 
29 // Records UMA metrics of TPM availability, latency and successful usage.
30 // Does the work on a new background task.
31 CRYPTO_EXPORT void MaybeMeasureTpmOperations(
32     UnexportableKeyProvider::Config config);
33 
34 // internal namespace to be used by tests only
35 namespace internal {
36 
37 // Note that values here are used in a recorded histogram. Don't change
38 // the values of existing members.
39 enum class TPMSupport {
40   kNone = 0,
41   kRSA = 1,
42   kECDSA = 2,
43   kMaxValue = 2,
44 };
45 
46 // Note that values here are used in a recorded histogram. Don't change
47 // the values of existing members.
48 enum class TPMType {
49   kNone = 0,
50   kHW = 1,
51   kVirtual = 2,
52   kBoth = 3,
53   kMaxValue = 3,
54 };
55 
56 // Exported for testing
57 CRYPTO_EXPORT void MeasureTpmOperationsInternalForTesting();
58 }  // namespace internal
59 
60 }  // namespace crypto
61 
62 #endif  // CRYPTO_UNEXPORTABLE_KEY_METRICS_H_
63