diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-23 14:20:10 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-23 14:20:10 +0100 |
commit | 66ebce7bb49432ab02b5c74ed4e787282b1ba474 (patch) | |
tree | cc72bebb537a0c418cd795b6eeb3e6f04504518d /oox/source/crypto | |
parent | e5ee33d7f0869a5fa541410913db44cc2b964e41 (diff) |
fdo#75955 use SHA1 from openssl/nss instead of rtl_digest_sha1
Change-Id: I92186b2ed8426d59e31080cfb629beb02cd01c41
Diffstat (limited to 'oox/source/crypto')
-rw-r--r-- | oox/source/crypto/CryptTools.cxx | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx index d025609ecd7f..60e544908dd6 100644 --- a/oox/source/crypto/CryptTools.cxx +++ b/oox/source/crypto/CryptTools.cxx @@ -188,15 +188,47 @@ sal_uInt32 Encrypt::update(vector<sal_uInt8>& output, vector<sal_uInt8>& input, bool sha1(vector<sal_uInt8>& output, vector<sal_uInt8>& input) { + bool aResult = false; + +#if USE_TLS_OPENSSL output.clear(); - output.resize(RTL_DIGEST_LENGTH_SHA1, 0); + output.resize(SHA_DIGEST_LENGTH, 0); + + SHA_CTX context; + SHA1_Init(&context); + SHA1_Update(&context, &input[0], input.size()); + SHA1_Final(&output[0], &context); + aResult = true; +#endif - rtlDigest aDigest = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); - rtl_digest_update( aDigest, &input[0], input.size() ); - rtl_digest_get( aDigest, &output[0], RTL_DIGEST_LENGTH_SHA1 ); - rtl_digest_destroy( aDigest ); +#if USE_TLS_NSS + output.clear(); + output.resize(SHA1_LENGTH, 0); - return true; + // Initialize NSS, database functions are not needed + NSS_NoDB_Init(NULL); + SECStatus status; + + PK11Context* mContext = PK11_CreateDigestContext(SEC_OID_SHA1); + status = PK11_DigestBegin(mContext); + if (status != SECSuccess) + return false; + + status = PK11_DigestOp(mContext, &input[0], input.size()); + if (status != SECSuccess) + return false; + + unsigned int outputLength = 0; + + status = PK11_DigestFinal(mContext, &output[0], &outputLength, SHA1_LENGTH); + if (status != SECSuccess || outputLength != SHA1_LENGTH) + return false; + + PK11_DestroyContext(mContext, PR_TRUE); + + aResult = true; +#endif + return aResult; } bool sha512(vector<sal_uInt8>& output, vector<sal_uInt8>& input) |