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 CONTENT_CHILD_WEBCRYPTO_OPENSSL_EC_ALGORITHM_OPENSSL_H_
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_EC_ALGORITHM_OPENSSL_H_
8 #include "content/child/webcrypto/algorithm_implementation.h"
14 // Base class for an EC algorithm. Provides functionality for generating,
15 // importing, and exporting keys.
16 class EcAlgorithm
: public AlgorithmImplementation
{
18 // |all_public_key_usages| and |all_private_key_usages| are the set of
19 // WebCrypto key usages that are valid for created keys (public and private
21 EcAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages
,
22 blink::WebCryptoKeyUsageMask all_private_key_usages
)
23 : all_public_key_usages_(all_public_key_usages
),
24 all_private_key_usages_(all_private_key_usages
) {}
26 // For instance "ES256".
27 virtual const char* GetJwkAlgorithm(
28 const blink::WebCryptoNamedCurve curve
) const = 0;
30 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
32 blink::WebCryptoKeyUsageMask usages
,
33 GenerateKeyResult
* result
) const override
;
35 Status
VerifyKeyUsagesBeforeImportKey(
36 blink::WebCryptoKeyFormat format
,
37 blink::WebCryptoKeyUsageMask usages
) const override
;
39 Status
ImportKeyPkcs8(const CryptoData
& key_data
,
40 const blink::WebCryptoAlgorithm
& algorithm
,
42 blink::WebCryptoKeyUsageMask usages
,
43 blink::WebCryptoKey
* key
) const override
;
45 Status
ImportKeySpki(const CryptoData
& key_data
,
46 const blink::WebCryptoAlgorithm
& algorithm
,
48 blink::WebCryptoKeyUsageMask usages
,
49 blink::WebCryptoKey
* key
) const override
;
51 Status
ImportKeyJwk(const CryptoData
& key_data
,
52 const blink::WebCryptoAlgorithm
& algorithm
,
54 blink::WebCryptoKeyUsageMask usages
,
55 blink::WebCryptoKey
* key
) const override
;
57 Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
58 std::vector
<uint8_t>* buffer
) const override
;
60 Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
61 std::vector
<uint8_t>* buffer
) const override
;
63 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
64 std::vector
<uint8_t>* buffer
) const override
;
66 Status
SerializeKeyForClone(
67 const blink::WebCryptoKey
& key
,
68 blink::WebVector
<uint8_t>* key_data
) const override
;
70 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
71 blink::WebCryptoKeyType type
,
73 blink::WebCryptoKeyUsageMask usages
,
74 const CryptoData
& key_data
,
75 blink::WebCryptoKey
* key
) const override
;
78 const blink::WebCryptoKeyUsageMask all_public_key_usages_
;
79 const blink::WebCryptoKeyUsageMask all_private_key_usages_
;
82 } // namespace webcrypto
84 } // namespace content
86 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_EC_ALGORITHM_OPENSSL_H_