diff options
author | esprehn <esprehn@chromium.org> | 2016-02-26 22:27:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-27 06:28:13 +0000 |
commit | 1cd6fb4fc436b16ebcd74be67c82b803d2eb16fa (patch) | |
tree | 960424da860e0e4b2de891278596d76160fd7876 | |
parent | f3130b413a8950d4eb43dc5409843245571f625d (diff) | |
download | chromium_src-1cd6fb4fc436b16ebcd74be67c82b803d2eb16fa.zip chromium_src-1cd6fb4fc436b16ebcd74be67c82b803d2eb16fa.tar.gz chromium_src-1cd6fb4fc436b16ebcd74be67c82b803d2eb16fa.tar.bz2 |
Remove WebCryptoUtil.
WebCrypto shouldn't be exposing util functions like this from the
public API in blink. This is only used in one place anyway, so
lets make it a method of the right class. If WebCrypto will
use this concept of BigInteger and conversion often it should
introduce a WebBigInteger class with methods.
Review URL: https://codereview.chromium.org/1741643002
Cr-Commit-Position: refs/heads/master@{#378120}
7 files changed, 20 insertions, 49 deletions
diff --git a/components/webcrypto/algorithms/rsa.cc b/components/webcrypto/algorithms/rsa.cc index 36da48b..c1fbc3c 100644 --- a/components/webcrypto/algorithms/rsa.cc +++ b/components/webcrypto/algorithms/rsa.cc @@ -19,7 +19,6 @@ #include "crypto/scoped_openssl_types.h" #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" -#include "third_party/WebKit/public/platform/WebCryptoUtil.h" namespace webcrypto { @@ -279,7 +278,7 @@ Status RsaHashedAlgorithm::GenerateKey( } unsigned int public_exponent = 0; - if (!blink::bigIntegerToUint(params->publicExponent(), public_exponent)) + if (!params->convertPublicExponentToUnsigned(public_exponent)) return Status::ErrorGenerateKeyPublicExponent(); // OpenSSL hangs when given bad public exponents. Use a whitelist. diff --git a/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp b/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp index 41ddd90..8ddc31d 100644 --- a/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp +++ b/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp @@ -69,7 +69,6 @@ #include "platform/mediastream/RTCOfferOptions.h" #include "public/platform/Platform.h" #include "public/platform/WebCryptoAlgorithmParams.h" -#include "public/platform/WebCryptoUtil.h" #include "public/platform/WebMediaStream.h" #include "public/platform/WebRTCCertificate.h" #include "public/platform/WebRTCCertificateGenerator.h" @@ -638,10 +637,10 @@ ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c // name: "RSASSA-PKCS1-v1_5" unsigned publicExponent; // "publicExponent" must fit in an unsigned int. The only recognized "hash" is "SHA-256". - if (bigIntegerToUint(cryptoAlgorithm.rsaHashedKeyGenParams()->publicExponent(), publicExponent) + if (cryptoAlgorithm.rsaHashedKeyGenParams()->convertPublicExponentToUnsigned(publicExponent) && cryptoAlgorithm.rsaHashedKeyGenParams()->hash().id() == WebCryptoAlgorithmIdSha256) { unsigned modulusLength = cryptoAlgorithm.rsaHashedKeyGenParams()->modulusLengthBits(); - keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, publicExponent)); + keyParams.set(WebRTCKeyParams::createRSA(modulusLength, publicExponent)); } else { return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, unsupportedParamsString)); } @@ -650,7 +649,7 @@ ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c // name: "ECDSA" // The only recognized "namedCurve" is "P-256". if (cryptoAlgorithm.ecKeyGenParams()->namedCurve() == WebCryptoNamedCurveP256) { - keyParams.set(blink::WebRTCKeyParams::createECDSA(blink::WebRTCECCurveNistP256)); + keyParams.set(WebRTCKeyParams::createECDSA(WebRTCECCurveNistP256)); } else { return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, unsupportedParamsString)); } diff --git a/third_party/WebKit/Source/platform/blink_platform.gypi b/third_party/WebKit/Source/platform/blink_platform.gypi index 383fb9c..5ffb920 100644 --- a/third_party/WebKit/Source/platform/blink_platform.gypi +++ b/third_party/WebKit/Source/platform/blink_platform.gypi @@ -313,7 +313,6 @@ 'exported/WebCryptoKey.cpp', 'exported/WebCryptoKeyAlgorithm.cpp', 'exported/WebCryptoResult.cpp', - 'exported/WebCryptoUtil.cpp', 'exported/WebCursorInfo.cpp', 'exported/WebData.cpp', 'exported/WebDataConsumerHandle.cpp', diff --git a/third_party/WebKit/Source/platform/exported/WebCryptoUtil.cpp b/third_party/WebKit/Source/platform/exported/WebCryptoUtil.cpp deleted file mode 100644 index c92f3d5..0000000 --- a/third_party/WebKit/Source/platform/exported/WebCryptoUtil.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "public/platform/WebCryptoUtil.h" - -namespace blink { - -bool bigIntegerToUint(const WebVector<unsigned char>& bigInteger, unsigned& result) -{ - result = 0; - for (size_t i = 0; i < bigInteger.size(); ++i) { - size_t iReversed = bigInteger.size() - i - 1; - - if (iReversed >= sizeof(result) && bigInteger[i]) - return false; // Too large for unsigned int. - - result |= bigInteger[i] << 8 * iReversed; - } - return true; -} - -} // namespace blink diff --git a/third_party/WebKit/public/blink_headers.gypi b/third_party/WebKit/public/blink_headers.gypi index a6464a2..660570d 100644 --- a/third_party/WebKit/public/blink_headers.gypi +++ b/third_party/WebKit/public/blink_headers.gypi @@ -52,7 +52,6 @@ "platform/WebCryptoKey.h", "platform/WebCryptoKeyAlgorithm.h", "platform/WebCryptoKeyAlgorithmParams.h", - "platform/WebCryptoUtil.h", "platform/WebCursorInfo.h", "platform/WebData.h", "platform/WebDataConsumerHandle.h", diff --git a/third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h b/third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h index e90e98d..f57eedf 100644 --- a/third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h +++ b/third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h @@ -227,6 +227,22 @@ public: const WebVector<unsigned char>& publicExponent() const { return m_publicExponent; } const WebCryptoAlgorithm& hash() const { return m_hash; } + // Converts the public exponent (big-endian WebCrypto BigInteger), + // with or without leading zeros, to unsigned int. Returns true on success. + bool convertPublicExponentToUnsigned(unsigned& result) const + { + result = 0; + for (size_t i = 0; i < m_publicExponent.size(); ++i) { + size_t iReversed = m_publicExponent.size() - i - 1; + + if (iReversed >= sizeof(result) && m_publicExponent[i]) + return false; // Too large for unsigned int. + + result |= m_publicExponent[i] << 8 * iReversed; + } + return true; + } + private: const unsigned m_modulusLengthBits; const WebVector<unsigned char> m_publicExponent; diff --git a/third_party/WebKit/public/platform/WebCryptoUtil.h b/third_party/WebKit/public/platform/WebCryptoUtil.h deleted file mode 100644 index b95d51a..0000000 --- a/third_party/WebKit/public/platform/WebCryptoUtil.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WebCryptoUtil_h -#define WebCryptoUtil_h - -#include "WebCommon.h" -#include "WebVector.h" - -namespace blink { - -// Converts the (big-endian) BigInteger to unsigned int. Returns true on success (if its value is not too large). -BLINK_PLATFORM_EXPORT bool bigIntegerToUint(const WebVector<unsigned char>& bigInteger, unsigned& result); - -} // namespace blink - -#endif // WebCryptoUtil_h |