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 // Signature for PK11_Encrypt and PK11_Decrypt.
27 typedef SECStatus (*PK11_EncryptDecryptFunction)(PK11SymKey*,
36 // Signature for PK11_PubEncrypt
37 typedef SECStatus (*PK11_PubEncryptFunction)(SECKEYPublicKey*,
47 // Signature for PK11_PrivDecrypt
48 typedef SECStatus (*PK11_PrivDecryptFunction)(SECKEYPrivateKey*,
57 // Singleton that detects whether or not AES-GCM and
58 // RSA-OAEP are supported by the version of NSS being used.
59 // On non-Linux platforms, Chromium embedders ship with a
60 // fixed version of NSS, and these are always available.
61 // However, on Linux (and ChromeOS), NSS is provided by the
62 // system, and thus not all algorithms may be available
64 class NssRuntimeSupport {
66 bool IsAesGcmSupported() const {
67 return pk11_encrypt_func_ && pk11_decrypt_func_;
70 bool IsRsaOaepSupported() const {
71 return pk11_pub_encrypt_func_ && pk11_priv_decrypt_func_ &&
72 internal_slot_does_oaep_;
75 // Returns NULL if unsupported.
76 PK11_EncryptDecryptFunction pk11_encrypt_func() const {
77 return pk11_encrypt_func_;
80 // Returns NULL if unsupported.
81 PK11_EncryptDecryptFunction pk11_decrypt_func() const {
82 return pk11_decrypt_func_;
85 // Returns NULL if unsupported.
86 PK11_PubEncryptFunction pk11_pub_encrypt_func() const {
87 return pk11_pub_encrypt_func_;
90 // Returns NULL if unsupported.
91 PK11_PrivDecryptFunction pk11_priv_decrypt_func() const {
92 return pk11_priv_decrypt_func_;
95 static NssRuntimeSupport* Get();
98 friend struct base::DefaultLazyInstanceTraits<NssRuntimeSupport>;
102 PK11_EncryptDecryptFunction pk11_encrypt_func_;
103 PK11_EncryptDecryptFunction pk11_decrypt_func_;
104 PK11_PubEncryptFunction pk11_pub_encrypt_func_;
105 PK11_PrivDecryptFunction pk11_priv_decrypt_func_;
106 bool internal_slot_does_oaep_;
109 } // namespace webcrypto
111 } // namespace content
113 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_