37.3.4.3 Swap

Purpose

This service performs swapping of two buffers.

How to Use the Service

Description

This service swaps two buffers, X and Y, of the same size in memory.

The service name for this operation is Swap.

Parameters Definition

This service can easily be accessed through the use of the PUKCL_Swap() macro.

Table 37-9. Swap Service Parameters
Parameter Type Direction Location Data Length Before Executing the Service After Executing the Service
nu1XBase nu1 I Crypto RAM u2Length Base of the number X Base of X filled with Y
nu1YBase nu1 I Crypto RAM u2Length Base of the number Y Base of Y filled with X
u2XLength u2 I Length of X and Y Length of X and Y

Code Example

_PARAM PUKCLParam;
PPUKCL_PARAM pvPUKCLParam = &PUKCLParam;

// Initialize parameters
PUKCL_Swap(nu1XBase) = <Base of the X number>; 
PUKCL_Swap(nu1YBase) = <Base of the Y number>; 
PUKCL_Swap(u2XLength) = <Length of the numbers>;

// vPUKCL_Process() is a macro command, which populates the service name
// and then calls the library... 
vPUKCL_Process(Swap,pvPUKCLParam); 
if (PUKCL(u2Status) == PUKCL_OK)
            {
            ...
            }
else // Manage the error

Constraints

The following conditions must be avoided to ensure that the service works correctly:

  • nu1XBase or nu1YBase are not aligned on 32-bit boundaries
  • u2XLength is either <4, > 0xffc, or not a 32-bit length
  • {nu1XBase, u2XLength} or {nu1YBase, u2XLength} do not entirely lie in PUKCCRAM
  • {nu1XBase, u2XLength} overlaps {nu1YBase,u2YLength}

Status Returned Values

Table 37-10. Swap Service Return Codes
Returned status Importance Meaning
PUKCL_OK Service functioned correctly