32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "em_device.h"
36 #include "em_crypto.h"
45 #if (EFM32GG11_CRYPTO_PKC_SUPPORT == ENABLED)
75 CRYPTO_ModulusSet(CRYPTO0, cryptoModulusEccP256);
76 CRYPTO_MulOperandWidthSet(CRYPTO0, cryptoMulOperandModulusBits);
77 CRYPTO_ResultWidthSet(CRYPTO0, cryptoResult256Bits);
80 for(i = 0; i <
a->size && i < 8; i++)
90 CRYPTO_DDataWrite(&CRYPTO0->DDATA1, temp);
93 for(i = 0; i <
b->size && i < 8; i++)
103 CRYPTO_DDataWrite(&CRYPTO0->DDATA2, temp);
106 CRYPTO_EXECUTE_2(CRYPTO0,
107 CRYPTO_CMD_INSTR_SELDDATA0DDATA2,
108 CRYPTO_CMD_INSTR_MMUL);
111 CRYPTO_InstructionSequenceWait(CRYPTO0);
114 CRYPTO_DDataRead(&CRYPTO0->DDATA0, temp);
120 for(i = 0; i < 8; i++)
122 r->data[i] = temp[i];
145 if(params->
mod != NULL)
147 error = params->
mod(
r, ¶ms->
p);
186 CRYPTO_ModulusSet(CRYPTO0, cryptoModulusEccP256);
187 CRYPTO_MulOperandWidthSet(CRYPTO0, cryptoMulOperandModulusBits);
188 CRYPTO_ResultWidthSet(CRYPTO0, cryptoResult256Bits);
191 for(i = 0; i <
a->size && i < 8; i++)
193 temp[i] =
a->data[i];
201 CRYPTO_DDataWrite(&CRYPTO0->DDATA1, temp);
204 CRYPTO_EXECUTE_3(CRYPTO0,
205 CRYPTO_CMD_INSTR_DDATA1TODDATA2,
206 CRYPTO_CMD_INSTR_SELDDATA0DDATA2,
207 CRYPTO_CMD_INSTR_MMUL);
210 CRYPTO_InstructionSequenceWait(CRYPTO0);
213 CRYPTO_DDataRead(&CRYPTO0->DDATA0, temp);
219 for(i = 0; i < 8; i++)
221 r->data[i] = temp[i];
244 if(params->
mod != NULL)
246 error = params->
mod(
r, ¶ms->
p);
260 #if (X25519_SUPPORT == ENABLED || ED25519_SUPPORT == ENABLED)
283 CRYPTO_MulOperandWidthSet(CRYPTO0, cryptoMulOperand256Bits);
284 CRYPTO_ResultWidthSet(CRYPTO0, cryptoResult256Bits);
287 CRYPTO_DDataWrite(&CRYPTO0->DDATA1,
a);
289 CRYPTO_DDataWrite(&CRYPTO0->DDATA2,
b);
292 CRYPTO_EXECUTE_2(CRYPTO0,
293 CRYPTO_CMD_INSTR_SELDDATA0DDATA2,
294 CRYPTO_CMD_INSTR_LMUL);
297 CRYPTO_InstructionSequenceWait(CRYPTO0);
300 CRYPTO_DDataRead(&CRYPTO0->DDATA0,
u);
301 CRYPTO_DDataRead(&CRYPTO0->DDATA1,
u + 8);
307 temp = (
u[7] >> 31) * 19;
312 for(i = 0; i < 8; i++)
315 temp += (uint64_t)
u[i + 8] * 38;
316 u[i] = temp & 0xFFFFFFFF;
323 temp += (
u[7] >> 31) * 19;
328 for(i = 0; i < 8; i++)
331 u[i] = temp & 0xFFFFFFFF;
360 CRYPTO_MulOperandWidthSet(CRYPTO0, cryptoMulOperand256Bits);
361 CRYPTO_ResultWidthSet(CRYPTO0, cryptoResult256Bits);
364 CRYPTO_DDataWrite(&CRYPTO0->DDATA1,
a);
367 CRYPTO_EXECUTE_3(CRYPTO0,
368 CRYPTO_CMD_INSTR_DDATA1TODDATA2,
369 CRYPTO_CMD_INSTR_SELDDATA0DDATA2,
370 CRYPTO_CMD_INSTR_LMUL);
373 CRYPTO_InstructionSequenceWait(CRYPTO0);
376 CRYPTO_DDataRead(&CRYPTO0->DDATA0,
u);
377 CRYPTO_DDataRead(&CRYPTO0->DDATA1,
u + 8);
383 temp = (
u[7] >> 31) * 19;
388 for(i = 0; i < 8; i++)
391 temp += (uint64_t)
u[i + 8] * 38;
392 u[i] = temp & 0xFFFFFFFF;
399 temp += (
u[7] >> 31) * 19;
404 for(i = 0; i < 8; i++)
407 u[i] = temp & 0xFFFFFFFF;