xref: /aoo42x/main/sal/qa/rtl/cipher/rtl_cipher.cxx (revision af2711e0)
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 "gtest/gtest.h"
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), sal_Int16(16) /* radix */ );
46         }
47         aBuffer.append( nValue, 16 /* radix */ );
48     }
49 
50     return aBuffer.makeStringAndClear();
51 }
52 
53 // -----------------------------------------------------------------------------
54 
55 class create : public ::testing::Test
56 {
57 public:
58     // initialise your test code values here.
SetUp()59     void SetUp()
60     {
61     }
62 
TearDown()63     void TearDown()
64     {
65     }
66 }; // class create
67 
TEST_F(create,create_001)68 TEST_F(create, create_001)
69 {
70     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
71     ASSERT_TRUE(aCipher != NULL) << "create failed.";
72     rtl_cipher_destroy(aCipher);
73 }
TEST_F(create,create_002)74 TEST_F(create, create_002)
75 {
76     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
77     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
78 }
TEST_F(create,create_003)79 TEST_F(create, create_003)
80 {
81     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
82     ASSERT_TRUE(aCipher != NULL) << "create failed.";
83     rtl_cipher_destroy(aCipher);
84 }
TEST_F(create,create_004)85 TEST_F(create, create_004)
86 {
87     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
88     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
89 }
TEST_F(create,create_005)90 TEST_F(create, create_005)
91 {
92     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
93     ASSERT_TRUE(aCipher != NULL) << "create failed.";
94     rtl_cipher_destroy(aCipher);
95 }
TEST_F(create,create_006)96 TEST_F(create, create_006)
97 {
98     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
99     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
100 }
TEST_F(create,create_007)101 TEST_F(create, create_007)
102 {
103     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
104     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
105 }
TEST_F(create,create_008)106 TEST_F(create, create_008)
107 {
108     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
109     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
110 }
111 // -----------------------------------------------------------------------------
112 class createBF : public ::testing::Test
113 {
114 public:
115     // initialise your test code values here.
SetUp()116     void SetUp()
117     {
118     }
119 
TearDown()120     void TearDown()
121     {
122     }
123 }; // class createBF
124 
TEST_F(createBF,createBF_001)125 TEST_F(createBF, createBF_001)
126 {
127     rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
128     ASSERT_TRUE(aCipher != NULL) << "create failed.";
129     rtl_cipher_destroy(aCipher);
130 }
TEST_F(createBF,createBF_002)131 TEST_F(createBF, createBF_002)
132 {
133     rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
134     ASSERT_TRUE(aCipher != NULL) << "create failed.";
135     rtl_cipher_destroy(aCipher);
136 }
TEST_F(createBF,createBF_003)137 TEST_F(createBF, createBF_003)
138 {
139     rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
140     ASSERT_TRUE(aCipher != NULL) << "create failed.";
141     rtl_cipher_destroy(aCipher);
142 }
TEST_F(createBF,createBF_004)143 TEST_F(createBF, createBF_004)
144 {
145     rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
146     ASSERT_TRUE(aCipher == NULL) << "create provide wrong object.";
147     // rtl_cipher_destroy(aCipher);
148 }
149 // -----------------------------------------------------------------------------
150 class decode : public ::testing::Test
151 {
152 public:
153     // initialise your test code values here.
SetUp()154     void SetUp()
155     {
156     }
157 
TearDown()158     void TearDown()
159     {
160     }
161 
test_encode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,rtl::OString const & _sPlainTextStr)162     void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
163     {
164         rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
165         ASSERT_TRUE(aCipher != NULL) << "create failed.";
166 
167         sal_uInt32     nKeyLen = 16;
168         sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
169         memset(pKeyBuffer, 0, nKeyLen);
170         pKeyBuffer[0] = _nKeyValue;
171 
172         sal_uInt32     nArgLen = 16;
173         sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
174         memset(pArgBuffer, 0, nArgLen);
175         pArgBuffer[0] = _nArgValue;
176 
177         printf("  init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
178         printf("  init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
179 
180         rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
181         ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
182 
183         sal_uInt32     nPlainTextLen = 16;
184         sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
185         memset(pPlainTextBuffer, 0, nPlainTextLen);
186         strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
187 
188         sal_uInt32     nCipherLen = 16;
189         sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
190         memset(pCipherBuffer, 0, nCipherLen);
191 
192         /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
193         ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong encode";
194 
195         printf("       Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
196         printf("       Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
197         printf("     Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
198         printf(           "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
199 
200         sal_uInt32     nPlainText2Len = 16;
201         sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
202         memset(pPlainText2Buffer, 0, nPlainText2Len);
203 
204         /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
205         ASSERT_TRUE(aError != rtl_Cipher_E_None) << "decode should not work";
206 
207         // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
208         // printf(" Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
209         // printf(" ascii: %s\n", sPlainText2Str.getStr());
210         //
211         // // printf("   Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
212         //
213         // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
214         //
215         // ASSERT_TRUE(nCompare == 0) << "compare between plain and decoded plain failed";
216         //
217         // delete [] pPlainText2Buffer;
218         //
219         // delete [] pCipherBuffer;
220         // delete [] pPlainTextBuffer;
221         //
222         // delete [] pArgBuffer;
223         // delete [] pKeyBuffer;
224         //
225         // rtl_cipher_destroy(aCipher);
226     }
227 
test_encode_and_decode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,rtl::OString const & _sPlainTextStr)228     void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
229     {
230         rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
231         ASSERT_TRUE(aCipher != NULL) << "create failed.";
232 
233         sal_uInt32     nKeyLen = 16;
234         sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
235         memset(pKeyBuffer, 0, nKeyLen);
236         pKeyBuffer[0] = _nKeyValue;
237 
238         sal_uInt32     nArgLen = 16;
239         sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
240         memset(pArgBuffer, 0, nArgLen);
241         pArgBuffer[0] = _nArgValue;
242 
243         printf("  init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
244         printf("  init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
245 
246         rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
247         ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
248 
249         sal_uInt32     nPlainTextLen = 16;
250         sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
251         memset(pPlainTextBuffer, 0, nPlainTextLen);
252         strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
253 
254         sal_uInt32     nCipherLen = 16;
255         sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
256         memset(pCipherBuffer, 0, nCipherLen);
257 
258         /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
259         ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong encode";
260 
261         printf("       Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
262         printf("       Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
263         printf("     Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
264         printf(           "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
265 
266         sal_uInt32     nPlainText2Len = 16;
267         sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
268         memset(pPlainText2Buffer, 0, nPlainText2Len);
269 
270         /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
271         ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong decode";
272 
273         rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
274         printf("     Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
275         printf("  as ascii: %s\n", sPlainText2Str.getStr());
276 
277         // printf("   Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
278 
279         sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
280 
281         ASSERT_TRUE(nCompare == 0) << "compare between plain and decoded plain failed";
282 
283         delete [] pPlainText2Buffer;
284 
285         delete [] pCipherBuffer;
286         delete [] pPlainTextBuffer;
287 
288         delete [] pArgBuffer;
289         delete [] pKeyBuffer;
290 
291         rtl_cipher_destroy(aCipher);
292     }
293 }; // class decode
294 
TEST_F(decode,decode_001)295 TEST_F(decode, decode_001)
296 {
297     test_encode_and_decode(0,0,"");
298     test_encode_and_decode(0,0,"hallo");
299     test_encode_and_decode(1,0,"B2Aahg5B");
300     test_encode_and_decode(1,2,"Longer text string");
301 }
302 
TEST_F(decode,decode_002)303 TEST_F(decode, decode_002)
304 {
305     test_encode(0,0,"");
306     test_encode(0,0,"hallo");
307     test_encode(1,0,"B2Aahg5B");
308     test_encode(1,2,"Longer text string");
309 }
310 // -----------------------------------------------------------------------------
311 class decodeBF : public ::testing::Test
312 {
313 public:
314     // initialise your test code values here.
SetUp()315     void SetUp()
316     {
317     }
318 
TearDown()319     void TearDown()
320     {
321     }
322 }; // class decodeBF
323 
TEST_F(decodeBF,decodeBF_001)324 TEST_F(decodeBF, decodeBF_001)
325 {
326 }
327 
328 // -----------------------------------------------------------------------------
329 class destroy : public ::testing::Test
330 {
331 public:
332     // initialise your test code values here.
SetUp()333     void SetUp()
334     {
335     }
336 
TearDown()337     void TearDown()
338     {
339     }
340 }; // class destroy
341 
TEST_F(destroy,destroy_001)342 TEST_F(destroy, destroy_001)
343 {
344     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
345     ASSERT_TRUE(aCipher != NULL) << "create failed.";
346     rtl_cipher_destroy(aCipher);
347 }
348 
349 // -----------------------------------------------------------------------------
350 class destroyBF : public ::testing::Test
351 {
352 public:
353     // initialise your test code values here.
SetUp()354     void SetUp()
355     {
356     }
357 
TearDown()358     void TearDown()
359     {
360     }
361 }; // class destroyBF
362 
TEST_F(destroyBF,destroyBF_001)363 TEST_F(destroyBF, destroyBF_001)
364 {
365     rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
366     ASSERT_TRUE(aCipher != NULL) << "create failed.";
367     rtl_cipher_destroyBF(aCipher);
368     // more proforma
369     // should not GPF
370 }
371 
372 // -----------------------------------------------------------------------------
373 class encode : public ::testing::Test
374 {
375 public:
376     // initialise your test code values here.
SetUp()377     void SetUp()
378     {
379     }
380 
TearDown()381     void TearDown()
382     {
383     }
384 }; // class encode
385 
test_encode(sal_uInt8 _nKeyValue,sal_uInt8 _nArgValue,sal_uInt8 _nDataValue)386 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
387 {
388     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
389     ASSERT_TRUE(aCipher != NULL) << "create failed.";
390 
391     sal_uInt32     nKeyLen = 16;
392     sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
393     memset(pKeyBuffer, 0, nKeyLen);
394     pKeyBuffer[0] = _nKeyValue;
395 
396     sal_uInt32     nArgLen = 16;
397     sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
398     memset(pArgBuffer, 0, nArgLen);
399     pArgBuffer[0] = _nArgValue;
400 
401     printf("init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
402     printf("init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
403 
404     rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
405     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
406 
407     sal_uInt32     nDataLen = 16;
408     sal_uInt8     *pDataBuffer = new sal_uInt8[ nDataLen ];
409     memset(pDataBuffer, 0, nDataLen);
410     pDataBuffer[0] = _nDataValue;
411 
412     sal_uInt32     nLen = 16;
413     sal_uInt8     *pBuffer = new sal_uInt8[ nLen ];
414     memset(pBuffer, 0, nLen);
415 
416     /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
417     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong encode";
418 
419     printf(" Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
420     printf(" Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
421     printf("Data: %s\n", createHex(pDataBuffer, nDataLen).getStr());
422     printf(" Buf: %s\n", createHex(pBuffer, nLen).getStr());
423 
424     delete [] pBuffer;
425     delete [] pDataBuffer;
426 
427     delete [] pArgBuffer;
428     delete [] pKeyBuffer;
429 
430     rtl_cipher_destroy(aCipher);
431 }
432 
encode_001()433 void encode_001()
434 {
435     test_encode(0,0,0);
436     test_encode(1,0,0);
437     test_encode(0,1,0);
438     test_encode(1,1,0);
439 
440     test_encode(0,0,1);
441     test_encode(1,0,1);
442     test_encode(0,1,1);
443     test_encode(1,1,1);
444 }
445 // -----------------------------------------------------------------------------
446 class encodeBF : public ::testing::Test
447 {
448 public:
449     // initialise your test code values here.
SetUp()450     void SetUp()
451     {
452     }
453 
TearDown()454     void TearDown()
455     {
456     }
457 }; // class encodeBF
458 
TEST_F(encodeBF,encodeBF_001)459 TEST_F(encodeBF, encodeBF_001)
460 {
461 }
462 
463 // -----------------------------------------------------------------------------
464 class init : public ::testing::Test
465 {
466 public:
467     // initialise your test code values here.
SetUp()468     void SetUp()
469     {
470     }
471 
TearDown()472     void TearDown()
473     {
474     }
475 }; // class init
476 
TEST_F(init,init_001)477 TEST_F(init, init_001)
478 {
479     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
480     ASSERT_TRUE(aCipher != NULL) << "create failed.";
481 
482     sal_uInt32     nKeyLen = 16;
483     sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
484     memset(pKeyBuffer, 0, nKeyLen);
485 
486     sal_uInt32     nArgLen = 16;
487     sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
488     memset(pArgBuffer, 0, nArgLen);
489 
490     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
491     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
492 
493     rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
494     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
495 
496     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
497     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
498 
499     delete [] pArgBuffer;
500     delete [] pKeyBuffer;
501 
502     rtl_cipher_destroy(aCipher);
503 }
504 
TEST_F(init,init_002)505 TEST_F(init, init_002)
506 {
507     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
508     ASSERT_TRUE(aCipher != NULL) << "create failed.";
509 
510     sal_uInt32     nKeyLen = 16;
511     sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
512     memset(pKeyBuffer, 0, nKeyLen);
513     pKeyBuffer[0] = 1;
514 
515     sal_uInt32     nArgLen = 16;
516     sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
517     memset(pArgBuffer, 0, nArgLen);
518 
519     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
520     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
521 
522     rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
523     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
524 
525     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
526     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
527 
528     delete [] pArgBuffer;
529     delete [] pKeyBuffer;
530 
531     rtl_cipher_destroy(aCipher);
532 }
TEST_F(init,init_003)533 TEST_F(init, init_003)
534 {
535     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
536     ASSERT_TRUE(aCipher != NULL) << "create failed.";
537 
538     sal_uInt32     nKeyLen = 16;
539     sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
540     memset(pKeyBuffer, 0, nKeyLen);
541 
542     sal_uInt32     nArgLen = 16;
543     sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
544     memset(pArgBuffer, 0, nArgLen);
545     pArgBuffer[0] = 1;
546 
547     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
548     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
549 
550     rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
551     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
552 
553     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
554     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
555 
556     delete [] pArgBuffer;
557     delete [] pKeyBuffer;
558 
559     rtl_cipher_destroy(aCipher);
560 }
TEST_F(init,init_004)561 TEST_F(init, init_004)
562 {
563     rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
564     ASSERT_TRUE(aCipher != NULL) << "create failed.";
565 
566     sal_uInt32     nKeyLen = 16;
567     sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
568     memset(pKeyBuffer, 0, nKeyLen);
569     pKeyBuffer[0] = 1;
570 
571     sal_uInt32     nArgLen = 16;
572     sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
573     memset(pArgBuffer, 0, nArgLen);
574     pArgBuffer[0] = 1;
575 
576     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
577     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
578 
579     rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
580     ASSERT_TRUE(aError == rtl_Cipher_E_None) << "wrong init";
581 
582     printf("Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
583     printf("Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
584 
585     delete [] pArgBuffer;
586     delete [] pKeyBuffer;
587 
588     rtl_cipher_destroy(aCipher);
589 }
590 // -----------------------------------------------------------------------------
591 class initBF : public ::testing::Test
592 {
593 public:
594     // initialise your test code values here.
SetUp()595     void SetUp()
596     {
597     }
598 
TearDown()599     void TearDown()
600     {
601     }
602 }; // class initBF
603 
TEST_F(initBF,initBF_001)604 TEST_F(initBF, initBF_001)
605 {
606     // seems to be the same as init, so empty
607 }
608 
609 
610 } // namespace rtl_cipher
611 
main(int argc,char ** argv)612 int main(int argc, char **argv)
613 {
614     ::testing::InitGoogleTest(&argc, argv);
615     return RUN_ALL_TESTS();
616 }
617