LPC55S28 CASPER ECC Multiply Execution Time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC55S28 CASPER ECC Multiply Execution Time

Jump to solution
100 Views
guitardenver
Contributor IV

I am trying to figure out if the below code is expected to execute within the time I'm measuring or if I have something set up wrong and it's making it very slow. This code is part of a function that generates a Public Key from given private key using kCASPER_ECC_P256.

The below code uses a GPIO toggle to measure execution time. Between the Set and Clear GPIO calls, it takes 337mS. Which seems slow for hardware accelerated math for this operation. Is this expected? My MCU has a core clock of 148MHz. Is there a way to choose the clock source for the CASPER engine to speed this up?

   /* Base Generator Point G(x, y) for secp256r1 in 32-bit Little-Endian word arrays */
    static const uint32_t G_x_le[8] = {
        0xD898C296, 0xF4A13945, 0x2DEB33A0, 0x77037D81,
        0x63A440F2, 0xF8BCE6E5, 0xE12C4247, 0x6B17D1F2
    };

    static const uint32_t G_y_le[8] = {
        0x37BF51F5, 0xCBB64068, 0x6B315ECE, 0x2BCE3357,
        0x7C0F9E16, 0x8EE7EB4A, 0xFE1A7F9B, 0x4FE342E2
    };

    uint32_t scalar_le[8];
    uint32_t Q_x_le[8];
    uint32_t Q_y_le[8];

    /* Copy Big-Endian private scalar and convert to Little-Endian for CASPER */
    memcpy(scalar_le, key_buffer, 32);
    swap_endian_32((uint8_t *)scalar_le);



    /* 1. Initialize CASPER coprocessor */
    CASPER_Init(CASPER);
    CASPER_ecc_init(kCASPER_ECC_P256);

    HW_DB_PinSet();

    /* 2. Compute Q = d * G using CASPER hardware */
    CASPER_ECC_SECP256R1_Mul(
        CASPER,
        Q_x_le, Q_y_le,
        G_x_le, G_y_le,
        scalar_le
    );
    HW_DB_PinClear();
0 Kudos
Reply
1 Solution
73 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @guitardenver 

We measured the same operation using the MCUXpresso SDK CASPER example on an LPC55S28 EVK running at 150 MHz. A single call to CASPER_ECC_SECP256R1_Mul() required approximately 24.1 million CPU cycles, corresponding to about 160 ms execution time.

Based on this result, the measured 337 ms in your application does not appear unreasonable, especially if additional key formatting, data conversion, initialization, or debug-build overhead is included.

CASPER does not provide a separate user-configurable clock source. The execution time is primarily determined by the ECC software implementation that utilizes the CASPER accelerator.

BR

Harry

View solution in original post

0 Kudos
Reply
3 Replies
53 Views
Niklschmidt
Contributor I
I am trying to figure out if the below code is expected to execute within the time I'm measuring or if I have something set up  Hey there! That 337ms for a hardware-accelerated ECC operation definitely sounds a bit high for a 148MHz MCU, even with P256. It's good you're looking into it. Sometimes driver overhead or clocking issues can sneak in. Have you checked the CASPER engine's specific clock source or any available documentation on optimizing its performance?
0 Kudos
Reply
49 Views
guitardenver
Contributor IV

There are a couple things you can do.  But I do not see any configurable clock options for CASPER engine on this MCU.

 

1. Use O2 optimizations for speed

2. Enable the Flash accelerator prefetch and wait state optimization. 

SYSCON->FMCCR |= SYSCON_FMCCR_PREFEN_MASK;
 
After this I am able to get it down to 160mS

 

0 Kudos
Reply
74 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @guitardenver 

We measured the same operation using the MCUXpresso SDK CASPER example on an LPC55S28 EVK running at 150 MHz. A single call to CASPER_ECC_SECP256R1_Mul() required approximately 24.1 million CPU cycles, corresponding to about 160 ms execution time.

Based on this result, the measured 337 ms in your application does not appear unreasonable, especially if additional key formatting, data conversion, initialization, or debug-build overhead is included.

CASPER does not provide a separate user-configurable clock source. The execution time is primarily determined by the ECC software implementation that utilizes the CASPER accelerator.

BR

Harry

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2413809%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELPC55S28%20CASPER%20ECC%20Multiply%20Execution%20Time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2413809%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20trying%20to%20figure%20out%20if%20the%20below%20code%20is%20expected%20to%20execute%20within%20the%20time%20I'm%20measuring%20or%20if%20I%20have%20something%20set%20up%20wrong%20and%20it's%20making%20it%20very%20slow.%20This%20code%20is%20part%20of%20a%20function%20that%20generates%20a%20Public%20Key%20from%20given%20private%20key%20using%20kCASPER_ECC_P256.%3C%2FP%3E%3CP%3EThe%20below%20code%20uses%20a%20GPIO%20toggle%20to%20measure%20execution%20time.%20Between%20the%20Set%20and%20Clear%20GPIO%20calls%2C%20it%20takes%20337mS.%20Which%20seems%20slow%20for%20hardware%20accelerated%20math%20for%20this%20operation.%20Is%20this%20expected%3F%20My%20MCU%20has%20a%20core%20clock%20of%20148MHz.%20Is%20there%20a%20way%20to%20choose%20the%20clock%20source%20for%20the%20CASPER%20engine%20to%20speed%20this%20up%3F%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%20%20%20%2F*%20Base%20Generator%20Point%20G(x%2C%20y)%20for%20secp256r1%20in%2032-bit%20Little-Endian%20word%20arrays%20*%2F%0A%20%20%20%20static%20const%20uint32_t%20G_x_le%5B8%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%200xD898C296%2C%200xF4A13945%2C%200x2DEB33A0%2C%200x77037D81%2C%0A%20%20%20%20%20%20%20%200x63A440F2%2C%200xF8BCE6E5%2C%200xE12C4247%2C%200x6B17D1F2%0A%20%20%20%20%7D%3B%0A%0A%20%20%20%20static%20const%20uint32_t%20G_y_le%5B8%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%200x37BF51F5%2C%200xCBB64068%2C%200x6B315ECE%2C%200x2BCE3357%2C%0A%20%20%20%20%20%20%20%200x7C0F9E16%2C%200x8EE7EB4A%2C%200xFE1A7F9B%2C%200x4FE342E2%0A%20%20%20%20%7D%3B%0A%0A%20%20%20%20uint32_t%20scalar_le%5B8%5D%3B%0A%20%20%20%20uint32_t%20Q_x_le%5B8%5D%3B%0A%20%20%20%20uint32_t%20Q_y_le%5B8%5D%3B%0A%0A%20%20%20%20%2F*%20Copy%20Big-Endian%20private%20scalar%20and%20convert%20to%20Little-Endian%20for%20CASPER%20*%2F%0A%20%20%20%20memcpy(scalar_le%2C%20key_buffer%2C%2032)%3B%0A%20%20%20%20swap_endian_32((uint8_t%20*)scalar_le)%3B%0A%0A%0A%0A%20%20%20%20%2F*%201.%20Initialize%20CASPER%20coprocessor%20*%2F%0A%20%20%20%20CASPER_Init(CASPER)%3B%0A%20%20%20%20CASPER_ecc_init(kCASPER_ECC_P256)%3B%0A%0A%20%20%20%20HW_DB_PinSet()%3B%0A%0A%20%20%20%20%2F*%202.%20Compute%20Q%20%3D%20d%20*%20G%20using%20CASPER%20hardware%20*%2F%0A%20%20%20%20CASPER_ECC_SECP256R1_Mul(%0A%20%20%20%20%20%20%20%20CASPER%2C%0A%20%20%20%20%20%20%20%20Q_x_le%2C%20Q_y_le%2C%0A%20%20%20%20%20%20%20%20G_x_le%2C%20G_y_le%2C%0A%20%20%20%20%20%20%20%20scalar_le%0A%20%20%20%20)%3B%0A%20%20%20%20HW_DB_PinClear()%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2413891%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%20LPC55S28%20CASPER%20ECC%20Multiply%20Execution%20Time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2413891%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F43524%22%20target%3D%22_blank%22%3E%40guitardenver%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20measured%20the%20same%20operation%20using%20the%20MCUXpresso%20SDK%20CASPER%20example%20on%20an%20LPC55S28%20EVK%20running%20at%20150%20MHz.%20A%20single%20call%20to%20CASPER_ECC_SECP256R1_Mul()%20required%20approximately%2024.1%20million%20CPU%20cycles%2C%20corresponding%20to%20about%20160%20ms%20execution%20time.%3C%2FP%3E%0A%3CP%3EBased%20on%20this%20result%2C%20the%20measured%20337%20ms%20in%20your%20application%20does%20not%20appear%20unreasonable%2C%20especially%20if%20additional%20key%20formatting%2C%20data%20conversion%2C%20initialization%2C%20or%20debug-build%20overhead%20is%20included.%3C%2FP%3E%0A%3CP%3ECASPER%20does%20not%20provide%20a%20separate%20user-configurable%20clock%20source.%20The%20execution%20time%20is%20primarily%20determined%20by%20the%20ECC%20software%20implementation%20that%20utilizes%20the%20CASPER%20accelerator.%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EHarry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2414646%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20LPC55S28%20CASPER%20ECC%20Multiply%20Execution%20Time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2414646%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThere%20are%20a%20couple%20things%20you%20can%20do.%26nbsp%3B%20But%20I%20do%20not%20see%20any%20configurable%20clock%20options%20for%20CASPER%20engine%20on%20this%20MCU.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E1.%20Use%20O2%20optimizations%20for%20speed%3C%2FP%3E%3CP%3E2.%26nbsp%3B%3CSPAN%3EEnable%20the%20Flash%20accelerator%20prefetch%20and%20wait%20state%20optimization.%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3ESYSCON%3C%2FSPAN%3E%3CSPAN%3E-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3EFMCCR%3C%2FSPAN%3E%20%3CSPAN%3E%7C%3D%3C%2FSPAN%3E%20%3CSPAN%3ESYSCON_FMCCR_PREFEN_MASK%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EAfter%20this%20I%20am%20able%20to%20get%20it%20down%20to%20160mS%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2414511%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20LPC55S28%20CASPER%20ECC%20Multiply%20Execution%20Time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2414511%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3EI%20am%20trying%20to%20figure%20out%20if%20the%20below%20code%20is%20expected%20to%20execute%20within%20the%20time%20I'm%20measuring%20or%20if%20I%20have%20something%20set%20up%20%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3EHey%20there!%20That%20337ms%20for%20a%20hardware-accelerated%20ECC%20operation%20definitely%20sounds%20a%20bit%20high%20for%20a%20148MHz%20MCU%2C%20even%20with%20P256.%20It's%20good%20you're%20looking%20into%20it.%20Sometimes%20driver%20overhead%20or%20clocking%20issues%20can%20sneak%20in.%20Have%20you%20checked%20the%20CASPER%20engine's%20specific%20clock%20source%20or%20any%20available%20documentation%20on%20optimizing%20its%20performance%3F%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E