Index: components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc |
diff --git a/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc b/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc |
index 476721c97c5caef0306f5bc113514e99fa7b52ac..4313ebb06d24de992221349f6cf4b62c0ac3e3d5 100644 |
--- a/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc |
+++ b/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc |
@@ -4,11 +4,32 @@ |
#include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" |
+#include <math.h> |
+ |
+#include "base/md5.h" |
#include "base/sha1.h" |
#include "components/proximity_auth/cryptauth/base64url.h" |
namespace proximity_auth { |
+int64_t HashStringToInt64(const std::string& string) { |
+ base::MD5Context context; |
+ base::MD5Init(&context); |
+ base::MD5Update(&context, string); |
+ |
+ base::MD5Digest digest; |
+ base::MD5Final(&digest, &context); |
sacomoto
2015/08/27 15:38:05
Why don't you use |base::MD5Sum()|?
Tim Song
2015/08/27 18:12:27
I feel it's a bit safer to use the MD5Context inte
sacomoto
2015/08/28 14:47:17
Ok. It makes sense.
|
+ |
+ // Fold the digest into an int64 value. |
sacomoto
2015/08/27 15:38:05
Please add a comment saying that |digest.a| has 12
Tim Song
2015/08/27 18:12:27
Done.
|
+ int64_t hash = 0; |
+ for (size_t i = 0; i < sizeof(digest.a); ++i) { |
+ uint8_t byte = digest.a[i]; |
+ hash += static_cast<int64_t>(byte) << (i % sizeof(int64_t)); |
+ } |
+ |
+ return hash; |
+} |
+ |
std::string CalculateDeviceUserId(const std::string& device_id, |
const std::string& user_id) { |
std::string device_user_id; |