Changeset 182895 in webkit
- Timestamp:
- Apr 16, 2015, 10:44:13 AM (11 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
wtf/MD5.cpp (modified) (3 diffs)
-
wtf/MD5.h (modified) (2 diffs)
-
wtf/SHA1.cpp (modified) (4 diffs)
-
wtf/SHA1.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r182890 r182895 1 2015-04-16 Antti Koivisto <antti@apple.com> 2 3 Use CommonCrypto for SHA1 and MD5 4 https://bugs.webkit.org/show_bug.cgi?id=143826 5 6 Reviewed by Anders Carlsson. 7 8 CommonCrypto SHA1 implementation is ~4x faster than the naive WTF one. Use it when available. 9 10 These are covered by existing API tests. 11 12 * wtf/MD5.cpp: 13 (WTF::MD5::MD5): 14 (WTF::MD5::addBytes): 15 (WTF::MD5::checksum): 16 * wtf/MD5.h: 17 * wtf/SHA1.cpp: 18 (WTF::SHA1::SHA1): 19 (WTF::SHA1::addBytes): 20 (WTF::SHA1::computeHash): 21 22 Remove the side effect where computeHash resets the state. No one relies on it. 23 24 (WTF::SHA1::hexDigest): 25 (WTF::SHA1::computeHexDigest): 26 * wtf/SHA1.h: 27 1 28 2015-04-16 Csaba Osztrogonác <ossy@webkit.org> 2 29 -
trunk/Source/WTF/wtf/MD5.cpp
r160460 r182895 3 3 /* 4 4 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2015 Apple Inc. All rights reserved. 5 6 * 6 7 * Redistribution and use in source and binary forms, with or without … … 59 60 namespace WTF { 60 61 62 #if PLATFORM(COCOA) 63 64 MD5::MD5() 65 { 66 CC_MD5_Init(&m_context); 67 } 68 69 void MD5::addBytes(const uint8_t* input, size_t length) 70 { 71 CC_MD5_Update(&m_context, input, length); 72 } 73 74 void MD5::checksum(Digest& hash) 75 { 76 CC_MD5_Final(hash.data(), &m_context); 77 } 78 79 #else 80 61 81 // Note: this code is harmless on little-endian machines. 62 82 … … 265 285 } 266 286 287 #endif 288 267 289 } // namespace WTF -
trunk/Source/WTF/wtf/MD5.h
r160386 r182895 35 35 #include <wtf/Vector.h> 36 36 37 #if PLATFORM(COCOA) 38 #include <CommonCrypto/CommonDigest.h> 39 #endif 40 37 41 namespace WTF { 38 42 … … 57 61 58 62 private: 63 #if PLATFORM(COCOA) 64 CC_MD5_CTX m_context; 65 #else 59 66 uint32_t m_buf[4]; 60 67 uint32_t m_bits[2]; 61 68 uint8_t m_in[64]; 69 #endif 62 70 }; 63 71 -
trunk/Source/WTF/wtf/SHA1.cpp
r160456 r182895 1 1 /* 2 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 29 30 */ 30 31 32 #include "config.h" 33 #include "SHA1.h" 34 35 #include "Assertions.h" 36 37 #include "StringExtras.h" 38 #include "text/CString.h" 39 40 namespace WTF { 41 42 #if PLATFORM(COCOA) 43 44 SHA1::SHA1() 45 { 46 CC_SHA1_Init(&m_context); 47 } 48 49 void SHA1::addBytes(const uint8_t* input, size_t length) 50 { 51 CC_SHA1_Update(&m_context, input, length); 52 } 53 54 void SHA1::computeHash(Digest& hash) 55 { 56 CC_SHA1_Final(hash.data(), &m_context); 57 } 58 59 #else 60 31 61 // A straightforward SHA-1 implementation based on RFC 3174. 32 62 // http://www.ietf.org/rfc/rfc3174.txt 33 63 // The names of functions and variables (such as "a", "b", and "f") follow notations in RFC 3174. 34 35 #include "config.h"36 #include "SHA1.h"37 38 #include "Assertions.h"39 40 #include "StringExtras.h"41 #include "text/CString.h"42 43 namespace WTF {44 64 45 65 static inline uint32_t f(int t, uint32_t b, uint32_t c, uint32_t d) … … 105 125 } 106 126 107 CString SHA1::hexDigest(const Digest& digest)108 {109 char* start = 0;110 CString result = CString::newUninitialized(40, start);111 char* buffer = start;112 for (size_t i = 0; i < hashSize; ++i) {113 snprintf(buffer, 3, "%02X", digest.at(i));114 buffer += 2;115 }116 return result;117 }118 119 CString SHA1::computeHexDigest()120 {121 Digest digest;122 computeHash(digest);123 return hexDigest(digest);124 }125 126 127 void SHA1::finalize() 127 128 { … … 196 197 } 197 198 199 #endif 200 201 CString SHA1::hexDigest(const Digest& digest) 202 { 203 char* start = 0; 204 CString result = CString::newUninitialized(40, start); 205 char* buffer = start; 206 for (size_t i = 0; i < hashSize; ++i) { 207 snprintf(buffer, 3, "%02X", digest.at(i)); 208 buffer += 2; 209 } 210 return result; 211 } 212 213 CString SHA1::computeHexDigest() 214 { 215 Digest digest; 216 computeHash(digest); 217 return hexDigest(digest); 218 } 219 198 220 } // namespace WTF -
trunk/Source/WTF/wtf/SHA1.h
r160456 r182895 36 36 #include <wtf/text/CString.h> 37 37 38 #if PLATFORM(COCOA) 39 #include <CommonCrypto/CommonDigest.h> 40 #endif 41 38 42 namespace WTF { 39 43 … … 64 68 typedef std::array<uint8_t, hashSize> Digest; 65 69 66 // computeHash has a side effect of resetting the state of the object.67 70 WTF_EXPORT_PRIVATE void computeHash(Digest&); 68 71 … … 74 77 75 78 private: 79 #if PLATFORM(COCOA) 80 CC_SHA1_CTX m_context; 81 #else 76 82 void finalize(); 77 83 void processBlock(); … … 82 88 uint64_t m_totalBytes; // Number of bytes added so far. 83 89 uint32_t m_hash[5]; 90 #endif 84 91 }; 85 92
Note:
See TracChangeset
for help on using the changeset viewer.