@@ -91,7 +91,7 @@ void signerAtsha204Init(void) {
91
91
92
92
bool signerAtsha204CheckTimer (void ) {
93
93
if (_signing_verification_ongoing) {
94
- if (millis () < _signing_timestamp || millis () > _signing_timestamp + MY_VERIFICATION_TIMEOUT_MS) {
94
+ if (hwMillis () < _signing_timestamp || hwMillis () > _signing_timestamp + MY_VERIFICATION_TIMEOUT_MS) {
95
95
DEBUG_SIGNING_PRINTBUF (F (" Verification timeout" ), NULL , 0 );
96
96
// Purge nonce
97
97
memset (_signing_current_nonce, 0x00 , NONCE_NUMIN_SIZE_PASSTHROUGH);
@@ -105,15 +105,15 @@ bool signerAtsha204CheckTimer(void) {
105
105
bool signerAtsha204GetNonce (MyMessage &msg) {
106
106
DEBUG_SIGNING_PRINTBUF (F (" Signing backend: ATSHA204" ), NULL , 0 );
107
107
// Generate random number for use as nonce
108
- // We used a basic whitening technique that takes the first byte of a new random value and builds up a 32-byte random value
108
+ // We used a basic whitening technique that XORs each byte in a 32byte random value with current hwMillis() counter
109
109
// This 32-byte random value is then hashed (SHA256) to produce the resulting nonce
110
+ if (atsha204.sha204m_execute (SHA204_RANDOM, RANDOM_SEED_UPDATE, 0 , 0 , NULL ,
111
+ RANDOM_COUNT, _singning_tx_buffer, RANDOM_RSP_SIZE, _singning_rx_buffer) != SHA204_SUCCESS) {
112
+ DEBUG_SIGNING_PRINTBUF (F (" Failed to generate nonce" ), NULL , 0 );
113
+ return false ;
114
+ }
110
115
for (int i = 0 ; i < 32 ; i++) {
111
- if (atsha204.sha204m_execute (SHA204_RANDOM, RANDOM_NO_SEED_UPDATE, 0 , 0 , NULL ,
112
- RANDOM_COUNT, _singning_tx_buffer, RANDOM_RSP_SIZE, _singning_rx_buffer) != SHA204_SUCCESS) {
113
- DEBUG_SIGNING_PRINTBUF (F (" Failed to generate nonce" ), NULL , 0 );
114
- return false ;
115
- }
116
- _signing_current_nonce[i] = _singning_rx_buffer[SHA204_BUFFER_POS_DATA];
116
+ _signing_current_nonce[i] = _singning_rx_buffer[SHA204_BUFFER_POS_DATA+i] ^ (hwMillis ()&0xFF );
117
117
}
118
118
memcpy (_signing_current_nonce, signerSha256 (_signing_current_nonce, 32 ), MAX_PAYLOAD);
119
119
@@ -123,11 +123,11 @@ bool signerAtsha204GetNonce(MyMessage &msg) {
123
123
// Transfer the first part of the nonce to the message
124
124
msg.set (_signing_current_nonce, MAX_PAYLOAD);
125
125
_signing_verification_ongoing = true ;
126
- _signing_timestamp = millis (); // Set timestamp to determine when to purge nonce
126
+ _signing_timestamp = hwMillis (); // Set timestamp to determine when to purge nonce
127
127
// Be a little fancy to handle turnover (prolong the time allowed to timeout after turnover)
128
128
// Note that if message is "too" quick, and arrives before turnover, it will be rejected
129
129
// but this is consider such a rare case that it is accepted and rejects are 'safe'
130
- if (_signing_timestamp + MY_VERIFICATION_TIMEOUT_MS < millis ()) _signing_timestamp = 0 ;
130
+ if (_signing_timestamp + MY_VERIFICATION_TIMEOUT_MS < hwMillis ()) _signing_timestamp = 0 ;
131
131
return true ;
132
132
}
133
133
0 commit comments