1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestAssert.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
26 #include <string_view>
28 #include <rtl/digest.h>
29 #include <rtl/string.h>
30 #include <rtl/strbuf.hxx>
39 constexpr OString
sSampleString ("This is a sample sentence, which we use to check some crypto functions in sal."_ostr
);
40 constexpr OStringLiteral
sSampleString_only_one_diff ("This is a sample sentence. which we use to check some crypto functions in sal.");
42 const rtlDigestAlgorithm constDigestAlgorithms
[] =
44 rtl_Digest_AlgorithmMD2
,
45 rtl_Digest_AlgorithmMD5
,
46 rtl_Digest_AlgorithmSHA
,
47 rtl_Digest_AlgorithmSHA1
,
48 rtl_Digest_AlgorithmHMAC_MD5
,
49 rtl_Digest_AlgorithmHMAC_SHA1
,
52 const sal_uInt32 constDigestAlgorithmLengths
[] =
54 RTL_DIGEST_LENGTH_MD2
,
55 RTL_DIGEST_LENGTH_MD5
,
56 RTL_DIGEST_LENGTH_SHA
,
57 RTL_DIGEST_LENGTH_SHA1
,
58 RTL_DIGEST_LENGTH_HMAC_MD5
,
59 RTL_DIGEST_LENGTH_HMAC_SHA1
,
62 const std::string_view constSampleStringSums
[] =
64 std::string_view("647ee6c9d4aa5fdd374ed9d7a156acbf"),
65 std::string_view("b16b903e6fc0b62ae389013ed93fe531"),
66 std::string_view("eab2814429b2613301c8a077b806af3680548914"),
67 std::string_view("2bc5bdb7506a2cdc2fd27fc8b9889343012d5008"),
68 std::string_view("0b1b0e1a6f2e4420326354b031063605"),
69 std::string_view("1998c6a556915be76451bfb587fa7c34d849936e")
72 // Create hex-value string from the digest value to keep the string size minimal
73 OString
createHex(const sal_uInt8
* pKeyBuffer
, sal_uInt32 nKeyLen
)
75 OStringBuffer
aBuffer(nKeyLen
* 2 + 1);
76 for (sal_uInt32 i
= 0; i
< nKeyLen
; ++i
)
78 sal_Int32 nValue
= static_cast<sal_Int32
>(pKeyBuffer
[i
]);
81 aBuffer
.append(nValue
, 16);
83 return aBuffer
.makeStringAndClear();
86 OString
getDigest(const OString
& aMessage
, rtlDigestAlgorithm aAlgorithm
)
88 rtlDigest handle
= rtl_digest_create(aAlgorithm
);
90 const sal_uInt8
* pData
= reinterpret_cast<const sal_uInt8
*>(aMessage
.getStr());
91 sal_uInt32 nSize
= aMessage
.getLength();
93 rtl_digest_init(handle
, pData
, nSize
);
94 rtl_digest_update(handle
, pData
, nSize
);
96 sal_uInt32 nKeyLen
= rtl_digest_queryLength(handle
);
97 std::unique_ptr
<sal_uInt8
[]> pKeyBuffer(new sal_uInt8
[nKeyLen
]);
99 rtl_digest_get(handle
, pKeyBuffer
.get(), nKeyLen
);
100 OString aSum
= createHex(pKeyBuffer
.get(), nKeyLen
);
102 rtl_digest_destroy( handle
);
106 class DigestTest
: public CppUnit::TestFixture
111 for (size_t i
= 0; i
< SAL_N_ELEMENTS(constDigestAlgorithms
); i
++)
113 rtlDigest handle
= rtl_digest_create( constDigestAlgorithms
[i
] );
114 CPPUNIT_ASSERT_MESSAGE("create digest", handle
!= nullptr);
115 rtl_digest_destroy( handle
);
118 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
119 CPPUNIT_ASSERT_EQUAL_MESSAGE("create invalid digest", static_cast<rtlDigest
>(nullptr), handle
);
120 rtl_digest_destroy( handle
);
125 for (size_t i
= 0; i
< SAL_N_ELEMENTS(constDigestAlgorithms
); i
++)
127 rtlDigest handle
= rtl_digest_create(constDigestAlgorithms
[i
]);
128 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
129 CPPUNIT_ASSERT_EQUAL_MESSAGE("query handle", aAlgo
, constDigestAlgorithms
[i
]);
130 rtl_digest_destroy( handle
);
135 void testQueryLength()
138 sal_uInt32 nAlgoLength
;
140 for (size_t i
= 0; i
< SAL_N_ELEMENTS(constDigestAlgorithms
); i
++)
142 handle
= rtl_digest_create(constDigestAlgorithms
[i
]);
143 nAlgoLength
= rtl_digest_queryLength(handle
);
144 CPPUNIT_ASSERT_EQUAL_MESSAGE("query Length", nAlgoLength
, constDigestAlgorithmLengths
[i
]);
145 rtl_digest_destroy( handle
);
148 handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
149 nAlgoLength
= rtl_digest_queryLength(handle
);
150 CPPUNIT_ASSERT_EQUAL_MESSAGE("query length", static_cast<sal_uInt32
>(0), nAlgoLength
);
151 rtl_digest_destroy( handle
);
156 rtlDigestError aError
;
160 aError
= rtl_digest_init(handle
, nullptr, 0);
161 CPPUNIT_ASSERT_EQUAL_MESSAGE("init(NULL, 0, 0)", rtl_Digest_E_Argument
, aError
);
163 handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
164 aError
= rtl_digest_init(handle
, nullptr, 0);
165 CPPUNIT_ASSERT_EQUAL_MESSAGE("init(handle, 0, 0)", rtl_Digest_E_None
, aError
);
166 rtl_digest_destroy( handle
);
168 for (size_t i
= 0; i
< SAL_N_ELEMENTS(constDigestAlgorithms
); i
++)
170 handle
= rtl_digest_create(constDigestAlgorithms
[i
]);
172 OString aMessage
= sSampleString
;
173 const sal_uInt8
* pData
= reinterpret_cast<const sal_uInt8
*>(aMessage
.getStr());
174 sal_uInt32 nSize
= aMessage
.getLength();
176 aError
= rtl_digest_init(handle
, pData
, nSize
);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("init(handle, pData, nSize)", rtl_Digest_E_None
, aError
);
179 rtl_digest_update(handle
, pData
, nSize
);
181 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
182 std::unique_ptr
<sal_uInt8
[]> pKeyBuffer(new sal_uInt8
[nKeyLen
]);
184 rtl_digest_get( handle
, pKeyBuffer
.get(), nKeyLen
);
185 createHex(pKeyBuffer
.get(), nKeyLen
);
187 rtl_digest_destroy( handle
);
194 OString aSum1
= getDigest(sSampleString
, rtl_Digest_AlgorithmMD5
);
195 OString aSum2
= getDigest(sSampleString
, rtl_Digest_AlgorithmMD5
);
197 CPPUNIT_ASSERT_EQUAL_MESSAGE(
198 "md5sum must have a length", sal_Int32(32), aSum1
.getLength() );
199 CPPUNIT_ASSERT_EQUAL_MESSAGE(
200 "md5sum must have a length", sal_Int32(32), aSum2
.getLength() );
201 CPPUNIT_ASSERT_EQUAL_MESSAGE("source is the same, dest must be also the same", aSum1
, aSum2
);
205 OString aSum1
= getDigest(sSampleString
, rtl_Digest_AlgorithmMD5
);
206 OString aSum2
= getDigest(sSampleString_only_one_diff
, rtl_Digest_AlgorithmMD5
);
208 CPPUNIT_ASSERT_EQUAL_MESSAGE(
209 "md5sum must have a length", sal_Int32(32), aSum1
.getLength() );
210 CPPUNIT_ASSERT_EQUAL_MESSAGE(
211 "md5sum must have a length", sal_Int32(32), aSum2
.getLength() );
212 CPPUNIT_ASSERT_MESSAGE("differ only in one char", aSum1
!= aSum2
);
218 for (size_t i
= 0; i
< SAL_N_ELEMENTS(constDigestAlgorithms
); i
++)
220 OString aSum
= getDigest(sSampleString
, constDigestAlgorithms
[i
]);
221 CPPUNIT_ASSERT_EQUAL_MESSAGE("Checksum of sample string is wrong.", OString(constSampleStringSums
[i
]), aSum
);
225 OString
runCheckPBKDF2(OString
& sPassword
, bool bClearSalt
, sal_uInt32 nCount
)
227 sal_uInt32 nKeyLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
228 std::unique_ptr
<sal_uInt8
[]> pKeyBuffer(new sal_uInt8
[nKeyLen
]);
230 memset(pKeyBuffer
.get(), 0, nKeyLen
);
232 sal_uInt8
const * pPassword
= reinterpret_cast<sal_uInt8
const *>(sPassword
.getStr());
233 sal_Int32 nPasswordLen
= sPassword
.getLength();
235 sal_uInt32 nSaltDataLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
236 std::unique_ptr
<sal_uInt8
[]> pSaltData(new sal_uInt8
[nSaltDataLen
]);
237 memset(pSaltData
.get(), 0, nSaltDataLen
);
241 // wilful contamination
245 rtlDigestError aError
= rtl_digest_PBKDF2(pKeyBuffer
.get(), nKeyLen
, pPassword
, nPasswordLen
, pSaltData
.get(), nSaltDataLen
, nCount
);
247 CPPUNIT_ASSERT_EQUAL(rtl_Digest_E_None
, aError
);
249 OString aKey
= createHex(pKeyBuffer
.get(), nKeyLen
);
251 // OString sSalt = createHex(pSaltData, nSaltDataLen);
252 // printf("Salt: %s\n", sSalt.getStr());
254 // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) );
260 OString aPassword
= "Password"_ostr
;
263 runCheckPBKDF2(aPassword
, false, 1);
264 runCheckPBKDF2(aPassword
, false, 2);
265 runCheckPBKDF2(aPassword
, true, 1);
266 runCheckPBKDF2(aPassword
, true, 2);
267 runCheckPBKDF2(aPassword
, false, 3);
268 runCheckPBKDF2(aPassword
, false, 4);
269 runCheckPBKDF2(aPassword
, true, 3);
270 runCheckPBKDF2(aPassword
, true, 4);
275 rtlDigestError aError
;
279 aError
= rtl_digest_update(aHandle
, nullptr, 0);
280 CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument
, aError
);
283 aError
= rtl_digest_updateMD2(aHandle
, nullptr, 0);
284 CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument
, aError
);
286 aError
= rtl_digest_updateMD5(aHandle
, nullptr, 0);
287 CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument
, aError
);
289 aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
290 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= nullptr);
292 const sal_uInt8
* pData
= reinterpret_cast<const sal_uInt8
*>(sSampleString
.getStr());
293 sal_uInt32 nSize
= sSampleString
.getLength();
295 aError
= rtl_digest_updateMD2(aHandle
, nullptr, 0);
296 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument
, aError
);
298 aError
= rtl_digest_updateMD2(aHandle
, pData
, 0);
299 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_None
, aError
);
301 rtl_digest_destroyMD2(aHandle
);
303 // use wrong Algorithm!!! This is volitional!
304 aHandle
= rtl_digest_create(rtl_Digest_AlgorithmMD2
);
305 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= nullptr);
307 aError
= rtl_digest_updateMD5(aHandle
, pData
, nSize
);
308 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'handle' wrong", rtl_Digest_E_Algorithm
, aError
);
310 rtl_digest_destroyMD5(aHandle
);
312 aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
313 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= nullptr);
315 aError
= rtl_digest_updateMD5(aHandle
, nullptr, 0);
316 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument
, aError
);
318 aError
= rtl_digest_updateMD5(aHandle
, pData
, 0);
319 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_None
, aError
);
321 rtl_digest_destroyMD5(aHandle
);
327 rtlDigestError aError
;
330 aError
= rtl_digest_get(aHandle
, nullptr, 0);
331 CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument
, aError
);
334 aError
= rtl_digest_getMD5(aHandle
, nullptr, 0);
335 CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument
, aError
);
337 // test with wrong algorithm
338 aHandle
= rtl_digest_create(rtl_Digest_AlgorithmMD2
);
339 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= nullptr);
341 sal_uInt32 nKeyLen
= rtl_digest_queryLength(aHandle
);
342 std::unique_ptr
<sal_uInt8
[]> pKeyBuffer(new sal_uInt8
[nKeyLen
]);
344 aError
= rtl_digest_getMD5(aHandle
, nullptr, 0);
345 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle 2. parameter wrong", rtl_Digest_E_Argument
, aError
);
347 aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
.get(), 0);
348 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'handle' wrong", rtl_Digest_E_Algorithm
, aError
);
350 rtl_digest_destroyMD2(aHandle
);
352 aHandle
= rtl_digest_create(rtl_Digest_AlgorithmMD5
);
353 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= nullptr);
355 aError
= rtl_digest_getMD5(aHandle
, nullptr, nKeyLen
);
356 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument
, aError
);
358 aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
.get(), 0);
359 CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_BufferSize
, aError
);
361 rtl_digest_destroyMD5(aHandle
);
364 void testSHA1SumForBiggerInputData()
366 // The test data was extracted from oox encrypted document (salt + password).
367 // First case: 16 bytes salt + 34 bytes password (12345678901234567)
368 // Second case: 16 bytes salt + 36 bytes password (123456789012345678)
370 const unsigned char aData
[] = {
371 0x37, 0x5f, 0x47, 0x7a, 0xd2, 0x13, 0xbe, 0xd2, 0x3c, 0x23, 0x33, 0x39,
372 0x68, 0x21, 0x03, 0x6d, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00,
373 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x30, 0x00,
374 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00,
378 std::unique_ptr
<sal_uInt8
[]> pResult(new sal_uInt8
[RTL_DIGEST_LENGTH_SHA1
]);
380 rtl_digest_SHA1(aData
, sizeof(aData
), pResult
.get(), RTL_DIGEST_LENGTH_SHA1
);
382 OString sKey
= createHex(pResult
.get(), RTL_DIGEST_LENGTH_SHA1
);
384 CPPUNIT_ASSERT_EQUAL("06f460d693aecdd3b5cbe8365408eccfc570f32a"_ostr
, sKey
);
387 // tdf#114939, verify that rtl_digest_SHA1 computes broken results for certain input (which
388 // is not fixed for compatibility reasons):
390 sal_uInt8 result
[RTL_DIGEST_LENGTH_SHA1
];
392 RTL_CONSTASCII_STRINGPARAM("1012345678901234567890123456789012345678901234567890"),
393 result
, RTL_DIGEST_LENGTH_SHA1
);
394 // Rather than correct "9cb1dab34448c1ea460da1f8736869c8852f212f":
395 CPPUNIT_ASSERT_EQUAL(
396 "90a461ee9cc69cedaeb25c2dc5cc62544ebd5241"_ostr
,
397 createHex(result
, RTL_DIGEST_LENGTH_SHA1
));
403 unsigned char const data
[] = {
404 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
405 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
406 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
407 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
408 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
409 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
410 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
411 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
413 OString
const expected
[] = {
414 "d41d8cd98f00b204e9800998ecf8427e"_ostr
,
415 "cfcd208495d565ef66e7dff9f98764da"_ostr
,
416 "b4b147bc522828731f1a016bfa72c073"_ostr
,
417 "c6f057b86584942e415435ffb1fa93d4"_ostr
,
418 "4a7d1ed414474e4033ac29ccb8653d9b"_ostr
,
419 "dcddb75469b4b4875094e14561e573d8"_ostr
,
420 "670b14728ad9902aecba32e22fa4f6bd"_ostr
,
421 "29c3eea3f305d6b823f562ac4be35217"_ostr
,
422 "dd4b21e9ef71e1291183a46b913ae6f2"_ostr
,
423 "4c93008615c2d041e33ebac605d14b5b"_ostr
,
424 "f1b708bba17f1ce948dc979f4d7092bc"_ostr
,
425 "645a8aca5a5b84527c57ee2f153f1946"_ostr
,
426 "35b9ab5a36f3234dd26db357fd4a0dc1"_ostr
,
427 "4aad0d9ff11812ebdd5e376fdbef6222"_ostr
,
428 "c47532bbb1e2883c902071591ae1ec9b"_ostr
,
429 "5284047f4ffb4e04824a2fd1d1f0cd62"_ostr
,
430 "1e4a1b03d1b6cd8a174a826f76e009f4"_ostr
,
431 "0e7b9f29a828b6f953b482fc299e536b"_ostr
,
432 "3ea032bf79e8c116b05f4698d5a8e044"_ostr
,
433 "15f47c8a3e5e9685307dd65a653b8dc0"_ostr
,
434 "cc545187d0745132de1e9941db0ef6ce"_ostr
,
435 "0585e303e79acd837c3a3e2a2bec8b18"_ostr
,
436 "b28ccfdee4b9f39ba18b58a4f61a03d1"_ostr
,
437 "d018229b1183c926c10ea688350afec8"_ostr
,
438 "660719b4a7591769583a7c8d20c6dfa4"_ostr
,
439 "1e2432adacf481836265fcc62ee8f3e3"_ostr
,
440 "6e88e2af74c1d9d7d7d652b90d03751e"_ostr
,
441 "780ca685003cec1d617beaa6f346e1be"_ostr
,
442 "7f2e1dcfd6e2a3f5c38f31e640136ff6"_ostr
,
443 "1a3dee46117aeb8010cf365b8653faa8"_ostr
,
444 "1d0064395af3c745f6c3194e92373d7a"_ostr
,
445 "b52582043219f2deb2d3c9cb05d6448a"_ostr
,
446 "cd9e459ea708a948d5c2f5a6ca8838cf"_ostr
,
447 "00de800ecd7a4fb2813986c987e46d51"_ostr
,
448 "15336d4b38561a82bd24c9398b781aed"_ostr
,
449 "5fe699d3c461ab5a795505f59d5adf15"_ostr
,
450 "c5e0eb03cbb4bea95ce3f8f48fca77d5"_ostr
,
451 "355c1410373ef02fff2b03844d72c7d4"_ostr
,
452 "02df97da8207de2b3afa69c151ca8958"_ostr
,
453 "82c66dbf3e73f87ffc9564b2098d6a4f"_ostr
,
454 "b373e3ddc3438d7c10c76f3ad9d4c401"_ostr
,
455 "fac901a4a3dbc4461541731a33a31d15"_ostr
,
456 "f573e011b414bf3f9dd284f7dad29592"_ostr
,
457 "11694570cc5dda099669f2ba3660a70d"_ostr
,
458 "60997cc8aef7fedd9995e6b3ca89ce26"_ostr
,
459 "63c5fcf83c2275fe64e880dd8dfc5cd6"_ostr
,
460 "c7a0a100057ebbfc63ee169562026aea"_ostr
,
461 "42c2dec247919384edece38033458627"_ostr
,
462 "b505acf9fc996902b0c547a2abfc62b2"_ostr
,
463 "2fa7a1321d6b5fa0e04ad46785f574f3"_ostr
,
464 "86d2bfc0bab44eecf21e1432be7b3efc"_ostr
,
465 "7ca318f12a0955a3e637dc5645a2f96e"_ostr
,
466 "3eda02765b8fb8bb9b20c735f4537827"_ostr
,
467 "26dead12262c9a5c115b01e0a3c805b6"_ostr
,
468 "978b0444e93c5f7d714575f28a77dca1"_ostr
,
469 "d7fe636bd28e2ee2ba4d6c5898318699"_ostr
,
470 "ce992c2ad906967c63c3f9ab0c2294a9"_ostr
,
471 "1f3b814e9d417e9fd8750299982feb1f"_ostr
,
472 "1a2f42174eaa78ce6a67d75e98a59cb6"_ostr
,
473 "17c772c45c9a09f6e56b7228ddd161a7"_ostr
,
474 "5b19445b70b493c78f3bc06eb7962315"_ostr
,
475 "e590c24cc612bdedd522dfe23bb29b42"_ostr
,
476 "4d78c699a0167bc0cfce8a5c5a715c0e"_ostr
,
477 "5703db92acb9d45e3975822c9206453f"_ostr
,
478 "10eab6008d5642cf42abd2aa41f847cb"_ostr
,
480 rtlDigest digest
= rtl_digest_createMD5();
481 for (size_t i
= 0; i
< sizeof(data
); ++i
)
483 rtl_digest_updateMD5(digest
, &data
, i
);
484 sal_uInt8 buf
[RTL_DIGEST_LENGTH_MD5
];
485 rtl_digest_getMD5(digest
, &buf
[0], sizeof(buf
));
486 OString
const sResult
= createHex(&buf
[0], sizeof(buf
));
487 CPPUNIT_ASSERT_EQUAL(expected
[i
], sResult
);
489 rtl_digest_destroyMD5(digest
);
492 CPPUNIT_TEST_SUITE(DigestTest
);
493 CPPUNIT_TEST(testCreate
);
494 CPPUNIT_TEST(testQuery
);
495 CPPUNIT_TEST(testQueryLength
);
496 CPPUNIT_TEST(testInit
);
497 CPPUNIT_TEST(testEqual
);
498 CPPUNIT_TEST(testCheckSum
);
499 CPPUNIT_TEST(testPBKDF2
);
500 CPPUNIT_TEST(testUpdate
);
501 CPPUNIT_TEST(testGet
);
502 CPPUNIT_TEST(testSHA1SumForBiggerInputData
);
503 CPPUNIT_TEST(testMD5
);
505 CPPUNIT_TEST_SUITE_END();
508 CPPUNIT_TEST_SUITE_REGISTRATION(DigestTest
);
510 } // namespace rtl_digest
512 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */