os/security/crypto/weakcrypto/test/tasymmetric/tbrokenrandom.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21 */
    22 
    23 #include "tbrokenrandom.h"
    24 
    25 /* CRandomSetSeed */
    26 CRandomSetSource::CRandomSetSource(const TDesC8& aSource)
    27     {
    28 	SetSource(aSource);
    29     }
    30 
    31 void CRandomSetSource::GenerateBytesL(TDes8& aDest) 
    32     {
    33 	if(aDest.Size() <= iValue.Size() - (TInt)iCounter)
    34 		{
    35 		for (int i = 0 ; i < aDest.Length() ; ++i)
    36 			{
    37 			aDest[i] = iValue[iCounter];
    38 			iCounter++;
    39 			} 
    40 		}
    41 	else
    42 		{
    43 		TRandom::RandomL(aDest);
    44 		}
    45     }
    46 
    47 void CRandomSetSource::SetSource(const TDesC8& aSource)
    48 	{
    49 	iValue.Set(aSource);
    50 	iCounter = 0;
    51 	}
    52 
    53 /* CRandomIncrementing */
    54 CRandomIncrementing::CRandomIncrementing(TUint aInitialValue)
    55     {
    56 	iValue = aInitialValue;
    57     }
    58 
    59 void CRandomIncrementing::GenerateBytesL(TDes8& aDest) 
    60     {
    61     for (int i = 0 ; i < aDest.Length() ; ++i)
    62         {
    63         aDest[i] = (char)(iValue)++;
    64         }
    65     }
    66 
    67