cancel
Showing results for 
Search instead for 
Did you mean: 

PKA - ecdsa curve support

Hedley
Associate III

The sample code uses p256v1 (which seems to actually be p256r1). This curve works well.

I Got PKA to sign correctly using p256k1 with some minor curve updates.

I​ am having trouble setting up p224r1. Has anyone got curves other that p256 to work?

T​nx

H​edley

2 REPLIES 2
Hedley
Associate III

Fixed it. The hash normalization for 224 was wrong. The padding in my case needed to be in the upper words before the unroll into pka ram.

  Hash : SHA256_Hash :=

   (16#00#, 16#00#, 16#00#, 16#00#, 16#24#, 16#f0#, 16#37#, 16#06#,

   16#1b#, 16#2b#, 16#3b#, 16#5e#, 16#ba#, 16#8c#, 16#d4#, 16#97#,

   16#36#, 16#ff#, 16#25#, 16#1f#, 16#f0#, 16#11#, 16#63#, 16#5b#,

   16#c3#, 16#c8#, 16#49#, 16#63#, 16#b5#, 16#39#, 16#4f#, 16#f2#);

secp224r1 works fine. I am sure the others will also.

Hedley
Associate III

All these curves are working:

  Test ("secp521r1", 521, H);

  Test ("secp384r1", 384, H);

  Test ("secp256r1", 256, H);

  Test ("secp256k1", 256, H);

  Test ("secp128r1", 128, H);

  Test ("secp112r1", 112, H);

  Test ("secp112r2", 112, H);

  Test ("nistp521", 521, H);

  Test ("nistp384", 384, H);

  Test ("nistp256", 256, H);

  Test ("nistp224", 224, H);

  Test ("nistp192", 192, H);

  Test ("brainpool256r1", 256, H);

  Test ("brainpool256t1", 256, H);

  Test ("brainpool384r1", 384, H);

  Test ("brainpool384t1", 384, H);

This is via an Ada generic:

package body Curve is

  procedure Test (Name : String; NB : UInt32; H : ECDSA_HashStr)

  is

   package EC is new STM32.PKA (Curve_Name => Name, Num_Bits => NB);

   use EC;

   Result   : Boolean;

   PrivateKey : ECDSA_KeyStr    := Make_Random_Group_String (NClamp => True);

   PublicKey : ECDSA_PublicKeyStr := Make_Public_Key_String (PrivateKey);

   K     : ECDSA_RandStr   := Make_Random_Group_String;

   Sig    : ECDSA_SignatureStr;

  begin

   Enable_Pka;

   Result := ECDSA_Sign (PrivateKey, H, K, Sig);

   Result := ECDSA_Valid (PublicKey, H, Sig);

   if not Result then

     raise Program_Error with "curve fail";

   end if;

  end Test;

end Curve;

Code is on github:

https://github.com/morbos/STM32/tree/master/L/L562/pka_gen