43.3.4.6 Conditional Copy/Clear
Purpose
This service conditionally performs a copy from a memory area to another or a memory area clear.
How to Use the Service
Description
This service copies a number X into another number R, padding with zero on the MSB side up to the length specified for R. This copy operation is performed under the conditions specified in the options.
If the condition is verified, R = X.
The copy or clear action is made under condition.
The four possible options for the condition are described in the following table. Two of the conditions check the Specific.CarryIn bit (see Accessing Different Library Services).
The processing is done as follows:
- If the condition is not verified, nothing is processed.
- If the condition is verified the copy or clear follows the
rules:
- If the lengths of R and X are equal, a complete fast copy is processed
- If the length of R is strictly greater than the length of X, X is first copied in the Low Significant Bytes side of R, and R is padded with zeros on the Most Significant Bytes side.
- If the pointer on the X area equals zero, R is filled with zeros.
The service name for this operation is
CondCopy
.
Parameters Definition
This service can easily be accessed through the use
of the PUKCL_CondCopy()
and
PUKCL()
macros.
Parameter | Type | Direction | Location | Data Length | Before Executing the Service | After Executing the Service |
---|---|---|---|---|---|---|
u2Options | u2 | I | – | – | Option for condition (see the following table) | Option for condition (see the following table) |
Specific/CarryIn | Bit | I | – | – | Bit CarryIn | Bit CarryIn |
nu1XBase | nu1 | I | Crypto RAM | u2XLength | Base of X | Base of X number untouched |
nu1RBase | nu1 | I | Crypto RAM | u2RLength | Base of R | Base of R filled with X if condition holds |
u2RLength | u2 | I | – | – | Length of R | Length of R |
u2XLength | u2 | I | – | – | Length of X | Length of X |
Available Options
The option for the condition is set by the u2Options input parameter that must take one of the values listed in the following table.
Option | Purpose | Needed parameters |
---|---|---|
PUKCL_CONDCOPY_ALWAYS | Always perform the copy | nu1XBase,u2XLength,nu1RBase, u2RLength |
PUKCL_CONDCOPY_NEVER | Never perform the copy | None |
PUKCL_CONDCOPY_IF_CARRY | Perform the copy if CarryIn is 1 | Specific/CarryIn nu1XBase,u2XLength,nu1RBase, u2RLength |
PUKCL_CONDCOPY_IF_NOT_CARRY | Perform the copy if CarryIn is zero | Specific/CarryIn nu1XBase,u2XLength,nu1RBase, u2RLength |
Code Example
PUKCL_PARAM PUKCLParam;
PPUKCL_PARAM pvPUKCLParam = &PUKCLParam;
// CarryIn shall be beforehand filled (with zero or one) PUKCL(Specific).CarryIn = ...;
// Condition Option PUKCL(u2Options) = ...;
// Initialize parameters
PUKCL_CondCopy(nu1XBase) = <Base of the X number>;
PUKCL_CondCopy(nu1RBase) = <Base of the R number>;
PUKCL_CondCopy(u2XLength) = <Length of the X number>;
PUKCL_CondCopy(u2RLength) = <Length of the R number>;
// vPUKCL_Process() is a macro command, which populates the service name
// and then calls the library...
vPUKCL_Process(CondCopy,pvPUKCLParam);
if (PUKCL(u2Status) == PUKCL_OK)
{
...
}
else // Manage the error
Constraints
The parameters placement that are not allowed are listed below.
If the conditional option and the CarryIn do not lead to execute the copy, no checks are made on the constraints to be respected.
If nu1XBase equals zero, no checks are made on nu1XBase (fixed) and u2XLength (unused).
The following conditions must be avoided to ensure that the service works correctly:
- nu1XBase or nu1RBase are not aligned on 32-bit boundaries
- u2XLength or u2RLength is either: <4, >0xffc or not a 32-bit length or u2XLength >u2RLength
- {nu1XBase, u2XLength} or {nu1RBase, u2RLength} do not entirely lie in Crypto RAM
- {nu1XBase, u2XLength} overlaps {nu1RBase,u2RLength}
Status Returned Values
Returned status | Importance | Meaning |
---|---|---|
PUKCL_WRONG_SERVICE | Severe | An inconsistency has been detected between the called service and the provided service number. |
PUKCL_OK | – | Service functioned correctly |