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_cipher.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"
35 #include <cppunit/simpleheader.hxx>
36 #include <rtl/strbuf.hxx>
37 #include <rtl/cipher.h>
39 // -----------------------------------------------------------------------------
43 rtl::OString
createHex(sal_uInt8
*_pKeyBuffer
, sal_uInt32 _nKeyLen
)
45 // Create hex-value string from the value to keep the string size minimal
46 rtl::OStringBuffer
aBuffer( _nKeyLen
* 2 + 1 );
47 for ( sal_uInt32 i
= 0; i
< _nKeyLen
; i
++ )
49 sal_Int32 nValue
= (sal_Int32
)_pKeyBuffer
[i
];
50 if (nValue
< 16) // maximul hex value for 1 byte
52 aBuffer
.append( sal_Int32(0), 16 /* radix */ );
54 aBuffer
.append( nValue
, 16 /* radix */ );
57 return aBuffer
.makeStringAndClear();
60 // -----------------------------------------------------------------------------
62 class create
: public CppUnit::TestFixture
65 // initialise your test code values here.
76 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
77 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
78 rtl_cipher_destroy(aCipher
);
82 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmInvalid
, rtl_Cipher_ModeECB
);
83 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
87 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeCBC
);
88 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
89 rtl_cipher_destroy(aCipher
);
93 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmInvalid
, rtl_Cipher_ModeCBC
);
94 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
98 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeStream
);
99 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
100 rtl_cipher_destroy(aCipher
);
104 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmInvalid
, rtl_Cipher_ModeStream
);
105 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
109 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeInvalid
);
110 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
114 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmInvalid
, rtl_Cipher_ModeInvalid
);
115 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
118 // Change the following lines only, if you add, remove or rename
119 // member functions of the current class,
120 // because these macros are need by auto register mechanism.
122 CPPUNIT_TEST_SUITE(create
);
123 CPPUNIT_TEST(create_001
);
124 CPPUNIT_TEST(create_002
);
125 CPPUNIT_TEST(create_003
);
126 CPPUNIT_TEST(create_004
);
127 CPPUNIT_TEST(create_005
);
128 CPPUNIT_TEST(create_006
);
129 CPPUNIT_TEST(create_007
);
130 CPPUNIT_TEST(create_008
);
131 CPPUNIT_TEST_SUITE_END();
134 // -----------------------------------------------------------------------------
135 class createBF
: public CppUnit::TestFixture
138 // initialise your test code values here.
149 rtlCipher aCipher
= rtl_cipher_createBF(rtl_Cipher_ModeECB
);
150 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
151 rtl_cipher_destroy(aCipher
);
155 rtlCipher aCipher
= rtl_cipher_createBF(rtl_Cipher_ModeCBC
);
156 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
157 rtl_cipher_destroy(aCipher
);
161 rtlCipher aCipher
= rtl_cipher_createBF(rtl_Cipher_ModeStream
);
162 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
163 rtl_cipher_destroy(aCipher
);
167 rtlCipher aCipher
= rtl_cipher_createBF(rtl_Cipher_ModeInvalid
);
168 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher
== NULL
);
169 // rtl_cipher_destroy(aCipher);
171 // Change the following lines only, if you add, remove or rename
172 // member functions of the current class,
173 // because these macros are need by auto register mechanism.
175 CPPUNIT_TEST_SUITE(createBF
);
176 CPPUNIT_TEST(createBF_001
);
177 CPPUNIT_TEST(createBF_002
);
178 CPPUNIT_TEST(createBF_003
);
179 CPPUNIT_TEST(createBF_004
);
180 CPPUNIT_TEST_SUITE_END();
182 // -----------------------------------------------------------------------------
183 class decode
: public CppUnit::TestFixture
186 // initialise your test code values here.
195 void test_encode(sal_uInt8 _nKeyValue
, sal_uInt8 _nArgValue
, rtl::OString
const& _sPlainTextStr
)
197 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
198 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
200 sal_uInt32 nKeyLen
= 16;
201 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
202 memset(pKeyBuffer
, 0, nKeyLen
);
203 pKeyBuffer
[0] = _nKeyValue
;
205 sal_uInt32 nArgLen
= 16;
206 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
207 memset(pArgBuffer
, 0, nArgLen
);
208 pArgBuffer
[0] = _nArgValue
;
210 t_print(T_VERBOSE
, " init Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
211 t_print(T_VERBOSE
, " init Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
213 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
214 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
216 sal_uInt32 nPlainTextLen
= 16;
217 sal_uInt8
*pPlainTextBuffer
= new sal_uInt8
[ nPlainTextLen
];
218 memset(pPlainTextBuffer
, 0, nPlainTextLen
);
219 strncpy((char*)pPlainTextBuffer
, _sPlainTextStr
.getStr(), 16);
221 sal_uInt32 nCipherLen
= 16;
222 sal_uInt8
*pCipherBuffer
= new sal_uInt8
[ nCipherLen
];
223 memset(pCipherBuffer
, 0, nCipherLen
);
225 /* rtlCipherError */ aError
= rtl_cipher_encode(aCipher
, pPlainTextBuffer
, nPlainTextLen
, pCipherBuffer
, nCipherLen
);
226 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError
== rtl_Cipher_E_None
);
228 t_print(T_VERBOSE
, " Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
229 t_print(T_VERBOSE
, " Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
230 t_print(T_VERBOSE
, " Plain: %s\n", createHex(pPlainTextBuffer
, nPlainTextLen
).getStr());
231 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer
, nCipherLen
).getStr());
233 sal_uInt32 nPlainText2Len
= 16;
234 sal_uInt8
*pPlainText2Buffer
= new sal_uInt8
[ nPlainText2Len
];
235 memset(pPlainText2Buffer
, 0, nPlainText2Len
);
237 /* rtlCipherError */ aError
= rtl_cipher_decode(aCipher
, pCipherBuffer
, nCipherLen
, pPlainText2Buffer
, nPlainText2Len
);
238 CPPUNIT_ASSERT_MESSAGE("decode should not work", aError
!= rtl_Cipher_E_None
);
240 // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
241 // t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
242 // t_print(T_VERBOSE, " ascii: %s\n", sPlainText2Str.getStr());
244 // // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
246 // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
248 // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
250 // delete [] pPlainText2Buffer;
252 // delete [] pCipherBuffer;
253 // delete [] pPlainTextBuffer;
255 // delete [] pArgBuffer;
256 // delete [] pKeyBuffer;
258 // rtl_cipher_destroy(aCipher);
261 void test_encode_and_decode(sal_uInt8 _nKeyValue
, sal_uInt8 _nArgValue
, rtl::OString
const& _sPlainTextStr
)
263 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
264 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
266 sal_uInt32 nKeyLen
= 16;
267 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
268 memset(pKeyBuffer
, 0, nKeyLen
);
269 pKeyBuffer
[0] = _nKeyValue
;
271 sal_uInt32 nArgLen
= 16;
272 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
273 memset(pArgBuffer
, 0, nArgLen
);
274 pArgBuffer
[0] = _nArgValue
;
276 t_print(T_VERBOSE
, " init Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
277 t_print(T_VERBOSE
, " init Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
279 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionBoth
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
280 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
282 sal_uInt32 nPlainTextLen
= 16;
283 sal_uInt8
*pPlainTextBuffer
= new sal_uInt8
[ nPlainTextLen
];
284 memset(pPlainTextBuffer
, 0, nPlainTextLen
);
285 strncpy((char*)pPlainTextBuffer
, _sPlainTextStr
.getStr(), 16);
287 sal_uInt32 nCipherLen
= 16;
288 sal_uInt8
*pCipherBuffer
= new sal_uInt8
[ nCipherLen
];
289 memset(pCipherBuffer
, 0, nCipherLen
);
291 /* rtlCipherError */ aError
= rtl_cipher_encode(aCipher
, pPlainTextBuffer
, nPlainTextLen
, pCipherBuffer
, nCipherLen
);
292 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError
== rtl_Cipher_E_None
);
294 t_print(T_VERBOSE
, " Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
295 t_print(T_VERBOSE
, " Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
296 t_print(T_VERBOSE
, " Plain: %s\n", createHex(pPlainTextBuffer
, nPlainTextLen
).getStr());
297 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer
, nCipherLen
).getStr());
299 sal_uInt32 nPlainText2Len
= 16;
300 sal_uInt8
*pPlainText2Buffer
= new sal_uInt8
[ nPlainText2Len
];
301 memset(pPlainText2Buffer
, 0, nPlainText2Len
);
303 /* rtlCipherError */ aError
= rtl_cipher_decode(aCipher
, pCipherBuffer
, nCipherLen
, pPlainText2Buffer
, nPlainText2Len
);
304 CPPUNIT_ASSERT_MESSAGE("wrong decode", aError
== rtl_Cipher_E_None
);
306 rtl::OString
sPlainText2Str((char*)pPlainText2Buffer
, nPlainText2Len
);
307 t_print(T_VERBOSE
, " Plain: %s\n", createHex(pPlainText2Buffer
, nPlainText2Len
).getStr());
308 t_print(T_VERBOSE
, " as ascii: %s\n", sPlainText2Str
.getStr());
310 // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
312 sal_Int32 nCompare
= memcmp(pPlainTextBuffer
, pPlainText2Buffer
, 16);
314 CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare
== 0);
316 delete [] pPlainText2Buffer
;
318 delete [] pCipherBuffer
;
319 delete [] pPlainTextBuffer
;
321 delete [] pArgBuffer
;
322 delete [] pKeyBuffer
;
324 rtl_cipher_destroy(aCipher
);
329 test_encode_and_decode(0,0,"");
330 test_encode_and_decode(0,0,"hallo");
331 test_encode_and_decode(1,0,"B2Aahg5B");
332 test_encode_and_decode(1,2,"Longer text string");
338 test_encode(0,0,"hallo");
339 test_encode(1,0,"B2Aahg5B");
340 test_encode(1,2,"Longer text string");
342 // Change the following lines only, if you add, remove or rename
343 // member functions of the current class,
344 // because these macros are need by auto register mechanism.
346 CPPUNIT_TEST_SUITE(decode
);
347 CPPUNIT_TEST(decode_001
);
348 CPPUNIT_TEST(decode_002
);
349 CPPUNIT_TEST_SUITE_END();
351 // -----------------------------------------------------------------------------
352 class decodeBF
: public CppUnit::TestFixture
355 // initialise your test code values here.
367 // Change the following lines only, if you add, remove or rename
368 // member functions of the current class,
369 // because these macros are need by auto register mechanism.
371 CPPUNIT_TEST_SUITE(decodeBF
);
372 CPPUNIT_TEST(decodeBF_001
);
373 CPPUNIT_TEST_SUITE_END();
375 // -----------------------------------------------------------------------------
376 class destroy
: public CppUnit::TestFixture
379 // initialise your test code values here.
390 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeCBC
);
391 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
392 rtl_cipher_destroy(aCipher
);
394 // Change the following lines only, if you add, remove or rename
395 // member functions of the current class,
396 // because these macros are need by auto register mechanism.
398 CPPUNIT_TEST_SUITE(destroy
);
399 CPPUNIT_TEST(destroy_001
);
400 CPPUNIT_TEST_SUITE_END();
402 // -----------------------------------------------------------------------------
403 class destroyBF
: public CppUnit::TestFixture
406 // initialise your test code values here.
417 rtlCipher aCipher
= rtl_cipher_createBF(rtl_Cipher_ModeECB
);
418 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
419 rtl_cipher_destroyBF(aCipher
);
423 // Change the following lines only, if you add, remove or rename
424 // member functions of the current class,
425 // because these macros are need by auto register mechanism.
427 CPPUNIT_TEST_SUITE(destroyBF
);
428 CPPUNIT_TEST(destroyBF_001
);
429 CPPUNIT_TEST_SUITE_END();
430 }; // class destroyBF
431 // -----------------------------------------------------------------------------
432 class encode
: public CppUnit::TestFixture
435 // initialise your test code values here.
444 void test_encode(sal_uInt8 _nKeyValue
, sal_uInt8 _nArgValue
, sal_uInt8 _nDataValue
)
446 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
447 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
449 sal_uInt32 nKeyLen
= 16;
450 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
451 memset(pKeyBuffer
, 0, nKeyLen
);
452 pKeyBuffer
[0] = _nKeyValue
;
454 sal_uInt32 nArgLen
= 16;
455 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
456 memset(pArgBuffer
, 0, nArgLen
);
457 pArgBuffer
[0] = _nArgValue
;
459 t_print(T_VERBOSE
, "init Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
460 t_print(T_VERBOSE
, "init Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
462 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
463 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
465 sal_uInt32 nDataLen
= 16;
466 sal_uInt8
*pDataBuffer
= new sal_uInt8
[ nDataLen
];
467 memset(pDataBuffer
, 0, nDataLen
);
468 pDataBuffer
[0] = _nDataValue
;
470 sal_uInt32 nLen
= 16;
471 sal_uInt8
*pBuffer
= new sal_uInt8
[ nLen
];
472 memset(pBuffer
, 0, nLen
);
474 /* rtlCipherError */ aError
= rtl_cipher_encode(aCipher
, pDataBuffer
, nDataLen
, pBuffer
, nLen
);
475 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError
== rtl_Cipher_E_None
);
477 t_print(T_VERBOSE
, " Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
478 t_print(T_VERBOSE
, " Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
479 t_print(T_VERBOSE
, "Data: %s\n", createHex(pDataBuffer
, nDataLen
).getStr());
480 t_print(T_VERBOSE
, " Buf: %s\n", createHex(pBuffer
, nLen
).getStr());
483 delete [] pDataBuffer
;
485 delete [] pArgBuffer
;
486 delete [] pKeyBuffer
;
488 rtl_cipher_destroy(aCipher
);
504 // Change the following lines only, if you add, remove or rename
505 // member functions of the current class,
506 // because these macros are need by auto register mechanism.
508 CPPUNIT_TEST_SUITE(encode
);
509 CPPUNIT_TEST(encode_001
);
510 CPPUNIT_TEST_SUITE_END();
512 // -----------------------------------------------------------------------------
513 class encodeBF
: public CppUnit::TestFixture
516 // initialise your test code values here.
528 // Change the following lines only, if you add, remove or rename
529 // member functions of the current class,
530 // because these macros are need by auto register mechanism.
532 CPPUNIT_TEST_SUITE(encodeBF
);
533 CPPUNIT_TEST(encodeBF_001
);
534 CPPUNIT_TEST_SUITE_END();
536 // -----------------------------------------------------------------------------
537 class init
: public CppUnit::TestFixture
540 // initialise your test code values here.
551 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
552 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
554 sal_uInt32 nKeyLen
= 16;
555 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
556 memset(pKeyBuffer
, 0, nKeyLen
);
558 sal_uInt32 nArgLen
= 16;
559 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
560 memset(pArgBuffer
, 0, nArgLen
);
562 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
563 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
565 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
566 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
568 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
569 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
571 delete [] pArgBuffer
;
572 delete [] pKeyBuffer
;
574 rtl_cipher_destroy(aCipher
);
579 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
580 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
582 sal_uInt32 nKeyLen
= 16;
583 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
584 memset(pKeyBuffer
, 0, nKeyLen
);
587 sal_uInt32 nArgLen
= 16;
588 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
589 memset(pArgBuffer
, 0, nArgLen
);
591 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
592 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
594 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
595 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
597 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
598 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
600 delete [] pArgBuffer
;
601 delete [] pKeyBuffer
;
603 rtl_cipher_destroy(aCipher
);
607 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
608 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
610 sal_uInt32 nKeyLen
= 16;
611 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
612 memset(pKeyBuffer
, 0, nKeyLen
);
614 sal_uInt32 nArgLen
= 16;
615 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
616 memset(pArgBuffer
, 0, nArgLen
);
619 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
620 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
622 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
623 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
625 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
626 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
628 delete [] pArgBuffer
;
629 delete [] pKeyBuffer
;
631 rtl_cipher_destroy(aCipher
);
635 rtlCipher aCipher
= rtl_cipher_create(rtl_Cipher_AlgorithmBF
, rtl_Cipher_ModeECB
);
636 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher
!= NULL
);
638 sal_uInt32 nKeyLen
= 16;
639 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
640 memset(pKeyBuffer
, 0, nKeyLen
);
643 sal_uInt32 nArgLen
= 16;
644 sal_uInt8
*pArgBuffer
= new sal_uInt8
[ nArgLen
];
645 memset(pArgBuffer
, 0, nArgLen
);
648 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
649 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
651 rtlCipherError aError
= rtl_cipher_init(aCipher
, rtl_Cipher_DirectionEncode
, pKeyBuffer
, nKeyLen
, pArgBuffer
, nArgLen
);
652 CPPUNIT_ASSERT_MESSAGE("wrong init", aError
== rtl_Cipher_E_None
);
654 t_print(T_VERBOSE
, "Key: %s\n", createHex(pKeyBuffer
, nKeyLen
).getStr());
655 t_print(T_VERBOSE
, "Arg: %s\n", createHex(pArgBuffer
, nArgLen
).getStr());
657 delete [] pArgBuffer
;
658 delete [] pKeyBuffer
;
660 rtl_cipher_destroy(aCipher
);
662 // Change the following lines only, if you add, remove or rename
663 // member functions of the current class,
664 // because these macros are need by auto register mechanism.
666 CPPUNIT_TEST_SUITE(init
);
667 CPPUNIT_TEST(init_001
);
668 CPPUNIT_TEST(init_002
);
669 CPPUNIT_TEST(init_003
);
670 CPPUNIT_TEST(init_004
);
671 CPPUNIT_TEST_SUITE_END();
673 // -----------------------------------------------------------------------------
674 class initBF
: public CppUnit::TestFixture
677 // initialise your test code values here.
688 // seems to be the same as init, so empty
691 // Change the following lines only, if you add, remove or rename
692 // member functions of the current class,
693 // because these macros are need by auto register mechanism.
695 CPPUNIT_TEST_SUITE(initBF
);
696 CPPUNIT_TEST(initBF_001
);
697 CPPUNIT_TEST_SUITE_END();
700 // -----------------------------------------------------------------------------
702 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::create
, "rtl_cipher");
703 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::createBF
, "rtl_cipher");
704 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decode
, "rtl_cipher");
705 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decodeBF
, "rtl_cipher");
706 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroy
, "rtl_cipher");
707 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroyBF
, "rtl_cipher");
708 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encode
, "rtl_cipher");
709 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encodeBF
, "rtl_cipher");
710 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::init
, "rtl_cipher");
711 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::initBF
, "rtl_cipher");
713 } // namespace rtl_cipher
716 // -----------------------------------------------------------------------------
718 // this macro creates an empty function, which will called by the RegisterAllFunctions()
719 // to let the user the possibility to also register some functions by hand.