Skip to content

Commit 02a6fd5

Browse files
committed
optimize mod mult code
1 parent fbd3bd4 commit 02a6fd5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main/crypto/esp32_ed25519.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ static inline void wait_op_complete(void)
161161
void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b)
162162
{
163163

164-
mpi_enable_hardware_hw_op();
165-
166164
uint32_t i;
167165

168166
// Set mode register
@@ -214,8 +212,6 @@ void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b)
214212
r[i] = DPORT_SEQUENCE_REG_READ(RSA_MEM_Z_BLOCK_BASE + i * 4);
215213
}
216214

217-
218-
mpi_disable_hardware_hw_op();
219215
}
220216

221217
void curve25519SetInt(uint32_t *a, uint32_t b)
@@ -652,6 +648,8 @@ int ed25519GeneratePublicKey(const uint8_t *privateKey, uint8_t *publicKey)
652648
// the buffer as the little-endian integer, forming a secret scalar s
653649
s = digest;
654650

651+
mpi_enable_hardware_hw_op();
652+
655653
// The lowest three bits of the first octet are cleared, the highest bit
656654
// of the last octet is cleared, and the second highest bit of the last
657655
// octet is set
@@ -665,6 +663,8 @@ int ed25519GeneratePublicKey(const uint8_t *privateKey, uint8_t *publicKey)
665663
// The public key A is the encoding of the point s * B
666664
ed25519Encode(&state->sb, publicKey);
667665

666+
mpi_disable_hardware_hw_op();
667+
668668
// Erase working state
669669
memset(state, 0, sizeof(Ed25519State));
670670

@@ -846,6 +846,8 @@ int ed25519GenerateSignatureEx(const uint8_t *privateKey,
846846
// Construct the secret scalar s from the first half of the digest
847847
memcpy(state->s, digest, 32);
848848

849+
mpi_enable_hardware_hw_op();
850+
849851
// The lowest three bits of the first octet are cleared, the highest bit
850852
// of the last octet is cleared, and the second highest bit of the last
851853
// octet is set
@@ -946,6 +948,8 @@ int ed25519GenerateSignatureEx(const uint8_t *privateKey,
946948
c = ed25519SubInt(state->p, state->s, ED25519_L, 32);
947949
ed25519SelectInt(signature + 32, state->p, state->s, c, 32);
948950

951+
mpi_disable_hardware_hw_op();
952+
949953
// Erase working state
950954
memset(state, 0, sizeof(Ed25519State));
951955

0 commit comments

Comments
 (0)