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.

Important: If the condition is verified, the length of R must be greater or equal to the length of X.

Parameters Definition

This service can easily be accessed through the use of the PUKCL_CondCopy() and PUKCL() macros.

Table 43-15. CondCopy Service Parameters
ParameterTypeDirectionLocationData LengthBefore Executing the ServiceAfter Executing the Service
u2Optionsu2IOption for condition (see the following table)Option for condition (see the following table)
Specific/CarryInBitIBit CarryInBit CarryIn
nu1XBasenu1ICrypto RAMu2XLengthBase of XBase of X number untouched
nu1RBasenu1ICrypto RAMu2RLengthBase of RBase of R filled with X if condition holds
u2RLengthu2ILength of RLength of R
u2XLengthu2ILength of XLength 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.

Table 43-16. CondCopy Service Options
OptionPurposeNeeded parameters
PUKCL_CONDCOPY_ALWAYSAlways perform the copynu1XBase,u2XLength,nu1RBase, u2RLength
PUKCL_CONDCOPY_NEVERNever perform the copyNone
PUKCL_CONDCOPY_IF_CARRYPerform the copy if CarryIn is 1Specific/CarryIn nu1XBase,u2XLength,nu1RBase, u2RLength
PUKCL_CONDCOPY_IF_NOT_CARRYPerform the copy if CarryIn is zeroSpecific/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

Table 43-17. CondCopy Service Return Codes
Returned statusImportanceMeaning
PUKCL_WRONG_SERVICESevereAn inconsistency has been detected between the called service and the provided service number.
PUKCL_OKService functioned correctly