m5531_crypto_pkc.c
Go to the documentation of this file.
1 /**
2  * @file m5531_crypto_pkc.c
3  * @brief M5531 public-key hardware accelerator
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "NuMicro.h"
36 #include "core/crypto.h"
39 #include "pkc/rsa.h"
40 #include "ecc/ec.h"
41 #include "ecc/ec_misc.h"
42 #include "debug.h"
43 
44 //Check crypto library configuration
45 #if (M5531_CRYPTO_PKC_SUPPORT == ENABLED)
46 #if (MPI_SUPPORT == ENABLED)
47 
48 //IAR EWARM compiler?
49 #if defined(__ICCARM__)
50 
51 RSA primitive arguments
52 #pragma data_alignment = 4
53 #pragma location = M5531_CRYPTO_RAM_SECTION
54 static M5531RsaArgs rsaArgs;
55 
56 //Keil MDK-ARM or GCC compiler?
57 #else
58 
59 //RSA primitive arguments
60 static M5531RsaArgs rsaArgs
61  __attribute__((aligned(4), __section__(M5531_CRYPTO_RAM_SECTION)));
62 
63 #endif
64 
65 
66 /**
67  * @brief Import multiple-precision integer
68  * @param[in] dest Pointer to the operand
69  * @param[in] length Length of the operand, in bytes
70  * @param[in] a Pointer to the multiple-precision integer
71  **/
72 
73 void rsaImportMpi(uint32_t *dest, uint_t length, const Mpi *a)
74 {
75  uint_t i;
76  uint_t n;
77 
78  //Get the length of the operand, in words
79  length = (length + 3) / 4;
80 
81  //Get the actual length of the multiple-precision integer, in words
82  n = mpiGetLength(a);
83 
84  //Copy the multiple-precision integer to the CRYPTO peripheral
85  for(i = 0; i < n && i < length; i++)
86  {
87  dest[i] = a->data[i];
88  }
89 
90  //Pad the operand with zeroes
91  for(; i < length; i++)
92  {
93  dest[i] = 0;
94  }
95 }
96 
97 
98 /**
99  * @brief Export multiple-precision integer
100  * @param[in] src Pointer to the operand
101  * @param[in] length Length of the operand, in bytes
102  * @param[out] r Pointer to the multiple-precision integer
103  * @return Error code
104  **/
105 
107 {
108  error_t error;
109  uint_t i;
110 
111  //Get the length of the operand, in words
112  length = (length + 3) / 4;
113 
114  //Skip trailing zeroes
115  while(length > 0 && src[length - 1] == 0)
116  {
117  length--;
118  }
119 
120  //Ajust the size of the multiple precision integer
121  error = mpiGrow(r, length);
122 
123  //Check status code
124  if(!error)
125  {
126  //Copy the multiple-precision integer from the CRYPTO peripheral
127  for(i = 0; i < length; i++)
128  {
129  r->data[i] = src[i];
130  }
131 
132  //Pad the resulting value with zeroes
133  for(; i < r->size; i++)
134  {
135  r->data[i] = 0;
136  }
137 
138  //Set the sign
139  r->sign = 1;
140  }
141 
142  //Return status code
143  return error;
144 }
145 
146 
147 /**
148  * @brief Modular exponentiation (fast calculation)
149  * @param[out] r Resulting integer R = A ^ E mod P
150  * @param[in] a Pointer to a multiple precision integer
151  * @param[in] e Exponent
152  * @param[in] p Modulus
153  * @return Error code
154  **/
155 
156 error_t mpiExpModFast(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
157 {
158  error_t error;
159  size_t aLen;
160  size_t eLen;
161  size_t pLen;
162 
163  //Get the length of the integer, in bytes
164  aLen = mpiGetByteLength(a);
165  //Get the length of the exponent, in bytes
166  eLen = mpiGetByteLength(e);
167  //Get the length of the modulus, in bytes
168  pLen = mpiGetByteLength(p);
169 
170  //The accelerator supports operand lengths up to 4096 bits
171  if((aLen <= 128 && eLen <= 128 && pLen == 128) ||
172  (aLen <= 256 && eLen <= 256 && pLen == 256) ||
173  (aLen <= 384 && eLen <= 384 && pLen == 384) ||
174  (aLen <= 512 && eLen <= 512 && pLen == 512))
175  {
176  //Acquire exclusive access to the CRYPTO module
178 
179  //Reset CRYPTO controller
180  SYS_ResetModule(SYS_CRYPTO0RST);
181 
182  //Copy the operands
183  rsaImportMpi(rsaArgs.m, pLen, a);
184  rsaImportMpi(rsaArgs.n, pLen, p);
185  rsaImportMpi(rsaArgs.e, pLen, e);
186 
187  //Program DMA source address to register CRYPTO_RSA_SADDR0-2
188  CRYPTO->RSA_SADDR[0] = (uint32_t) rsaArgs.m;
189  CRYPTO->RSA_SADDR[1] = (uint32_t) rsaArgs.n;
190  CRYPTO->RSA_SADDR[2] = (uint32_t) rsaArgs.e;
191 
192  //Program DMA destination address to register CRYPTO_RSA_DADDR
193  CRYPTO->RSA_DADDR = (uint32_t) rsaArgs.r;
194 
195  //Select appropriate key length
196  CRYPTO->RSA_CTL = (((pLen / 128) - 1) << CRYPTO_RSA_CTL_KEYLENG_Pos);
197 
198  //Clear RSA interrupt flag
199  CRYPTO->INTSTS = CRYPTO_INTSTS_RSAIF_Msk;
200  //Start operation
201  CRYPTO->RSA_CTL |= CRYPTO_RSA_CTL_START_Msk;
202 
203  //Wait for the operation to complete
204  while((CRYPTO->INTSTS & CRYPTO_INTSTS_RSAIF_Msk) == 0)
205  {
206  }
207 
208  //Read output data
209  rsaExportMpi(rsaArgs.r, pLen, r);
210 
211  //Release exclusive access to the CRYPTO module
213 
214  //Successful operation
215  error = NO_ERROR;
216  }
217  else
218  {
219  //Perform modular exponentiation (r = a ^ e mod p)
220  error = mpiExpMod(r, a, e, p);
221  }
222 
223  //Return status code
224  return error;
225 }
226 
227 
228 /**
229  * @brief Modular exponentiation (regular calculation)
230  * @param[out] r Resulting integer R = A ^ E mod P
231  * @param[in] a Pointer to a multiple precision integer
232  * @param[in] e Exponent
233  * @param[in] p Modulus
234  * @return Error code
235  **/
236 
237 error_t mpiExpModRegular(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
238 {
239  error_t error;
240  size_t aLen;
241  size_t eLen;
242  size_t pLen;
243 
244  //Get the length of the integer, in bytes
245  aLen = mpiGetByteLength(a);
246  //Get the length of the exponent, in bytes
247  eLen = mpiGetByteLength(e);
248  //Get the length of the modulus, in bytes
249  pLen = mpiGetByteLength(p);
250 
251  //The accelerator supports operand lengths up to 4096 bits
252  if((pLen == 128 && aLen <= 128 && eLen <= 128) ||
253  (pLen == 256 && aLen <= 256 && eLen <= 256) ||
254  (pLen == 384 && aLen <= 384 && eLen <= 384) ||
255  (pLen == 512 && aLen <= 512 && eLen <= 512))
256  {
257  //Acquire exclusive access to the CRYPTO module
259 
260  //Reset CRYPTO controller
261  SYS_ResetModule(SYS_CRYPTO0RST);
262 
263  //Copy the operands
264  rsaImportMpi(rsaArgs.m, pLen, a);
265  rsaImportMpi(rsaArgs.n, pLen, p);
266  rsaImportMpi(rsaArgs.e, pLen, e);
267 
268  //Program DMA source address to register CRYPTO_RSA_SADDR0-2
269  CRYPTO->RSA_SADDR[0] = (uint32_t) rsaArgs.m;
270  CRYPTO->RSA_SADDR[1] = (uint32_t) rsaArgs.n;
271  CRYPTO->RSA_SADDR[2] = (uint32_t) rsaArgs.e;
272 
273  //Program DMA destination address to register CRYPTO_RSA_DADDR
274  CRYPTO->RSA_DADDR = (uint32_t) rsaArgs.r;
275 
276  //Select appropriate key length
277  CRYPTO->RSA_CTL = (((pLen / 128) - 1) << CRYPTO_RSA_CTL_KEYLENG_Pos);
278 
279  //Clear RSA interrupt flag
280  CRYPTO->INTSTS = CRYPTO_INTSTS_RSAIF_Msk;
281  //Start operation
282  CRYPTO->RSA_CTL |= CRYPTO_RSA_CTL_START_Msk;
283 
284  //Wait for the operation to complete
285  while((CRYPTO->INTSTS & CRYPTO_INTSTS_RSAIF_Msk) == 0)
286  {
287  }
288 
289  //Read output data
290  rsaExportMpi(rsaArgs.r, pLen, r);
291 
292  //Release exclusive access to the CRYPTO module
294 
295  //Successful operation
296  error = NO_ERROR;
297  }
298  else
299  {
300  //Perform modular exponentiation (r = a ^ e mod p)
301  error = mpiExpMod(r, a, e, p);
302  }
303 
304  //Return status code
305  return error;
306 }
307 
308 #endif
309 #if (RSA_SUPPORT == ENABLED)
310 
311 /**
312  * @brief RSA decryption primitive
313  *
314  * The RSA decryption primitive recovers the message representative from
315  * the ciphertext representative under the control of a private key
316  *
317  * @param[in] key RSA private key
318  * @param[in] c Ciphertext representative
319  * @param[out] m Message representative
320  * @return Error code
321  **/
322 
323 error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m)
324 {
325  error_t error;
326  size_t nLen;
327  size_t dLen;
328  size_t pLen;
329  size_t qLen;
330  size_t dpLen;
331  size_t dqLen;
332  size_t qinvLen;
333 
334  //Get the length of the private key
335  nLen = mpiGetByteLength(&key->n);
336  dLen = mpiGetByteLength(&key->d);
337  pLen = mpiGetByteLength(&key->p);
338  qLen = mpiGetByteLength(&key->q);
339  dpLen = mpiGetByteLength(&key->dp);
340  dqLen = mpiGetByteLength(&key->dq);
341  qinvLen = mpiGetByteLength(&key->qinv);
342 
343  //Sanity check
344  if(nLen == 0)
346 
347  //The ciphertext representative c shall be between 0 and n - 1
348  if(mpiCompInt(c, 0) < 0 || mpiComp(c, &key->n) >= 0)
349  return ERROR_OUT_OF_RANGE;
350 
351  //Check the length of the private key
352  if((nLen == 128 && dLen <= 128) || (nLen == 384 && dLen <= 384))
353  {
354  //Let m = c ^ d mod n
355  error = mpiExpModRegular(m, c, &key->d, &key->n);
356  }
357  else if(nLen > 0 && pLen > 0 && qLen > 0 && dpLen > 0 && dqLen > 0 &&
358  qinvLen > 0)
359  {
360  Mpi m1;
361  Mpi m2;
362  Mpi h;
363 
364  //Initialize multiple-precision integers
365  mpiInit(&m1);
366  mpiInit(&m2);
367  mpiInit(&h);
368 
369  //Compute m1 = c ^ dP mod p
370  error = mpiMod(&m1, c, &key->p);
371 
372  if(!error)
373  {
374  error = mpiExpModRegular(&m1, &m1, &key->dp, &key->p);
375  }
376 
377  //Compute m2 = c ^ dQ mod q
378  if(!error)
379  {
380  error = mpiMod(&m2, c, &key->q);
381  }
382 
383  if(!error)
384  {
385  error = mpiExpModRegular(&m2, &m2, &key->dq, &key->q);
386  }
387 
388  //Let h = (m1 - m2) * qInv mod p
389  if(!error)
390  {
391  error = mpiSub(&h, &m1, &m2);
392  }
393 
394  if(!error)
395  {
396  error = mpiMulMod(&h, &h, &key->qinv, &key->p);
397  }
398 
399  //Let m = m2 + q * h
400  if(!error)
401  {
402  error = mpiMul(m, &key->q, &h);
403  }
404 
405  if(!error)
406  {
407  error = mpiAdd(m, m, &m2);
408  }
409 
410  //Free previously allocated memory
411  mpiFree(&m1);
412  mpiFree(&m2);
413  mpiFree(&h);
414  }
415  else if(nLen > 0 && dLen > 0)
416  {
417  //Let m = c ^ d mod n
418  error = mpiExpModRegular(m, c, &key->d, &key->n);
419  }
420  else
421  {
422  //Report an error
423  error = ERROR_INVALID_PARAMETER;
424  }
425 
426  //Return status code
427  return error;
428 }
429 
430 #endif
431 #if (EC_SUPPORT == ENABLED)
432 
433 /**
434  * @brief Import scalar
435  * @param[in] dest Pointer to the operand
436  * @param[in] length Length of the operand, in bits
437  * @param[in] src Pointer to the scalar
438  **/
439 
440 void eccImportScalar(volatile uint32_t *dest, uint_t length, const uint32_t *src)
441 {
442  uint_t i;
443 
444  //Get the length of the operand, in words
445  length = (length + 31) / 32;
446 
447  //Copy the scalar to the CRYPTO peripheral
448  for(i = 0; i < length; i++)
449  {
450  dest[i] = src[i];
451  }
452 }
453 
454 
455 /**
456  * @brief Export scalar
457  * @param[in] src Pointer to the operand
458  * @param[in] length Length of the operand, in bits
459  * @param[out] dest Pointer to the scalar
460  **/
461 
462 void eccExportScalar(volatile uint32_t *src, uint_t length, uint32_t *dest)
463 {
464  uint_t i;
465 
466  //Get the length of the operand, in words
467  length = (length + 31) / 32;
468 
469  //Copy the scalar from the CRYPTO peripheral
470  for(i = 0; i < length; i++)
471  {
472  dest[i] = src[i];
473  }
474 }
475 
476 
477 /**
478  * @brief Scalar multiplication (fast calculation)
479  * @param[in] curve Elliptic curve parameters
480  * @param[out] r Resulting point R = d.S
481  * @param[in] d An integer d such as 0 <= d < p
482  * @param[in] s EC point
483  * @return Error code
484  **/
485 
486 error_t ecMulFast(const EcCurve *curve, EcPoint3 *r, const uint32_t *d,
487  const EcPoint3 *s)
488 {
489  //Compute R = d.S
490  return ecMulRegular(curve, r, d, s);
491 }
492 
493 
494 /**
495  * @brief Scalar multiplication (regular calculation)
496  * @param[in] curve Elliptic curve parameters
497  * @param[out] r Resulting point R = d.S
498  * @param[in] d An integer d such as 0 <= d < q
499  * @param[in] s EC point
500  * @return Error code
501  **/
502 
503 error_t ecMulRegular(const EcCurve *curve, EcPoint3 *r, const uint32_t *d,
504  const EcPoint3 *s)
505 {
506  error_t error;
507  uint_t modLen;
508  uint_t orderLen;
509 
510  //Get the length of the modulus, in bits
511  modLen = curve->fieldSize;
512  //Get the length of the order, in bits
513  orderLen = curve->orderSize;
514 
515  //Check the length of the operands
516  if(modLen <= 576 && orderLen <= 576)
517  {
518  //Acquire exclusive access to the CRYPTO module
520 
521  //Reset CRYPTO controller
522  SYS_ResetModule(SYS_CRYPTO0RST);
523 
524  //Load input arguments
525  eccImportScalar(CRYPTO->ECC_N, modLen, curve->p);
526  eccImportScalar(CRYPTO->ECC_A, modLen, curve->a);
527  eccImportScalar(CRYPTO->ECC_B, modLen, curve->b);
528  eccImportScalar(CRYPTO->ECC_K, orderLen, d);
529  eccImportScalar(CRYPTO->ECC_X1, modLen, s->x);
530  eccImportScalar(CRYPTO->ECC_Y1, modLen, s->y);
531  eccImportScalar(CRYPTO->ECC_X2, orderLen, curve->q);
532 
533  //Set up a point multiplication operation
534  CRYPTO->ECC_CTL = (modLen << CRYPTO_ECC_CTL_CURVEM_Pos) |
535  CRYPTO_ECC_CTL_SCAP_Msk | (0 << CRYPTO_ECC_CTL_ECCOP_Pos) |
536  CRYPTO_ECC_CTL_FSEL_Msk;
537 
538  //Clear ECC interrupt flag
539  CRYPTO->INTSTS = CRYPTO_INTSTS_ECCIF_Msk;
540  //Start operation
541  CRYPTO->ECC_CTL |= CRYPTO_ECC_CTL_START_Msk;
542 
543  //Wait for the operation to complete
544  while((CRYPTO->INTSTS & CRYPTO_INTSTS_ECCIF_Msk) == 0)
545  {
546  }
547 
548  //Copy the x-coordinate of the result
550  eccExportScalar(CRYPTO->ECC_X1, modLen, r->x);
551 
552  //Copy the y-coordinate of the result
554  eccExportScalar(CRYPTO->ECC_Y1, modLen, r->y);
555 
556  //Set the z-coordinate of the result
558 
559  //Release exclusive access to the CRYPTO module
561 
562  //Successful processing
563  error = NO_ERROR;
564  }
565  else
566  {
567  //Report an error
568  error = ERROR_FAILURE;
569  }
570 
571  //Return status code
572  return error;
573 }
574 
575 
576 /**
577  * @brief Twin multiplication
578  * @param[in] curve Elliptic curve parameters
579  * @param[out] r Resulting point R = d0.S + d1.T
580  * @param[in] d0 An integer d such as 0 <= d0 < p
581  * @param[in] s EC point
582  * @param[in] d1 An integer d such as 0 <= d1 < p
583  * @param[in] t EC point
584  * @return Error code
585  **/
586 
587 error_t ecTwinMul(const EcCurve *curve, EcPoint3 *r, const uint32_t *d0,
588  const EcPoint3 *s, const uint32_t *d1, const EcPoint3 *t)
589 {
590  error_t error;
591  EcPoint3 u;
592 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
593  EcState *state;
594 #else
595  EcState state[1];
596 #endif
597 
598 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
599  //Allocate working state
600  state = cryptoAllocMem(sizeof(EcState));
601  //Failed to allocate memory?
602  if(state == NULL)
603  return ERROR_OUT_OF_MEMORY;
604 #endif
605 
606  //Initialize working state
607  osMemset(state, 0, sizeof(EcState));
608  //Save elliptic curve parameters
609  state->curve = curve;
610 
611  //Compute d0.S
612  error = ecMulFast(curve, r, d0, s);
613 
614  //Check status code
615  if(!error)
616  {
617  //Compute d1.T
618  error = ecMulFast(curve, &u, d1, t);
619  }
620 
621  //Check status code
622  if(!error)
623  {
624  //Compute d0.S + d1.T
625  ecFullAdd(state, r, r, &u);
626  }
627 
628  //Return status code
629  return error;
630 }
631 
632 #endif
633 #endif
void eccExportScalar(volatile uint32_t *src, uint_t length, uint32_t *dest)
Export scalar.
@ ERROR_OUT_OF_RANGE
Definition: error.h:138
Mpi p
First factor.
Definition: rsa.h:72
uint8_t a
Definition: ndp.h:411
Arbitrary precision integer.
Definition: mpi.h:102
error_t mpiExpModFast(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation (fast calculation)
uint8_t p
Definition: ndp.h:300
uint8_t t
Definition: lldp_ext_med.h:212
void ecFullAdd(EcState *state, EcPoint3 *r, const EcPoint3 *s, const EcPoint3 *t)
Point addition.
Definition: ec.c:1136
error_t ecMulRegular(const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
Scalar multiplication (regular calculation)
RSA primitive arguments.
error_t ecTwinMul(const EcCurve *curve, EcPoint3 *r, const uint32_t *d0, const EcPoint3 *s, const uint32_t *d1, const EcPoint3 *t)
Twin multiplication.
Mpi n
Modulus.
Definition: rsa.h:69
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
void mpiInit(Mpi *r)
Initialize a multiple precision integer.
Definition: mpi.c:49
void rsaImportMpi(uint32_t *dest, uint_t length, const Mpi *a)
Import multiple-precision integer.
Mpi d
Private exponent.
Definition: rsa.h:71
uint8_t r
Definition: ndp.h:346
error_t mpiMod(Mpi *r, const Mpi *a, const Mpi *p)
Modulo operation.
Definition: mpi.c:1589
error_t mpiMul(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision multiplication.
uint8_t h
Definition: ndp.h:302
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t mpiSub(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision subtraction.
Definition: mpi.c:971
error_t
Error codes.
Definition: error.h:43
error_t mpiExpModRegular(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation (regular calculation)
error_t mpiAdd(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision addition.
Definition: mpi.c:893
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
void ecScalarSetInt(uint32_t *a, uint32_t b, uint_t n)
Set integer value.
Definition: ec_misc.c:505
Mpi q
Second factor.
Definition: rsa.h:73
Helper routines for ECC.
General definitions for cryptographic algorithms.
RSA public-key cryptography standard.
void eccImportScalar(volatile uint32_t *dest, uint_t length, const uint32_t *src)
Import scalar.
uint8_t u
Definition: lldp_ext_med.h:213
uint8_t length
Definition: tcp.h:375
M5531 public-key hardware accelerator.
error_t ecMulFast(const EcCurve *curve, EcPoint3 *r, const uint32_t *d, const EcPoint3 *s)
Scalar multiplication (fast calculation)
OsMutex m5531CryptoMutex
Definition: m5531_crypto.c:42
Mpi qinv
CRT coefficient.
Definition: rsa.h:76
Mpi dq
Second factor's CRT exponent.
Definition: rsa.h:75
uint_t mpiGetLength(const Mpi *a)
Get the actual length in words.
Definition: mpi.c:189
const EcCurve * curve
Definition: ec.h:446
Working state (point addition/subtraction/doubling)
Definition: ec.h:445
uint8_t m
Definition: ndp.h:304
uint8_t n
RSA private key.
Definition: rsa.h:68
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
EC point (projective coordinates)
Definition: ec.h:409
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
M5531 hardware cryptographic accelerator.
#define M5531_CRYPTO_RAM_SECTION
Definition: m5531_crypto.h:39
error_t rsaExportMpi(uint32_t *src, uint_t length, Mpi *r)
Export multiple-precision integer.
#define cryptoAllocMem(size)
Definition: crypto.h:870
uint8_t s
Definition: igmp_common.h:234
#define EcCurve
Definition: ec.h:346
int_t mpiComp(const Mpi *a, const Mpi *b)
Compare two multiple precision integers.
Definition: mpi.c:359
Mpi dp
First factor's CRT exponent.
Definition: rsa.h:74
error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m)
RSA decryption primitive.
int_t mpiCompInt(const Mpi *a, mpi_sword_t b)
Compare a multiple precision integer with an integer.
Definition: mpi.c:430
unsigned int uint_t
Definition: compiler_port.h:57
#define osMemset(p, value, length)
Definition: os_port.h:141
error_t mpiMulMod(Mpi *r, const Mpi *a, const Mpi *b, const Mpi *p)
Modular multiplication.
ECC (Elliptic Curve Cryptography)
error_t mpiGrow(Mpi *r, uint_t size)
Adjust the size of multiple precision integer.
Definition: mpi.c:103
error_t mpiExpMod(Mpi *r, const Mpi *a, const Mpi *e, const Mpi *p)
Modular exponentiation.
#define EC_MAX_MODULUS_SIZE
Definition: ec.h:284
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t c
Definition: ndp.h:514
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
Debugging facilities.
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
Definition: mpi.c:216
void mpiFree(Mpi *r)
Release a multiple precision integer.
Definition: mpi.c:65