43.3.7.10 Verifying an ECDSA Signature (Compliant with FIPS 186-2)

Purpose

This service is used to verify an ECDSA signature following the FIPS 186-2. It performs the second step of the Signature Verification.

A hash value (HashVal) must be provided as input, it has to be previously computed from the message to be signed using a secure hash algorithm.

As second significant input, the Signature is provided to be checked. This service checks the signature and fills the status accordingly.

How to Use the Service

Description

The operation performed is:

Verify = EcDsaVerifySignature(PtA, HashVal, Signature, CurveParameters, PublicKey)

The points used for this operation are represented in different coordinate systems. In this computation, the following parameters need to be provided:

  • A the input point is filled with the affine values (X,Y) and Z = 1 (pointed by{nu1PointABase,3*u2ModLength + 12})
  • Cns the working space for the Fast Modular Constant not initialized (pointed by {nu1CnsBase,u2ScalarLength + 8})
  • P the modulus filled (pointed by {nu1ModBase,u2ModLength +4})
  • The workspace not initialized (pointed by {nu1WorkSpace, 8*u2ModLength +44} The a and b parameters relative to the elliptic curve (pointed by {nu1ABase,2*u2ModLength + 8})
  • The order of the Point A on the elliptic curve (pointed by {nu1OrderPointBase,u2ScalarLength +4})
  • HashVal the hash value beforehand generated and filled (pointed by {nu1HashBase,u2ScalarLength +4})
  • The Public Key point is filled in “mixed” coordinates (X,Y) with the affine values and Z = 1 (pointed by {nu1PointPublicKeyGen, 3*u2ModLength + 12})
  • The input signature (R,S), even if it is not a Point, is represented in memory like a point in affine coordinates (X,Y) (pointed by {nu1PointSignature, 2*u2ScalarLength + 8})
    Important: For the ECDSA signature verification be sure to follow the directives given for the RNG on the chip you use (particularly initialization, seeding) and compulsorily start the RNG.
  • The operation consists in obtaining a V value with all these input parameter and check that V equals the provided R. If all is correct and the signature is the good one, the status is set to PUKCL_OK. If all is correct and the signature is wrong, the status is set to PUKCL_WRONG_SIGNATURE. If an error occurs, the status is set to the corresponding error value (see Status Returned Values below).

The service name for this operation is GF2NEcDsaVerifyFast. This service uses Fast mode and Fast Modular Reduction for computation.

Parameters Definition

Table 43-110. GF2NEcDsaVerifyFast Service Parameters
ParameterTypeDirectionLocationData LengthBefore Executing the ServiceAfter Executing the Service
nu1ModBasenu1ICrypto RAMu2ModLength + 4Base of modulus PBase of modulus P
nu1CnsBasenu1ICrypto RAMu2ScalarLength + 8Base of CnsBase of Cns
u2ModLengthu2ILength of modulus PLength of modulus P
nu1OrderPointBasenu1ICrypto RAMu2ScalarLength + 4Order of the Point A in the elliptic curveUnchanged
nu1PointSignaturenu1ICrypto RAM2*u2ScalarLength + 8Signature(r, s)Corrupted
nu1HashBase (see Note 1)nu1ICrypto RAMu2ScalarLength + 4Base of the hash value resulting from the previous SHACorrupted
u2ScalarLengthu2ILength of scalarLength of scalar
nu1PointABasenu1I/OCrypto RAM3*u2ModLength + 12Generator pointCorrupted
nu1PointPublicKeyGennu1I/OCrypto RAM3*u2ModLength + 12Public pointCorrupted
nu1ABasenu1ICrypto RAM

2*u2ModLength + 8

Parameter a and b of the elliptic curveUnchanged
nu1Workspacenu1ICrypto RAM8*u2ModLength + 44Corrupted workspace
Note:
  1. Whatever the chosen SHA, the resulting hash value may have a length inferior or equal to the modulo length and be padded with zeros until its total length is u2ModLength + 4.

Code Example

PUKCL_PARAM PUKCLParam;
PPUKCL_PARAM pvPUKCLParam = &PUKCLParam;

// ! The Random Number Generator must be initialized and started
// ! following the directives given for the RNG on the chip

PUKCL (u2Option) = 0;

// Depending on the option specified, not all fields should be filled PUKCL _GF2NEcDsaVerify(nu1ModBase) = <Base of the ram location of P>; 
PUKCL _GF2NEcDsaVerify(u2ModLength) = <Byte length of P>;
PUKCL _GF2NEcDsaVerify(nu1CnsBase) = <Base of the ram location of Cns>; 
PUKCL _GF2NEcDsaVerify(nu1PointABase) = <Base of the A point>;
PUKCL _GF2NEcDsaVerify(nu1PrivateKey) = <Base of the Private Key>;
PUKCL _GF2NEcDsaVerify(nu1ScalarNumber) = <Base of the ScalarNumber>;
PUKCL _GF2NEcDsaVerify(nu1OrderPointBase) = <Base of the order of A point>; 
PUKCL _GF2NEcDsaVerify(nu1ABase) = <Base of the a parameter of the curve>; PUKCL _GF2NEcDsaVerify(nu1Workspace) = <Base of the workspace>;
PUKCL _GF2NEcDsaVerify(nu1HashBase) = <Base of the SHA resulting hash>;
...

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

Constraints

No overlapping between either input and output are allowed. The following conditions must be avoided to ensure the service works correctly:

  • nu1ModBase, nu1CnsBase, nu1PointABase, nu1PointPublicKeyGen, nu1PointSignature, nu1OrderPointBase,nu1ABBase, nu1Workspace or nu1HashBase are not aligned on 32-bit boundaries
  • {nu1ModBase, u2ModLength + 4}, {nu1CnsBase, u2ModLength + 8}, {nu1PointABase, 3*u2ModLength + 12}, {nu1PointPublicKeyGen, 3*u2ModLength + 12}, {nu1PointSignature,2*u2ScalarLength + 8}, {nu1OrderPointBase, u2ScalarLength + 4}, {nu1ABBase, 2*u2ModLength + 8}, {nu1Workspace, <WorkspaceLength>} or {nu1HashBase, u2ScalarLength + 4} are not in Crypto RAM
  • u2ModLength is either: < 12, > 0xffc or not a 32-bit length
  • All overlapping between {nu1ModBase, u2ModLength + 4}, {nu1CnsBase, u2ModLength +8}, {nu1PointABase, 3*u2ModLength + 12}, {nu1PointPublicKeyGen, 3*u2ModLength + 12}, {nu1PointSignature, 2*u2ScalarLength + 8}, {nu1OrderPointBase, u2ScalarLength + 4}, {nu1ABBase, 2*u2ModLength + 8}, {nu1Workspace, <WorkspaceLength>} and {nu1HashBase, u2ScalarLength + 4}

Status Returned Values

Table 43-111. GF2NEcDsaVerifyFast Service Return Codes
Returned StatusImportanceMeaning
PUKCL_OKThe computation passed without errors. The signature is correct.
PUKCL_WRONG_SIGNATUREWarningThe signature is incorrect.