Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
89182507
Kaydet (Commit)
89182507
authored
Şub 24, 2018
tarafından
Eike Rathke
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Hash Base64, Sequence and cleansing, tdf#104250 prep
Change-Id: I58d48b8caa780138b8431bec9db20c9d0e9abce7
üst
4446ac90
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
13 deletions
+51
-13
test_hash.cxx
comphelper/qa/unit/test_hash.cxx
+2
-2
hash.cxx
comphelper/source/misc/hash.cxx
+23
-10
hash.hxx
include/comphelper/hash.hxx
+26
-1
No files found.
comphelper/qa/unit/test_hash.cxx
Dosyayı görüntüle @
89182507
...
@@ -111,8 +111,8 @@ void TestHash::testSHA512_saltspin()
...
@@ -111,8 +111,8 @@ void TestHash::testSHA512_saltspin()
const
OUString
aPass
(
"pwd"
);
const
OUString
aPass
(
"pwd"
);
const
OUString
aAlgo
(
"SHA-512"
);
const
OUString
aAlgo
(
"SHA-512"
);
const
OUString
aSalt
(
"876MLoKTq42+/DLp415iZQ=="
);
const
OUString
aSalt
(
"876MLoKTq42+/DLp415iZQ=="
);
const
OUString
aHash
=
comphelper
::
Hash
::
calculateHash
(
aPass
,
aSalt
,
100000
,
aAlgo
);
const
OUString
aHash
=
comphelper
::
Hash
::
calculateHash
Base64
(
aPass
,
aSalt
,
100000
,
aAlgo
);
OUString
aStr
(
"5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="
);
const
OUString
aStr
(
"5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="
);
CPPUNIT_ASSERT_EQUAL
(
aStr
,
aHash
);
CPPUNIT_ASSERT_EQUAL
(
aStr
,
aHash
);
}
}
...
...
comphelper/source/misc/hash.cxx
Dosyayı görüntüle @
89182507
...
@@ -168,7 +168,6 @@ std::vector<unsigned char> Hash::calculateHash(
...
@@ -168,7 +168,6 @@ std::vector<unsigned char> Hash::calculateHash(
return
calculateHash
(
pInput
,
nLength
,
eType
);
return
calculateHash
(
pInput
,
nLength
,
eType
);
Hash
aHash
(
eType
);
Hash
aHash
(
eType
);
std
::
vector
<
unsigned
char
>
hash
;
if
(
nSaltLen
)
if
(
nSaltLen
)
{
{
std
::
vector
<
unsigned
char
>
initialData
(
nSaltLen
+
nLength
);
std
::
vector
<
unsigned
char
>
initialData
(
nSaltLen
+
nLength
);
...
@@ -181,7 +180,7 @@ std::vector<unsigned char> Hash::calculateHash(
...
@@ -181,7 +180,7 @@ std::vector<unsigned char> Hash::calculateHash(
{
{
aHash
.
update
(
pInput
,
nLength
);
aHash
.
update
(
pInput
,
nLength
);
}
}
hash
=
aHash
.
finalize
(
);
std
::
vector
<
unsigned
char
>
hash
(
aHash
.
finalize
()
);
if
(
nSpinCount
)
if
(
nSpinCount
)
{
{
...
@@ -232,7 +231,7 @@ std::vector<unsigned char> Hash::calculateHash(
...
@@ -232,7 +231,7 @@ std::vector<unsigned char> Hash::calculateHash(
return
calculateHash
(
pPassBytes
,
nPassBytesLen
,
rSaltValue
.
data
(),
rSaltValue
.
size
(),
nSpinCount
,
eType
);
return
calculateHash
(
pPassBytes
,
nPassBytesLen
,
rSaltValue
.
data
(),
rSaltValue
.
size
(),
nSpinCount
,
eType
);
}
}
OUString
Hash
::
calculateHash
(
css
::
uno
::
Sequence
<
sal_Int8
>
Hash
::
calculateHashSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
sal_uInt32
nSpinCount
,
...
@@ -248,17 +247,31 @@ OUString Hash::calculateHash(
...
@@ -248,17 +247,31 @@ OUString Hash::calculateHash(
else
if
(
rAlgorithmName
==
"MD5"
)
else
if
(
rAlgorithmName
==
"MD5"
)
eType
=
HashType
::
MD5
;
eType
=
HashType
::
MD5
;
else
else
return
OUString
();
return
css
::
uno
::
Sequence
<
sal_Int8
>
();
css
::
uno
::
Sequence
<
sal_Int8
>
aSaltSeq
;
std
::
vector
<
unsigned
char
>
aSaltVec
;
comphelper
::
Base64
::
decode
(
aSaltSeq
,
rSaltValue
);
if
(
!
rSaltValue
.
isEmpty
())
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSaltSeq
;
comphelper
::
Base64
::
decode
(
aSaltSeq
,
rSaltValue
);
aSaltVec
=
comphelper
::
sequenceToContainer
<
std
::
vector
<
unsigned
char
>>
(
aSaltSeq
);
}
std
::
vector
<
unsigned
char
>
hash
(
calculateHash
(
rPassword
,
aSaltVec
,
nSpinCount
,
eType
));
return
comphelper
::
containerToSequence
<
sal_Int8
>
(
hash
);
}
std
::
vector
<
unsigned
char
>
hash
=
calculateHash
(
rPassword
,
OUString
Hash
::
calculateHashBase64
(
comphelper
::
sequenceToContainer
<
std
::
vector
<
unsigned
char
>>
(
aSaltSeq
),
const
rtl
::
OUString
&
rPassword
,
nSpinCount
,
eType
);
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
)
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSeq
(
calculateHashSequence
(
rPassword
,
rSaltValue
,
nSpinCount
,
rAlgorithmName
));
OUStringBuffer
aBuf
;
OUStringBuffer
aBuf
;
comphelper
::
Base64
::
encode
(
aBuf
,
comphelper
::
containerToSequence
<
sal_Int8
>
(
hash
)
);
comphelper
::
Base64
::
encode
(
aBuf
,
aSeq
);
return
aBuf
.
makeStringAndClear
();
return
aBuf
.
makeStringAndClear
();
}
}
...
...
include/comphelper/hash.hxx
Dosyayı görüntüle @
89182507
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
#include <comphelper/comphelperdllapi.h>
#include <comphelper/comphelperdllapi.h>
#include <com/sun/star/uno/Sequence.hxx>
#include <memory>
#include <memory>
#include <vector>
#include <vector>
...
@@ -82,6 +84,29 @@ public:
...
@@ -82,6 +84,29 @@ public:
sal_uInt32
nSpinCount
,
sal_uInt32
nSpinCount
,
HashType
eType
);
HashType
eType
);
/** Convenience function to calculate a salted hash with iterations.
@param rPassword
UTF-16LE encoded string without leading BOM character
@param rSaltValue
Base64 encoded salt that will be decoded and prepended to password
data.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed in
https://msdn.microsoft.com/en-us/library/dd920692
that have a valid match in HashType. If not, an empty string is
returned. Not all algorithm names are supported.
@return the raw hash value as sal_Int8 sequence.
*/
static
css
::
uno
::
Sequence
<
sal_Int8
>
calculateHashSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
);
/** Convenience function to calculate a salted hash with iterations.
/** Convenience function to calculate a salted hash with iterations.
@param rPassword
@param rPassword
...
@@ -100,7 +125,7 @@ public:
...
@@ -100,7 +125,7 @@ public:
@return the base64 encoded string of the hash value, that can be
@return the base64 encoded string of the hash value, that can be
compared against a stored base64 encoded hash value.
compared against a stored base64 encoded hash value.
*/
*/
static
rtl
::
OUString
calculateHash
(
static
rtl
::
OUString
calculateHash
Base64
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
sal_uInt32
nSpinCount
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment