@@ -88,13 +88,7 @@ static int ed25519_hash_init(ed25519_key* key, wc_Sha512 *sha)
8888{
8989 int ret ;
9090
91- #ifndef WOLFSSL_ED25519_PERSISTENT_SHA
92- /* when not using persistent SHA, we'll zero the sha param */
93- XMEMSET (sha , 0 , sizeof (wc_Sha512 ));
94- #endif
95-
9691 ret = wc_InitSha512_ex (sha , key -> heap ,
97-
9892#if defined(WOLF_CRYPTO_CB )
9993 key -> devId
10094#else
@@ -103,8 +97,9 @@ static int ed25519_hash_init(ed25519_key* key, wc_Sha512 *sha)
10397 );
10498
10599#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
106- if (ret == 0 )
100+ if (ret == 0 ) {
107101 key -> sha_clean_flag = 1 ;
102+ }
108103#endif
109104
110105 return ret ;
@@ -114,8 +109,10 @@ static int ed25519_hash_init(ed25519_key* key, wc_Sha512 *sha)
114109static int ed25519_hash_reset (ed25519_key * key )
115110{
116111 int ret ;
117- if (key -> sha_clean_flag )
112+
113+ if (key -> sha_clean_flag ) {
118114 ret = 0 ;
115+ }
119116 else {
120117 wc_Sha512Free (& key -> sha );
121118 ret = wc_InitSha512_ex (& key -> sha , key -> heap ,
@@ -128,6 +125,7 @@ static int ed25519_hash_reset(ed25519_key* key)
128125 if (ret == 0 )
129126 key -> sha_clean_flag = 1 ;
130127 }
128+
131129 return ret ;
132130}
133131#endif /* WOLFSSL_ED25519_PERSISTENT_SHA */
@@ -136,8 +134,9 @@ static int ed25519_hash_update(ed25519_key* key, wc_Sha512 *sha,
136134 const byte * data , word32 len )
137135{
138136#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
139- if (key -> sha_clean_flag )
137+ if (key -> sha_clean_flag ) {
140138 key -> sha_clean_flag = 0 ;
139+ }
141140#else
142141 (void )key ;
143142#endif
@@ -148,8 +147,9 @@ static int ed25519_hash_final(ed25519_key* key, wc_Sha512 *sha, byte* hash)
148147{
149148 int ret = wc_Sha512Final (sha , hash );
150149#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
151- if (ret == 0 )
150+ if (ret == 0 ) {
152151 key -> sha_clean_flag = 1 ;
152+ }
153153#else
154154 (void )key ;
155155#endif
@@ -187,16 +187,15 @@ static int ed25519_hash(ed25519_key* key, const byte* in, word32 inLen,
187187#else
188188 ret = ed25519_hash_init (key , sha );
189189#endif
190- if (ret < 0 )
191- return ret ;
192-
193- ret = ed25519_hash_update (key , sha , in , inLen );
194- if (ret == 0 )
195- ret = ed25519_hash_final (key , sha , hash );
190+ if (ret == 0 ) {
191+ ret = ed25519_hash_update (key , sha , in , inLen );
192+ if (ret == 0 )
193+ ret = ed25519_hash_final (key , sha , hash );
196194
197- #ifndef WOLFSSL_ED25519_PERSISTENT_SHA
198- ed25519_hash_free (key , sha );
199- #endif
195+ #ifndef WOLFSSL_ED25519_PERSISTENT_SHA
196+ ed25519_hash_free (key , sha );
197+ #endif
198+ }
200199
201200 return ret ;
202201}
0 commit comments