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_NSS_RSA_HASHED_ALGORITHM_NSS_H_
6 #define COMPONENTS_WEBCRYPTO_NSS_RSA_HASHED_ALGORITHM_NSS_H_
10 #include "components/webcrypto/algorithm_implementation.h"
17 // Base class for an RSA algorithm whose keys additionaly have a hash parameter
18 // bound to them. Provides functionality for generating, importing, and
20 class RsaHashedAlgorithm
: public AlgorithmImplementation
{
22 // Constructs an RSA algorithm which will use the NSS flags |generate_flags|
23 // when generating keys. |all_public_key_usages| and |all_private_key_usages|
24 // are the set of WebCrypto key usages that are valid for created keys
25 // (public and private respectively).
27 // For instance if public keys support encryption and wrapping, and private
28 // keys support decryption and unwrapping callers should set:
29 // all_public_key_usages = UsageEncrypt | UsageWrap
30 // all_private_key_usages = UsageDecrypt | UsageUnwrap
31 // This information is used when importing or generating keys, to enforce
32 // that valid key usages are allowed.
33 RsaHashedAlgorithm(CK_FLAGS generate_flags
,
34 blink::WebCryptoKeyUsageMask all_public_key_usages
,
35 blink::WebCryptoKeyUsageMask all_private_key_usages
)
36 : generate_flags_(generate_flags
),
37 all_public_key_usages_(all_public_key_usages
),
38 all_private_key_usages_(all_private_key_usages
) {}
40 // For instance "RSA-OAEP-256".
41 virtual const char* GetJwkAlgorithm(
42 const blink::WebCryptoAlgorithmId hash
) const = 0;
44 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
46 blink::WebCryptoKeyUsageMask usages
,
47 GenerateKeyResult
* result
) const override
;
49 Status
VerifyKeyUsagesBeforeImportKey(
50 blink::WebCryptoKeyFormat format
,
51 blink::WebCryptoKeyUsageMask usages
) const override
;
53 Status
ImportKeyPkcs8(const CryptoData
& key_data
,
54 const blink::WebCryptoAlgorithm
& algorithm
,
56 blink::WebCryptoKeyUsageMask usages
,
57 blink::WebCryptoKey
* key
) const override
;
59 Status
ImportKeySpki(const CryptoData
& key_data
,
60 const blink::WebCryptoAlgorithm
& algorithm
,
62 blink::WebCryptoKeyUsageMask usages
,
63 blink::WebCryptoKey
* key
) const override
;
65 Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
66 std::vector
<uint8_t>* buffer
) const override
;
68 Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
69 std::vector
<uint8_t>* buffer
) const override
;
71 Status
ImportKeyJwk(const CryptoData
& key_data
,
72 const blink::WebCryptoAlgorithm
& algorithm
,
74 blink::WebCryptoKeyUsageMask usages
,
75 blink::WebCryptoKey
* key
) const override
;
77 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
78 std::vector
<uint8_t>* buffer
) const override
;
80 Status
SerializeKeyForClone(
81 const blink::WebCryptoKey
& key
,
82 blink::WebVector
<uint8_t>* key_data
) const override
;
84 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
85 blink::WebCryptoKeyType type
,
87 blink::WebCryptoKeyUsageMask usages
,
88 const CryptoData
& key_data
,
89 blink::WebCryptoKey
* key
) const override
;
92 const CK_FLAGS generate_flags_
;
93 const blink::WebCryptoKeyUsageMask all_public_key_usages_
;
94 const blink::WebCryptoKeyUsageMask all_private_key_usages_
;
97 } // namespace webcrypto
99 #endif // COMPONENTS_WEBCRYPTO_NSS_RSA_HASHED_ALGORITHM_NSS_H_