Changeset 197575 in webkit


Ignore:
Timestamp:
Mar 4, 2016 11:26:23 AM (8 years ago)
Author:
dbates@webkit.org
Message:

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.

Location:
trunk/Source/WebCore
Files:
3 added
12 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r197468 r197575  
    7070    "${WEBCORE_DIR}/platform/animation"
    7171    "${WEBCORE_DIR}/platform/audio"
     72    "${WEBCORE_DIR}/platform/crypto"
    7273    "${WEBCORE_DIR}/platform/graphics"
    7374    "${WEBCORE_DIR}/platform/graphics/cpu/arm"
  • trunk/Source/WebCore/ChangeLog

    r197573 r197575  
     12016-03-04  Daniel Bates  <dabates@apple.com>
     2
     3        Move CryptoDigest to WebCore/platform
     4        https://bugs.webkit.org/show_bug.cgi?id=155008
     5        <rdar://problem/24969787>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        CryptoDigest provides a platform-independent interface for interacting with platform-
     10        specific cryptographic hashing services. We currently make use of this code as part
     11        of the implementation of Web Crypto. This code will also be beneficial as part of
     12        implementing support for Content Security Policy inline script and inline stylesheet
     13        hashes. We should move CryptoDigest to WebCore/platform to convey that it a general
     14        purpose platform abstraction.
     15
     16        * CMakeLists.txt: Add include directory WebCore/platform/crypto.
     17        * PlatformEfl.cmake: Add file platform/crypto/gnutls/CryptoDigestGnuTLS.cpp and
     18        remove file crypto/gnutls/CryptoDigestGnuTLS.cpp.
     19        * PlatformGTK.cmake: Ditto.
     20        * PlatformMac.cmake: Add file platform/crypto/mac/CryptoDigestMac.cpp and
     21        remove file crypto/mac/CryptoDigestMac.cpp.
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * crypto/algorithms/CryptoAlgorithmSHA1.cpp:
     24        (WebCore::CryptoAlgorithmSHA1::digest): Substitute "CryptoDigest::Algorithm" for "CryptoAlgorithmIdentifier".
     25        * crypto/algorithms/CryptoAlgorithmSHA224.cpp:
     26        (WebCore::CryptoAlgorithmSHA224::digest): Ditto.
     27        * crypto/algorithms/CryptoAlgorithmSHA256.cpp:
     28        (WebCore::CryptoAlgorithmSHA256::digest): Ditto.
     29        * crypto/algorithms/CryptoAlgorithmSHA384.cpp:
     30        (WebCore::CryptoAlgorithmSHA384::digest): Ditto.
     31        * crypto/algorithms/CryptoAlgorithmSHA512.cpp:
     32        (WebCore::CryptoAlgorithmSHA512::digest): Ditto.
     33        * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
     34        (WebCore::getCryptoDigestAlgorithm): Converts a CryptoAlgorithmIdentifier enumerator to a
     35        CryptoDigest::Algorithm enumerator, if applicable.
     36        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): Write in terms of WebCore::getCryptoDigestAlgorithm().
     37        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify): Ditto.
     38        * platform/crypto/CryptoDigest.h: Renamed from Source/WebCore/crypto/CryptoDigest.h. Also added enum CryptoDigest::Algorithm
     39        and changed constructor to take this enum.
     40        * platform/crypto/gnutls/CryptoDigestGnuTLS.cpp: Renamed from Source/WebCore/crypto/gnutls/CryptoDigestGnuTLS.cpp.
     41        (WebCore::CryptoDigest::CryptoDigest): Substitute "CryptoDigest::Algorithm" for "CryptoAlgorithmIdentifier".
     42        (WebCore::CryptoDigest::~CryptoDigest): Ditto.
     43        (WebCore::CryptoDigest::create): Ditto.
     44        (WebCore::CryptoDigest::addBytes): Ditto.
     45        (WebCore::CryptoDigest::computeHash): Ditto.
     46        * platform/crypto/mac/CryptoDigestMac.cpp: Renamed from Source/WebCore/crypto/mac/CryptoDigestMac.cpp.
     47        (WebCore::toSHA1Context): Ditto.
     48        (WebCore::toSHA224Context): Ditto.
     49        (WebCore::toSHA256Context): Ditto.
     50        (WebCore::toSHA384Context): Ditto.
     51        (WebCore::toSHA512Context): Ditto.
     52        (WebCore::CryptoDigest::CryptoDigest): Ditto.
     53        (WebCore::CryptoDigest::~CryptoDigest): Ditto.
     54        (WebCore::CryptoDigest::create): Ditto.
     55        (WebCore::CryptoDigest::addBytes): Ditto.
     56        (WebCore::CryptoDigest::computeHash): Ditto.
     57
    1582016-03-04  Myles C. Maxfield  <mmaxfield@apple.com>
    259
  • trunk/Source/WebCore/PlatformEfl.cmake

    r196578 r197575  
    8989    platform/audio/efl/AudioBusEfl.cpp
    9090
     91    platform/crypto/gnutls/CryptoDigestGnuTLS.cpp
     92
    9193    platform/efl/BatteryProviderEfl.cpp
    9294    platform/efl/CursorEfl.cpp
     
    433435        crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp
    434436        crypto/gnutls/CryptoAlgorithmRegistryGnuTLS.cpp
    435         crypto/gnutls/CryptoDigestGnuTLS.cpp
    436437        crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
    437438        crypto/gnutls/SerializedCryptoKeyWrapGnuTLS.cpp
  • trunk/Source/WebCore/PlatformGTK.cmake

    r197142 r197575  
    8282
    8383    platform/audio/glib/AudioBusGLib.cpp
     84
     85    platform/crypto/gnutls/CryptoDigestGnuTLS.cpp
    8486
    8587    platform/geoclue/GeolocationProviderGeoclue1.cpp
     
    808810        crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp
    809811        crypto/gnutls/CryptoAlgorithmRegistryGnuTLS.cpp
    810         crypto/gnutls/CryptoDigestGnuTLS.cpp
    811812        crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
    812813        crypto/gnutls/SerializedCryptoKeyWrapGnuTLS.cpp
  • trunk/Source/WebCore/PlatformMac.cmake

    r197398 r197575  
    219219    crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
    220220    crypto/mac/CryptoAlgorithmRegistryMac.cpp
    221     crypto/mac/CryptoDigestMac.cpp
    222221    crypto/mac/CryptoKeyMac.cpp
    223222    crypto/mac/CryptoKeyRSAMac.cpp
     
    340339    platform/cocoa/VNodeTrackerCocoa.cpp
    341340    platform/cocoa/WebCoreNSErrorExtras.mm
     341
     342    platform/crypto/mac/CryptoDigestMac.cpp
    342343
    343344    platform/graphics/DisplayRefreshMonitor.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r197550 r197575  
    1455114551                E1F80B8B183172B5007885C3 /* JSCryptoKeyPair.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyPair.cpp; sourceTree = "<group>"; };
    1455214552                E1F80B8C183172B5007885C3 /* JSCryptoKeyPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCryptoKeyPair.h; sourceTree = "<group>"; };
    14553                 E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoDigestMac.cpp; sourceTree = "<group>"; };
    14554                 E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoDigest.h; sourceTree = "<group>"; };
     14553                E1FE13621834351100892F13 /* CryptoDigestMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoDigestMac.cpp; path = crypto/mac/CryptoDigestMac.cpp; sourceTree = "<group>"; };
     14554                E1FE136618343A1000892F13 /* CryptoDigest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoDigest.h; path = crypto/CryptoDigest.h; sourceTree = "<group>"; };
    1455514555                E1FE1368183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRSA_OAEP.cpp; sourceTree = "<group>"; };
    1455614556                E1FE1369183FE1AB00892F13 /* CryptoAlgorithmRSA_OAEP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRSA_OAEP.h; sourceTree = "<group>"; };
     
    2279222792                                1AE42F670AA4B8CB00C8612D /* cf */,
    2279322793                                A5C974CE11485FDA0066F2AB /* cocoa */,
     22794                                CE50D8CE1C8932ED0072EA5A /* crypto */,
    2279422795                                B2A015910AF6CD53006BCE0E /* graphics */,
    2279522796                                A59E3C1B11580F340072928E /* ios */,
     
    2317723178                        sourceTree = "<group>";
    2317823179                };
     23180                CE50D8CE1C8932ED0072EA5A /* crypto */ = {
     23181                        isa = PBXGroup;
     23182                        children = (
     23183                                CE50D8CF1C8932FB0072EA5A /* mac */,
     23184                                E1FE136618343A1000892F13 /* CryptoDigest.h */,
     23185                        );
     23186                        name = crypto;
     23187                        sourceTree = "<group>";
     23188                };
     23189                CE50D8CF1C8932FB0072EA5A /* mac */ = {
     23190                        isa = PBXGroup;
     23191                        children = (
     23192                                E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
     23193                        );
     23194                        name = mac;
     23195                        sourceTree = "<group>";
     23196                };
    2317923197                DF9AFD6F13FC31B00015FEB7 /* objc */ = {
    2318023198                        isa = PBXGroup;
     
    2323123249                                E1233F0E185A4130008DFAF5 /* CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp */,
    2323223250                                E1C266D618317AB4003F8B33 /* CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp */,
    23233                                 E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
    2323423251                                E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
    2323523252                                E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
     
    2342223439                                E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */,
    2342323440                                E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */,
    23424                                 E1FE136618343A1000892F13 /* CryptoDigest.h */,
    2342523441                                E157A8E218173A3A009F821D /* CryptoKey.cpp */,
    2342623442                                E157A8E318173A3A009F821D /* CryptoKey.h */,
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp

    r188118 r197575  
    5555void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    5656{
    57     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_1);
     57    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
    5858    if (!digest) {
    5959        failureCallback();
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp

    r188118 r197575  
    5555void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    5656{
    57     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_224);
     57    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_224);
    5858    if (!digest) {
    5959        failureCallback();
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp

    r188118 r197575  
    5555void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    5656{
    57     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_256);
     57    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_256);
    5858    if (!digest) {
    5959        failureCallback();
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp

    r188118 r197575  
    5555void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    5656{
    57     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_384);
     57    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_384);
    5858    if (!digest) {
    5959        failureCallback();
  • trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp

    r188118 r197575  
    5555void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode&)
    5656{
    57     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_512);
     57    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_512);
    5858    if (!digest) {
    5959        failureCallback();
  • trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp

    r188118 r197575  
    3737namespace WebCore {
    3838
     39inline bool getCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction, CryptoDigest::Algorithm& algorithm)
     40{
     41    switch (hashFunction) {
     42    case CryptoAlgorithmIdentifier::SHA_1:
     43        algorithm = CryptoDigest::Algorithm::SHA_1;
     44        return true;
     45    case CryptoAlgorithmIdentifier::SHA_224:
     46        algorithm = CryptoDigest::Algorithm::SHA_224;
     47        return true;
     48    case CryptoAlgorithmIdentifier::SHA_256:
     49        algorithm = CryptoDigest::Algorithm::SHA_256;
     50        return true;
     51    case CryptoAlgorithmIdentifier::SHA_384:
     52        algorithm = CryptoDigest::Algorithm::SHA_384;
     53        return true;
     54    case CryptoAlgorithmIdentifier::SHA_512:
     55        algorithm = CryptoDigest::Algorithm::SHA_512;
     56        return true;
     57    default:
     58        return false;
     59    }
     60}
     61
    3962void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback, ExceptionCode& ec)
    4063{
     
    4568    }
    4669
    47     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
     70    CryptoDigest::Algorithm cryptoDigestAlgorithm;
     71    if (!getCryptoDigestAlgorithm(parameters.hash, cryptoDigestAlgorithm)) {
     72        ec = NOT_SUPPORTED_ERR;
     73        return;
     74    }
     75
     76    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(cryptoDigestAlgorithm);
    4877    if (!digest) {
    4978        ec = NOT_SUPPORTED_ERR;
     
    76105    }
    77106
    78     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
     107    CryptoDigest::Algorithm cryptoDigestAlgorithm;
     108    if (!getCryptoDigestAlgorithm(parameters.hash, cryptoDigestAlgorithm)) {
     109        ec = NOT_SUPPORTED_ERR;
     110        return;
     111    }
     112
     113    std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(cryptoDigestAlgorithm);
    79114    if (!digest) {
    80115        ec = NOT_SUPPORTED_ERR;
  • trunk/Source/WebCore/platform/crypto/CryptoDigest.h

    r197574 r197575  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define CryptoDigest_h
    2828
    29 #include "CryptoAlgorithmIdentifier.h"
    3029#include <wtf/Noncopyable.h>
    3130#include <wtf/Vector.h>
    32 
    33 #if ENABLE(SUBTLE_CRYPTO)
    3431
    3532namespace WebCore {
     
    4037    WTF_MAKE_NONCOPYABLE(CryptoDigest);
    4138public:
    42     static std::unique_ptr<CryptoDigest> create(CryptoAlgorithmIdentifier);
     39    enum class Algorithm {
     40        SHA_1,
     41        SHA_224,
     42        SHA_256,
     43        SHA_384,
     44        SHA_512,
     45    };
     46    static std::unique_ptr<CryptoDigest> create(Algorithm);
    4347    ~CryptoDigest();
    4448
     
    5458} // namespace WebCore
    5559
    56 #endif // ENABLE(SUBTLE_CRYPTO)
    5760#endif // CryptoDigest_h
  • trunk/Source/WebCore/platform/crypto/gnutls/CryptoDigestGnuTLS.cpp

    r197574 r197575  
    2727#include "CryptoDigest.h"
    2828
    29 #if ENABLE(SUBTLE_CRYPTO)
    30 
    3129#include <gnutls/gnutls.h>
    3230#include <gnutls/crypto.h>
     
    4947}
    5048
    51 std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoAlgorithmIdentifier algorithm)
     49std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoDigest::Algorithm algorithm)
    5250{
    5351    gnutls_digest_algorithm_t gnutlsAlgorithm;
    5452
    5553    switch (algorithm) {
    56     case CryptoAlgorithmIdentifier::SHA_1: {
     54    case CryptoDigest::Algorithm::SHA_1: {
    5755        gnutlsAlgorithm = GNUTLS_DIG_SHA1;
    5856        break;
    5957    }
    60     case CryptoAlgorithmIdentifier::SHA_224: {
     58    case CryptoDigest::Algorithm::SHA_224: {
    6159        gnutlsAlgorithm = GNUTLS_DIG_SHA224;
    6260        break;
    6361    }
    64     case CryptoAlgorithmIdentifier::SHA_256: {
     62    case CryptoDigest::Algorithm::SHA_256: {
    6563        gnutlsAlgorithm = GNUTLS_DIG_SHA256;
    6664        break;
    6765    }
    68     case CryptoAlgorithmIdentifier::SHA_384: {
     66    case CryptoDigest::Algorithm::SHA_384: {
    6967        gnutlsAlgorithm = GNUTLS_DIG_SHA384;
    7068        break;
    7169    }
    72     case CryptoAlgorithmIdentifier::SHA_512: {
     70    case CryptoDigest::Algorithm::SHA_512: {
    7371        gnutlsAlgorithm = GNUTLS_DIG_SHA512;
    7472        break;
    7573    }
    76     default:
    77         return nullptr;
    7874    }
    7975
     
    105101
    106102} // namespace WebCore
    107 
    108 #endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/platform/crypto/mac/CryptoDigestMac.cpp

    r197574 r197575  
    2727#include "CryptoDigest.h"
    2828
    29 #if ENABLE(SUBTLE_CRYPTO)
    30 
    3129#include <CommonCrypto/CommonCrypto.h>
    3230
     
    3432
    3533struct CryptoDigestContext {
    36     CryptoAlgorithmIdentifier algorithm;
     34    CryptoDigest::Algorithm algorithm;
    3735    void* ccContext;
    3836};
     
    4038inline CC_SHA1_CTX* toSHA1Context(CryptoDigestContext* context)
    4139{
    42     ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_1);
     40    ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_1);
    4341    return static_cast<CC_SHA1_CTX*>(context->ccContext);
    4442}
    4543inline CC_SHA256_CTX* toSHA224Context(CryptoDigestContext* context)
    4644{
    47     ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_224);
     45    ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_224);
    4846    return static_cast<CC_SHA256_CTX*>(context->ccContext);
    4947}
    5048inline CC_SHA256_CTX* toSHA256Context(CryptoDigestContext* context)
    5149{
    52     ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_256);
     50    ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_256);
    5351    return static_cast<CC_SHA256_CTX*>(context->ccContext);
    5452}
    5553inline CC_SHA512_CTX* toSHA384Context(CryptoDigestContext* context)
    5654{
    57     ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_384);
     55    ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_384);
    5856    return static_cast<CC_SHA512_CTX*>(context->ccContext);
    5957}
    6058inline CC_SHA512_CTX* toSHA512Context(CryptoDigestContext* context)
    6159{
    62     ASSERT(context->algorithm == CryptoAlgorithmIdentifier::SHA_512);
     60    ASSERT(context->algorithm == CryptoDigest::Algorithm::SHA_512);
    6361    return static_cast<CC_SHA512_CTX*>(context->ccContext);
    6462}
     
    7270{
    7371    switch (m_context->algorithm) {
    74     case CryptoAlgorithmIdentifier::SHA_1:
     72    case CryptoDigest::Algorithm::SHA_1:
    7573        delete toSHA1Context(m_context.get());
    7674        return;
    77     case CryptoAlgorithmIdentifier::SHA_224:
     75    case CryptoDigest::Algorithm::SHA_224:
    7876        delete toSHA224Context(m_context.get());
    7977        return;
    80     case CryptoAlgorithmIdentifier::SHA_256:
     78    case CryptoDigest::Algorithm::SHA_256:
    8179        delete toSHA256Context(m_context.get());
    8280        return;
    83     case CryptoAlgorithmIdentifier::SHA_384:
     81    case CryptoDigest::Algorithm::SHA_384:
    8482        delete toSHA384Context(m_context.get());
    8583        return;
    86     case CryptoAlgorithmIdentifier::SHA_512:
     84    case CryptoDigest::Algorithm::SHA_512:
    8785        delete toSHA512Context(m_context.get());
    8886        return;
    89     default:
    90         ASSERT_NOT_REACHED();
    9187    }
    9288}
    9389
    9490
    95 std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoAlgorithmIdentifier algorithm)
     91std::unique_ptr<CryptoDigest> CryptoDigest::create(CryptoDigest::Algorithm algorithm)
    9692{
    9793    std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
     
    9995
    10096    switch (algorithm) {
    101     case CryptoAlgorithmIdentifier::SHA_1: {
     97    case CryptoDigest::Algorithm::SHA_1: {
    10298        CC_SHA1_CTX* context = new CC_SHA1_CTX;
    10399        digest->m_context->ccContext = context;
     
    105101        return digest;
    106102    }
    107     case CryptoAlgorithmIdentifier::SHA_224: {
     103    case CryptoDigest::Algorithm::SHA_224: {
    108104        CC_SHA256_CTX* context = new CC_SHA256_CTX;
    109105        digest->m_context->ccContext = context;
     
    111107        return digest;
    112108    }
    113     case CryptoAlgorithmIdentifier::SHA_256: {
     109    case CryptoDigest::Algorithm::SHA_256: {
    114110        CC_SHA256_CTX* context = new CC_SHA256_CTX;
    115111        digest->m_context->ccContext = context;
     
    117113        return digest;
    118114    }
    119     case CryptoAlgorithmIdentifier::SHA_384: {
     115    case CryptoDigest::Algorithm::SHA_384: {
    120116        CC_SHA512_CTX* context = new CC_SHA512_CTX;
    121117        digest->m_context->ccContext = context;
     
    123119        return digest;
    124120    }
    125     case CryptoAlgorithmIdentifier::SHA_512: {
     121    case CryptoDigest::Algorithm::SHA_512: {
    126122        CC_SHA512_CTX* context = new CC_SHA512_CTX;
    127123        digest->m_context->ccContext = context;
     
    129125        return digest;
    130126    }
    131     default:
    132         return nullptr;
    133127    }
    134128}
     
    137131{
    138132    switch (m_context->algorithm) {
    139     case CryptoAlgorithmIdentifier::SHA_1:
     133    case CryptoDigest::Algorithm::SHA_1:
    140134        CC_SHA1_Update(toSHA1Context(m_context.get()), input, length);
    141135        return;
    142     case CryptoAlgorithmIdentifier::SHA_224:
     136    case CryptoDigest::Algorithm::SHA_224:
    143137        CC_SHA224_Update(toSHA224Context(m_context.get()), input, length);
    144138        return;
    145     case CryptoAlgorithmIdentifier::SHA_256:
     139    case CryptoDigest::Algorithm::SHA_256:
    146140        CC_SHA256_Update(toSHA256Context(m_context.get()), input, length);
    147141        return;
    148     case CryptoAlgorithmIdentifier::SHA_384:
     142    case CryptoDigest::Algorithm::SHA_384:
    149143        CC_SHA384_Update(toSHA384Context(m_context.get()), input, length);
    150144        return;
    151     case CryptoAlgorithmIdentifier::SHA_512:
     145    case CryptoDigest::Algorithm::SHA_512:
    152146        CC_SHA512_Update(toSHA512Context(m_context.get()), input, length);
    153147        return;
    154     default:
    155         ASSERT_NOT_REACHED();
    156148    }
    157149}
     
    161153    Vector<uint8_t> result;
    162154    switch (m_context->algorithm) {
    163     case CryptoAlgorithmIdentifier::SHA_1:
     155    case CryptoDigest::Algorithm::SHA_1:
    164156        result.resize(CC_SHA1_DIGEST_LENGTH);
    165157        CC_SHA1_Final(result.data(), toSHA1Context(m_context.get()));
    166158        break;
    167     case CryptoAlgorithmIdentifier::SHA_224:
     159    case CryptoDigest::Algorithm::SHA_224:
    168160        result.resize(CC_SHA224_DIGEST_LENGTH);
    169161        CC_SHA224_Final(result.data(), toSHA224Context(m_context.get()));
    170162        break;
    171     case CryptoAlgorithmIdentifier::SHA_256:
     163    case CryptoDigest::Algorithm::SHA_256:
    172164        result.resize(CC_SHA256_DIGEST_LENGTH);
    173165        CC_SHA256_Final(result.data(), toSHA256Context(m_context.get()));
    174166        break;
    175     case CryptoAlgorithmIdentifier::SHA_384:
     167    case CryptoDigest::Algorithm::SHA_384:
    176168        result.resize(CC_SHA384_DIGEST_LENGTH);
    177169        CC_SHA384_Final(result.data(), toSHA384Context(m_context.get()));
    178170        break;
    179     case CryptoAlgorithmIdentifier::SHA_512:
     171    case CryptoDigest::Algorithm::SHA_512:
    180172        result.resize(CC_SHA512_DIGEST_LENGTH);
    181173        CC_SHA512_Final(result.data(), toSHA512Context(m_context.get()));
    182174        break;
    183     default:
    184         ASSERT_NOT_REACHED();
    185175    }
    186176    return result;
     
    188178
    189179} // namespace WebCore
    190 
    191 #endif // ENABLE(SUBTLE_CRYPTO)
Note: See TracChangeset for help on using the changeset viewer.