3636#include "sha/sha_core.h"
3737
3838/* Implementation that should never be optimized out by the compiler */
39- static void mbedtls_zeroize ( void * v , size_t n )
39+ static void mbedtls_zeroize (void * v , size_t n )
4040{
4141 volatile unsigned char * p = v ;
42- while ( n -- ) {
42+ while (n -- ) {
4343 * p ++ = 0 ;
4444 }
4545}
@@ -50,51 +50,51 @@ static void mbedtls_zeroize( void *v, size_t n )
5050#ifndef GET_UINT32_BE
5151#define GET_UINT32_BE (n ,b ,i ) \
5252do { \
53- (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
54- | ( (uint32_t) (b)[(i) + 1] << 16 ) \
55- | ( (uint32_t) (b)[(i) + 2] << 8 ) \
56- | ( (uint32_t) (b)[(i) + 3] ); \
57- } while( 0 )
53+ (n) = ((uint32_t) (b)[(i) ] << 24) \
54+ | ((uint32_t) (b)[(i) + 1] << 16) \
55+ | ((uint32_t) (b)[(i) + 2] << 8) \
56+ | ((uint32_t) (b)[(i) + 3] ); \
57+ } while(0 )
5858#endif
5959
6060#ifndef PUT_UINT32_BE
6161#define PUT_UINT32_BE (n ,b ,i ) \
6262do { \
63- (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
64- (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
65- (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
66- (b)[(i) + 3] = (unsigned char) ( (n) ); \
67- } while( 0 )
63+ (b)[(i) ] = (unsigned char) ((n) >> 24); \
64+ (b)[(i) + 1] = (unsigned char) ((n) >> 16); \
65+ (b)[(i) + 2] = (unsigned char) ((n) >> 8); \
66+ (b)[(i) + 3] = (unsigned char) ((n) ); \
67+ } while(0 )
6868#endif
6969
70- void mbedtls_sha256_init ( mbedtls_sha256_context * ctx )
70+ void mbedtls_sha256_init (mbedtls_sha256_context * ctx )
7171{
72- memset ( ctx , 0 , sizeof ( mbedtls_sha256_context ) );
72+ memset (ctx , 0 , sizeof (mbedtls_sha256_context ) );
7373}
7474
75- void mbedtls_sha256_free ( mbedtls_sha256_context * ctx )
75+ void mbedtls_sha256_free (mbedtls_sha256_context * ctx )
7676{
77- if ( ctx == NULL ) {
77+ if (ctx == NULL ) {
7878 return ;
7979 }
8080
81- mbedtls_zeroize ( ctx , sizeof ( mbedtls_sha256_context ) );
81+ mbedtls_zeroize (ctx , sizeof (mbedtls_sha256_context ) );
8282}
8383
84- void mbedtls_sha256_clone ( mbedtls_sha256_context * dst ,
85- const mbedtls_sha256_context * src )
84+ void mbedtls_sha256_clone (mbedtls_sha256_context * dst ,
85+ const mbedtls_sha256_context * src )
8686{
8787 * dst = * src ;
8888}
8989
9090/*
9191 * SHA-256 context setup
9292 */
93- int mbedtls_sha256_starts ( mbedtls_sha256_context * ctx , int is224 )
93+ int mbedtls_sha256_starts (mbedtls_sha256_context * ctx , int is224 )
9494{
95- memset ( ctx , 0 , sizeof ( mbedtls_sha256_context ) );
95+ memset (ctx , 0 , sizeof (mbedtls_sha256_context ) );
9696
97- if ( is224 ) {
97+ if (is224 ) {
9898 ctx -> mode = SHA2_224 ;
9999 } else {
100100 ctx -> mode = SHA2_256 ;
@@ -123,7 +123,7 @@ static void esp_internal_sha256_block_process(mbedtls_sha256_context *ctx, const
123123 }
124124}
125125
126- int mbedtls_internal_sha256_process ( mbedtls_sha256_context * ctx , const unsigned char data [64 ] )
126+ int mbedtls_internal_sha256_process (mbedtls_sha256_context * ctx , const unsigned char data [64 ])
127127{
128128 esp_sha_acquire_hardware ();
129129 esp_internal_sha_update_state (ctx );
@@ -149,13 +149,13 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, const unsigned
149149/*
150150 * SHA-256 process buffer
151151 */
152- int mbedtls_sha256_update ( mbedtls_sha256_context * ctx , const unsigned char * input ,
153- size_t ilen )
152+ int mbedtls_sha256_update (mbedtls_sha256_context * ctx , const unsigned char * input ,
153+ size_t ilen )
154154{
155155 size_t fill , left , len ;
156156 uint32_t local_len = 0 ;
157157
158- if ( ilen == 0 ) {
158+ if (ilen == 0 ) {
159159 return 0 ;
160160 }
161161
@@ -165,13 +165,13 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
165165 ctx -> total [0 ] += (uint32_t ) ilen ;
166166 ctx -> total [0 ] &= 0xFFFFFFFF ;
167167
168- if ( ctx -> total [0 ] < (uint32_t ) ilen ) {
168+ if (ctx -> total [0 ] < (uint32_t ) ilen ) {
169169 ctx -> total [1 ]++ ;
170170 }
171171
172172 /* Check if any data pending from previous call to this API */
173- if ( left && ilen >= fill ) {
174- memcpy ( (void * ) (ctx -> buffer + left ), input , fill );
173+ if (left && ilen >= fill ) {
174+ memcpy ((void * ) (ctx -> buffer + left ), input , fill );
175175
176176 input += fill ;
177177 ilen -= fill ;
@@ -181,7 +181,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
181181
182182 len = SHA_ALIGN_DOWN (ilen , 64 );
183183
184- if ( len || local_len ) {
184+ if (len || local_len ) {
185185
186186 esp_sha_acquire_hardware ();
187187
@@ -198,12 +198,12 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
198198#endif /* SOC_SHA_SUPPORT_DMA */
199199 {
200200 /* First process buffered block, if any */
201- if ( local_len ) {
201+ if (local_len ) {
202202 esp_internal_sha256_block_process (ctx , ctx -> buffer );
203203 }
204204
205205 uint32_t length_processed = 0 ;
206- while ( len - length_processed != 0 ) {
206+ while (len - length_processed != 0 ) {
207207 esp_internal_sha256_block_process (ctx , input + length_processed );
208208 length_processed += 64 ;
209209 }
@@ -214,8 +214,8 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
214214 esp_sha_release_hardware ();
215215 }
216216
217- if ( ilen > 0 ) {
218- memcpy ( (void * ) (ctx -> buffer + left ), input + len , ilen - len );
217+ if (ilen > 0 ) {
218+ memcpy ((void * ) (ctx -> buffer + left ), input + len , ilen - len );
219219 }
220220
221221 return 0 ;
@@ -231,28 +231,28 @@ static const unsigned char sha256_padding[64] = {
231231/*
232232 * SHA-256 final digest
233233 */
234- int mbedtls_sha256_finish ( mbedtls_sha256_context * ctx , unsigned char * output )
234+ int mbedtls_sha256_finish (mbedtls_sha256_context * ctx , unsigned char * output )
235235{
236236 int ret = -1 ;
237237 uint32_t last , padn ;
238238 uint32_t high , low ;
239239 unsigned char msglen [8 ];
240240
241- high = ( ctx -> total [0 ] >> 29 )
242- | ( ctx -> total [1 ] << 3 );
243- low = ( ctx -> total [0 ] << 3 );
241+ high = (ctx -> total [0 ] >> 29 )
242+ | (ctx -> total [1 ] << 3 );
243+ low = (ctx -> total [0 ] << 3 );
244244
245- PUT_UINT32_BE ( high , msglen , 0 );
246- PUT_UINT32_BE ( low , msglen , 4 );
245+ PUT_UINT32_BE (high , msglen , 0 );
246+ PUT_UINT32_BE (low , msglen , 4 );
247247
248248 last = ctx -> total [0 ] & 0x3F ;
249- padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
249+ padn = (last < 56 ) ? (56 - last ) : (120 - last );
250250
251- if ( ( ret = mbedtls_sha256_update ( ctx , sha256_padding , padn ) ) != 0 ) {
251+ if (( ret = mbedtls_sha256_update (ctx , sha256_padding , padn ) ) != 0 ) {
252252 return ret ;
253253 }
254254
255- if ( ( ret = mbedtls_sha256_update ( ctx , msglen , 8 ) ) != 0 ) {
255+ if (( ret = mbedtls_sha256_update (ctx , msglen , 8 ) ) != 0 ) {
256256 return ret ;
257257 }
258258
0 commit comments