Changeset 173874 in webkit


Ignore:
Timestamp:
Sep 23, 2014 9:41:45 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Adds implementation of subtle crypto HMAC algorithm
https://bugs.webkit.org/show_bug.cgi?id=133320

Patch by Eduardo Lima Mitev <elima@igalia.com> on 2014-09-23
Reviewed by Philippe Normand.

Source/WebCore:

Tests are already in place under crypto/subtle/hmac-*.html

  • crypto/gtk/CryptoAlgorithmHMACGtk.cpp:

(WebCore::getGnutlsDigestAlgorithm):
(WebCore::calculateSignature):
(WebCore::CryptoAlgorithmHMAC::platformSign):
(WebCore::CryptoAlgorithmHMAC::platformVerify):

LayoutTests:

  • platform/gtk/TestExpectations: Whitelists HMAC related tests that are passing
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r173873 r173874  
     12014-09-23  Eduardo Lima Mitev  <elima@igalia.com>
     2
     3        [GTK] Adds implementation of subtle crypto HMAC algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=133320
     5
     6        Reviewed by Philippe Normand.
     7
     8        * platform/gtk/TestExpectations: Whitelists HMAC related tests that are passing
     9
    1102014-09-23  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    211
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r173872 r173874  
    364364webkit.org/b/133319 crypto/subtle/sha-384.html [ Pass ]
    365365webkit.org/b/133319 crypto/subtle/sha-512.html [ Pass ]
     366webkit.org/b/133320 crypto/subtle/hmac-check-algorithm.html [ Pass ]
     367webkit.org/b/133320 crypto/subtle/hmac-export-key.html [ Pass ]
     368webkit.org/b/133320 crypto/subtle/hmac-generate-key.html [ Pass ]
     369webkit.org/b/133320 crypto/subtle/hmac-import-jwk.html [ Pass ]
     370webkit.org/b/133320 crypto/subtle/hmac-sign-verify-empty-key.html [ Pass ]
     371webkit.org/b/133320 crypto/subtle/hmac-sign-verify.html [ Pass ]
    366372
    367373# QuickTime plug-in not relevant to this port
  • trunk/Source/WebCore/ChangeLog

    r173872 r173874  
     12014-09-23  Eduardo Lima Mitev  <elima@igalia.com>
     2
     3        [GTK] Adds implementation of subtle crypto HMAC algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=133320
     5
     6        Reviewed by Philippe Normand.
     7
     8        Tests are already in place under crypto/subtle/hmac-*.html
     9
     10        * crypto/gtk/CryptoAlgorithmHMACGtk.cpp:
     11        (WebCore::getGnutlsDigestAlgorithm):
     12        (WebCore::calculateSignature):
     13        (WebCore::CryptoAlgorithmHMAC::platformSign):
     14        (WebCore::CryptoAlgorithmHMAC::platformVerify):
     15
    1162014-09-23  Eduardo Lima Mitev  <elima@igalia.com>
    217
  • trunk/Source/WebCore/crypto/gtk/CryptoAlgorithmHMACGtk.cpp

    r172389 r173874  
    3232#include "CryptoKeyHMAC.h"
    3333#include "ExceptionCode.h"
    34 #include "NotImplemented.h"
     34#include <gnutls/gnutls.h>
     35#include <gnutls/crypto.h>
     36#include <wtf/CryptographicUtilities.h>
    3537
    3638namespace WebCore {
    3739
     40static gnutls_mac_algorithm_t getGnutlsDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction)
     41{
     42    switch (hashFunction) {
     43    case CryptoAlgorithmIdentifier::SHA_1:
     44        return GNUTLS_MAC_SHA1;
     45    case CryptoAlgorithmIdentifier::SHA_224:
     46        return GNUTLS_MAC_SHA224;
     47    case CryptoAlgorithmIdentifier::SHA_256:
     48        return GNUTLS_MAC_SHA256;
     49    case CryptoAlgorithmIdentifier::SHA_384:
     50        return GNUTLS_MAC_SHA384;
     51    case CryptoAlgorithmIdentifier::SHA_512:
     52        return GNUTLS_MAC_SHA512;
     53    default:
     54        return GNUTLS_MAC_UNKNOWN;
     55    }
     56}
     57
     58static Vector<uint8_t> calculateSignature(gnutls_mac_algorithm_t algorithm, const Vector<uint8_t>& key, const CryptoOperationData& data)
     59{
     60    size_t digestLength = gnutls_hmac_get_len(algorithm);
     61
     62    Vector<uint8_t> result(digestLength);
     63    const void* keyData = key.data() ? key.data() : reinterpret_cast<const uint8_t*>("");
     64    int ret = gnutls_hmac_fast(algorithm, keyData, key.size(), data.first, data.second, result.data());
     65    ASSERT(ret == GNUTLS_E_SUCCESS);
     66    UNUSED_PARAM(ret);
     67
     68    return result;
     69}
     70
    3871void CryptoAlgorithmHMAC::platformSign(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
    3972{
    40     notImplemented();
    41     ec = NOT_SUPPORTED_ERR;
    42     failureCallback();
     73    gnutls_mac_algorithm_t algorithm = getGnutlsDigestAlgorithm(parameters.hash);
     74    if (algorithm == GNUTLS_MAC_UNKNOWN) {
     75        ec = NOT_SUPPORTED_ERR;
     76        failureCallback();
     77        return;
     78    }
    4379
    44     UNUSED_PARAM(parameters);
    45     UNUSED_PARAM(key);
    46     UNUSED_PARAM(data);
    47     UNUSED_PARAM(callback);
    48     UNUSED_PARAM(ec);
     80    Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data);
     81
     82    callback(signature);
    4983}
    5084
    5185void CryptoAlgorithmHMAC::platformVerify(const CryptoAlgorithmHmacParams& parameters, const CryptoKeyHMAC& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
    5286{
    53     notImplemented();
    54     ec = NOT_SUPPORTED_ERR;
    55     failureCallback();
     87    gnutls_mac_algorithm_t algorithm = getGnutlsDigestAlgorithm(parameters.hash);
     88    if (algorithm == GNUTLS_MAC_UNKNOWN) {
     89        ec = NOT_SUPPORTED_ERR;
     90        failureCallback();
     91        return;
     92    }
    5693
    57     UNUSED_PARAM(parameters);
    58     UNUSED_PARAM(key);
    59     UNUSED_PARAM(expectedSignature);
    60     UNUSED_PARAM(data);
    61     UNUSED_PARAM(callback);
    62     UNUSED_PARAM(ec);
     94    Vector<uint8_t> signature = calculateSignature(algorithm, key.key(), data);
     95
     96    // Using a constant time comparison to prevent timing attacks.
     97    bool result = signature.size() == expectedSignature.second && !constantTimeMemcmp(signature.data(), expectedSignature.first, signature.size());
     98
     99    callback(result);
    63100}
    64101
Note: See TracChangeset for help on using the changeset viewer.