43.3.4.8 Compare

Purpose

The purpose of this service is to compare two numbers in classical arithmetic GF(p).

Important: This service works only with integers.

How to Use the Service

Description

This service accepts two numbers in classical arithmetic in input and performs a comparison, virtually subtracting (X + CarryIn) from Y:

CompareGetFlags (Y - (X + CarryIn))

The numbers X and Y are untouched but the resulting flags CarryOut and the Zero Bit are filled. If the lengths of Y and X are equal, a comparison is processed.

If the length of Y is strictly greater than the length of X, X is first virtually padded with zeros on the Most Significant Bytes side, then a comparison is processed.

Note: The length of Y must be greater or equal to the length of X.

In this computation, the following data need to be provided:

  • X (pointed by{nu1XBase,u2XLength})
  • Y (pointed by{nu1YBase,u2YLength})

The service name for this operation is Comp.

Parameters Definition

Table 43-23. Comp Service Parameters
ParameterTypeDirectionLocationData LengthBefore Executing the ServiceAfter Executing the Service
Specific/Gf2n CarryInBitsIGF(2n) Bit and Carry In
Specific/CarryOut Zero ViolationBitsICarry Out, Zero Bit and Violation Bit filled according to the result
nu1XBasenu1ICrypto RAMu2XLengthBase of XBase of X
u2XLengthu2ILength of XLength of X
nu1YBasenu1ICrypto RAMu2YLengthBase of YBase of Y
u2YLengthu2ILength of YLength of Y

Code Example

PUKCL_PARAM PUKCLParam;
PPUKCL_PARAM pvPUKCLParam = &PUKCLParam;

// CarryIn shall be beforehand filled (with zero or one) PUKCL(Specific).CarryIn = ...;

// Initializing parameters
PUKCL_Comp(nu1XBase) = <Base of the ram location of X>; 
PUKCL_Comp(u2XLength) = <Length of X>; 
PUKCL_Comp(nu1YBase) = <Base of the ram location of Y>; 
PUKCL_Comp(u2YLength) = <Length of Y>;

// vPUKCL_Process() is a macro command, 
// and then calls the library... 
vPUKCL_Process(Comp,pvPUKCLParam); 
if (PUKCL(u2Status) == PUKCL_OK)
            {
            // The COMPARE has been executed correctly
            // CarryOut, Zero ... are available
            ... = PUKCL(Specific).CarryOut;
            ... = PUKCL(Specific).Zero;
            }
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
  • {nu1XBase, u2XLength} or {nu1YLength, u2YLength} are not in Crypto RAM
  • u2XLength or u2YLength is either: < 4, > 0xffc or not a 32-bit length or u2XLength >u2YLength

Status Returned Values

Table 43-24. Comp Service Return Codes
Returned StatusImportanceMeaning
PUKCL_OKService functioned correctly