37.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 37-23. Comp Service Parameters
Parameter Type Direction Location Data Length Before Executing the Service After Executing the Service
Specific/Gf2n CarryIn Bits I GF(2n) Bit and Carry In
Specific/CarryOut Zero Violation Bits I Carry Out, Zero Bit and Violation Bit filled according to the result
nu1XBase nu1 I Crypto RAM u2XLength Base of X Base of X
u2XLength u2 I Length of X Length of X
nu1YBase nu1 I Crypto RAM u2YLength Base of Y Base of Y
u2YLength u2 I Length of Y Length 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 37-24. Comp Service Return Codes
Returned Status Importance Meaning
PUKCL_OK Service functioned correctly