OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_ |
| 6 #define CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_ |
| 7 |
| 8 #include <keythi.h> |
| 9 #include <pkcs11t.h> |
| 10 #include <seccomon.h> |
| 11 #include <secmodt.h> |
| 12 |
| 13 #include "base/lazy_instance.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace webcrypto { |
| 18 |
| 19 class CryptoData; |
| 20 |
| 21 SECItem MakeSECItemForBuffer(const CryptoData& buffer); |
| 22 enum EncryptOrDecrypt { ENCRYPT, DECRYPT }; |
| 23 |
| 24 CryptoData SECItemToCryptoData(const SECItem& item); |
| 25 |
| 26 // Signature for PK11_Encrypt and PK11_Decrypt. |
| 27 typedef SECStatus (*PK11_EncryptDecryptFunction)(PK11SymKey*, |
| 28 CK_MECHANISM_TYPE, |
| 29 SECItem*, |
| 30 unsigned char*, |
| 31 unsigned int*, |
| 32 unsigned int, |
| 33 const unsigned char*, |
| 34 unsigned int); |
| 35 |
| 36 // Signature for PK11_PubEncrypt |
| 37 typedef SECStatus (*PK11_PubEncryptFunction)(SECKEYPublicKey*, |
| 38 CK_MECHANISM_TYPE, |
| 39 SECItem*, |
| 40 unsigned char*, |
| 41 unsigned int*, |
| 42 unsigned int, |
| 43 const unsigned char*, |
| 44 unsigned int, |
| 45 void*); |
| 46 |
| 47 // Signature for PK11_PrivDecrypt |
| 48 typedef SECStatus (*PK11_PrivDecryptFunction)(SECKEYPrivateKey*, |
| 49 CK_MECHANISM_TYPE, |
| 50 SECItem*, |
| 51 unsigned char*, |
| 52 unsigned int*, |
| 53 unsigned int, |
| 54 const unsigned char*, |
| 55 unsigned int); |
| 56 |
| 57 // Singleton to abstract away dynamically loading libnss3.so |
| 58 class NssRuntimeSupport { |
| 59 public: |
| 60 bool IsAesGcmSupported() const { |
| 61 return pk11_encrypt_func_ && pk11_decrypt_func_; |
| 62 } |
| 63 |
| 64 bool IsRsaOaepSupported() const { |
| 65 return pk11_pub_encrypt_func_ && pk11_priv_decrypt_func_ && |
| 66 internal_slot_does_oaep_; |
| 67 } |
| 68 |
| 69 // Returns NULL if unsupported. |
| 70 PK11_EncryptDecryptFunction pk11_encrypt_func() const { |
| 71 return pk11_encrypt_func_; |
| 72 } |
| 73 |
| 74 // Returns NULL if unsupported. |
| 75 PK11_EncryptDecryptFunction pk11_decrypt_func() const { |
| 76 return pk11_decrypt_func_; |
| 77 } |
| 78 |
| 79 // Returns NULL if unsupported. |
| 80 PK11_PubEncryptFunction pk11_pub_encrypt_func() const { |
| 81 return pk11_pub_encrypt_func_; |
| 82 } |
| 83 |
| 84 // Returns NULL if unsupported. |
| 85 PK11_PrivDecryptFunction pk11_priv_decrypt_func() const { |
| 86 return pk11_priv_decrypt_func_; |
| 87 } |
| 88 |
| 89 static NssRuntimeSupport* Get(); |
| 90 |
| 91 private: |
| 92 friend struct base::DefaultLazyInstanceTraits<NssRuntimeSupport>; |
| 93 |
| 94 NssRuntimeSupport(); |
| 95 |
| 96 PK11_EncryptDecryptFunction pk11_encrypt_func_; |
| 97 PK11_EncryptDecryptFunction pk11_decrypt_func_; |
| 98 PK11_PubEncryptFunction pk11_pub_encrypt_func_; |
| 99 PK11_PrivDecryptFunction pk11_priv_decrypt_func_; |
| 100 bool internal_slot_does_oaep_; |
| 101 }; |
| 102 |
| 103 } // namespace webcrypto |
| 104 |
| 105 } // namespace content |
| 106 |
| 107 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_UTIL_NSS_H_ |
OLD | NEW |