diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-23 18:27:11 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-23 18:36:59 +0100 |
commit | 970517af3e02e6c05e4d2b44d63745e8a414bb43 (patch) | |
tree | 53478016de414bd4e73b68ca544f27d7c8f6cdcb /include | |
parent | 346a5e85bba832b24376de6f3d7a06979310367d (diff) |
oox: add Digest class which uses NSS or OpenSSL for digest calc.
Document encryption and decryption uses either NSS or OpenSSL to
calculate digest. Digest class hides the implementation details
between the two implementations. Previously, functions sha1 and
sha512 were used for this, but were less generic.
Change-Id: I60119e2ab9c5c1f4a2b02bc417c3c89c53a63fda
Diffstat (limited to 'include')
-rw-r--r-- | include/oox/crypto/CryptTools.hxx | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/include/oox/crypto/CryptTools.hxx b/include/oox/crypto/CryptTools.hxx index ae2c6f6f4209..dde778d4df8c 100644 --- a/include/oox/crypto/CryptTools.hxx +++ b/include/oox/crypto/CryptTools.hxx @@ -28,9 +28,11 @@ #include <openssl/evp.h> #include <openssl/sha.h> #endif // USE_TLS_OPENSSL + #if USE_TLS_NSS #include <nss.h> #include <pk11pub.h> +#include <sechash.h> #endif // USE_TLS_NSS #include <rtl/digest.h> @@ -115,12 +117,45 @@ public: sal_uInt32 inputLength = 0); }; -const sal_uInt32 SHA1_LENGTH = 20; -const sal_uInt32 SHA512_LENGTH = 64; +class Digest +{ +public: + enum DigestType + { + UNKNOWN, + SHA1, + SHA512 + }; + + static const sal_uInt32 DIGEST_LENGTH_SHA1; + static const sal_uInt32 DIGEST_LENGTH_SHA512; + +private: + DigestType meType; -bool sha1( std::vector<sal_uInt8>& output, std::vector<sal_uInt8>& input ); +#if USE_TLS_OPENSSL + EVP_MD_CTX* mpContext; +#endif + +#if USE_TLS_NSS + HASHContext* mpContext; +#endif + +public: + Digest(DigestType eType); + virtual ~Digest(); + + bool update(std::vector<sal_uInt8>& input); + bool finalize(std::vector<sal_uInt8>& digest); + + sal_uInt32 getLength(); + + static bool sha1( std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input); + static bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input); +}; -bool sha512( std::vector<sal_uInt8>& output, std::vector<sal_uInt8>& input ); +bool sha1( std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input); +bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input); } // namespace core } // namespace oox |