@@ -38,9 +38,10 @@ static pico_aes_context_t aes_context = {};
3838})
3939
4040
41+ #if PICO_AES_SINGLE_USE
4142// The function lock_key() is called from pico_aes_decrypt_internal() after key initialisation is complete and before decryption begins.
4243// That is a suitable point to lock the OTP area where key information is stored.
43- __weak void pico_aes_lock_key () {
44+ void pico_aes_lock_key () {
4445 io_rw_32 * sw_lock = __get_opaque_ptr (& otp_hw -> sw_lock [0 ]) + aes_context .otp_key_page ;
4546#if PICO_AES_HARDENING
4647 // prevent compiler from re-using sw_lock pointer
@@ -79,7 +80,15 @@ __weak void pico_aes_lock_key() {
7980#endif
8081}
8182
82- __weak void pico_aes_lock_all (void ) {
83+ #else // not PICO_AES_SINGLE_USE
84+ void pico_aes_lock_key (void ) {
85+ #if RC_COUNT
86+ rcp_count_check_nodelay (31 + PICO_AES256_RCP_COUNT_DELTA );
87+ #endif
88+ }
89+ #endif // PICO_AES_SINGLE_USE
90+
91+ void pico_aes_lock_all (void ) {
8392 io_rw_32 * sw_lock = __get_opaque_ptr (& otp_hw -> sw_lock [0 ]) + aes_context .otp_key_page ;
8493#if PICO_AES_HARDENING
8594 // we only actually need to lock page 2 but we lock and check 0, 1, 2 anyway
@@ -116,21 +125,23 @@ __weak void pico_aes_lock_all(void) {
116125#endif
117126}
118127
119- #include <stdio.h>
128+
120129int pico_aes_try_decrypt (uint8_t (* data )[16 ], size_t data_size , uint32_t otp_key_page , uint8_t * iv_public ) {
121130 if (!bootrom_try_acquire_lock (BOOTROM_LOCK_SHA_256 )) return PICO_ERROR_RESOURCE_IN_USE ;
122131
123132 aes_context .otp_key_page = otp_key_page ;
124133
125134 uint16_t * otp_data = (uint16_t * )OTP_DATA_GUARDED_BASE ;
126135
136+ #if !PICO_AES_SINGLE_USE
127137 // Restore aes_scratch_y from stored location in RAM_STORE
128138 extern uint32_t __aes_scratch_y_source__ ;
129139 extern uint32_t __aes_scratch_y_start__ ;
130140 extern uint32_t __aes_scratch_y_end__ ;
131141
132142 uint32_t stored_words = (uint32_t )(& __aes_scratch_y_end__ - & __aes_scratch_y_start__ );
133143 memcpy (& __aes_scratch_y_start__ , & __aes_scratch_y_source__ , stored_words * sizeof (uint32_t ));
144+ #endif // !PICO_AES_SINGLE_USE
134145
135146 pico_aes_decrypt_internal (
136147 (uint8_t * )& (otp_data [otp_key_page * 0x40 ]),
0 commit comments