mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-11-03 14:33:37 +03:00 
			
		
		
		
	Use 2nd stack for update signature verification (#7149)
* Use 2nd stack for update signature verification Fixes #7145 When doing a signed update, the signature calculation can use a lot of stack, so move it silently to the BearSSL second stack. Also fix a memory leak of signature-bytes found by @JiriBilek * Reset state on any error condition in Updater::end
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							afb9921d38
						
					
				
				
					commit
					e252873263
				
			@@ -870,9 +870,9 @@ uint32_t SigningVerifier::length()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
 | 
			
		||||
  if (!_pubKey || !hash || !signature || signatureLen != length()) return false;
 | 
			
		||||
 | 
			
		||||
// We need to use the 2nd stack to do a verification, so do the thunk
 | 
			
		||||
// directly inside the class function for ease of use.
 | 
			
		||||
extern "C" bool SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
 | 
			
		||||
  if (_pubKey->isRSA()) {
 | 
			
		||||
    bool ret;
 | 
			
		||||
    unsigned char vrf[hash->len()];
 | 
			
		||||
@@ -890,6 +890,20 @@ bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#if !CORE_MOCK
 | 
			
		||||
make_stack_thunk(SigningVerifier_verify);
 | 
			
		||||
extern "C" bool thunk_SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
 | 
			
		||||
  if (!_pubKey || !hash || !signature || signatureLen != length()) return false;
 | 
			
		||||
#if !CORE_MOCK
 | 
			
		||||
    return thunk_SigningVerifier_verify(_pubKey, hash, signature, signatureLen);
 | 
			
		||||
#else
 | 
			
		||||
    return SigningVerifier_verify(_pubKey, hash, signature, signatureLen);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !CORE_MOCK
 | 
			
		||||
 | 
			
		||||
// Second stack thunked helpers
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user