11
11
#include "hardware/sha256.h"
12
12
#include "pico/bootrom/lock.h"
13
13
#include "pico/sha256.h"
14
+ #if !defined(__ZEPHYR__ )
14
15
#include "pico/time.h"
16
+ #endif
15
17
16
18
// We add one 0x80 byte, then 8 bytes for the size
17
19
#define SHA256_PADDING_DATA_BYTES 9
18
20
#define SHA256_BLOCK_SIZE_BYTES 64
19
21
22
+ #if !defined(__ZEPHYR__ )
20
23
bool __weak pico_sha256_lock (pico_sha256_state_t * state ) {
21
24
if (!bootrom_try_acquire_lock (BOOTROM_LOCK_SHA_256 ))
22
25
return false;
@@ -68,8 +71,10 @@ int pico_sha256_start_blocking_until(pico_sha256_state_t *state, enum sha256_end
68
71
} while (true);
69
72
return rc ;
70
73
}
74
+ #endif
71
75
72
76
static void write_to_hardware (pico_sha256_state_t * state , const uint8_t * data , size_t data_size_bytes ) {
77
+ #if !defined(__ZEPHYR__ )
73
78
if (state -> channel >= 0 ) {
74
79
dma_channel_wait_for_finish_blocking (state -> channel );
75
80
assert (!sha256_err_not_ready ());
@@ -83,6 +88,7 @@ static void write_to_hardware(pico_sha256_state_t *state, const uint8_t *data, s
83
88
true
84
89
);
85
90
} else {
91
+ #endif
86
92
if (!state -> cache_used && !(((uintptr_t )data )& 3u )) {
87
93
GCC_Like_Pragma ("GCC diagnostic ignored \"-Wcast-align\"" )
88
94
const uint32_t * data32 = (const uint32_t * )data ;
@@ -103,7 +109,9 @@ static void write_to_hardware(pico_sha256_state_t *state, const uint8_t *data, s
103
109
sha256_put_word (state -> cache .word );
104
110
}
105
111
}
112
+ #if !defined(__ZEPHYR__ )
106
113
}
114
+ #endif
107
115
}
108
116
109
117
static void update_internal (pico_sha256_state_t * state , const uint8_t * data , size_t data_size_bytes ) {
@@ -138,12 +146,14 @@ void pico_sha256_update(pico_sha256_state_t *state, const uint8_t *data, size_t
138
146
update_internal (state , data , data_size_bytes );
139
147
}
140
148
149
+ #if !defined(__ZEPHYR__ )
141
150
void pico_sha256_update_blocking (pico_sha256_state_t * state , const uint8_t * data , size_t data_size_bytes ) {
142
151
update_internal (state , data , data_size_bytes );
143
152
if (state -> channel >= 0 ) {
144
153
dma_channel_wait_for_finish_blocking (state -> channel );
145
154
}
146
155
}
156
+ #endif
147
157
148
158
// write the SHA-256 padding to hardware
149
159
static void write_padding (pico_sha256_state_t * state ) {
@@ -164,6 +174,7 @@ static void write_padding(pico_sha256_state_t *state) {
164
174
update_internal (state , (uint8_t * )& size , sizeof (uint64_t )); // last write
165
175
}
166
176
177
+ #if !defined(__ZEPHYR__ )
167
178
void pico_sha256_finish (pico_sha256_state_t * state , sha256_result_t * out ) {
168
179
assert (state -> locked );
169
180
// pass NULL to abandon the current hash in case of an error
@@ -183,3 +194,10 @@ void pico_sha256_finish(pico_sha256_state_t *state, sha256_result_t *out) {
183
194
}
184
195
pico_sha256_unlock (state );
185
196
}
197
+ #endif
198
+
199
+ #if defined(__ZEPHYR__ )
200
+ void pico_sha256_write_padding (pico_sha256_state_t * state ) {
201
+ write_padding (state );
202
+ }
203
+ #endif
0 commit comments