Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (197574 => 197575)
--- trunk/Source/WebCore/CMakeLists.txt 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-03-04 19:26:23 UTC (rev 197575)
@@ -69,6 +69,7 @@
"${WEBCORE_DIR}/platform"
"${WEBCORE_DIR}/platform/animation"
"${WEBCORE_DIR}/platform/audio"
+ "${WEBCORE_DIR}/platform/crypto"
"${WEBCORE_DIR}/platform/graphics"
"${WEBCORE_DIR}/platform/graphics/cpu/arm"
"${WEBCORE_DIR}/platform/graphics/cpu/arm/filters"
Modified: trunk/Source/WebCore/ChangeLog (197574 => 197575)
--- trunk/Source/WebCore/ChangeLog 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/ChangeLog 2016-03-04 19:26:23 UTC (rev 197575)
@@ -1,3 +1,60 @@
+2016-03-04 Daniel Bates <[email protected]>
+
+ Move CryptoDigest to WebCore/platform
+ https://bugs.webkit.org/show_bug.cgi?id=155008
+ <rdar://problem/24969787>
+
+ Reviewed by Brent Fulgham.
+
+ CryptoDigest provides a platform-independent interface for interacting with platform-
+ specific cryptographic hashing services. We currently make use of this code as part
+ of the implementation of Web Crypto. This code will also be beneficial as part of
+ implementing support for Content Security Policy inline script and inline stylesheet
+ hashes. We should move CryptoDigest to WebCore/platform to convey that it a general
+ purpose platform abstraction.
+
+ * CMakeLists.txt: Add include directory WebCore/platform/crypto.
+ * PlatformEfl.cmake: Add file platform/crypto/gnutls/CryptoDigestGnuTLS.cpp and
+ remove file crypto/gnutls/CryptoDigestGnuTLS.cpp.
+ * PlatformGTK.cmake: Ditto.
+ * PlatformMac.cmake: Add file platform/crypto/mac/CryptoDigestMac.cpp and
+ remove file crypto/mac/CryptoDigestMac.cpp.
+ * WebCore.xcodeproj/project.pbxproj:
+ * crypto/algorithms/CryptoAlgorithmSHA1.cpp:
+ (WebCore::CryptoAlgorithmSHA1::digest): Substitute "CryptoDigest::Algorithm" for "CryptoAlgorithmIdentifier".
+ * crypto/algorithms/CryptoAlgorithmSHA224.cpp:
+ (WebCore::CryptoAlgorithmSHA224::digest): Ditto.
+ * crypto/algorithms/CryptoAlgorithmSHA256.cpp:
+ (WebCore::CryptoAlgorithmSHA256::digest): Ditto.
+ * crypto/algorithms/CryptoAlgorithmSHA384.cpp:
+ (WebCore::CryptoAlgorithmSHA384::digest): Ditto.
+ * crypto/algorithms/CryptoAlgorithmSHA512.cpp:
+ (WebCore::CryptoAlgorithmSHA512::digest): Ditto.
+ * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
+ (WebCore::getCryptoDigestAlgorithm): Converts a CryptoAlgorithmIdentifier enumerator to a
+ CryptoDigest::Algorithm enumerator, if applicable.
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): Write in terms of WebCore::getCryptoDigestAlgorithm().
+ (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify): Ditto.
+ * platform/crypto/CryptoDigest.h: Renamed from Source/WebCore/crypto/CryptoDigest.h. Also added enum CryptoDigest::Algorithm
+ and changed constructor to take this enum.
+ * platform/crypto/gnutls/CryptoDigestGnuTLS.cpp: Renamed from Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp.
+ (WebCore::CryptoDigest::CryptoDigest): Substitute "CryptoDigest::Algorithm" for "CryptoAlgorithmIdentifier".
+ (WebCore::CryptoDigest::~CryptoDigest): Ditto.
+ (WebCore::CryptoDigest::create): Ditto.
+ (WebCore::CryptoDigest::addBytes): Ditto.
+ (WebCore::CryptoDigest::computeHash): Ditto.
+ * platform/crypto/mac/CryptoDigestMac.cpp: Renamed from Source/WebCore/crypto/mac/CryptoDigestMac.cpp.
+ (WebCore::toSHA1Context): Ditto.
+ (WebCore::toSHA224Context): Ditto.
+ (WebCore::toSHA256Context): Ditto.
+ (WebCore::toSHA384Context): Ditto.
+ (WebCore::toSHA512Context): Ditto.
+ (WebCore::CryptoDigest::CryptoDigest): Ditto.
+ (WebCore::CryptoDigest::~CryptoDigest): Ditto.
+ (WebCore::CryptoDigest::create): Ditto.
+ (WebCore::CryptoDigest::addBytes): Ditto.
+ (WebCore::CryptoDigest::computeHash): Ditto.
+
2016-03-04 Myles C. Maxfield <[email protected]>
Whitespace causes font-variant: all-small-caps to synthesize
Modified: trunk/Source/WebCore/PlatformEfl.cmake (197574 => 197575)
--- trunk/Source/WebCore/PlatformEfl.cmake 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/PlatformEfl.cmake 2016-03-04 19:26:23 UTC (rev 197575)
@@ -88,6 +88,8 @@
platform/audio/efl/AudioBusEfl.cpp
+ platform/crypto/gnutls/CryptoDigestGnuTLS.cpp
+
platform/efl/BatteryProviderEfl.cpp
platform/efl/CursorEfl.cpp
platform/efl/DragDataEfl.cpp
@@ -432,7 +434,6 @@
crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp
crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp
crypto/gnutls/CryptoAlgorithmRegistryGnuTLS.cpp
- crypto/gnutls/CryptoDigestGnuTLS.cpp
crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
crypto/gnutls/SerializedCryptoKeyWrapGnuTLS.cpp
Modified: trunk/Source/WebCore/PlatformGTK.cmake (197574 => 197575)
--- trunk/Source/WebCore/PlatformGTK.cmake 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2016-03-04 19:26:23 UTC (rev 197575)
@@ -82,6 +82,8 @@
platform/audio/glib/AudioBusGLib.cpp
+ platform/crypto/gnutls/CryptoDigestGnuTLS.cpp
+
platform/geoclue/GeolocationProviderGeoclue1.cpp
platform/geoclue/GeolocationProviderGeoclue2.cpp
@@ -807,7 +809,6 @@
crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp
crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp
crypto/gnutls/CryptoAlgorithmRegistryGnuTLS.cpp
- crypto/gnutls/CryptoDigestGnuTLS.cpp
crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
crypto/gnutls/SerializedCryptoKeyWrapGnuTLS.cpp
Modified: trunk/Source/WebCore/PlatformMac.cmake (197574 => 197575)
--- trunk/Source/WebCore/PlatformMac.cmake 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/PlatformMac.cmake 2016-03-04 19:26:23 UTC (rev 197575)
@@ -218,7 +218,6 @@
crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
crypto/mac/CryptoAlgorithmRegistryMac.cpp
- crypto/mac/CryptoDigestMac.cpp
crypto/mac/CryptoKeyMac.cpp
crypto/mac/CryptoKeyRSAMac.cpp
crypto/mac/SerializedCryptoKeyWrapMac.mm
@@ -340,6 +339,8 @@
platform/cocoa/VNodeTrackerCocoa.cpp
platform/cocoa/WebCoreNSErrorExtras.mm
+ platform/crypto/mac/CryptoDigestMac.cpp
+
platform/graphics/DisplayRefreshMonitor.cpp
platform/graphics/DisplayRefreshMonitorManager.cpp
platform/graphics/FontPlatformData.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (197574 => 197575)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-03-04 19:26:23 UTC (rev 197575)
@@ -14550,8 +14550,8 @@
E1F80B89183172A2007885C3 /* JSCryptoKeyPairCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyPairCustom.cpp; sourceTree = "<group>"; };
E1F80B8B183172B5007885C3 /* JSCryptoKeyPair.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyPair.cpp; sourceTree = "<group>"; };
E1F80B8C183172B5007885C3 /* JSCryptoKeyPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCryptoKeyPair.h; sourceTree = "<group>"; };
- E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoDigestMac.cpp; sourceTree = "<group>"; };
- E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoDigest.h; sourceTree = "<group>"; };
+ E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoDigestMac.cpp; path = crypto/mac/CryptoDigestMac.cpp; sourceTree = "<group>"; };
+ E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoDigest.h; path = crypto/CryptoDigest.h; sourceTree = "<group>"; };
E1FE1368183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSA_OAEP.cpp; sourceTree = "<group>"; };
E1FE1369183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSA_OAEP.h; sourceTree = "<group>"; };
E1FE136E183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSA_OAEPMac.cpp; sourceTree = "<group>"; };
@@ -22791,6 +22791,7 @@
FD31604012B026A300C1A359 /* audio */,
1AE42F670AA4B8CB00C8612D /* cf */,
A5C974CE11485FDA0066F2AB /* cocoa */,
+ CE50D8CE1C8932ED0072EA5A /* crypto */,
B2A015910AF6CD53006BCE0E /* graphics */,
A59E3C1B11580F340072928E /* ios */,
6582A14809999D6C00BEEB6D /* mac */,
@@ -23176,6 +23177,23 @@
path = ios;
sourceTree = "<group>";
};
+ CE50D8CE1C8932ED0072EA5A /* crypto */ = {
+ isa = PBXGroup;
+ children = (
+ CE50D8CF1C8932FB0072EA5A /* mac */,
+ E1FE136618343A1000892F13 /* CryptoDigest.h */,
+ );
+ name = crypto;
+ sourceTree = "<group>";
+ };
+ CE50D8CF1C8932FB0072EA5A /* mac */ = {
+ isa = PBXGroup;
+ children = (
+ E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
+ );
+ name = mac;
+ sourceTree = "<group>";
+ };
DF9AFD6F13FC31B00015FEB7 /* objc */ = {
isa = PBXGroup;
children = (
@@ -23230,7 +23248,6 @@
E1FE136E183FECF000892F13 /* CryptoAlgorithmRSA_OAEPMac.cpp */,
E1233F0E185A4130008DFAF5 /* CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp */,
E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */,
- E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */,
@@ -23421,7 +23438,6 @@
E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */,
E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */,
E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */,
- E1FE136618343A1000892F13 /* CryptoDigest.h */,
E157A8E218173A3A009F821D /* CryptoKey.cpp */,
E157A8E318173A3A009F821D /* CryptoKey.h */,
E157A8DC18172C2C009F821D /* CryptoKey.idl */,
Deleted: trunk/Source/WebCore/crypto/CryptoDigest.h (197574 => 197575)
--- trunk/Source/WebCore/crypto/CryptoDigest.h 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/CryptoDigest.h 2016-03-04 19:26:23 UTC (rev 197575)
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CryptoDigest_h
-#define CryptoDigest_h
-
-#include "CryptoAlgorithmIdentifier.h"
-#include <wtf/Noncopyable.h>
-#include <wtf/Vector.h>
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-namespace WebCore {
-
-struct CryptoDigestContext;
-
-class CryptoDigest {
- WTF_MAKE_NONCOPYABLE(CryptoDigest);
-public:
- static std::unique_ptr<CryptoDigest> create(CryptoAlgorithmIdentifier);
- ~CryptoDigest();
-
- void addBytes(const void* input, size_t length);
- Vector<uint8_t> computeHash();
-
-private:
- CryptoDigest();
-
- std::unique_ptr<CryptoDigestContext> m_context;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
-#endif // CryptoDigest_h
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -54,7 +54,7 @@
void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
{
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_1);
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
if (!digest) {
failureCallback();
return;
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -54,7 +54,7 @@
void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
{
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_224);
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_224);
if (!digest) {
failureCallback();
return;
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -54,7 +54,7 @@
void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
{
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_256);
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_256);
if (!digest) {
failureCallback();
return;
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -54,7 +54,7 @@
void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
{
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_384);
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_384);
if (!digest) {
failureCallback();
return;
Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -54,7 +54,7 @@
void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
{
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_512);
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_512);
if (!digest) {
failureCallback();
return;
Deleted: trunk/Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2014 Igalia S.L. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CryptoDigest.h"
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-#include <gnutls/gnutls.h>
-#include <gnutls/crypto.h>
-
-namespace WebCore {
-
-struct CryptoDigestContext {
- gnutls_digest_algorithm_t algorithm;
- gnutls_hash_hd_t hash;
-};
-
-CryptoDigest::CryptoDigest()
- : m_context(new CryptoDigestContext)
-{
-}
-
-CryptoDigest::~CryptoDigest()
-{
- gnutls_hash_deinit(m_context->hash, 0);
-}
-
-std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoAlgorithmIdentifier algorithm)
-{
- gnutls_digest_algorithm_t gnutlsAlgorithm;
-
- switch (algorithm) {
- case CryptoAlgorithmIdentifier::SHA_1: {
- gnutlsAlgorithm = GNUTLS_DIG_SHA1;
- break;
- }
- case CryptoAlgorithmIdentifier::SHA_224: {
- gnutlsAlgorithm = GNUTLS_DIG_SHA224;
- break;
- }
- case CryptoAlgorithmIdentifier::SHA_256: {
- gnutlsAlgorithm = GNUTLS_DIG_SHA256;
- break;
- }
- case CryptoAlgorithmIdentifier::SHA_384: {
- gnutlsAlgorithm = GNUTLS_DIG_SHA384;
- break;
- }
- case CryptoAlgorithmIdentifier::SHA_512: {
- gnutlsAlgorithm = GNUTLS_DIG_SHA512;
- break;
- }
- default:
- return nullptr;
- }
-
- std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
- digest->m_context->algorithm = gnutlsAlgorithm;
-
- int ret = gnutls_hash_init(&digest->m_context->hash, gnutlsAlgorithm);
- if (ret != GNUTLS_E_SUCCESS)
- return nullptr;
-
- return digest;
-}
-
-void CryptoDigest::addBytes(const void* input, size_t length)
-{
- gnutls_hash(m_context->hash, input, length);
-}
-
-Vector<uint8_t> CryptoDigest::computeHash()
-{
- Vector<uint8_t> result;
- int digestLen = gnutls_hash_get_len(m_context->algorithm);
- result.resize(digestLen);
-
- gnutls_hash_output(m_context->hash, result.data());
-
- return result;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -36,6 +36,29 @@
namespace WebCore {
+inline bool getCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction, CryptoDigest::Algorithm& algorithm)
+{
+ switch (hashFunction) {
+ case CryptoAlgorithmIdentifier::SHA_1:
+ algorithm = CryptoDigest::Algorithm::SHA_1;
+ return true;
+ case CryptoAlgorithmIdentifier::SHA_224:
+ algorithm = CryptoDigest::Algorithm::SHA_224;
+ return true;
+ case CryptoAlgorithmIdentifier::SHA_256:
+ algorithm = CryptoDigest::Algorithm::SHA_256;
+ return true;
+ case CryptoAlgorithmIdentifier::SHA_384:
+ algorithm = CryptoDigest::Algorithm::SHA_384;
+ return true;
+ case CryptoAlgorithmIdentifier::SHA_512:
+ algorithm = CryptoDigest::Algorithm::SHA_512;
+ return true;
+ default:
+ return false;
+ }
+}
+
void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode& ec)
{
CCDigestAlgorithm digestAlgorithm;
@@ -44,7 +67,13 @@
return;
}
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
+ CryptoDigest::Algorithm cryptoDigestAlgorithm;
+ if (!getCryptoDigestAlgorithm(parameters.hash, cryptoDigestAlgorithm)) {
+ ec = NOT_SUPPORTED_ERR;
+ return;
+ }
+
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(cryptoDigestAlgorithm);
if (!digest) {
ec = NOT_SUPPORTED_ERR;
return;
@@ -75,7 +104,13 @@
return;
}
- std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
+ CryptoDigest::Algorithm cryptoDigestAlgorithm;
+ if (!getCryptoDigestAlgorithm(parameters.hash, cryptoDigestAlgorithm)) {
+ ec = NOT_SUPPORTED_ERR;
+ return;
+ }
+
+ std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(cryptoDigestAlgorithm);
if (!digest) {
ec = NOT_SUPPORTED_ERR;
return;
Deleted: trunk/Source/WebCore/crypto/mac/CryptoDigestMac.cpp (197574 => 197575)
--- trunk/Source/WebCore/crypto/mac/CryptoDigestMac.cpp 2016-03-04 19:13:25 UTC (rev 197574)
+++ trunk/Source/WebCore/crypto/mac/CryptoDigestMac.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CryptoDigest.h"
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-#include <CommonCrypto/CommonCrypto.h>
-
-namespace WebCore {
-
-struct CryptoDigestContext {
- CryptoAlgorithmIdentifier algorithm;
- void* ccContext;
-};
-
-inline CC_SHA1_CTX* toSHA1Context(CryptoDigestContext* context)
-{
- ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_1);
- return static_cast<CC_SHA1_CTX*>(context->ccContext);
-}
-inline CC_SHA256_CTX* toSHA224Context(CryptoDigestContext* context)
-{
- ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_224);
- return static_cast<CC_SHA256_CTX*>(context->ccContext);
-}
-inline CC_SHA256_CTX* toSHA256Context(CryptoDigestContext* context)
-{
- ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_256);
- return static_cast<CC_SHA256_CTX*>(context->ccContext);
-}
-inline CC_SHA512_CTX* toSHA384Context(CryptoDigestContext* context)
-{
- ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_384);
- return static_cast<CC_SHA512_CTX*>(context->ccContext);
-}
-inline CC_SHA512_CTX* toSHA512Context(CryptoDigestContext* context)
-{
- ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_512);
- return static_cast<CC_SHA512_CTX*>(context->ccContext);
-}
-
-CryptoDigest::CryptoDigest()
- : m_context(new CryptoDigestContext)
-{
-}
-
-CryptoDigest::~CryptoDigest()
-{
- switch (m_context->algorithm) {
- case CryptoAlgorithmIdentifier::SHA_1:
- delete toSHA1Context(m_context.get());
- return;
- case CryptoAlgorithmIdentifier::SHA_224:
- delete toSHA224Context(m_context.get());
- return;
- case CryptoAlgorithmIdentifier::SHA_256:
- delete toSHA256Context(m_context.get());
- return;
- case CryptoAlgorithmIdentifier::SHA_384:
- delete toSHA384Context(m_context.get());
- return;
- case CryptoAlgorithmIdentifier::SHA_512:
- delete toSHA512Context(m_context.get());
- return;
- default:
- ASSERT_NOT_REACHED();
- }
-}
-
-
-std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoAlgorithmIdentifier algorithm)
-{
- std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
- digest->m_context->algorithm = algorithm;
-
- switch (algorithm) {
- case CryptoAlgorithmIdentifier::SHA_1: {
- CC_SHA1_CTX* context = new CC_SHA1_CTX;
- digest->m_context->ccContext = context;
- CC_SHA1_Init(context);
- return digest;
- }
- case CryptoAlgorithmIdentifier::SHA_224: {
- CC_SHA256_CTX* context = new CC_SHA256_CTX;
- digest->m_context->ccContext = context;
- CC_SHA224_Init(context);
- return digest;
- }
- case CryptoAlgorithmIdentifier::SHA_256: {
- CC_SHA256_CTX* context = new CC_SHA256_CTX;
- digest->m_context->ccContext = context;
- CC_SHA256_Init(context);
- return digest;
- }
- case CryptoAlgorithmIdentifier::SHA_384: {
- CC_SHA512_CTX* context = new CC_SHA512_CTX;
- digest->m_context->ccContext = context;
- CC_SHA384_Init(context);
- return digest;
- }
- case CryptoAlgorithmIdentifier::SHA_512: {
- CC_SHA512_CTX* context = new CC_SHA512_CTX;
- digest->m_context->ccContext = context;
- CC_SHA512_Init(context);
- return digest;
- }
- default:
- return nullptr;
- }
-}
-
-void CryptoDigest::addBytes(const void* input, size_t length)
-{
- switch (m_context->algorithm) {
- case CryptoAlgorithmIdentifier::SHA_1:
- CC_SHA1_Update(toSHA1Context(m_context.get()), input, length);
- return;
- case CryptoAlgorithmIdentifier::SHA_224:
- CC_SHA224_Update(toSHA224Context(m_context.get()), input, length);
- return;
- case CryptoAlgorithmIdentifier::SHA_256:
- CC_SHA256_Update(toSHA256Context(m_context.get()), input, length);
- return;
- case CryptoAlgorithmIdentifier::SHA_384:
- CC_SHA384_Update(toSHA384Context(m_context.get()), input, length);
- return;
- case CryptoAlgorithmIdentifier::SHA_512:
- CC_SHA512_Update(toSHA512Context(m_context.get()), input, length);
- return;
- default:
- ASSERT_NOT_REACHED();
- }
-}
-
-Vector<uint8_t> CryptoDigest::computeHash()
-{
- Vector<uint8_t> result;
- switch (m_context->algorithm) {
- case CryptoAlgorithmIdentifier::SHA_1:
- result.resize(CC_SHA1_DIGEST_LENGTH);
- CC_SHA1_Final(result.data(), toSHA1Context(m_context.get()));
- break;
- case CryptoAlgorithmIdentifier::SHA_224:
- result.resize(CC_SHA224_DIGEST_LENGTH);
- CC_SHA224_Final(result.data(), toSHA224Context(m_context.get()));
- break;
- case CryptoAlgorithmIdentifier::SHA_256:
- result.resize(CC_SHA256_DIGEST_LENGTH);
- CC_SHA256_Final(result.data(), toSHA256Context(m_context.get()));
- break;
- case CryptoAlgorithmIdentifier::SHA_384:
- result.resize(CC_SHA384_DIGEST_LENGTH);
- CC_SHA384_Final(result.data(), toSHA384Context(m_context.get()));
- break;
- case CryptoAlgorithmIdentifier::SHA_512:
- result.resize(CC_SHA512_DIGEST_LENGTH);
- CC_SHA512_Final(result.data(), toSHA512Context(m_context.get()));
- break;
- default:
- ASSERT_NOT_REACHED();
- }
- return result;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
Copied: trunk/Source/WebCore/platform/crypto/CryptoDigest.h (from rev 197574, trunk/Source/WebCore/crypto/CryptoDigest.h) (0 => 197575)
--- trunk/Source/WebCore/platform/crypto/CryptoDigest.h (rev 0)
+++ trunk/Source/WebCore/platform/crypto/CryptoDigest.h 2016-03-04 19:26:23 UTC (rev 197575)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CryptoDigest_h
+#define CryptoDigest_h
+
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+struct CryptoDigestContext;
+
+class CryptoDigest {
+ WTF_MAKE_NONCOPYABLE(CryptoDigest);
+public:
+ enum class Algorithm {
+ SHA_1,
+ SHA_224,
+ SHA_256,
+ SHA_384,
+ SHA_512,
+ };
+ static std::unique_ptr<CryptoDigest> create(Algorithm);
+ ~CryptoDigest();
+
+ void addBytes(const void* input, size_t length);
+ Vector<uint8_t> computeHash();
+
+private:
+ CryptoDigest();
+
+ std::unique_ptr<CryptoDigestContext> m_context;
+};
+
+} // namespace WebCore
+
+#endif // CryptoDigest_h
Copied: trunk/Source/WebCore/platform/crypto/gnutls/CryptoDigestGnuTLS.cpp (from rev 197574, trunk/Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp) (0 => 197575)
--- trunk/Source/WebCore/platform/crypto/gnutls/CryptoDigestGnuTLS.cpp (rev 0)
+++ trunk/Source/WebCore/platform/crypto/gnutls/CryptoDigestGnuTLS.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CryptoDigest.h"
+
+#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
+
+namespace WebCore {
+
+struct CryptoDigestContext {
+ gnutls_digest_algorithm_t algorithm;
+ gnutls_hash_hd_t hash;
+};
+
+CryptoDigest::CryptoDigest()
+ : m_context(new CryptoDigestContext)
+{
+}
+
+CryptoDigest::~CryptoDigest()
+{
+ gnutls_hash_deinit(m_context->hash, 0);
+}
+
+std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoDigest::Algorithm algorithm)
+{
+ gnutls_digest_algorithm_t gnutlsAlgorithm;
+
+ switch (algorithm) {
+ case CryptoDigest::Algorithm::SHA_1: {
+ gnutlsAlgorithm = GNUTLS_DIG_SHA1;
+ break;
+ }
+ case CryptoDigest::Algorithm::SHA_224: {
+ gnutlsAlgorithm = GNUTLS_DIG_SHA224;
+ break;
+ }
+ case CryptoDigest::Algorithm::SHA_256: {
+ gnutlsAlgorithm = GNUTLS_DIG_SHA256;
+ break;
+ }
+ case CryptoDigest::Algorithm::SHA_384: {
+ gnutlsAlgorithm = GNUTLS_DIG_SHA384;
+ break;
+ }
+ case CryptoDigest::Algorithm::SHA_512: {
+ gnutlsAlgorithm = GNUTLS_DIG_SHA512;
+ break;
+ }
+ }
+
+ std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
+ digest->m_context->algorithm = gnutlsAlgorithm;
+
+ int ret = gnutls_hash_init(&digest->m_context->hash, gnutlsAlgorithm);
+ if (ret != GNUTLS_E_SUCCESS)
+ return nullptr;
+
+ return digest;
+}
+
+void CryptoDigest::addBytes(const void* input, size_t length)
+{
+ gnutls_hash(m_context->hash, input, length);
+}
+
+Vector<uint8_t> CryptoDigest::computeHash()
+{
+ Vector<uint8_t> result;
+ int digestLen = gnutls_hash_get_len(m_context->algorithm);
+ result.resize(digestLen);
+
+ gnutls_hash_output(m_context->hash, result.data());
+
+ return result;
+}
+
+} // namespace WebCore
Copied: trunk/Source/WebCore/platform/crypto/mac/CryptoDigestMac.cpp (from rev 197574, trunk/Source/WebCore/crypto/mac/CryptoDigestMac.cpp) (0 => 197575)
--- trunk/Source/WebCore/platform/crypto/mac/CryptoDigestMac.cpp (rev 0)
+++ trunk/Source/WebCore/platform/crypto/mac/CryptoDigestMac.cpp 2016-03-04 19:26:23 UTC (rev 197575)
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CryptoDigest.h"
+
+#include <CommonCrypto/CommonCrypto.h>
+
+namespace WebCore {
+
+struct CryptoDigestContext {
+ CryptoDigest::Algorithm algorithm;
+ void* ccContext;
+};
+
+inline CC_SHA1_CTX* toSHA1Context(CryptoDigestContext* context)
+{
+ ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_1);
+ return static_cast<CC_SHA1_CTX*>(context->ccContext);
+}
+inline CC_SHA256_CTX* toSHA224Context(CryptoDigestContext* context)
+{
+ ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_224);
+ return static_cast<CC_SHA256_CTX*>(context->ccContext);
+}
+inline CC_SHA256_CTX* toSHA256Context(CryptoDigestContext* context)
+{
+ ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_256);
+ return static_cast<CC_SHA256_CTX*>(context->ccContext);
+}
+inline CC_SHA512_CTX* toSHA384Context(CryptoDigestContext* context)
+{
+ ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_384);
+ return static_cast<CC_SHA512_CTX*>(context->ccContext);
+}
+inline CC_SHA512_CTX* toSHA512Context(CryptoDigestContext* context)
+{
+ ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_512);
+ return static_cast<CC_SHA512_CTX*>(context->ccContext);
+}
+
+CryptoDigest::CryptoDigest()
+ : m_context(new CryptoDigestContext)
+{
+}
+
+CryptoDigest::~CryptoDigest()
+{
+ switch (m_context->algorithm) {
+ case CryptoDigest::Algorithm::SHA_1:
+ delete toSHA1Context(m_context.get());
+ return;
+ case CryptoDigest::Algorithm::SHA_224:
+ delete toSHA224Context(m_context.get());
+ return;
+ case CryptoDigest::Algorithm::SHA_256:
+ delete toSHA256Context(m_context.get());
+ return;
+ case CryptoDigest::Algorithm::SHA_384:
+ delete toSHA384Context(m_context.get());
+ return;
+ case CryptoDigest::Algorithm::SHA_512:
+ delete toSHA512Context(m_context.get());
+ return;
+ }
+}
+
+
+std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoDigest::Algorithm algorithm)
+{
+ std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
+ digest->m_context->algorithm = algorithm;
+
+ switch (algorithm) {
+ case CryptoDigest::Algorithm::SHA_1: {
+ CC_SHA1_CTX* context = new CC_SHA1_CTX;
+ digest->m_context->ccContext = context;
+ CC_SHA1_Init(context);
+ return digest;
+ }
+ case CryptoDigest::Algorithm::SHA_224: {
+ CC_SHA256_CTX* context = new CC_SHA256_CTX;
+ digest->m_context->ccContext = context;
+ CC_SHA224_Init(context);
+ return digest;
+ }
+ case CryptoDigest::Algorithm::SHA_256: {
+ CC_SHA256_CTX* context = new CC_SHA256_CTX;
+ digest->m_context->ccContext = context;
+ CC_SHA256_Init(context);
+ return digest;
+ }
+ case CryptoDigest::Algorithm::SHA_384: {
+ CC_SHA512_CTX* context = new CC_SHA512_CTX;
+ digest->m_context->ccContext = context;
+ CC_SHA384_Init(context);
+ return digest;
+ }
+ case CryptoDigest::Algorithm::SHA_512: {
+ CC_SHA512_CTX* context = new CC_SHA512_CTX;
+ digest->m_context->ccContext = context;
+ CC_SHA512_Init(context);
+ return digest;
+ }
+ }
+}
+
+void CryptoDigest::addBytes(const void* input, size_t length)
+{
+ switch (m_context->algorithm) {
+ case CryptoDigest::Algorithm::SHA_1:
+ CC_SHA1_Update(toSHA1Context(m_context.get()), input, length);
+ return;
+ case CryptoDigest::Algorithm::SHA_224:
+ CC_SHA224_Update(toSHA224Context(m_context.get()), input, length);
+ return;
+ case CryptoDigest::Algorithm::SHA_256:
+ CC_SHA256_Update(toSHA256Context(m_context.get()), input, length);
+ return;
+ case CryptoDigest::Algorithm::SHA_384:
+ CC_SHA384_Update(toSHA384Context(m_context.get()), input, length);
+ return;
+ case CryptoDigest::Algorithm::SHA_512:
+ CC_SHA512_Update(toSHA512Context(m_context.get()), input, length);
+ return;
+ }
+}
+
+Vector<uint8_t> CryptoDigest::computeHash()
+{
+ Vector<uint8_t> result;
+ switch (m_context->algorithm) {
+ case CryptoDigest::Algorithm::SHA_1:
+ result.resize(CC_SHA1_DIGEST_LENGTH);
+ CC_SHA1_Final(result.data(), toSHA1Context(m_context.get()));
+ break;
+ case CryptoDigest::Algorithm::SHA_224:
+ result.resize(CC_SHA224_DIGEST_LENGTH);
+ CC_SHA224_Final(result.data(), toSHA224Context(m_context.get()));
+ break;
+ case CryptoDigest::Algorithm::SHA_256:
+ result.resize(CC_SHA256_DIGEST_LENGTH);
+ CC_SHA256_Final(result.data(), toSHA256Context(m_context.get()));
+ break;
+ case CryptoDigest::Algorithm::SHA_384:
+ result.resize(CC_SHA384_DIGEST_LENGTH);
+ CC_SHA384_Final(result.data(), toSHA384Context(m_context.get()));
+ break;
+ case CryptoDigest::Algorithm::SHA_512:
+ result.resize(CC_SHA512_DIGEST_LENGTH);
+ CC_SHA512_Final(result.data(), toSHA512Context(m_context.get()));
+ break;
+ }
+ return result;
+}
+
+} // namespace WebCore