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_UTIL_NSS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_
13 #include "base/lazy_instance.h"
21 SECItem
MakeSECItemForBuffer(const CryptoData
& buffer
);
22 enum EncryptOrDecrypt
{ ENCRYPT
, DECRYPT
};
24 CryptoData
SECItemToCryptoData(const SECItem
& item
);
26 const CK_FLAGS kAllOperationFlags
=
27 CKF_ENCRYPT
| CKF_DECRYPT
| CKF_SIGN
| CKF_VERIFY
| CKF_WRAP
| CKF_UNWRAP
;
29 // Signature for PK11_Encrypt and PK11_Decrypt.
30 typedef SECStatus (*PK11_EncryptDecryptFunction
)(PK11SymKey
*,
39 // Signature for PK11_PubEncrypt
40 typedef SECStatus (*PK11_PubEncryptFunction
)(SECKEYPublicKey
*,
50 // Signature for PK11_PrivDecrypt
51 typedef SECStatus (*PK11_PrivDecryptFunction
)(SECKEYPrivateKey
*,
60 // Singleton that detects whether or not AES-GCM and
61 // RSA-OAEP are supported by the version of NSS being used.
62 // On non-Linux platforms, Chromium embedders ship with a
63 // fixed version of NSS, and these are always available.
64 // However, on Linux (and ChromeOS), NSS is provided by the
65 // system, and thus not all algorithms may be available
67 class NssRuntimeSupport
{
69 bool IsAesGcmSupported() const {
70 return pk11_encrypt_func_
&& pk11_decrypt_func_
;
73 bool IsRsaOaepSupported() const {
74 return pk11_pub_encrypt_func_
&& pk11_priv_decrypt_func_
&&
75 internal_slot_does_oaep_
;
78 // Returns NULL if unsupported.
79 PK11_EncryptDecryptFunction
pk11_encrypt_func() const {
80 return pk11_encrypt_func_
;
83 // Returns NULL if unsupported.
84 PK11_EncryptDecryptFunction
pk11_decrypt_func() const {
85 return pk11_decrypt_func_
;
88 // Returns NULL if unsupported.
89 PK11_PubEncryptFunction
pk11_pub_encrypt_func() const {
90 return pk11_pub_encrypt_func_
;
93 // Returns NULL if unsupported.
94 PK11_PrivDecryptFunction
pk11_priv_decrypt_func() const {
95 return pk11_priv_decrypt_func_
;
98 static NssRuntimeSupport
* Get();
101 friend struct base::DefaultLazyInstanceTraits
<NssRuntimeSupport
>;
105 PK11_EncryptDecryptFunction pk11_encrypt_func_
;
106 PK11_EncryptDecryptFunction pk11_decrypt_func_
;
107 PK11_PubEncryptFunction pk11_pub_encrypt_func_
;
108 PK11_PrivDecryptFunction pk11_priv_decrypt_func_
;
109 bool internal_slot_does_oaep_
;
112 } // namespace webcrypto
114 } // namespace content
116 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_