crypto/weakcryptospi/test/tpadding/tpaddingPKCS1.cpp
branchRCL_3
changeset 41 9b5a3a9fddf8
parent 8 35751d3474b7
equal deleted inserted replaced
37:721a5e5fe251 41:9b5a3a9fddf8
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <random.h>
    19 #include <random.h>
    20 #include <padding.h>
    20 #include <padding.h>
       
    21 #include <securityerr.h>
    21 #include "tpaddingPKCS1.h"
    22 #include "tpaddingPKCS1.h"
    22 
    23 
    23 CTestPadPKCS1::CTestPadPKCS1()
    24 CTestPadPKCS1::CTestPadPKCS1()
    24 {
    25 {
    25    SetTestStepName(KPadPKCS1);
    26    SetTestStepName(KPadPKCS1);
   279       TInt endOfPadding = aBlockSize - 1 - i;
   280       TInt endOfPadding = aBlockSize - 1 - i;
   280       in.SetLength(endOfPadding+1);
   281       in.SetLength(endOfPadding+1);
   281       in[0] = 0;
   282       in[0] = 0;
   282       in[1] = 2;
   283       in[1] = 2;
   283       TBuf8<256> rnd(256);
   284       TBuf8<256> rnd(256);
   284       GenerateRandomBytesL(rnd);
   285       TRAPD(err, GenerateRandomBytesL(rnd));
       
   286       if((err != KErrNone) && (err != KErrNotSecure))
       
   287           User::Leave(err);
       
   288 
   285 
   289 
   286       TInt k = 2;
   290       TInt k = 2;
   287       TInt j = 0;
   291       TInt j = 0;
   288       while (k < endOfPadding)
   292       while (k < endOfPadding)
   289       {
   293       {
   292             in[k++] = rnd[j%256];
   296             in[k++] = rnd[j%256];
   293          }
   297          }
   294          
   298          
   295          if (++j%256 == 0)
   299          if (++j%256 == 0)
   296          {
   300          {
   297             GenerateRandomBytesL(rnd);
   301          TRAP(err, GenerateRandomBytesL(rnd));
       
   302          if((err != KErrNone) && (err != KErrNotSecure))
       
   303              User::Leave(err);
   298          }
   304          }
   299       }
   305       }
   300       in[endOfPadding] = 0; // delimiter
   306       in[endOfPadding] = 0; // delimiter
   301 
   307 
   302       for (j = 0; j < i; j++)
   308       for (j = 0; j < i; j++)
   304 	 TInt text('a'+j%25);
   310 	 TInt text('a'+j%25);
   305 	 in.Append(text);
   311 	 in.Append(text);
   306      comp.Append(text);
   312      comp.Append(text);
   307       }
   313       }
   308 
   314 
   309       TRAPD(err, padding->UnPadL(in, out));
   315       TRAP(err, padding->UnPadL(in, out));
   310       TEST(err == KErrNone);
   316       TEST(err == KErrNone);
   311 
   317 
   312 	  TEST(out == comp);		  
   318 	  TEST(out == comp);		  
   313 
   319 
   314       TEST(out.Length() == i);
   320       TEST(out.Length() == i);