1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_digest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
36 #include <rtl/digest.h>
37 #include <rtl/ustring.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/strbuf.hxx>
41 // sample, how to use digest
43 rtl::OUString
CreateMD5FromString( const rtl::OUString
& aMsg
)
46 // BACK: Str "ababab....0f" Hexcode String
48 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
51 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
52 sal_uInt32 nSize
= ( aMsg
.getLength() * sizeof( sal_Unicode
));
53 sal_uInt32 nMD5KeyLen
= rtl_digest_queryLength( handle
);
54 sal_uInt8
* pMD5KeyBuffer
= new sal_uInt8
[ nMD5KeyLen
];
56 rtl_digest_init( handle
, pData
, nSize
);
57 rtl_digest_update( handle
, pData
, nSize
);
58 rtl_digest_get( handle
, pMD5KeyBuffer
, nMD5KeyLen
);
59 rtl_digest_destroy( handle
);
61 // Create hex-value string from the MD5 value to keep the string size minimal
62 rtl::OUStringBuffer
aBuffer( nMD5KeyLen
* 2 + 1 );
63 for ( sal_uInt32 i
= 0; i
< nMD5KeyLen
; i
++ )
64 aBuffer
.append( (sal_Int32
)pMD5KeyBuffer
[i
], 16 );
66 delete [] pMD5KeyBuffer
;
67 return aBuffer
.makeStringAndClear();
70 return rtl::OUString();
73 // -----------------------------------------------------------------------------
77 rtl::OString sSampleString
= "This is a sample sentence, which we use to check some crypto functions in sal.";
78 rtl::OString sSampleString_MD2
= "647ee6c9d4aa5fdd374ed9d7a156acbf";
79 rtl::OString sSampleString_MD5
= "b16b903e6fc0b62ae389013ed93fe531";
80 rtl::OString sSampleString_SHA
= "eab2814429b2613301c8a077b806af3680548914";
81 rtl::OString sSampleString_SHA1
= "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008";
82 rtl::OString sSampleString_HMAC_MD5
= "dd9cba48c972fba0a882baa72b079674";
83 rtl::OString sSampleString_HMAC_SHA1
= "5d7f43ce6abd1de4438d7e69e01495864490cf3e";
85 rtl::OString sSampleString_only_one_diff
= "This is a sample sentence. which we use to check some crypto functions in sal.";
87 class create
: public CppUnit::TestFixture
90 // initialise your test code values here.
101 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
102 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle
!= 0);
103 rtl_digest_destroy( handle
);
107 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
108 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", handle
!= 0);
109 rtl_digest_destroy( handle
);
113 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
114 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA", handle
!= 0);
115 rtl_digest_destroy( handle
);
119 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
120 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA1", handle
!= 0);
121 rtl_digest_destroy( handle
);
125 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
126 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_MD5", handle
!= 0);
127 rtl_digest_destroy( handle
);
131 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
132 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_SHA1", handle
!= 0);
133 rtl_digest_destroy( handle
);
138 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
139 t_print("Handle is %x\n", handle
);
140 CPPUNIT_ASSERT_MESSAGE("create with NULL", handle
== 0);
141 rtl_digest_destroy( handle
);
144 // Change the following lines only, if you add, remove or rename
145 // member functions of the current class,
146 // because these macros are need by auto register mechanism.
148 CPPUNIT_TEST_SUITE(create
);
149 CPPUNIT_TEST(create_001
);
150 CPPUNIT_TEST(create_002
);
151 CPPUNIT_TEST(create_003
);
152 CPPUNIT_TEST(create_004
);
153 CPPUNIT_TEST(create_005
);
154 CPPUNIT_TEST(create_006
);
155 CPPUNIT_TEST(create_007
);
156 CPPUNIT_TEST_SUITE_END();
162 // -----------------------------------------------------------------------------
164 class createMD5
: public CppUnit::TestFixture
167 // initialise your test code values here.
178 rtlDigest handle
= rtl_digest_createMD5();
180 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
181 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5
== aAlgo
);
183 rtl_digest_destroy( handle
);
185 CPPUNIT_TEST_SUITE(createMD5
);
186 CPPUNIT_TEST(createMD5_001
);
187 CPPUNIT_TEST_SUITE_END();
191 // -----------------------------------------------------------------------------
193 class createMD2
: public CppUnit::TestFixture
196 // initialise your test code values here.
207 rtlDigest handle
= rtl_digest_createMD2( );
209 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
210 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2
== aAlgo
);
212 rtl_digest_destroy( handle
);
214 CPPUNIT_TEST_SUITE(createMD2
);
215 CPPUNIT_TEST(createMD2_001
);
216 CPPUNIT_TEST_SUITE_END();
219 // -----------------------------------------------------------------------------
221 class createSHA
: public CppUnit::TestFixture
224 // initialise your test code values here.
235 rtlDigest handle
= rtl_digest_createSHA( );
237 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
238 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA
== aAlgo
);
240 rtl_digest_destroy( handle
);
242 CPPUNIT_TEST_SUITE(createSHA
);
243 CPPUNIT_TEST(createSHA_001
);
244 CPPUNIT_TEST_SUITE_END();
246 // -----------------------------------------------------------------------------
248 class createSHA1
: public CppUnit::TestFixture
251 // initialise your test code values here.
260 void createSHA1_001()
262 rtlDigest handle
= rtl_digest_createSHA1();
264 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
265 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1
== aAlgo
);
267 rtl_digest_destroy( handle
);
269 CPPUNIT_TEST_SUITE(createSHA1
);
270 CPPUNIT_TEST(createSHA1_001
);
271 CPPUNIT_TEST_SUITE_END();
273 // -----------------------------------------------------------------------------
275 class createHMAC_MD5
: public CppUnit::TestFixture
278 // initialise your test code values here.
287 void createHMAC_MD5_001()
289 rtlDigest handle
= rtl_digest_createHMAC_MD5();
291 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
292 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5
== aAlgo
);
294 rtl_digest_destroy( handle
);
296 CPPUNIT_TEST_SUITE(createHMAC_MD5
);
297 CPPUNIT_TEST(createHMAC_MD5_001
);
298 CPPUNIT_TEST_SUITE_END();
300 // -----------------------------------------------------------------------------
302 class createHMAC_SHA1
: public CppUnit::TestFixture
305 // initialise your test code values here.
314 void createHMAC_SHA1_001()
316 rtlDigest handle
= rtl_digest_createHMAC_SHA1();
318 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
319 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1
== aAlgo
);
321 rtl_digest_destroy( handle
);
325 CPPUNIT_TEST_SUITE(createHMAC_SHA1
);
326 CPPUNIT_TEST(createHMAC_SHA1_001
);
327 CPPUNIT_TEST_SUITE_END();
330 // -----------------------------------------------------------------------------
332 class queryAlgorithm
: public CppUnit::TestFixture
335 // initialise your test code values here.
346 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
348 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
349 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5
== aAlgo
);
351 rtl_digest_destroy( handle
);
355 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
357 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
358 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2
== aAlgo
);
360 rtl_digest_destroy( handle
);
364 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
366 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
367 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA
== aAlgo
);
369 rtl_digest_destroy( handle
);
373 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
375 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
376 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1
== aAlgo
);
378 rtl_digest_destroy( handle
);
382 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
384 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
385 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5
== aAlgo
);
387 rtl_digest_destroy( handle
);
391 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
393 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
394 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1
== aAlgo
);
396 rtl_digest_destroy( handle
);
400 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
402 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
403 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmInvalid
== aAlgo
);
405 rtl_digest_destroy( handle
);
408 // Change the following lines only, if you add, remove or rename
409 // member functions of the current class,
410 // because these macros are need by auto register mechanism.
412 CPPUNIT_TEST_SUITE(queryAlgorithm
);
413 CPPUNIT_TEST( query_001
);
414 CPPUNIT_TEST( query_002
);
415 CPPUNIT_TEST( query_003
);
416 CPPUNIT_TEST( query_004
);
417 CPPUNIT_TEST( query_005
);
418 CPPUNIT_TEST( query_006
);
419 CPPUNIT_TEST( query_007
);
420 CPPUNIT_TEST_SUITE_END();
424 // -----------------------------------------------------------------------------
425 class queryLength
: public CppUnit::TestFixture
428 // initialise your test code values here.
437 void queryLength_MD5()
439 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
441 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
442 // t_print("nAlgoLength:=%d\n", nAlgoLength);
443 CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5
== nAlgoLength
);
445 rtl_digest_destroy( handle
);
447 void queryLength_MD2()
449 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
451 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
452 // t_print("nAlgoLength:=%d\n", nAlgoLength);
453 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2
== nAlgoLength
);
455 rtl_digest_destroy( handle
);
457 void queryLength_SHA()
459 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
461 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
462 // t_print("nAlgoLength:=%d\n", nAlgoLength);
463 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA
== nAlgoLength
);
465 rtl_digest_destroy( handle
);
467 void queryLength_SHA1()
469 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
471 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
472 // t_print("nAlgoLength:=%d\n", nAlgoLength);
473 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1
== nAlgoLength
);
475 rtl_digest_destroy( handle
);
477 void queryLength_HMAC_MD5()
479 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
481 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
482 // t_print("nAlgoLength:=%d\n", nAlgoLength);
483 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5
== nAlgoLength
);
485 rtl_digest_destroy( handle
);
487 void queryLength_HMAC_SHA1()
489 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
491 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
492 // t_print("nAlgoLength:=%d\n", nAlgoLength);
493 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1
== nAlgoLength
);
495 rtl_digest_destroy( handle
);
498 void queryLength_Illegal()
500 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
502 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
503 // t_print("nAlgoLength:=%d\n", nAlgoLength);
504 CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength
);
506 rtl_digest_destroy( handle
);
509 // Change the following lines only, if you add, remove or rename
510 // member functions of the current class,
511 // because these macros are need by auto register mechanism.
513 CPPUNIT_TEST_SUITE(queryLength
);
514 CPPUNIT_TEST( queryLength_MD2
);
515 CPPUNIT_TEST( queryLength_MD5
);
516 CPPUNIT_TEST( queryLength_SHA
);
517 CPPUNIT_TEST( queryLength_SHA1
);
518 CPPUNIT_TEST( queryLength_HMAC_MD5
);
519 CPPUNIT_TEST( queryLength_HMAC_SHA1
);
520 CPPUNIT_TEST( queryLength_Illegal
);
521 CPPUNIT_TEST_SUITE_END();
524 // -----------------------------------------------------------------------------
526 rtl::OString
createHex(sal_uInt8
*_pMD5KeyBuffer
, sal_uInt32 _nMD5KeyLen
)
528 // Create hex-value string from the MD5 value to keep the string size minimal
529 rtl::OStringBuffer
aBuffer( _nMD5KeyLen
* 2 + 1 );
530 for ( sal_uInt32 i
= 0; i
< _nMD5KeyLen
; i
++ )
532 sal_Int32 nValue
= (sal_Int32
)_pMD5KeyBuffer
[i
];
533 if (nValue
< 16) // maximul hex value for 1 byte
535 aBuffer
.append( sal_Int32(0), 16 /* radix */ );
537 aBuffer
.append( nValue
, 16 /* radix */ );
540 return aBuffer
.makeStringAndClear();
544 // -----------------------------------------------------------------------------
545 class init
: public CppUnit::TestFixture
548 // initialise your test code values here.
559 rtlDigest handle
= NULL
;
561 rtlDigestError aError
= rtl_digest_init(handle
, NULL
, 0);
563 CPPUNIT_ASSERT_MESSAGE("init(NULL, 0, 0)", aError
== rtl_Digest_E_Argument
);
568 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
570 rtlDigestError aError
= rtl_digest_init(handle
, NULL
, 0);
572 CPPUNIT_ASSERT_MESSAGE("init(handle, 0, 0)", aError
== rtl_Digest_E_None
);
574 rtl_digest_destroy( handle
);
577 // ------------------------------------
580 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
582 rtl::OString aMsg
= sSampleString
;
583 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
584 sal_uInt32 nSize
= ( aMsg
.getLength() );
586 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
588 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
590 rtl_digest_update( handle
, pData
, nSize
);
592 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
593 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
595 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
596 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
597 delete [] pKeyBuffer
;
599 t_print("MD2 Sum: %s\n", aSum
.getStr());
600 // LLA: how to check right values
603 rtl_digest_destroy( handle
);
608 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
610 rtl::OString aMsg
= sSampleString
;
611 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
612 sal_uInt32 nSize
= ( aMsg
.getLength() );
614 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
616 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
618 rtl_digest_update( handle
, pData
, nSize
);
620 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
621 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
623 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
624 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
625 delete [] pKeyBuffer
;
627 t_print("MD5 Sum: %s\n", aSum
.getStr());
628 // LLA: how to check right values
631 rtl_digest_destroy( handle
);
636 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
638 rtl::OString aMsg
= sSampleString
;
639 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
640 sal_uInt32 nSize
= ( aMsg
.getLength() );
642 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
644 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
646 rtl_digest_update( handle
, pData
, nSize
);
648 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
649 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
651 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
652 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
653 delete [] pKeyBuffer
;
655 t_print("SHA Sum: %s\n", aSum
.getStr());
656 // LLA: how to check right values
659 rtl_digest_destroy( handle
);
663 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
665 rtl::OString aMsg
= sSampleString
;
666 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
667 sal_uInt32 nSize
= ( aMsg
.getLength() );
669 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
671 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
673 rtl_digest_update( handle
, pData
, nSize
);
675 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
676 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
678 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
679 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
680 delete [] pKeyBuffer
;
682 t_print("SHA1 Sum: %s\n", aSum
.getStr());
683 // LLA: how to check right values
686 rtl_digest_destroy( handle
);
690 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
692 rtl::OString aMsg
= sSampleString
;
693 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
694 sal_uInt32 nSize
= ( aMsg
.getLength() );
696 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
697 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen
);
699 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
700 CPPUNIT_ASSERT( pKeyBuffer
);
701 memset(pKeyBuffer
, 0, nKeyLen
);
703 rtlDigestError aError
= rtl_digest_init(handle
, pKeyBuffer
, nKeyLen
);
705 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
707 rtl_digest_update( handle
, pData
, nSize
);
709 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
710 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
711 delete [] pKeyBuffer
;
713 t_print("HMAC_MD5 Sum: %s\n", aSum
.getStr());
714 // LLA: how to check right values
717 rtl_digest_destroy( handle
);
719 void init_HMAC_SHA1()
721 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
723 rtl::OString aMsg
= sSampleString
;
724 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
725 sal_uInt32 nSize
= ( aMsg
.getLength() );
727 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
728 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen
);
730 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
731 CPPUNIT_ASSERT( pKeyBuffer
);
732 memset(pKeyBuffer
, 0, nKeyLen
);
734 rtlDigestError aError
= rtl_digest_init(handle
, pKeyBuffer
, nKeyLen
);
736 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
738 rtl_digest_update( handle
, pData
, nSize
);
740 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
741 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
742 delete [] pKeyBuffer
;
744 t_print("HMAC_SHA1 Sum: %s\n", aSum
.getStr());
745 // LLA: how to check right values
748 rtl_digest_destroy( handle
);
752 // Change the following lines only, if you add, remove or rename
753 // member functions of the current class,
754 // because these macros are need by auto register mechanism.
756 CPPUNIT_TEST_SUITE(init
);
757 CPPUNIT_TEST( init_000
);
758 CPPUNIT_TEST( init_001
);
759 CPPUNIT_TEST( init_MD2
);
760 CPPUNIT_TEST( init_MD5
);
761 CPPUNIT_TEST( init_SHA
);
762 CPPUNIT_TEST( init_SHA1
);
763 CPPUNIT_TEST( init_HMAC_MD5
);
764 CPPUNIT_TEST( init_HMAC_SHA1
);
765 CPPUNIT_TEST_SUITE_END();
768 // ------------------------------------
770 rtl::OString
getMD5Sum(rtl::OString
const& _aMsg
)
772 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
774 const sal_uInt8
*pData
= (const sal_uInt8
*)_aMsg
.getStr();
775 sal_uInt32 nSize
= ( _aMsg
.getLength() );
777 rtl_digest_init(handle
, pData
, nSize
);
778 rtl_digest_update( handle
, pData
, nSize
);
780 sal_uInt32 nMD5KeyLen
= rtl_digest_queryLength( handle
);
781 sal_uInt8
*pMD5KeyBuffer
= new sal_uInt8
[ nMD5KeyLen
];
783 rtl_digest_get( handle
, pMD5KeyBuffer
, nMD5KeyLen
);
784 rtl::OString aMD5Sum
= createHex(pMD5KeyBuffer
, nMD5KeyLen
);
785 delete [] pMD5KeyBuffer
;
787 rtl_digest_destroy( handle
);
791 // -----------------------------------------------------------------------------
793 class equalTests
: public CppUnit::TestFixture
796 // initialise your test code values here.
805 // ------------------------------------
808 rtl::OString aMsg1
= sSampleString
;
809 rtl::OString aMsg2
= sSampleString
;
811 rtl::OString aMsgMD5Sum1
= getMD5Sum(aMsg1
);
812 rtl::OString aMsgMD5Sum2
= getMD5Sum(aMsg2
);
814 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1
.getLength() == 32 && aMsgMD5Sum2
.getLength() == 32 );
815 CPPUNIT_ASSERT_MESSAGE("source is the same, dest must be also the same", aMsgMD5Sum1
.equals(aMsgMD5Sum2
) == sal_True
);
817 // ------------------------------------
820 rtl::OString aMsg1
= sSampleString
;
821 rtl::OString aMsg2
= sSampleString_only_one_diff
;
823 rtl::OString aMsgMD5Sum1
= getMD5Sum(aMsg1
);
824 rtl::OString aMsgMD5Sum2
= getMD5Sum(aMsg2
);
826 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1
.getLength() == 32 && aMsgMD5Sum2
.getLength() == 32 );
827 CPPUNIT_ASSERT_MESSAGE("differ only in one char", aMsgMD5Sum1
.equals(aMsgMD5Sum2
) == sal_False
);
830 // Change the following lines only, if you add, remove or rename
831 // member functions of the current class,
832 // because these macros are need by auto register mechanism.
834 CPPUNIT_TEST_SUITE(equalTests
);
835 CPPUNIT_TEST( equal_001
);
836 CPPUNIT_TEST( equal_002
);
837 CPPUNIT_TEST_SUITE_END();
841 // -----------------------------------------------------------------------------
842 class digest_MD2
: public CppUnit::TestFixture
845 // initialise your test code values here.
854 // ------------------------------------
857 rtl::OString aMsg1
= sSampleString
;
859 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_MD2
];
860 CPPUNIT_ASSERT( pBuffer
);
861 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_MD2
);
863 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
864 sal_Int32 nLen
= aMsg1
.getLength();
866 rtlDigestError aError
= rtl_digest_MD2(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_MD2
);
868 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
870 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_MD2
);
871 t_print("Decrypt MD2: %s\n", aStr
.getStr());
872 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_MD2
) );
877 // Change the following lines only, if you add, remove or rename
878 // member functions of the current class,
879 // because these macros are need by auto register mechanism.
881 CPPUNIT_TEST_SUITE(digest_MD2
);
882 CPPUNIT_TEST( MD2_001
);
883 CPPUNIT_TEST_SUITE_END();
885 // -----------------------------------------------------------------------------
886 class digest_MD5
: public CppUnit::TestFixture
889 // initialise your test code values here.
897 // ------------------------------------
900 rtl::OString aMsg1
= sSampleString
;
902 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_MD5
];
903 CPPUNIT_ASSERT( pBuffer
);
904 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_MD5
);
906 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
907 sal_Int32 nLen
= aMsg1
.getLength();
909 rtlDigestError aError
= rtl_digest_MD5(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_MD5
);
911 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
913 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_MD5
);
914 t_print("Decrypt MD5: %s\n", aStr
.getStr());
915 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_MD5
) );
920 // Change the following lines only, if you add, remove or rename
921 // member functions of the current class,
922 // because these macros are need by auto register mechanism.
924 CPPUNIT_TEST_SUITE(digest_MD5
);
925 CPPUNIT_TEST( MD5_001
);
926 CPPUNIT_TEST_SUITE_END();
929 // -----------------------------------------------------------------------------
930 class digest_SHA
: public CppUnit::TestFixture
933 // initialise your test code values here.
942 // ------------------------------------
945 rtl::OString aMsg1
= sSampleString
;
947 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_SHA
];
948 CPPUNIT_ASSERT( pBuffer
);
949 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_SHA
);
951 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
952 sal_Int32 nLen
= aMsg1
.getLength();
954 rtlDigestError aError
= rtl_digest_SHA(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_SHA
);
956 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
958 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_SHA
);
959 t_print("Decrypt SHA: %s\n", aStr
.getStr());
960 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_SHA
) );
965 // Change the following lines only, if you add, remove or rename
966 // member functions of the current class,
967 // because these macros are need by auto register mechanism.
969 CPPUNIT_TEST_SUITE(digest_SHA
);
970 CPPUNIT_TEST( SHA_001
);
971 CPPUNIT_TEST_SUITE_END();
974 // -----------------------------------------------------------------------------
975 class digest_SHA1
: public CppUnit::TestFixture
978 // initialise your test code values here.
987 // ------------------------------------
990 rtl::OString aMsg1
= sSampleString
;
992 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_SHA1
];
993 CPPUNIT_ASSERT( pBuffer
);
994 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_SHA1
);
996 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
997 sal_Int32 nLen
= aMsg1
.getLength();
999 rtlDigestError aError
= rtl_digest_SHA1(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_SHA1
);
1001 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1003 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_SHA1
);
1004 t_print("Decrypt SHA1: %s\n", aStr
.getStr());
1005 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_SHA1
) );
1009 // Change the following lines only, if you add, remove or rename
1010 // member functions of the current class,
1011 // because these macros are need by auto register mechanism.
1013 CPPUNIT_TEST_SUITE(digest_SHA1
);
1014 CPPUNIT_TEST( SHA1_001
);
1015 CPPUNIT_TEST_SUITE_END();
1017 // -----------------------------------------------------------------------------
1018 class digest_HMAC_MD5
: public CppUnit::TestFixture
1021 // initialise your test code values here.
1030 // ------------------------------------
1033 rtl::OString aMsg1
= sSampleString
;
1035 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_MD5
];
1036 CPPUNIT_ASSERT( pKeyBuffer
);
1037 memset(pKeyBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_MD5
);
1039 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_MD5
];
1040 CPPUNIT_ASSERT( pBuffer
);
1041 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_MD5
);
1043 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
1044 sal_Int32 nLen
= aMsg1
.getLength();
1046 rtlDigestError aError
= rtl_digest_HMAC_MD5(pKeyBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
, pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
);
1048 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1050 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
);
1051 t_print("Decrypt HMAC_MD5: %s\n", aStr
.getStr());
1052 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_HMAC_MD5
) );
1056 // Change the following lines only, if you add, remove or rename
1057 // member functions of the current class,
1058 // because these macros are need by auto register mechanism.
1060 CPPUNIT_TEST_SUITE(digest_HMAC_MD5
);
1061 CPPUNIT_TEST( HMAC_MD5_001
);
1062 CPPUNIT_TEST_SUITE_END();
1064 // -----------------------------------------------------------------------------
1065 class digest_HMAC_SHA1
: public CppUnit::TestFixture
1068 // initialise your test code values here.
1077 // ------------------------------------
1078 void HMAC_SHA1_001()
1080 rtl::OString aMsg1
= sSampleString
;
1082 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_SHA1
];
1083 CPPUNIT_ASSERT( pKeyBuffer
);
1084 memset(pKeyBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1086 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_SHA1
];
1087 CPPUNIT_ASSERT( pBuffer
);
1088 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1090 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
1091 sal_Int32 nLen
= aMsg1
.getLength();
1093 rtlDigestError aError
= rtl_digest_HMAC_SHA1(pKeyBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
, pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1095 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1097 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1098 t_print("Decrypt HMAC_SHA1: %s\n", aStr
.getStr());
1099 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_HMAC_SHA1
) );
1104 // Change the following lines only, if you add, remove or rename
1105 // member functions of the current class,
1106 // because these macros are need by auto register mechanism.
1108 CPPUNIT_TEST_SUITE(digest_HMAC_SHA1
);
1109 CPPUNIT_TEST( HMAC_SHA1_001
);
1110 CPPUNIT_TEST_SUITE_END();
1112 // -----------------------------------------------------------------------------
1113 class digest_PBKDF2
: public CppUnit::TestFixture
1116 // initialise your test code values here.
1125 // ------------------------------------
1126 rtl::OString
/* key */ run_check_PBKDF2(rtl::OString
const& _sPassword
, bool _bClearSalt
, sal_uInt32 _nCount
)
1128 sal_uInt32 nKeyLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
1129 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1130 CPPUNIT_ASSERT( pKeyBuffer
);
1131 memset(pKeyBuffer
, 0, nKeyLen
);
1133 sal_uInt8
*pPassword
= (sal_uInt8
*)_sPassword
.getStr();
1134 sal_Int32 nPasswordLen
= _sPassword
.getLength();
1136 sal_uInt32 nSaltDataLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
1137 sal_uInt8
*pSaltData
= new sal_uInt8
[ nSaltDataLen
];
1138 CPPUNIT_ASSERT( pSaltData
);
1139 memset(pSaltData
, 0, nSaltDataLen
);
1143 // wilful contamination
1147 rtlDigestError aError
= rtl_digest_PBKDF2(pKeyBuffer
, nKeyLen
, pPassword
, nPasswordLen
, pSaltData
, nSaltDataLen
, _nCount
);
1149 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1151 rtl::OString aKey
= createHex(pKeyBuffer
, nKeyLen
);
1152 t_print("Key: %s\n", aKey
.getStr());
1154 // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen);
1155 // t_print("Salt: %s\n", sSalt.getStr());
1157 // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) );
1159 delete [] pSaltData
;
1160 delete [] pKeyBuffer
;
1166 rtl::OString aPassword
= "Password";
1169 run_check_PBKDF2(aPassword
, false, 1);
1170 run_check_PBKDF2(aPassword
, false, 2);
1171 run_check_PBKDF2(aPassword
, true, 1);
1172 run_check_PBKDF2(aPassword
, true, 2);
1173 run_check_PBKDF2(aPassword
, false, 3);
1174 run_check_PBKDF2(aPassword
, false, 4);
1175 run_check_PBKDF2(aPassword
, true, 3);
1176 run_check_PBKDF2(aPassword
, true, 4);
1178 // Change the following lines only, if you add, remove or rename
1179 // member functions of the current class,
1180 // because these macros are need by auto register mechanism.
1182 CPPUNIT_TEST_SUITE(digest_PBKDF2
);
1183 CPPUNIT_TEST( PBKDF2_001
);
1184 CPPUNIT_TEST_SUITE_END();
1186 // -----------------------------------------------------------------------------
1188 class update
: public CppUnit::TestFixture
1191 // initialise your test code values here.
1202 rtlDigest aHandle
= NULL
;
1203 rtlDigestError aError
= rtl_digest_update(aHandle
, NULL
, 0);
1204 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1207 void updateMD2_000()
1209 rtlDigest aHandle
= NULL
;
1210 rtlDigestError aError
= rtl_digest_updateMD2(aHandle
, NULL
, 0);
1211 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1214 void updateMD2_001()
1216 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1217 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1219 rtl::OString aMsg
= sSampleString
;
1220 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1222 rtlDigestError aError
= rtl_digest_updateMD2(aHandle
, NULL
, 0);
1223 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1225 /* rtlDigestError */ aError
= rtl_digest_updateMD2(aHandle
, pData
, 0);
1226 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_None
);
1228 rtl_digest_destroyMD2(aHandle
);
1230 void updateMD5_000()
1232 rtlDigest aHandle
= NULL
;
1233 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, NULL
, 0);
1234 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1237 void updateMD5_001()
1239 // use wrong Algorithm!!! This is volitional!
1240 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1241 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1243 rtl::OString aMsg
= sSampleString
;
1244 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1245 sal_uInt32 nSize
= ( aMsg
.getLength() );
1247 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, pData
, nSize
);
1248 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError
== rtl_Digest_E_Algorithm
);
1250 rtl_digest_destroyMD5(aHandle
);
1253 void updateMD5_002()
1255 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1256 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= 0);
1258 rtl::OString aMsg
= sSampleString
;
1259 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1261 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, NULL
, 0);
1262 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1264 /* rtlDigestError */ aError
= rtl_digest_updateMD5(aHandle
, pData
, 0);
1265 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_None
);
1267 rtl_digest_destroyMD5(aHandle
);
1270 void updateSHA_000()
1272 rtlDigest aHandle
= NULL
;
1273 rtlDigestError aError
= rtl_digest_updateSHA(aHandle
, NULL
, 0);
1274 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1277 void updateSHA1_000()
1279 rtlDigest aHandle
= NULL
;
1280 rtlDigestError aError
= rtl_digest_updateSHA1(aHandle
, NULL
, 0);
1281 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1284 void updateHMAC_MD5_000()
1286 rtlDigest aHandle
= NULL
;
1287 rtlDigestError aError
= rtl_digest_updateHMAC_MD5(aHandle
, NULL
, 0);
1288 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1291 void updateHMAC_SHA1_000()
1293 rtlDigest aHandle
= NULL
;
1294 rtlDigestError aError
= rtl_digest_updateHMAC_SHA1(aHandle
, NULL
, 0);
1295 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1298 // Change the following lines only, if you add, remove or rename
1299 // member functions of the current class,
1300 // because these macros are need by auto register mechanism.
1302 CPPUNIT_TEST_SUITE(update
);
1303 CPPUNIT_TEST(update_000
);
1304 CPPUNIT_TEST(updateMD5_000
);
1305 CPPUNIT_TEST(updateMD5_001
);
1306 CPPUNIT_TEST(updateMD5_002
);
1307 CPPUNIT_TEST(updateMD5_000
);
1308 CPPUNIT_TEST(updateSHA_000
);
1309 CPPUNIT_TEST(updateSHA1_000
);
1310 CPPUNIT_TEST(updateHMAC_MD5_000
);
1311 CPPUNIT_TEST(updateHMAC_SHA1_000
);
1312 CPPUNIT_TEST_SUITE_END();
1314 // -----------------------------------------------------------------------------
1316 class get
: public CppUnit::TestFixture
1319 // initialise your test code values here.
1330 rtlDigest aHandle
= NULL
;
1331 rtlDigestError aError
= rtl_digest_get(aHandle
, NULL
, 0);
1332 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1336 rtlDigest aHandle
= NULL
;
1337 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
, 0);
1338 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1342 // test with wrong algorithm
1343 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1344 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1346 sal_uInt32 nKeyLen
= rtl_digest_queryLength( aHandle
);
1347 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1349 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
, 0);
1350 CPPUNIT_ASSERT_MESSAGE("handle 2. parameter wrong", aError
== rtl_Digest_E_Argument
);
1352 /* rtlDigestError */ aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
, 0);
1353 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError
== rtl_Digest_E_Algorithm
);
1355 rtl_digest_destroyMD2(aHandle
);
1360 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1361 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= 0);
1363 sal_uInt32 nKeyLen
= rtl_digest_queryLength( aHandle
);
1364 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1366 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
/* pKeyBuffer */ , nKeyLen
);
1367 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1369 /* rtlDigestError */ aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
, 0);
1370 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_BufferSize
);
1372 rtl_digest_destroyMD5(aHandle
);
1373 delete [] pKeyBuffer
;
1376 // Change the following lines only, if you add, remove or rename
1377 // member functions of the current class,
1378 // because these macros are need by auto register mechanism.
1380 CPPUNIT_TEST_SUITE(get
);
1381 CPPUNIT_TEST(get_000
);
1382 CPPUNIT_TEST(getMD5_000
);
1383 CPPUNIT_TEST(getMD5_001
);
1384 CPPUNIT_TEST(getMD5_002
);
1385 CPPUNIT_TEST_SUITE_END();
1388 // -----------------------------------------------------------------------------
1389 class destroy
: public CppUnit::TestFixture
1392 // initialise your test code values here.
1403 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1404 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle
!= 0);
1406 // not really testable
1407 // LLA: good will test.
1408 rtl_digest_destroy( handle
);
1411 // Change the following lines only, if you add, remove or rename
1412 // member functions of the current class,
1413 // because these macros are need by auto register mechanism.
1415 CPPUNIT_TEST_SUITE(destroy
);
1416 CPPUNIT_TEST(destroy_001
);
1417 CPPUNIT_TEST_SUITE_END();
1419 // -----------------------------------------------------------------------------
1421 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create
, "rtl_digest");
1422 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2
, "rtl_digest");
1423 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5
, "rtl_digest");
1424 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA
, "rtl_digest");
1425 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1
, "rtl_digest");
1426 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5
, "rtl_digest");
1427 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1
, "rtl_digest");
1429 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy
, "rtl_digest");
1431 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm
, "rtl_digest");
1432 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength
, "rtl_digest");
1433 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init
, "rtl_digest");
1434 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests
, "rtl_digest");
1436 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2
, "rtl_digest");
1437 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5
, "rtl_digest");
1438 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA
, "rtl_digest");
1439 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1
, "rtl_digest");
1440 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5
, "rtl_digest");
1441 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1
, "rtl_digest");
1442 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2
, "rtl_digest");
1444 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update
, "rtl_digest");
1445 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get
, "rtl_digest");
1446 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy
, "rtl_digest");
1447 } // namespace rtl_digest
1450 // -----------------------------------------------------------------------------
1452 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1453 // to let the user the possibility to also register some functions by hand.