1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tutils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,67 @@
1.4 +/*
1.5 +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "tutils.h"
1.23 +#include <bigint.h>
1.24 +#include "t_output.h"
1.25 +
1.26 +void Utils::DumpInteger(Output& aOut, const TDesC& aDesc,
1.27 + const RInteger& aThat)
1.28 + {
1.29 + aOut.writeString(aDesc);
1.30 + HBufC8* buf = aThat.BufferLC();
1.31 + aOut.writeOctetString(*buf);
1.32 + aOut.writeNewLine();
1.33 + CleanupStack::PopAndDestroy(buf);
1.34 + }
1.35 +
1.36 +
1.37 +/* CRandomSetSource */
1.38 +CRandomSetSource::CRandomSetSource(const TDesC8& aSource)
1.39 + {
1.40 + SetSource(aSource);
1.41 + }
1.42 +
1.43 +void CRandomSetSource::GenerateBytesL(TDes8& aDest)
1.44 + {
1.45 + TInt i=0;
1.46 + //Reverse the string by bytes up to the point of the end of the given string
1.47 + //of "random" bytes.
1.48 + for (i=0; iCounter >= 0 && i< aDest.Length(); ++i,--iCounter)
1.49 + {
1.50 + aDest[i] = iValue[iCounter];
1.51 + }
1.52 + //Then fill the remaining (if any) bytes in aDest with 0's. This is all to
1.53 + //allow the stuff to work with bigint style integers; we're writing straight
1.54 + //into a RInteger.Ptr() here
1.55 + for(;i<aDest.Length(); ++i)
1.56 + {
1.57 + aDest[i] = 0x00;
1.58 + }
1.59 + }
1.60 +
1.61 +void CRandomSetSource::SetSource(const TDesC8& aSource)
1.62 + {
1.63 + iValue.Set(aSource);
1.64 + Reset();
1.65 + }
1.66 +
1.67 +void CRandomSetSource::Reset(void)
1.68 + {
1.69 + iCounter = iValue.Length() - 1;
1.70 + }