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_RSA_KEY_OPENSSL_H_
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_KEY_OPENSSL_H_
8 #include "content/child/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 // |all_public_key_usages| and |all_private_key_usages| are the set of
23 // WebCrypto key usages that are valid for created keys (public and private
26 // For instance if public keys support encryption and wrapping, and private
27 // keys support decryption and unwrapping callers should set:
28 // all_public_key_usages = UsageEncrypt | UsageWrap
29 // all_private_key_usages = UsageDecrypt | UsageUnwrap
30 // This information is used when importing or generating keys, to enforce
31 // that valid key usages are allowed.
32 RsaHashedAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages
,
33 blink::WebCryptoKeyUsageMask all_private_key_usages
)
34 : all_public_key_usages_(all_public_key_usages
),
35 all_private_key_usages_(all_private_key_usages
) {}
37 // For instance "RSA-OAEP-256".
38 virtual const char* GetJwkAlgorithm(
39 const blink::WebCryptoAlgorithmId hash
) const = 0;
41 virtual Status
VerifyKeyUsagesBeforeGenerateKeyPair(
42 blink::WebCryptoKeyUsageMask combined_usage_mask
,
43 blink::WebCryptoKeyUsageMask
* public_usage_mask
,
44 blink::WebCryptoKeyUsageMask
* private_usage_mask
) const OVERRIDE
;
46 virtual Status
GenerateKeyPair(
47 const blink::WebCryptoAlgorithm
& algorithm
,
49 blink::WebCryptoKeyUsageMask public_usage_mask
,
50 blink::WebCryptoKeyUsageMask private_usage_mask
,
51 blink::WebCryptoKey
* public_key
,
52 blink::WebCryptoKey
* private_key
) const OVERRIDE
;
54 virtual Status
VerifyKeyUsagesBeforeImportKey(
55 blink::WebCryptoKeyFormat format
,
56 blink::WebCryptoKeyUsageMask usage_mask
) const OVERRIDE
;
58 virtual Status
ImportKeyPkcs8(const CryptoData
& key_data
,
59 const blink::WebCryptoAlgorithm
& algorithm
,
61 blink::WebCryptoKeyUsageMask usage_mask
,
62 blink::WebCryptoKey
* key
) const OVERRIDE
;
64 virtual Status
ImportKeySpki(const CryptoData
& key_data
,
65 const blink::WebCryptoAlgorithm
& algorithm
,
67 blink::WebCryptoKeyUsageMask usage_mask
,
68 blink::WebCryptoKey
* key
) const OVERRIDE
;
70 virtual Status
ImportKeyJwk(const CryptoData
& key_data
,
71 const blink::WebCryptoAlgorithm
& algorithm
,
73 blink::WebCryptoKeyUsageMask usage_mask
,
74 blink::WebCryptoKey
* key
) const OVERRIDE
;
76 virtual Status
ExportKeyPkcs8(const blink::WebCryptoKey
& key
,
77 std::vector
<uint8_t>* buffer
) const OVERRIDE
;
79 virtual Status
ExportKeySpki(const blink::WebCryptoKey
& key
,
80 std::vector
<uint8_t>* buffer
) const OVERRIDE
;
82 virtual Status
ExportKeyJwk(const blink::WebCryptoKey
& key
,
83 std::vector
<uint8_t>* buffer
) const OVERRIDE
;
86 blink::WebCryptoKeyUsageMask all_public_key_usages_
;
87 blink::WebCryptoKeyUsageMask all_private_key_usages_
;
90 } // namespace webcrypto
92 } // namespace content
94 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_KEY_OPENSSL_H_