xref: /aoo4110/main/sal/qa/rtl/cipher/rtl_cipher.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_sal.hxx"
27 
28 #include <testshl/simpleheader.hxx>
29 #include <rtl/strbuf.hxx>
30 #include <rtl/cipher.h>
31 
32 // -----------------------------------------------------------------------------
33 namespace rtl_cipher
34 {
35 
createHex(sal_uInt8 * _pKeyBuffer,sal_uInt32 _nKeyLen)36 rtl::OString createHex(sal_uInt8 *_pKeyBuffer, sal_uInt32 _nKeyLen)
37 {
38     // Create hex-value string from the  value to keep the string size minimal
39     rtl::OStringBuffer aBuffer( _nKeyLen * 2 + 1 );
40     for ( sal_uInt32 i = 0; i < _nKeyLen; i++ )
41     {
42         sal_Int32 nValue = (sal_Int32)_pKeyBuffer[i];
43         if (nValue < 16)                         // maximul hex value for 1 byte
44         {
45             aBuffer.append( sal_Int32(0), 16 /* radix */ );
46         }
47         aBuffer.append( nValue, 16 /* radix */ );
48     }
49 
50     return aBuffer.makeStringAndClear();
51 }
52 
53 // -----------------------------------------------------------------------------
54 
55 class create : public CppUnit::TestFixture
56 {
57 public:
58     // initialise your test code values here.
setUp()59     void setUp()
60     {
61     }
62 
tearDown()63     void tearDown()
64     {
65     }
66 
create_001()67     void create_001()
68         {
69             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
70             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
71             rtl_cipher_destroy(aCipher);
72         }
create_002()73     void create_002()
74         {
75             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
76             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
77         }
create_003()78     void create_003()
79         {
80             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
81             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
82             rtl_cipher_destroy(aCipher);
83         }
create_004()84     void create_004()
85         {
86             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
87             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
88         }
create_005()89     void create_005()
90         {
91             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
92             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
93             rtl_cipher_destroy(aCipher);
94         }
create_006()95     void create_006()
96         {
97             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
98             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
99         }
create_007()100     void create_007()
101         {
102             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
103             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
104         }
create_008()105     void create_008()
106         {
107             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
108             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
109         }
110 
111     // Change the following lines only, if you add, remove or rename
112     // member functions of the current class,
113     // because these macros are need by auto register mechanism.
114 
115     CPPUNIT_TEST_SUITE(create);
116     CPPUNIT_TEST(create_001);
117     CPPUNIT_TEST(create_002);
118     CPPUNIT_TEST(create_003);
119     CPPUNIT_TEST(create_004);
120     CPPUNIT_TEST(create_005);
121     CPPUNIT_TEST(create_006);
122     CPPUNIT_TEST(create_007);
123     CPPUNIT_TEST(create_008);
124     CPPUNIT_TEST_SUITE_END();
125 }; // class create
126 
127 // -----------------------------------------------------------------------------
128 class createBF : public CppUnit::TestFixture
129 {
130 public:
131     // initialise your test code values here.
setUp()132     void setUp()
133     {
134     }
135 
tearDown()136     void tearDown()
137     {
138     }
139 
createBF_001()140     void createBF_001()
141         {
142             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
143             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
144             rtl_cipher_destroy(aCipher);
145         }
createBF_002()146     void createBF_002()
147         {
148             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
149             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
150             rtl_cipher_destroy(aCipher);
151         }
createBF_003()152     void createBF_003()
153         {
154             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
155             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
156             rtl_cipher_destroy(aCipher);
157         }
createBF_004()158     void createBF_004()
159         {
160             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
161             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
162             // rtl_cipher_destroy(aCipher);
163         }
164     // Change the following lines only, if you add, remove or rename
165     // member functions of the current class,
166     // because these macros are need by auto register mechanism.
167 
168     CPPUNIT_TEST_SUITE(createBF);
169     CPPUNIT_TEST(createBF_001);
170     CPPUNIT_TEST(createBF_002);
171     CPPUNIT_TEST(createBF_003);
172     CPPUNIT_TEST(createBF_004);
173     CPPUNIT_TEST_SUITE_END();
174 }; // class createBF
175 // -----------------------------------------------------------------------------
176 class decode : public CppUnit::TestFixture
177 {
178 public:
179     // initialise your test code values here.
setUp()180     void setUp()
181     {
182     }
183 
tearDown()184     void tearDown()
185     {
186     }
187 
test_encode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,rtl::OString const & _sPlainTextStr)188     void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
189         {
190             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
191             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
192 
193             sal_uInt32     nKeyLen = 16;
194             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
195             memset(pKeyBuffer, 0, nKeyLen);
196             pKeyBuffer[0] = _nKeyValue;
197 
198             sal_uInt32     nArgLen = 16;
199             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
200             memset(pArgBuffer, 0, nArgLen);
201             pArgBuffer[0] = _nArgValue;
202 
203             t_print(T_VERBOSE, "  init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
204             t_print(T_VERBOSE, "  init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
205 
206             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
207             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
208 
209             sal_uInt32     nPlainTextLen = 16;
210             sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
211             memset(pPlainTextBuffer, 0, nPlainTextLen);
212             strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
213 
214             sal_uInt32     nCipherLen = 16;
215             sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
216             memset(pCipherBuffer, 0, nCipherLen);
217 
218             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
219             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
220 
221             t_print(T_VERBOSE, "       Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
222             t_print(T_VERBOSE, "       Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
223             t_print(T_VERBOSE, "     Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
224             t_print(           "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
225 
226             sal_uInt32     nPlainText2Len = 16;
227             sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
228             memset(pPlainText2Buffer, 0, nPlainText2Len);
229 
230             /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
231             CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None);
232 
233             // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
234             // t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
235             // t_print(T_VERBOSE, " ascii: %s\n", sPlainText2Str.getStr());
236             //
237             // // t_print("   Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
238             //
239             // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
240             //
241             // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
242             //
243             // delete [] pPlainText2Buffer;
244             //
245             // delete [] pCipherBuffer;
246             // delete [] pPlainTextBuffer;
247             //
248             // delete [] pArgBuffer;
249             // delete [] pKeyBuffer;
250             //
251             // rtl_cipher_destroy(aCipher);
252         }
253 
test_encode_and_decode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,rtl::OString const & _sPlainTextStr)254     void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
255         {
256             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
257             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
258 
259             sal_uInt32     nKeyLen = 16;
260             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
261             memset(pKeyBuffer, 0, nKeyLen);
262             pKeyBuffer[0] = _nKeyValue;
263 
264             sal_uInt32     nArgLen = 16;
265             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
266             memset(pArgBuffer, 0, nArgLen);
267             pArgBuffer[0] = _nArgValue;
268 
269             t_print(T_VERBOSE, "  init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
270             t_print(T_VERBOSE, "  init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
271 
272             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
273             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
274 
275             sal_uInt32     nPlainTextLen = 16;
276             sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
277             memset(pPlainTextBuffer, 0, nPlainTextLen);
278             strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
279 
280             sal_uInt32     nCipherLen = 16;
281             sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
282             memset(pCipherBuffer, 0, nCipherLen);
283 
284             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
285             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
286 
287             t_print(T_VERBOSE, "       Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
288             t_print(T_VERBOSE, "       Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
289             t_print(T_VERBOSE, "     Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
290             t_print(           "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
291 
292             sal_uInt32     nPlainText2Len = 16;
293             sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
294             memset(pPlainText2Buffer, 0, nPlainText2Len);
295 
296             /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
297             CPPUNIT_ASSERT_MESSAGE("wrong decode", aError == rtl_Cipher_E_None);
298 
299             rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
300             t_print(T_VERBOSE, "     Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
301             t_print(T_VERBOSE, "  as ascii: %s\n", sPlainText2Str.getStr());
302 
303             // t_print("   Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
304 
305             sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
306 
307             CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
308 
309             delete [] pPlainText2Buffer;
310 
311             delete [] pCipherBuffer;
312             delete [] pPlainTextBuffer;
313 
314             delete [] pArgBuffer;
315             delete [] pKeyBuffer;
316 
317             rtl_cipher_destroy(aCipher);
318         }
319 
decode_001()320     void decode_001()
321         {
322             test_encode_and_decode(0,0,"");
323             test_encode_and_decode(0,0,"hallo");
324             test_encode_and_decode(1,0,"B2Aahg5B");
325             test_encode_and_decode(1,2,"Longer text string");
326         }
327 
decode_002()328     void decode_002()
329         {
330             test_encode(0,0,"");
331             test_encode(0,0,"hallo");
332             test_encode(1,0,"B2Aahg5B");
333             test_encode(1,2,"Longer text string");
334         }
335     // Change the following lines only, if you add, remove or rename
336     // member functions of the current class,
337     // because these macros are need by auto register mechanism.
338 
339     CPPUNIT_TEST_SUITE(decode);
340     CPPUNIT_TEST(decode_001);
341     CPPUNIT_TEST(decode_002);
342     CPPUNIT_TEST_SUITE_END();
343 }; // class decode
344 // -----------------------------------------------------------------------------
345 class decodeBF : public CppUnit::TestFixture
346 {
347 public:
348     // initialise your test code values here.
setUp()349     void setUp()
350     {
351     }
352 
tearDown()353     void tearDown()
354     {
355     }
356 
decodeBF_001()357     void decodeBF_001()
358         {
359         }
360     // Change the following lines only, if you add, remove or rename
361     // member functions of the current class,
362     // because these macros are need by auto register mechanism.
363 
364     CPPUNIT_TEST_SUITE(decodeBF);
365     CPPUNIT_TEST(decodeBF_001);
366     CPPUNIT_TEST_SUITE_END();
367 }; // class decodeBF
368 // -----------------------------------------------------------------------------
369 class destroy : public CppUnit::TestFixture
370 {
371 public:
372     // initialise your test code values here.
setUp()373     void setUp()
374     {
375     }
376 
tearDown()377     void tearDown()
378     {
379     }
380 
destroy_001()381     void destroy_001()
382         {
383             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
384             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
385             rtl_cipher_destroy(aCipher);
386         }
387     // Change the following lines only, if you add, remove or rename
388     // member functions of the current class,
389     // because these macros are need by auto register mechanism.
390 
391     CPPUNIT_TEST_SUITE(destroy);
392     CPPUNIT_TEST(destroy_001);
393     CPPUNIT_TEST_SUITE_END();
394 }; // class destroy
395 // -----------------------------------------------------------------------------
396 class destroyBF : public CppUnit::TestFixture
397 {
398 public:
399     // initialise your test code values here.
setUp()400     void setUp()
401     {
402     }
403 
tearDown()404     void tearDown()
405     {
406     }
407 
destroyBF_001()408     void destroyBF_001()
409         {
410             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
411             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
412             rtl_cipher_destroyBF(aCipher);
413             // more proforma
414             // should not GPF
415         }
416     // Change the following lines only, if you add, remove or rename
417     // member functions of the current class,
418     // because these macros are need by auto register mechanism.
419 
420     CPPUNIT_TEST_SUITE(destroyBF);
421     CPPUNIT_TEST(destroyBF_001);
422     CPPUNIT_TEST_SUITE_END();
423 }; // class destroyBF
424 // -----------------------------------------------------------------------------
425 class encode : public CppUnit::TestFixture
426 {
427 public:
428     // initialise your test code values here.
setUp()429     void setUp()
430     {
431     }
432 
tearDown()433     void tearDown()
434     {
435     }
436 
test_encode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,sal_uInt8 _nDataValue)437     void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
438         {
439             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
440             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
441 
442             sal_uInt32     nKeyLen = 16;
443             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
444             memset(pKeyBuffer, 0, nKeyLen);
445             pKeyBuffer[0] = _nKeyValue;
446 
447             sal_uInt32     nArgLen = 16;
448             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
449             memset(pArgBuffer, 0, nArgLen);
450             pArgBuffer[0] = _nArgValue;
451 
452             t_print(T_VERBOSE, "init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
453             t_print(T_VERBOSE, "init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
454 
455             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
456             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
457 
458             sal_uInt32     nDataLen = 16;
459             sal_uInt8     *pDataBuffer = new sal_uInt8[ nDataLen ];
460             memset(pDataBuffer, 0, nDataLen);
461             pDataBuffer[0] = _nDataValue;
462 
463             sal_uInt32     nLen = 16;
464             sal_uInt8     *pBuffer = new sal_uInt8[ nLen ];
465             memset(pBuffer, 0, nLen);
466 
467             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
468             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
469 
470             t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
471             t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
472             t_print(T_VERBOSE, "Data: %s\n", createHex(pDataBuffer, nDataLen).getStr());
473             t_print(T_VERBOSE, " Buf: %s\n", createHex(pBuffer, nLen).getStr());
474 
475             delete [] pBuffer;
476             delete [] pDataBuffer;
477 
478             delete [] pArgBuffer;
479             delete [] pKeyBuffer;
480 
481             rtl_cipher_destroy(aCipher);
482         }
483 
encode_001()484     void encode_001()
485         {
486             test_encode(0,0,0);
487             test_encode(1,0,0);
488             test_encode(0,1,0);
489             test_encode(1,1,0);
490 
491             test_encode(0,0,1);
492             test_encode(1,0,1);
493             test_encode(0,1,1);
494             test_encode(1,1,1);
495         }
496 
497     // Change the following lines only, if you add, remove or rename
498     // member functions of the current class,
499     // because these macros are need by auto register mechanism.
500 
501     CPPUNIT_TEST_SUITE(encode);
502     CPPUNIT_TEST(encode_001);
503     CPPUNIT_TEST_SUITE_END();
504 }; // class encode
505 // -----------------------------------------------------------------------------
506 class encodeBF : public CppUnit::TestFixture
507 {
508 public:
509     // initialise your test code values here.
setUp()510     void setUp()
511     {
512     }
513 
tearDown()514     void tearDown()
515     {
516     }
517 
encodeBF_001()518     void encodeBF_001()
519         {
520         }
521     // Change the following lines only, if you add, remove or rename
522     // member functions of the current class,
523     // because these macros are need by auto register mechanism.
524 
525     CPPUNIT_TEST_SUITE(encodeBF);
526     CPPUNIT_TEST(encodeBF_001);
527     CPPUNIT_TEST_SUITE_END();
528 }; // class encodeBF
529 // -----------------------------------------------------------------------------
530 class init : public CppUnit::TestFixture
531 {
532 public:
533     // initialise your test code values here.
setUp()534     void setUp()
535     {
536     }
537 
tearDown()538     void tearDown()
539     {
540     }
541 
init_001()542     void init_001()
543         {
544             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
545             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
546 
547             sal_uInt32     nKeyLen = 16;
548             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
549             memset(pKeyBuffer, 0, nKeyLen);
550 
551             sal_uInt32     nArgLen = 16;
552             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
553             memset(pArgBuffer, 0, nArgLen);
554 
555             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
556             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
557 
558             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
559             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
560 
561             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
562             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
563 
564             delete [] pArgBuffer;
565             delete [] pKeyBuffer;
566 
567             rtl_cipher_destroy(aCipher);
568         }
569 
init_002()570     void init_002()
571         {
572             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
573             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
574 
575             sal_uInt32     nKeyLen = 16;
576             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
577             memset(pKeyBuffer, 0, nKeyLen);
578             pKeyBuffer[0] = 1;
579 
580             sal_uInt32     nArgLen = 16;
581             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
582             memset(pArgBuffer, 0, nArgLen);
583 
584             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
585             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
586 
587             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
588             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
589 
590             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
591             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
592 
593             delete [] pArgBuffer;
594             delete [] pKeyBuffer;
595 
596             rtl_cipher_destroy(aCipher);
597         }
init_003()598     void init_003()
599         {
600             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
601             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
602 
603             sal_uInt32     nKeyLen = 16;
604             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
605             memset(pKeyBuffer, 0, nKeyLen);
606 
607             sal_uInt32     nArgLen = 16;
608             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
609             memset(pArgBuffer, 0, nArgLen);
610             pArgBuffer[0] = 1;
611 
612             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
613             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
614 
615             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
616             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
617 
618             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
619             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
620 
621             delete [] pArgBuffer;
622             delete [] pKeyBuffer;
623 
624             rtl_cipher_destroy(aCipher);
625         }
init_004()626     void init_004()
627         {
628             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
629             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
630 
631             sal_uInt32     nKeyLen = 16;
632             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
633             memset(pKeyBuffer, 0, nKeyLen);
634             pKeyBuffer[0] = 1;
635 
636             sal_uInt32     nArgLen = 16;
637             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
638             memset(pArgBuffer, 0, nArgLen);
639             pArgBuffer[0] = 1;
640 
641             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
642             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
643 
644             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
645             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
646 
647             t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
648             t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
649 
650             delete [] pArgBuffer;
651             delete [] pKeyBuffer;
652 
653             rtl_cipher_destroy(aCipher);
654         }
655     // Change the following lines only, if you add, remove or rename
656     // member functions of the current class,
657     // because these macros are need by auto register mechanism.
658 
659     CPPUNIT_TEST_SUITE(init);
660     CPPUNIT_TEST(init_001);
661     CPPUNIT_TEST(init_002);
662     CPPUNIT_TEST(init_003);
663     CPPUNIT_TEST(init_004);
664     CPPUNIT_TEST_SUITE_END();
665 }; // class init
666 // -----------------------------------------------------------------------------
667 class initBF : public CppUnit::TestFixture
668 {
669 public:
670     // initialise your test code values here.
setUp()671     void setUp()
672     {
673     }
674 
tearDown()675     void tearDown()
676     {
677     }
678 
initBF_001()679     void initBF_001()
680         {
681             // seems to be the same as init, so empty
682         }
683 
684     // Change the following lines only, if you add, remove or rename
685     // member functions of the current class,
686     // because these macros are need by auto register mechanism.
687 
688     CPPUNIT_TEST_SUITE(initBF);
689     CPPUNIT_TEST(initBF_001);
690     CPPUNIT_TEST_SUITE_END();
691 }; // class initBF
692 
693 // -----------------------------------------------------------------------------
694 
695 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::create, "rtl_cipher");
696 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::createBF, "rtl_cipher");
697 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decode, "rtl_cipher");
698 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decodeBF, "rtl_cipher");
699 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroy, "rtl_cipher");
700 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroyBF, "rtl_cipher");
701 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encode, "rtl_cipher");
702 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encodeBF, "rtl_cipher");
703 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::init, "rtl_cipher");
704 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::initBF, "rtl_cipher");
705 
706 } // namespace rtl_cipher
707 
708 
709 // -----------------------------------------------------------------------------
710 
711 // this macro creates an empty function, which will called by the RegisterAllFunctions()
712 // to let the user the possibility to also register some functions by hand.
713 NOADDITIONAL;
714