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_RSA_H_
6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_RSA_H_
8 #include "components/webcrypto/algorithm_implementation.h"
12 // Base class for an RSA algorithm whose keys additionaly have a hash parameter
13 // bound to them. Provides functionality for generating, importing, and
15 class RsaHashedAlgorithm
: public AlgorithmImplementation
{
17 // |all_public_key_usages| and |all_private_key_usages| are the set of
18 // WebCrypto key usages that are valid for created keys (public and private
21 // For instance if public keys support encryption and wrapping, and private
22 // keys support decryption and unwrapping callers should set:
23 // all_public_key_usages = UsageEncrypt | UsageWrap
24 // all_private_key_usages = UsageDecrypt | UsageUnwrap
25 // This information is used when importing or generating keys, to enforce
26 // that valid key usages are allowed.
27 RsaHashedAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages
,
28 blink::WebCryptoKeyUsageMask all_private_key_usages
)
29 : all_public_key_usages_(all_public_key_usages
),
30 all_private_key_usages_(all_private_key_usages
) {}
32 // For instance "RSA-OAEP-256".
33 virtual const char* GetJwkAlgorithm(
34 const blink::WebCryptoAlgorithmId hash
) const = 0;
36 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
38 blink::WebCryptoKeyUsageMask usages
,
39 GenerateKeyResult
* result
) const override
;
41 Status
VerifyKeyUsagesBeforeImportKey(
42 blink::WebCryptoKeyFormat format
,
43 blink::WebCryptoKeyUsageMask usages
) const override
;
45 Status
ImportKeyPkcs8(const CryptoData
& key_data
,
46 const blink::WebCryptoAlgorithm
& algorithm
,
48 blink::WebCryptoKeyUsageMask usages
,
49 blink::WebCryptoKey
* key
) const override
;
51 Status
ImportKeySpki(const CryptoData
& key_data
,
52 const blink::WebCryptoAlgorithm
& algorithm
,
54 blink::WebCryptoKeyUsageMask usages
,
55 blink::WebCryptoKey
* key
) const override
;
57 Status
ImportKeyJwk(const CryptoData
& key_data
,
58 const blink::WebCryptoAlgorithm
& algorithm
,
60 blink::WebCryptoKeyUsageMask usages
,
61 blink::WebCryptoKey
* key
) const override
;
63 Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
64 std::vector
<uint8_t>* buffer
) const override
;
66 Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
67 std::vector
<uint8_t>* buffer
) const override
;
69 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
70 std::vector
<uint8_t>* buffer
) const override
;
72 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
73 blink::WebCryptoKeyType type
,
75 blink::WebCryptoKeyUsageMask usages
,
76 const CryptoData
& key_data
,
77 blink::WebCryptoKey
* key
) const override
;
80 const blink::WebCryptoKeyUsageMask all_public_key_usages_
;
81 const blink::WebCryptoKeyUsageMask all_private_key_usages_
;
84 } // namespace webcrypto
86 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_RSA_H_