Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c231bbf

Browse files
committed
Merge branch 'evp' of https://github.com/xkszltl/aws-sdk-cpp into xkszltl-evp
2 parents a670a3e + d892907 commit c231bbf

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

aws-cpp-sdk-core/source/utils/crypto/openssl/CryptoImpl.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,22 @@ namespace Aws
126126

127127
HashResult MD5OpenSSLImpl::Calculate(const Aws::String& str)
128128
{
129-
MD5_CTX md5;
130-
MD5_Init(&md5);
131-
MD5_Update(&md5, str.c_str(), str.size());
129+
auto ctx = EVP_MD_CTX_create();
130+
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
131+
EVP_DigestInit_ex(ctx, EVP_md5(), nullptr);
132+
EVP_DigestUpdate(ctx, str.c_str(), str.size());
132133

133-
ByteBuffer hash(MD5_DIGEST_LENGTH);
134-
MD5_Final(hash.GetUnderlyingData(), &md5);
134+
ByteBuffer hash(EVP_MD_size(EVP_md5()));
135+
EVP_DigestFinal(ctx, hash.GetUnderlyingData(), nullptr);
135136

136137
return HashResult(std::move(hash));
137138
}
138139

139140
HashResult MD5OpenSSLImpl::Calculate(Aws::IStream& stream)
140141
{
141-
MD5_CTX md5;
142-
MD5_Init(&md5);
142+
auto ctx = EVP_MD_CTX_create();
143+
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
144+
EVP_DigestInit_ex(ctx, EVP_md5(), nullptr);
143145

144146
auto currentPos = stream.tellg();
145147
if (currentPos == -1)
@@ -157,35 +159,35 @@ namespace Aws
157159

158160
if (bytesRead > 0)
159161
{
160-
MD5_Update(&md5, streamBuffer, static_cast<size_t>(bytesRead));
162+
EVP_DigestUpdate(ctx, streamBuffer, static_cast<size_t>(bytesRead));
161163
}
162164
}
163165

164166
stream.clear();
165167
stream.seekg(currentPos, stream.beg);
166168

167-
ByteBuffer hash(MD5_DIGEST_LENGTH);
168-
MD5_Final(hash.GetUnderlyingData(), &md5);
169+
ByteBuffer hash(EVP_MD_size(EVP_md5()));
170+
EVP_DigestFinal(ctx, hash.GetUnderlyingData(), nullptr);
169171

170172
return HashResult(std::move(hash));
171173
}
172174

173175
HashResult Sha256OpenSSLImpl::Calculate(const Aws::String& str)
174176
{
175-
SHA256_CTX sha256;
176-
SHA256_Init(&sha256);
177-
SHA256_Update(&sha256, str.c_str(), str.size());
177+
auto ctx = EVP_MD_CTX_create();
178+
EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr);
179+
EVP_DigestUpdate(ctx, str.c_str(), str.size());
178180

179-
ByteBuffer hash(SHA256_DIGEST_LENGTH);
180-
SHA256_Final(hash.GetUnderlyingData(), &sha256);
181+
ByteBuffer hash(EVP_MD_size(EVP_sha256()));
182+
EVP_DigestFinal(ctx, hash.GetUnderlyingData(), nullptr);
181183

182184
return HashResult(std::move(hash));
183185
}
184186

185187
HashResult Sha256OpenSSLImpl::Calculate(Aws::IStream& stream)
186188
{
187-
SHA256_CTX sha256;
188-
SHA256_Init(&sha256);
189+
auto ctx = EVP_MD_CTX_create();
190+
EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr);
189191

190192
auto currentPos = stream.tellg();
191193
if (currentPos == -1)
@@ -204,15 +206,15 @@ namespace Aws
204206

205207
if (bytesRead > 0)
206208
{
207-
SHA256_Update(&sha256, streamBuffer, static_cast<size_t>(bytesRead));
209+
EVP_DigestUpdate(ctx, streamBuffer, static_cast<size_t>(bytesRead));
208210
}
209211
}
210212

211213
stream.clear();
212214
stream.seekg(currentPos, stream.beg);
213215

214-
ByteBuffer hash(SHA256_DIGEST_LENGTH);
215-
SHA256_Final(hash.GetUnderlyingData(), &sha256);
216+
ByteBuffer hash(EVP_MD_size(EVP_sha256()));
217+
EVP_DigestFinal(ctx, hash.GetUnderlyingData(), nullptr);
216218

217219
return HashResult(std::move(hash));
218220
}

0 commit comments

Comments
 (0)