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_NSS_RSA_HASHED_ALGORITHM_NSS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_RSA_HASHED_ALGORITHM_NSS_H_
10 #include "content/child/webcrypto/algorithm_implementation.h"
19 // Base class for an RSA algorithm whose keys additionaly have a hash parameter
20 // bound to them. Provides functionality for generating, importing, and
22 class RsaHashedAlgorithm
: public AlgorithmImplementation
{
24 // Constructs an RSA algorithm which will use the NSS flags |generate_flags|
25 // when generating keys. |all_public_key_usages| and |all_private_key_usages|
26 // are the set of WebCrypto key usages that are valid for created keys
27 // (public and private respectively).
29 // For instance if public keys support encryption and wrapping, and private
30 // keys support decryption and unwrapping callers should set:
31 // all_public_key_usages = UsageEncrypt | UsageWrap
32 // all_private_key_usages = UsageDecrypt | UsageUnwrap
33 // This information is used when importing or generating keys, to enforce
34 // that valid key usages are allowed.
35 RsaHashedAlgorithm(CK_FLAGS generate_flags
,
36 blink::WebCryptoKeyUsageMask all_public_key_usages
,
37 blink::WebCryptoKeyUsageMask all_private_key_usages
)
38 : generate_flags_(generate_flags
),
39 all_public_key_usages_(all_public_key_usages
),
40 all_private_key_usages_(all_private_key_usages
) {}
42 // For instance "RSA-OAEP-256".
43 virtual const char* GetJwkAlgorithm(
44 const blink::WebCryptoAlgorithmId hash
) const = 0;
46 Status
GenerateKey(const blink::WebCryptoAlgorithm
& algorithm
,
48 blink::WebCryptoKeyUsageMask usages
,
49 GenerateKeyResult
* result
) const override
;
51 Status
VerifyKeyUsagesBeforeImportKey(
52 blink::WebCryptoKeyFormat format
,
53 blink::WebCryptoKeyUsageMask usages
) const override
;
55 Status
ImportKeyPkcs8(const CryptoData
& key_data
,
56 const blink::WebCryptoAlgorithm
& algorithm
,
58 blink::WebCryptoKeyUsageMask usages
,
59 blink::WebCryptoKey
* key
) const override
;
61 Status
ImportKeySpki(const CryptoData
& key_data
,
62 const blink::WebCryptoAlgorithm
& algorithm
,
64 blink::WebCryptoKeyUsageMask usages
,
65 blink::WebCryptoKey
* key
) const override
;
67 Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
68 std::vector
<uint8_t>* buffer
) const override
;
70 Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
71 std::vector
<uint8_t>* buffer
) const override
;
73 Status
ImportKeyJwk(const CryptoData
& key_data
,
74 const blink::WebCryptoAlgorithm
& algorithm
,
76 blink::WebCryptoKeyUsageMask usages
,
77 blink::WebCryptoKey
* key
) const override
;
79 Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
80 std::vector
<uint8_t>* buffer
) const override
;
82 Status
SerializeKeyForClone(
83 const blink::WebCryptoKey
& key
,
84 blink::WebVector
<uint8_t>* key_data
) const override
;
86 Status
DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm
& algorithm
,
87 blink::WebCryptoKeyType type
,
89 blink::WebCryptoKeyUsageMask usages
,
90 const CryptoData
& key_data
,
91 blink::WebCryptoKey
* key
) const override
;
94 const CK_FLAGS generate_flags_
;
95 const blink::WebCryptoKeyUsageMask all_public_key_usages_
;
96 const blink::WebCryptoKeyUsageMask all_private_key_usages_
;
99 } // namespace webcrypto
101 } // namespace content
103 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_RSA_HASHED_ALGORITHM_NSS_H_