1 // Copyright 2014 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.
5 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_EC_H_
6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_EC_H_
8 #include "components/webcrypto/algorithm_implementation.h"
12 // Base class for an EC algorithm. Provides functionality for generating,
13 // importing, and exporting keys.
14 class EcAlgorithm
: public AlgorithmImplementation
{
16 // |all_public_key_usages| and |all_private_key_usages| are the set of
17 // WebCrypto key usages that are valid for created keys (public and private
19 EcAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages
,
20 blink::WebCryptoKeyUsageMask all_private_key_usages
)
21 : all_public_key_usages_(all_public_key_usages
),
22 all_private_key_usages_(all_private_key_usages
) {}
24 // For instance "ES256".
25 virtual const char* GetJwkAlgorithm(
26 const blink::WebCryptoNamedCurve curve
) const = 0;
28 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
30 blink::WebCryptoKeyUsageMask usages
,
31 GenerateKeyResult
* result
) const override
;
33 Status
VerifyKeyUsagesBeforeImportKey(
34 blink::WebCryptoKeyFormat format
,
35 blink::WebCryptoKeyUsageMask usages
) const override
;
37 Status
ImportKeyPkcs8(const CryptoData
& key_data
,
38 const blink::WebCryptoAlgorithm
& algorithm
,
40 blink::WebCryptoKeyUsageMask usages
,
41 blink::WebCryptoKey
* key
) const override
;
43 Status
ImportKeySpki(const CryptoData
& key_data
,
44 const blink::WebCryptoAlgorithm
& algorithm
,
46 blink::WebCryptoKeyUsageMask usages
,
47 blink::WebCryptoKey
* key
) const override
;
49 Status
ImportKeyJwk(const CryptoData
& key_data
,
50 const blink::WebCryptoAlgorithm
& algorithm
,
52 blink::WebCryptoKeyUsageMask usages
,
53 blink::WebCryptoKey
* key
) const override
;
55 Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
56 std::vector
<uint8_t>* buffer
) const override
;
58 Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
59 std::vector
<uint8_t>* buffer
) const override
;
61 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
62 std::vector
<uint8_t>* buffer
) const override
;
64 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
65 blink::WebCryptoKeyType type
,
67 blink::WebCryptoKeyUsageMask usages
,
68 const CryptoData
& key_data
,
69 blink::WebCryptoKey
* key
) const override
;
72 const blink::WebCryptoKeyUsageMask all_public_key_usages_
;
73 const blink::WebCryptoKeyUsageMask all_private_key_usages_
;
76 } // namespace webcrypto
78 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_EC_H_