@@ -209,15 +209,62 @@ WC_MISC_STATIC WC_INLINE void ByteReverseWords(word32* out, const word32* in,
209209#endif
210210}
211211
212+ WC_MISC_STATIC WC_INLINE word32 readUnalignedWord32 (const byte * in )
213+ {
214+ if (((wc_ptr_t )in & (wc_ptr_t )(sizeof (word32 ) - 1U )) == (wc_ptr_t )0 )
215+ return * (word32 * )in ;
216+ else {
217+ word32 out = 0 ; /* else CONFIG_FORTIFY_SOURCE -Wmaybe-uninitialized */
218+ XMEMCPY (& out , in , sizeof (out ));
219+ return out ;
220+ }
221+ }
222+
223+ WC_MISC_STATIC WC_INLINE word32 writeUnalignedWord32 (void * out , word32 in )
224+ {
225+ if (((wc_ptr_t )out & (wc_ptr_t )(sizeof (word32 ) - 1U )) == (wc_ptr_t )0 )
226+ * (word32 * )out = in ;
227+ else {
228+ XMEMCPY (out , & in , sizeof (in ));
229+ }
230+ return in ;
231+ }
232+
233+ WC_MISC_STATIC WC_INLINE void readUnalignedWords32 (word32 * out , const byte * in ,
234+ size_t count )
235+ {
236+ if (((wc_ptr_t )in & (wc_ptr_t )(sizeof (word32 ) - 1U )) == (wc_ptr_t )0 ) {
237+ const word32 * in_word32 = (const word32 * )in ;
238+ while (count -- > 0 )
239+ * out ++ = * in_word32 ++ ;
240+ }
241+ else {
242+ XMEMCPY (out , in , count * sizeof (* out ));
243+ }
244+ }
245+
246+ WC_MISC_STATIC WC_INLINE void writeUnalignedWords32 (byte * out , const word32 * in ,
247+ size_t count )
248+ {
249+ if (((wc_ptr_t )out & (wc_ptr_t )(sizeof (word32 ) - 1U )) == (wc_ptr_t )0 ) {
250+ word32 * out_word32 = (word32 * )out ;
251+ while (count -- > 0 )
252+ * out_word32 ++ = * in ++ ;
253+ }
254+ else {
255+ XMEMCPY (out , in , count * sizeof (* in ));
256+ }
257+ }
258+
212259#if defined(WORD64_AVAILABLE ) && !defined(WOLFSSL_NO_WORD64_OPS )
213260
214261WC_MISC_STATIC WC_INLINE word64 readUnalignedWord64 (const byte * in )
215262{
216263 if (((wc_ptr_t )in & (wc_ptr_t )(sizeof (word64 ) - 1U )) == (wc_ptr_t )0 )
217264 return * (word64 * )in ;
218265 else {
219- word64 out ;
220- XMEMCPY (& out , in , sizeof (word64 ));
266+ word64 out = 0 ; /* else CONFIG_FORTIFY_SOURCE -Wmaybe-uninitialized */
267+ XMEMCPY (& out , in , sizeof (out ));
221268 return out ;
222269 }
223270}
@@ -227,7 +274,7 @@ WC_MISC_STATIC WC_INLINE word64 writeUnalignedWord64(void *out, word64 in)
227274 if (((wc_ptr_t )out & (wc_ptr_t )(sizeof (word64 ) - 1U )) == (wc_ptr_t )0 )
228275 * (word64 * )out = in ;
229276 else {
230- XMEMCPY (out , & in , sizeof (word64 ));
277+ XMEMCPY (out , & in , sizeof (in ));
231278 }
232279 return in ;
233280}
@@ -241,7 +288,7 @@ WC_MISC_STATIC WC_INLINE void readUnalignedWords64(word64 *out, const byte *in,
241288 * out ++ = * in_word64 ++ ;
242289 }
243290 else {
244- XMEMCPY (out , in , count * sizeof (word64 ));
291+ XMEMCPY (out , in , count * sizeof (* out ));
245292 }
246293}
247294
@@ -254,7 +301,7 @@ WC_MISC_STATIC WC_INLINE void writeUnalignedWords64(byte *out, const word64 *in,
254301 * out_word64 ++ = * in ++ ;
255302 }
256303 else {
257- XMEMCPY (out , in , count * sizeof (word64 ));
304+ XMEMCPY (out , in , count * sizeof (* in ));
258305 }
259306}
260307
0 commit comments