Some types of cryptography require the handling of finite arbitrary length integers. This big integer library attempts to provide support for that requirement.
It is capable of representing both negative and positive integers with an absolute value of less than 2^(2 37 ).
There are four categories of exposed APIs:
Creation of new integers given some other representation (descriptor, TUint, etc). RInteger::NewL()
Exporting of previously created integers to descriptors. TInteger::BufferLC()
The following code demonstrates how to create an RInteger from a bit string representation of a big integer.
//This creates an RInteger from the following binary hexadecimal (base 16) //descriptor. Note that the number is written overall in big endian (most //significant digit is first, least significant digit (ones digit) is last). //P.S. The hexadecimal binary descriptor below is the base 16 representation //of the base 10 number 123456789012345678901234567890. RInteger integer = RInteger::NewL(_L8("18EE90FF6C373E0EE4E3F0AD2")); CleanupStack::PushL(integer); //This next line converts the number stored by an RInteger into a binary, big //endian, hexadecimal descriptor. HBufC8* descriptor = integer.BufferLC(); CleanupStack::Pop(descriptor); CleanupStack::PopAndDestroy(integer); //descriptor is the same as the original _L8 input value now.
For more information on integers, including important memory management information and additional creation overloads, see RInteger in the Cryptography API Reference material.
The diagram below shows the main classes used in bigint and which are implemented in cryptography.dll . The color of the boxes indicates the type of Symbian class, that is, M , C , R or T class. For detailed information on each component see the Cryptography API Reference material.
RInteger is a TInteger derived class allowing the construction of variable length big integers.
This class follows standard R class rules. As a quick refresher, the following rules apply to RInteger s:
You can construct an empty RInteger .
This is a constructed, but uninitialized integer. It does not own memory and no operations can be performed on it. It is useful, mostly, to assign the result of another integer operation to. Push ing and then PopAndDestroy ing an empty RInteger works, although it's not needed.
RInteger s can be bitwised copied (the default assignment operator and copy constructor are valid), but you need to be careful you don't lose your original memory in the process. You should only use the assignment operator on a newly declared integer. To set an RInteger to another value without losing memory see TInteger::Set() .
You own any RInteger returned by value from a TInteger function.
You must call Close() on all RInteger s that own memory before they go out of scope. (The cleanup stack can do this for you as well, see further bullet points below).
RInteger has a operator TCleanupItem() cast function that allows you to call CleanupStack::PushL(RInteger&) . Use this in preference to CleanupClosePushL(RInteger&) , which although it does the same thing, generates more code.
Be careful calling TInteger::Set() . After calling this, two RInteger s have a pointer to the same heap-based integer. Calling Close() on one, either explicitly or through the cleanup stack, leaves a dangling pointer to the other. You probably want to use code similar to the following:
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License v1.0.