Use uint8_t vectors for WebCrypto data
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Nov 2013 21:41:46 +0000 (21:41 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Nov 2013 21:41:46 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124466

Reviewed by Sam Weinig.

Source/WebCore:

Using Vector<char> for crypto key data is somewhat non-idiomatic, and it gets simply
dangerous for bignums, because signed arithmetic is not appropriate for bignum digits.

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::generateSecWebSocketKey):
(WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
No longer need to cast data to char* here.

* bindings/js/JSCryptoKeySerializationJWK.cpp:
* bindings/js/JSCryptoKeySerializationJWK.h:
* crypto/CryptoDigest.h:
* crypto/CryptoKey.h:
* crypto/keys/CryptoKeyAES.cpp:
* crypto/keys/CryptoKeyAES.h:
* crypto/keys/CryptoKeyDataOctetSequence.h:
* crypto/keys/CryptoKeyDataRSAComponents.cpp:
* crypto/keys/CryptoKeyDataRSAComponents.h:
* crypto/keys/CryptoKeyHMAC.cpp:
* crypto/keys/CryptoKeyHMAC.h:
* crypto/keys/CryptoKeyRSA.h:
* crypto/keys/CryptoKeySerializationRaw.cpp:
* crypto/keys/CryptoKeySerializationRaw.h:
* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
* crypto/mac/CryptoAlgorithmHMACMac.cpp:
* crypto/mac/CryptoDigestMac.cpp:
* crypto/mac/CryptoKeyMac.cpp:
* crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
Switched to Vector<uint8_t>.

* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::getPublicKeyComponents): Extracted from buildAlgorithmDescription() and simplified.
(WebCore::CryptoKeyRSA::create): Switched to Vector<uint8_t>.
(WebCore::CryptoKeyRSA::buildAlgorithmDescription): No longer need to copy data just
to change type from Vector<char> to Vector<unsigned char>.
(WebCore::bigIntegerToUInt32): Ditto. No longer need to cast types when dealing with the bignum.
(WebCore::CryptoKeyRSA::generatePair): Improved an error message a little.

* fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL):
* inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest):
* inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::archive):
* platform/graphics/cg/ImageBufferCG.cpp: (WebCore::CGImageToDataURL):
No longer need to cast data to char* here.

Source/WTF:

Binary data can be UTF-8, in which case "char*" is idiomatic, or it can be arbitrary
binary data, in which case "uint8_t*" is more common.

Changed encode functions that took "const char *" to "const void*", and decode
functions that took "Vector<char>&" now take an adapter class.

The adapter relies on Vector<char> and Vector<uint8_t> classes having an identical layout.

* wtf/text/Base64.cpp:
(WTF::base64Encode):
(WTF::base64URLEncode):
(WTF::base64DecodeInternal):
(WTF::base64Decode):
(WTF::base64URLDecode):
* wtf/text/Base64.h:
(WTF::SignedOrUnsignedCharVectorAdapter):
(WTF::ConstSignedOrUnsignedCharVectorAdapter):
(WTF::base64Encode):
(WTF::base64URLEncode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159390 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/text/Base64.cpp
Source/WTF/wtf/text/Base64.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h
Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
Source/WebCore/crypto/CryptoDigest.h
Source/WebCore/crypto/CryptoKey.cpp
Source/WebCore/crypto/CryptoKey.h
Source/WebCore/crypto/keys/CryptoKeyAES.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h
Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.cpp
Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.h
Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.cpp
Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/keys/CryptoKeyRSA.h
Source/WebCore/crypto/keys/CryptoKeySerializationRaw.cpp
Source/WebCore/crypto/keys/CryptoKeySerializationRaw.h
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
Source/WebCore/crypto/mac/CryptoDigestMac.cpp
Source/WebCore/crypto/mac/CryptoKeyMac.cpp
Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h
Source/WebCore/fileapi/FileReaderLoader.cpp
Source/WebCore/inspector/DOMPatchSupport.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

index 455b7ad..f6de57e 100644 (file)
@@ -1,3 +1,30 @@
+2013-11-16  Alexey Proskuryakov  <ap@apple.com>
+
+        Use uint8_t vectors for WebCrypto data
+        https://bugs.webkit.org/show_bug.cgi?id=124466
+
+        Reviewed by Sam Weinig.
+
+        Binary data can be UTF-8, in which case "char*" is idiomatic, or it can be arbitrary
+        binary data, in which case "uint8_t*" is more common.
+
+        Changed encode functions that took "const char *" to "const void*", and decode
+        functions that took "Vector<char>&" now take an adapter class.
+
+        The adapter relies on Vector<char> and Vector<uint8_t> classes having an identical layout.
+
+        * wtf/text/Base64.cpp:
+        (WTF::base64Encode):
+        (WTF::base64URLEncode):
+        (WTF::base64DecodeInternal):
+        (WTF::base64Decode):
+        (WTF::base64URLDecode):
+        * wtf/text/Base64.h:
+        (WTF::SignedOrUnsignedCharVectorAdapter):
+        (WTF::ConstSignedOrUnsignedCharVectorAdapter):
+        (WTF::base64Encode):
+        (WTF::base64URLEncode):
+
 2013-11-15  Alexey Proskuryakov  <ap@apple.com>
 
         Support exporting symmetric keys as JWK
index 1411f44..1811b1e 100644 (file)
@@ -157,28 +157,28 @@ inline void base64EncodeInternal(const char* data, unsigned len, Vector<char>& o
     }
 }
 
-String base64Encode(const char* data, unsigned length, Base64EncodePolicy policy)
+String base64Encode(const void* data, unsigned length, Base64EncodePolicy policy)
 {
     Vector<char> result;
-    base64EncodeInternal(data, length, result, policy, base64EncMap);
+    base64EncodeInternal(static_cast<const char*>(data), length, result, policy, base64EncMap);
     return String(result.data(), result.size());
 }
 
-void base64Encode(const char* data, unsigned len, Vector<char>& out, Base64EncodePolicy policy)
+void base64Encode(const void* data, unsigned len, Vector<char>& out, Base64EncodePolicy policy)
 {
-    base64EncodeInternal(data, len, out, policy, base64EncMap);
+    base64EncodeInternal(static_cast<const char*>(data), len, out, policy, base64EncMap);
 }
 
-String base64URLEncode(const char* data, unsigned length)
+String base64URLEncode(const void* data, unsigned length)
 {
     Vector<char> result;
-    base64EncodeInternal(data, length, result, Base64URLPolicy, base64URLEncMap);
+    base64EncodeInternal(static_cast<const char*>(data), length, result, Base64URLPolicy, base64URLEncMap);
     return String(result.data(), result.size());
 }
 
-void base64URLEncode(const char* data, unsigned len, Vector<char>& out)
+void base64URLEncode(const void* data, unsigned len, Vector<char>& out)
 {
-    base64EncodeInternal(data, len, out, Base64URLPolicy, base64URLEncMap);
+    base64EncodeInternal(static_cast<const char*>(data), len, out, Base64URLPolicy, base64URLEncMap);
 }
 
 template<typename T>
@@ -201,6 +201,7 @@ static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<c
             if (policy == Base64FailOnInvalidCharacterOrExcessPadding && (length % 4 || equalsSignCount > 2))
                 return false;
         } else {
+            ASSERT(static_cast<size_t>(ch) < 128);
             char decodedCharacter = decodeMap[ch];
             if (decodedCharacter != nonAlphabet) {
                 if (equalsSignCount)
@@ -248,12 +249,12 @@ static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<c
     return true;
 }
 
-bool base64Decode(const String& in, Vector<char>& out, Base64DecodePolicy policy)
+bool base64Decode(const String& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
 {
     return base64DecodeInternal<UChar>(in.characters(), in.length(), out, policy, base64DecMap);
 }
 
-bool base64Decode(const Vector<char>& in, Vector<char>& out, Base64DecodePolicy policy)
+bool base64Decode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
 {
     out.clear();
 
@@ -264,17 +265,17 @@ bool base64Decode(const Vector<char>& in, Vector<char>& out, Base64DecodePolicy
     return base64DecodeInternal<char>(in.data(), in.size(), out, policy, base64DecMap);
 }
 
-bool base64Decode(const char* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
+bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
 {
     return base64DecodeInternal<char>(data, len, out, policy, base64DecMap);
 }
 
-bool base64URLDecode(const String& in, Vector<char>& out)
+bool base64URLDecode(const String& in, SignedOrUnsignedCharVectorAdapter out)
 {
     return base64DecodeInternal<UChar>(in.characters(), in.length(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
 
-bool base64URLDecode(const Vector<char>& in, Vector<char>& out)
+bool base64URLDecode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out)
 {
     out.clear();
 
@@ -285,7 +286,7 @@ bool base64URLDecode(const Vector<char>& in, Vector<char>& out)
     return base64DecodeInternal<char>(in.data(), in.size(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
 
-bool base64URLDecode(const char* data, unsigned len, Vector<char>& out)
+bool base64URLDecode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out)
 {
     return base64DecodeInternal<char>(data, len, out, Base64FailOnInvalidCharacter, base64URLDecMap);
 }
index 078dafc..1dfcf26 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
  * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ * 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
@@ -46,18 +47,49 @@ enum Base64DecodePolicy {
     Base64IgnoreInvalidCharacters
 };
 
-WTF_EXPORT_PRIVATE void base64Encode(const char*, unsigned, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
-WTF_EXPORT_PRIVATE void base64Encode(const Vector<char>&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
+class SignedOrUnsignedCharVectorAdapter {
+public:
+    SignedOrUnsignedCharVectorAdapter(Vector<char>& vector) { m_vector.c = &vector; }
+    SignedOrUnsignedCharVectorAdapter(Vector<uint8_t>& vector) { m_vector.u = &vector; }
+
+    operator Vector<char>&() { return *m_vector.c; }
+    void clear() { m_vector.c->clear(); }
+
+private:
+    union {
+        Vector<char>* c;
+        Vector<uint8_t>* u;
+    } m_vector;
+};
+
+class ConstSignedOrUnsignedCharVectorAdapter {
+public:
+    ConstSignedOrUnsignedCharVectorAdapter(const Vector<char>& vector) { m_vector.c = &vector; }
+    ConstSignedOrUnsignedCharVectorAdapter(const Vector<uint8_t>& vector) { m_vector.u = &vector; }
+
+    operator const Vector<char>&() { return *m_vector.c; }
+    const char* data() const { return m_vector.c->data(); }
+    size_t size() const { return m_vector.c->size(); }
+
+private:
+    union {
+        const Vector<char>* c;
+        const Vector<uint8_t>* u;
+    } m_vector;
+};
+
+WTF_EXPORT_PRIVATE void base64Encode(const void*, unsigned, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
+WTF_EXPORT_PRIVATE void base64Encode(ConstSignedOrUnsignedCharVectorAdapter, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
 WTF_EXPORT_PRIVATE void base64Encode(const CString&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
-WTF_EXPORT_PRIVATE String base64Encode(const char*, unsigned, Base64EncodePolicy = Base64DoNotInsertLFs);
-WTF_EXPORT_PRIVATE String base64Encode(const Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
+WTF_EXPORT_PRIVATE String base64Encode(const void*, unsigned, Base64EncodePolicy = Base64DoNotInsertLFs);
+WTF_EXPORT_PRIVATE String base64Encode(ConstSignedOrUnsignedCharVectorAdapter, Base64EncodePolicy = Base64DoNotInsertLFs);
 WTF_EXPORT_PRIVATE String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotInsertLFs);
 
-WTF_EXPORT_PRIVATE bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);
-WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);
-WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);
+WTF_EXPORT_PRIVATE bool base64Decode(const String&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
+WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
+WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
 
-inline void base64Encode(const Vector<char>& in, Vector<char>& out, Base64EncodePolicy policy)
+inline void base64Encode(ConstSignedOrUnsignedCharVectorAdapter in, Vector<char>& out, Base64EncodePolicy policy)
 {
     base64Encode(in.data(), in.size(), out, policy);
 }
@@ -67,7 +99,7 @@ inline void base64Encode(const CString& in, Vector<char>& out, Base64EncodePolic
     base64Encode(in.data(), in.length(), out, policy);
 }
 
-inline String base64Encode(const Vector<char>& in, Base64EncodePolicy policy)
+inline String base64Encode(ConstSignedOrUnsignedCharVectorAdapter in, Base64EncodePolicy policy)
 {
     return base64Encode(in.data(), in.size(), policy);
 }
@@ -82,18 +114,18 @@ inline String base64Encode(const CString& in, Base64EncodePolicy policy)
 // This format uses '-' and '_' instead of '+' and '/' respectively.
 // ======================================================================================
 
-WTF_EXPORT_PRIVATE void base64URLEncode(const char*, unsigned, Vector<char>&);
-WTF_EXPORT_PRIVATE void base64URLEncode(const Vector<char>&, Vector<char>&);
+WTF_EXPORT_PRIVATE void base64URLEncode(const void*, unsigned, Vector<char>&);
+WTF_EXPORT_PRIVATE void base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter, Vector<char>&);
 WTF_EXPORT_PRIVATE void base64URLEncode(const CString&, Vector<char>&);
-WTF_EXPORT_PRIVATE String base64URLEncode(const char*, unsigned);
-WTF_EXPORT_PRIVATE String base64URLEncode(const Vector<char>&);
+WTF_EXPORT_PRIVATE String base64URLEncode(const void*, unsigned);
+WTF_EXPORT_PRIVATE String base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter);
 WTF_EXPORT_PRIVATE String base64URLEncode(const CString&);
 
-WTF_EXPORT_PRIVATE bool base64URLDecode(const String&, Vector<char>&);
-WTF_EXPORT_PRIVATE bool base64URLDecode(const Vector<char>&, Vector<char>&);
-WTF_EXPORT_PRIVATE bool base64URLDecode(const char*, unsigned, Vector<char>&);
+WTF_EXPORT_PRIVATE bool base64URLDecode(const String&, SignedOrUnsignedCharVectorAdapter);
+WTF_EXPORT_PRIVATE bool base64URLDecode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter);
+WTF_EXPORT_PRIVATE bool base64URLDecode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter);
 
-inline void base64URLEncode(const Vector<char>& in, Vector<char>& out)
+inline void base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter in, Vector<char>& out)
 {
     base64URLEncode(in.data(), in.size(), out);
 }
@@ -103,7 +135,7 @@ inline void base64URLEncode(const CString& in, Vector<char>& out)
     base64URLEncode(in.data(), in.length(), out);
 }
 
-inline String base64URLEncode(const Vector<char>& in)
+inline String base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter in)
 {
     return base64URLEncode(in.data(), in.size());
 }
index ef2b7ea..50c6c8d 100644 (file)
@@ -1,3 +1,53 @@
+2013-11-16  Alexey Proskuryakov  <ap@apple.com>
+
+        Use uint8_t vectors for WebCrypto data
+        https://bugs.webkit.org/show_bug.cgi?id=124466
+
+        Reviewed by Sam Weinig.
+
+        Using Vector<char> for crypto key data is somewhat non-idiomatic, and it gets simply
+        dangerous for bignums, because signed arithmetic is not appropriate for bignum digits.
+
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::generateSecWebSocketKey):
+        (WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
+        No longer need to cast data to char* here.
+
+        * bindings/js/JSCryptoKeySerializationJWK.cpp:
+        * bindings/js/JSCryptoKeySerializationJWK.h:
+        * crypto/CryptoDigest.h:
+        * crypto/CryptoKey.h:
+        * crypto/keys/CryptoKeyAES.cpp:
+        * crypto/keys/CryptoKeyAES.h:
+        * crypto/keys/CryptoKeyDataOctetSequence.h:
+        * crypto/keys/CryptoKeyDataRSAComponents.cpp:
+        * crypto/keys/CryptoKeyDataRSAComponents.h:
+        * crypto/keys/CryptoKeyHMAC.cpp:
+        * crypto/keys/CryptoKeyHMAC.h:
+        * crypto/keys/CryptoKeyRSA.h:
+        * crypto/keys/CryptoKeySerializationRaw.cpp:
+        * crypto/keys/CryptoKeySerializationRaw.h:
+        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
+        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
+        * crypto/mac/CryptoDigestMac.cpp:
+        * crypto/mac/CryptoKeyMac.cpp:
+        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
+        Switched to Vector<uint8_t>.
+
+        * crypto/mac/CryptoKeyRSAMac.cpp:
+        (WebCore::getPublicKeyComponents): Extracted from buildAlgorithmDescription() and simplified.
+        (WebCore::CryptoKeyRSA::create): Switched to Vector<uint8_t>.
+        (WebCore::CryptoKeyRSA::buildAlgorithmDescription): No longer need to copy data just
+        to change type from Vector<char> to Vector<unsigned char>.
+        (WebCore::bigIntegerToUInt32): Ditto. No longer need to cast types when dealing with the bignum.
+        (WebCore::CryptoKeyRSA::generatePair): Improved an error message a little.
+
+        * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL):
+        * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest):
+        * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::archive):
+        * platform/graphics/cg/ImageBufferCG.cpp: (WebCore::CGImageToDataURL):
+        No longer need to cast data to char* here.
+
 2013-11-17  Antti Koivisto  <antti@apple.com>
 
         REGRESSION (r158774): Iteration over element children is broken
index a3b7667..1def45e 100644 (file)
@@ -103,7 +103,7 @@ static String generateSecWebSocketKey()
     static const size_t nonceSize = 16;
     unsigned char key[nonceSize];
     cryptographicallyRandomValues(key, nonceSize);
-    return base64Encode(reinterpret_cast<char*>(key), nonceSize);
+    return base64Encode(key, nonceSize);
 }
 
 String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocketKey)
@@ -116,7 +116,7 @@ String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocket
     sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), strlen(webSocketKeyGUID));
     Vector<uint8_t, sha1HashSize> hash;
     sha1.computeHash(hash);
-    return base64Encode(reinterpret_cast<const char*>(hash.data()), sha1HashSize);
+    return base64Encode(hash.data(), sha1HashSize);
 }
 
 WebSocketHandshake::WebSocketHandshake(const URL& url, const String& protocol, ScriptExecutionContext* context)
index b33240e..b6eb92b 100644 (file)
@@ -109,7 +109,7 @@ static bool getBooleanFromJSON(ExecState* exec, JSObject* json, const char* key,
     return true;
 }
 
-static bool getBigIntegerVectorFromJSON(ExecState* exec, JSObject* json, const char* key, Vector<char>& result)
+static bool getBigIntegerVectorFromJSON(ExecState* exec, JSObject* json, const char* key, Vector<uint8_t>& result)
 {
     String base64urlEncodedNumber;
     if (!getStringFromJSON(exec, json, key, base64urlEncodedNumber))
@@ -289,7 +289,7 @@ std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataOctetSequence
         return nullptr;
     }
 
-    Vector<char> octetSequence;
+    Vector<uint8_t> octetSequence;
     if (!base64URLDecode(keyBase64URL, octetSequence)) {
         throwTypeError(m_exec, "Cannot decode base64url key data in JWK");
         return nullptr;
@@ -305,9 +305,9 @@ std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataOctetSequence
 
 std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataRSAComponents() const
 {
-    Vector<char> modulus;
-    Vector<char> exponent;
-    Vector<char> privateExponent;
+    Vector<uint8_t> modulus;
+    Vector<uint8_t> exponent;
+    Vector<uint8_t> privateExponent;
 
     if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "n", modulus)) {
         if (!m_exec->hadException())
@@ -416,7 +416,7 @@ std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyData() const
     return nullptr;
 }
 
-void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector<char>& keyData, JSObject* result)
+void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector<uint8_t>& keyData, JSObject* result)
 {
     addToJSON(exec, result, "kty", "oct");
     addToJSON(exec, result, "k", base64URLEncode(keyData));
index 2f65ba4..2e1b459 100644 (file)
@@ -65,7 +65,7 @@ private:
 
     virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE;
 
-    static void buildJSONForOctetSequence(JSC::ExecState*, const Vector<char>&, JSC::JSObject* result);
+    static void buildJSONForOctetSequence(JSC::ExecState*, const Vector<uint8_t>&, JSC::JSObject* result);
     static void addJWKAlgorithmToJSON(JSC::ExecState*, JSC::JSObject*, const CryptoKey& key);
     static void addJWKUseToJSON(JSC::ExecState*, JSC::JSObject*, CryptoKeyUsage);
     static void addToJSON(JSC::ExecState*, JSC::JSObject*, const char* key, const String& value);
index 6e3413a..977f4f2 100644 (file)
@@ -113,9 +113,9 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& par
 
     digest->addBytes(data.first, data.second);
 
-    Vector<unsigned char> digestData = digest->computeHash();
+    Vector<uint8_t> digestData = digest->computeHash();
 
-    Vector<unsigned char> signature(512);
+    Vector<uint8_t> signature(512);
     size_t signatureSize = signature.size();
 
     CCCryptorStatus status = CCRSACryptorSign(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize);
@@ -152,7 +152,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& p
 
     digest->addBytes(data.first, data.second);
 
-    Vector<unsigned char> digestData = digest->computeHash();
+    Vector<uint8_t> digestData = digest->computeHash();
 
     CCCryptorStatus status = CCRSACryptorVerify(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second);
     if (!status)
index a3daafa..353b13e 100644 (file)
@@ -43,7 +43,7 @@ public:
     ~CryptoDigest();
 
     void addBytes(const void* input, size_t length);
-    Vector<unsigned char> computeHash();
+    Vector<uint8_t> computeHash();
 
 private:
     CryptoDigest();
index 0cc26ba..678b433 100644 (file)
@@ -89,9 +89,9 @@ Vector<String> CryptoKey::usages() const
 }
 
 #if !PLATFORM(MAC)
-Vector<char> CryptoKey::randomData(size_t size)
+Vector<uint8_t> CryptoKey::randomData(size_t size)
 {
-    Vector<char> result(size);
+    Vector<uint8_t> result(size);
     cryptographicallyRandomValues(result.data(), result.size());
     return result;
 }
index a457cbf..12276ef 100644 (file)
@@ -64,7 +64,7 @@ public:
 
     virtual std::unique_ptr<CryptoKeyData> exportData() const = 0;
 
-    static Vector<char> randomData(size_t);
+    static Vector<uint8_t> randomData(size_t);
 
 private:
     CryptoAlgorithmIdentifier m_algorithm;
index 0fd9ab2..278a50d 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace WebCore {
 
-CryptoKeyAES::CryptoKeyAES(CryptoAlgorithmIdentifier algorithm, const Vector<char>& key, bool extractable, CryptoKeyUsage usage)
+CryptoKeyAES::CryptoKeyAES(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage)
     : CryptoKey(algorithm, CryptoKeyType::Secret, extractable, usage)
     , m_key(key)
 {
index d1b26c4..f8a8057 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 
 class CryptoKeyAES FINAL : public CryptoKey {
 public:
-    static PassRefPtr<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector<char>& key, bool extractable, CryptoKeyUsage usage)
+    static PassRefPtr<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage)
     {
         return adoptRef(new CryptoKeyAES(algorithm, key, extractable, usage));
     }
@@ -46,15 +46,15 @@ public:
 
     virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::AES; }
 
-    const Vector<char>& key() const { return m_key; }
+    const Vector<uint8_t>& key() const { return m_key; }
 
 private:
-    CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<char>& key, bool extractable, CryptoKeyUsage);
+    CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage);
 
     virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;
     virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE;
 
-    Vector<char> m_key;
+    Vector<uint8_t> m_key;
 };
 
 inline bool isCryptoKeyAES(const CryptoKey& key)
index 14853f0..27a4e6c 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-CryptoKeyDataOctetSequence::CryptoKeyDataOctetSequence(const Vector<char>& data)
+CryptoKeyDataOctetSequence::CryptoKeyDataOctetSequence(const Vector<uint8_t>& data)
     : CryptoKeyData(CryptoKeyData::Format::OctetSequence)
     , m_keyData(data)
 {
index 76d84da..6a64ca8 100644 (file)
@@ -35,18 +35,18 @@ namespace WebCore {
 
 class CryptoKeyDataOctetSequence FINAL : public CryptoKeyData {
 public:
-    static std::unique_ptr<CryptoKeyDataOctetSequence> create(const Vector<char>& keyData)
+    static std::unique_ptr<CryptoKeyDataOctetSequence> create(const Vector<uint8_t>& keyData)
     {
         return std::unique_ptr<CryptoKeyDataOctetSequence>(new CryptoKeyDataOctetSequence(keyData));
     }
     virtual ~CryptoKeyDataOctetSequence();
 
-    const Vector<char>& octetSequence() const { return m_keyData; }
+    const Vector<uint8_t>& octetSequence() const { return m_keyData; }
 
 private:
-    CryptoKeyDataOctetSequence(const Vector<char>&);
+    CryptoKeyDataOctetSequence(const Vector<uint8_t>&);
 
-    Vector<char> m_keyData;
+    Vector<uint8_t> m_keyData;
 };
 
 inline bool isCryptoKeyDataOctetSequence(const CryptoKeyData& data)
index 5d8d511..e484926 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent)
+CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent)
     : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     , m_type(Type::Public)
     , m_modulus(modulus)
@@ -38,7 +38,7 @@ CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modul
 {
 }
 
-CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent)
+CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent)
     : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     , m_type(Type::Private)
     , m_modulus(modulus)
@@ -48,7 +48,7 @@ CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modul
 {
 }
 
-CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)
+CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)
     : CryptoKeyData(CryptoKeyData::Format::RSAComponents)
     , m_type(Type::Private)
     , m_modulus(modulus)
index 33c6dd2..06d2134 100644 (file)
@@ -41,22 +41,22 @@ public:
     };
 
     struct PrimeInfo {
-        Vector<char> primeFactor;
-        Vector<char> factorCRTExponent;
-        Vector<char> factorCRTCoefficient;
+        Vector<uint8_t> primeFactor;
+        Vector<uint8_t> factorCRTExponent;
+        Vector<uint8_t> factorCRTCoefficient;
     };
 
-    static std::unique_ptr<CryptoKeyDataRSAComponents> createPublic(const Vector<char>& modulus, const Vector<char>& exponent)
+    static std::unique_ptr<CryptoKeyDataRSAComponents> createPublic(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent)
     {
         return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent));
     }
 
-    static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivate(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent)
+    static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivate(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent)
     {
         return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent, privateExponent));
     }
 
-    static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivateWithAdditionalData(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)
+    static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivateWithAdditionalData(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)
     {
         return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos));
     }
@@ -66,29 +66,29 @@ public:
     Type type() const { return m_type; }
 
     // Private and public keys.
-    const Vector<char>& modulus() const { return m_modulus; }
-    const Vector<char>& exponent() const { return m_exponent; }
+    const Vector<uint8_t>& modulus() const { return m_modulus; }
+    const Vector<uint8_t>& exponent() const { return m_exponent; }
 
     // Only private keys.
-    const Vector<char>& privateExponent() const { return m_privateExponent; }
+    const Vector<uint8_t>& privateExponent() const { return m_privateExponent; }
     bool hasAdditionalPrivateKeyParameters() const { return m_hasAdditionalPrivateKeyParameters; }
     const PrimeInfo& firstPrimeInfo() const { return m_firstPrimeInfo; }
     const PrimeInfo& secondPrimeInfo() const { return m_secondPrimeInfo; }
     const Vector<PrimeInfo>& otherPrimeInfos() const { return m_otherPrimeInfos; }
 
 private:
-    CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent);
-    CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent);
-    CryptoKeyDataRSAComponents(const Vector<char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos);
+    CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent);
+    CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent);
+    CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos);
 
     Type m_type;
 
     // Private and public keys.
-    Vector<char> m_modulus;
-    Vector<char> m_exponent;
+    Vector<uint8_t> m_modulus;
+    Vector<uint8_t> m_exponent;
 
     // Only private keys.
-    Vector<char> m_privateExponent;
+    Vector<uint8_t> m_privateExponent;
     bool m_hasAdditionalPrivateKeyParameters;
     PrimeInfo m_firstPrimeInfo;
     PrimeInfo m_secondPrimeInfo;
index 04530b4..747e8c2 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace WebCore {
 
-CryptoKeyHMAC::CryptoKeyHMAC(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
+CryptoKeyHMAC::CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
     : CryptoKey(CryptoAlgorithmIdentifier::HMAC, CryptoKeyType::Secret, extractable, usage)
     , m_hash(hash)
     , m_key(key)
index cacf2fc..bdfc137 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 
 class CryptoKeyHMAC FINAL : public CryptoKey {
 public:
-    static PassRefPtr<CryptoKeyHMAC> create(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
+    static PassRefPtr<CryptoKeyHMAC> create(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
     {
         return adoptRef(new CryptoKeyHMAC(key, hash, extractable, usage));
     }
@@ -46,18 +46,18 @@ public:
 
     virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::HMAC; }
 
-    const Vector<char>& key() const { return m_key; }
+    const Vector<uint8_t>& key() const { return m_key; }
 
     CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; }
 
 private:
-    CryptoKeyHMAC(const Vector<char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
+    CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
 
     virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE;
     virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE;
 
     CryptoAlgorithmIdentifier m_hash;
-    Vector<char> m_key;
+    Vector<uint8_t> m_key;
 };
 
 inline bool isCryptoKeyHMAC(const CryptoKey& key)
index 8121bc7..b3641a0 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     void restrictToHash(CryptoAlgorithmIdentifier);
 
-    static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<char>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>);
+    static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>);
 
     virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::RSA; }
 
index d6503e2..609dd97 100644 (file)
@@ -61,7 +61,7 @@ std::unique_ptr<CryptoKeyData> CryptoKeySerializationRaw::keyData() const
     return CryptoKeyDataOctetSequence::create(m_data);
 }
 
-bool CryptoKeySerializationRaw::serialize(const CryptoKey& key, Vector<unsigned char>& result)
+bool CryptoKeySerializationRaw::serialize(const CryptoKey& key, Vector<uint8_t>& result)
 {
     std::unique_ptr<CryptoKeyData> keyData = key.exportData();
     if (!keyData) {
index ef53c01..a5764c7 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     virtual ~CryptoKeySerializationRaw();
 
-    static bool serialize(const CryptoKey&, Vector<unsigned char>&);
+    static bool serialize(const CryptoKey&, Vector<uint8_t>&);
 
 private:
     CryptoKeySerializationRaw(const CryptoOperationData&);
@@ -58,7 +58,7 @@ private:
 
     virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE;
 
-    Vector<char> m_data;
+    Vector<uint8_t> m_data;
 };
 
 } // namespace WebCore
index df2c131..25638d7 100644 (file)
@@ -58,7 +58,7 @@ static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcP
         return;
     }
 
-    Vector<unsigned char> result(CCCryptorGetOutputLength(cryptor, data.second, true));
+    Vector<uint8_t> result(CCCryptorGetOutputLength(cryptor, data.second, true));
 
     size_t bytesWritten;
     status = CCCryptorUpdate(cryptor, data.first, data.second, result.data(), result.size(), &bytesWritten);
@@ -67,7 +67,7 @@ static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcP
         return;
     }
 
-    unsigned char* p = result.data() + bytesWritten;
+    uint8_t* p = result.data() + bytesWritten;
     status = CCCryptorFinal(cryptor, p, result.end() - p, &bytesWritten);
     p += bytesWritten;
     if (status) {
index 2a7dd41..21601fe 100644 (file)
@@ -59,7 +59,7 @@ static bool getCommonCryptoAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCH
     }
 }
 
-static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const Vector<char>& key, const CryptoOperationData& data)
+static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const CryptoOperationData& data)
 {
     size_t digestLength;
     switch (algorithm) {
@@ -80,11 +80,11 @@ static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const
         break;
     default:
         ASSERT_NOT_REACHED();
-        return Vector<unsigned char>();
+        return Vector<uint8_t>();
     }
 
-    Vector<unsigned char> result(digestLength);
-    const char* keyData = key.data() ? key.data() : ""; // <rdar://problem/15467425> HMAC crashes when key pointer is null.
+    Vector<uint8_t> result(digestLength);
+    const void* keyData = key.data() ? key.data() : reinterpret_cast<const uint8_t*>(""); // <rdar://problem/15467425> HMAC crashes when key pointer is null.
     CCHmac(algorithm, keyData, key.size(), data.first, data.second, result.data());
     return result;
 }
@@ -105,7 +105,7 @@ void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, cons
         return;
     }
 
-    Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);
+    Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data);
 
     promise->fulfill(signature);
 }
@@ -126,7 +126,7 @@ void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, co
         return;
     }
 
-    Vector<unsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);
+    Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data);
 
     bool result = signature.size() == expectedSignature.second && !memcmp(signature.data(), expectedSignature.first, signature.size());
 
index cdc888a..0225b75 100644 (file)
@@ -156,9 +156,9 @@ void CryptoDigest::addBytes(const void* input, size_t length)
     }
 }
 
-Vector<unsigned char> CryptoDigest::computeHash()
+Vector<uint8_t> CryptoDigest::computeHash()
 {
-    Vector<unsigned char> result;
+    Vector<uint8_t> result;
     switch (m_context->algorithm) {
     case CryptoAlgorithmIdentifier::SHA_1:
         result.resize(CC_SHA1_DIGEST_LENGTH);
index 5b2a755..7d5f482 100644 (file)
@@ -40,9 +40,9 @@ extern "C" int CCRandomCopyBytes(CCRandomRef rnd, void *bytes, size_t count);
 
 namespace WebCore {
 
-Vector<char> CryptoKey::randomData(size_t size)
+Vector<uint8_t> CryptoKey::randomData(size_t size)
 {
-    Vector<char> result(size);
+    Vector<uint8_t> result(size);
     CCRandomCopyBytes(kCCRandomDefault, result.data(), result.size());
     return result;
 }
index 4aaf0cb..c1a5848 100644 (file)
@@ -58,6 +58,23 @@ extern "C" CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
 
 namespace WebCore {
 
+static CCCryptorStatus getPublicKeyComponents(CCRSACryptorRef rsaKey, Vector<uint8_t>& modulus, Vector<uint8_t>& publicExponent)
+{
+    ASSERT(CCRSAGetKeyType(rsaKey) == ccRSAKeyPublic);
+
+    modulus.resize(16384);
+    size_t modulusLength = modulus.size();
+    publicExponent.resize(16384);
+    size_t exponentLength = publicExponent.size();
+    CCCryptorStatus status = CCRSAGetKeyComponents(rsaKey, modulus.data(), &modulusLength, publicExponent.data(), &exponentLength, 0, 0, 0, 0);
+    if (status)
+        return status;
+
+    modulus.shrink(modulusLength);
+    publicExponent.shrink(exponentLength);
+    return status;
+}
+
 CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
     : CryptoKey(identifier, type, extractable, usage)
     , m_platformKey(platformKey)
@@ -68,6 +85,7 @@ CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType t
 PassRefPtr<CryptoKeyRSA> CryptoKeyRSA::create(CryptoAlgorithmIdentifier identifier, const CryptoKeyDataRSAComponents& keyData, bool extractable, CryptoKeyUsage usage)
 {
     if (keyData.type() == CryptoKeyDataRSAComponents::Type::Private && !keyData.hasAdditionalPrivateKeyParameters()) {
+        // <rdar://problem/15452324> tracks adding support.
         WTFLogAlways("Private keys without additional data are not supported");
         return nullptr;
     }
@@ -112,15 +130,9 @@ void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&
     bool platformKeyIsPublic = CCRSAGetKeyType(m_platformKey) == ccRSAKeyPublic;
     CCRSACryptorRef publicKey = platformKeyIsPublic ? m_platformKey : CCRSACryptorGetPublicKeyFromPrivateKey(m_platformKey);
 
-    uint8_t modulus[16384];
-    size_t modulusLength = sizeof(modulus);
-    uint8_t publicExponent[16384];
-    size_t exponentLength = sizeof(16384);
-    uint8_t p[16384];
-    size_t pLength = sizeof(p);
-    uint8_t q[16384];
-    size_t qLength = sizeof(q);
-    CCCryptorStatus status = CCRSAGetKeyComponents(publicKey, modulus, &modulusLength, publicExponent, &exponentLength, p, &pLength, q, &qLength);
+    Vector<uint8_t> modulus;
+    Vector<uint8_t> publicExponent;
+    CCCryptorStatus status = getPublicKeyComponents(publicKey, modulus, publicExponent);
     if (!platformKeyIsPublic) {
         // CCRSACryptorGetPublicKeyFromPrivateKey has "Get" in the name, but its result needs to be released (see <rdar://problem/15449697>).
         CCRSACryptorRelease(publicKey);
@@ -130,11 +142,8 @@ void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&
         return;
     }
 
-    builder.add("modulusLength", modulusLength * 8);
-
-    Vector<unsigned char> publicExponentVector;
-    publicExponentVector.append(publicExponent, exponentLength);
-    builder.add("publicExponent", publicExponentVector);
+    builder.add("modulusLength", modulus.size() * 8);
+    builder.add("publicExponent", publicExponent);
 
     if (m_restrictedToSpecificHash) {
         auto hashDescriptionBuilder = builder.createEmptyClone();
@@ -150,7 +159,7 @@ std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const
     return nullptr;
 }
 
-static bool bigIntegerToUInt32(const Vector<char>& bigInteger, uint32_t& result)
+static bool bigIntegerToUInt32(const Vector<uint8_t>& bigInteger, uint32_t& result)
 {
     result = 0;
     for (size_t i = 0; i + 4 < bigInteger.size(); ++i) {
@@ -160,17 +169,17 @@ static bool bigIntegerToUInt32(const Vector<char>& bigInteger, uint32_t& result)
 
     for (size_t i = bigInteger.size() > 4 ? bigInteger.size() - 4 : 0; i < bigInteger.size(); ++i) {
         result <<= 8;
-        result += static_cast<unsigned char>(bigInteger[i]);
+        result += bigInteger[i];
     }
     return true;
 }
 
-void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<char>& publicExponent, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise)
+void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise)
 {
     uint32_t e;
     if (!bigIntegerToUInt32(publicExponent, e)) {
         // Adding support is tracked as <rdar://problem/15444034>.
-        WTFLogAlways("Public exponent is too big, not supported by CommonCrypto");
+        WTFLogAlways("Public exponent is too big, not supported");
         promise->reject(nullptr);
         return;
     }
index 6739a6f..706fec8 100644 (file)
@@ -38,7 +38,7 @@ public:
     // The length, in bits, of the RSA modulus.
     unsigned modulusLength;
     // The RSA public exponent, encoded as BigInteger.
-    Vector<char> publicExponent;
+    Vector<uint8_t> publicExponent;
 
     virtual Class parametersClass() const OVERRIDE { return Class::RsaKeyGenParams; }
 };
index e648495..007ff70 100644 (file)
@@ -341,7 +341,7 @@ void FileReaderLoader::convertToDataURL()
     builder.append(";base64,");
 
     Vector<char> out;
-    base64Encode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded, out);
+    base64Encode(m_rawData->data(), m_bytesLoaded, out);
     out.append('\0');
     builder.append(out.data());
 
index d2c674a..8d36d96 100644 (file)
@@ -442,14 +442,14 @@ PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un
             }
             Vector<uint8_t, 20> attrsHash;
             attrsSHA1.computeHash(attrsHash);
-            digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(attrsHash.data()), 10);
+            digest->m_attrsSHA1 = base64Encode(attrsHash.data(), 10);
             addStringToSHA1(sha1, digest->m_attrsSHA1);
         }
     }
 
     Vector<uint8_t, 20> hash;
     sha1.computeHash(hash);
-    digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(hash.data()), 10);
+    digest->m_sha1 = base64Encode(hash.data(), 10);
     if (unusedNodesMap)
         unusedNodesMap->add(digest->m_sha1, digest);
     return adoptPtr(digest);
index ec3d243..3247d3d 100644 (file)
@@ -1284,7 +1284,7 @@ void InspectorPageAgent::archive(ErrorString* errorString, String* data)
     }
 
     RetainPtr<CFDataRef> buffer = archive->rawDataRepresentation();
-    *data = base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(buffer.get())), CFDataGetLength(buffer.get()));
+    *data = base64Encode(CFDataGetBytePtr(buffer.get()), CFDataGetLength(buffer.get()));
 #else
     UNUSED_PARAM(data);
     *errorString = "No support for creating archives";
index 4fab678..d7a97e6 100644 (file)
@@ -410,7 +410,7 @@ static String CGImageToDataURL(CGImageRef image, const String& mimeType, const d
         return "data:,";
 
     Vector<char> base64Data;
-    base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), base64Data);
+    base64Encode(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()), base64Data);
 
     return "data:" + mimeType + ";base64," + base64Data;
 }