Changeset 159390 in webkit
- Timestamp:
- Nov 17, 2013, 1:41:46 PM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r159377 r159390 1 2013-11-16 Alexey Proskuryakov <ap@apple.com> 2 3 Use uint8_t vectors for WebCrypto data 4 https://bugs.webkit.org/show_bug.cgi?id=124466 5 6 Reviewed by Sam Weinig. 7 8 Binary data can be UTF-8, in which case "char*" is idiomatic, or it can be arbitrary 9 binary data, in which case "uint8_t*" is more common. 10 11 Changed encode functions that took "const char *" to "const void*", and decode 12 functions that took "Vector<char>&" now take an adapter class. 13 14 The adapter relies on Vector<char> and Vector<uint8_t> classes having an identical layout. 15 16 * wtf/text/Base64.cpp: 17 (WTF::base64Encode): 18 (WTF::base64URLEncode): 19 (WTF::base64DecodeInternal): 20 (WTF::base64Decode): 21 (WTF::base64URLDecode): 22 * wtf/text/Base64.h: 23 (WTF::SignedOrUnsignedCharVectorAdapter): 24 (WTF::ConstSignedOrUnsignedCharVectorAdapter): 25 (WTF::base64Encode): 26 (WTF::base64URLEncode): 27 1 28 2013-11-15 Alexey Proskuryakov <ap@apple.com> 2 29 -
trunk/Source/WTF/wtf/text/Base64.cpp
r159377 r159390 158 158 } 159 159 160 String base64Encode(const char* data, unsigned length, Base64EncodePolicy policy)160 String base64Encode(const void* data, unsigned length, Base64EncodePolicy policy) 161 161 { 162 162 Vector<char> result; 163 base64EncodeInternal( data, length, result, policy, base64EncMap);163 base64EncodeInternal(static_cast<const char*>(data), length, result, policy, base64EncMap); 164 164 return String(result.data(), result.size()); 165 165 } 166 166 167 void base64Encode(const char* data, unsigned len, Vector<char>& out, Base64EncodePolicy policy)168 { 169 base64EncodeInternal( data, len, out, policy, base64EncMap);170 } 171 172 String base64URLEncode(const char* data, unsigned length)167 void base64Encode(const void* data, unsigned len, Vector<char>& out, Base64EncodePolicy policy) 168 { 169 base64EncodeInternal(static_cast<const char*>(data), len, out, policy, base64EncMap); 170 } 171 172 String base64URLEncode(const void* data, unsigned length) 173 173 { 174 174 Vector<char> result; 175 base64EncodeInternal( data, length, result, Base64URLPolicy, base64URLEncMap);175 base64EncodeInternal(static_cast<const char*>(data), length, result, Base64URLPolicy, base64URLEncMap); 176 176 return String(result.data(), result.size()); 177 177 } 178 178 179 void base64URLEncode(const char* data, unsigned len, Vector<char>& out)180 { 181 base64EncodeInternal( data, len, out, Base64URLPolicy, base64URLEncMap);179 void base64URLEncode(const void* data, unsigned len, Vector<char>& out) 180 { 181 base64EncodeInternal(static_cast<const char*>(data), len, out, Base64URLPolicy, base64URLEncMap); 182 182 } 183 183 … … 202 202 return false; 203 203 } else { 204 ASSERT(static_cast<size_t>(ch) < 128); 204 205 char decodedCharacter = decodeMap[ch]; 205 206 if (decodedCharacter != nonAlphabet) { … … 249 250 } 250 251 251 bool base64Decode(const String& in, Vector<char>&out, Base64DecodePolicy policy)252 bool base64Decode(const String& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy) 252 253 { 253 254 return base64DecodeInternal<UChar>(in.characters(), in.length(), out, policy, base64DecMap); 254 255 } 255 256 256 bool base64Decode(const Vector<char>& in, Vector<char>&out, Base64DecodePolicy policy)257 bool base64Decode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy) 257 258 { 258 259 out.clear(); … … 265 266 } 266 267 267 bool base64Decode(const char* data, unsigned len, Vector<char>&out, Base64DecodePolicy policy)268 bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy) 268 269 { 269 270 return base64DecodeInternal<char>(data, len, out, policy, base64DecMap); 270 271 } 271 272 272 bool base64URLDecode(const String& in, Vector<char>&out)273 bool base64URLDecode(const String& in, SignedOrUnsignedCharVectorAdapter out) 273 274 { 274 275 return base64DecodeInternal<UChar>(in.characters(), in.length(), out, Base64FailOnInvalidCharacter, base64URLDecMap); 275 276 } 276 277 277 bool base64URLDecode(const Vector<char>& in, Vector<char>&out)278 bool base64URLDecode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out) 278 279 { 279 280 out.clear(); … … 286 287 } 287 288 288 bool base64URLDecode(const char* data, unsigned len, Vector<char>&out)289 bool base64URLDecode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out) 289 290 { 290 291 return base64DecodeInternal<char>(data, len, out, Base64FailOnInvalidCharacter, base64URLDecMap); -
trunk/Source/WTF/wtf/text/Base64.h
r159377 r159390 2 2 * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 3 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 4 * Copyright (C) 2013 Apple Inc. All rights reserved. 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without … … 47 48 }; 48 49 49 WTF_EXPORT_PRIVATE void base64Encode(const char*, unsigned, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 50 WTF_EXPORT_PRIVATE void base64Encode(const Vector<char>&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 50 class SignedOrUnsignedCharVectorAdapter { 51 public: 52 SignedOrUnsignedCharVectorAdapter(Vector<char>& vector) { m_vector.c = &vector; } 53 SignedOrUnsignedCharVectorAdapter(Vector<uint8_t>& vector) { m_vector.u = &vector; } 54 55 operator Vector<char>&() { return *m_vector.c; } 56 void clear() { m_vector.c->clear(); } 57 58 private: 59 union { 60 Vector<char>* c; 61 Vector<uint8_t>* u; 62 } m_vector; 63 }; 64 65 class ConstSignedOrUnsignedCharVectorAdapter { 66 public: 67 ConstSignedOrUnsignedCharVectorAdapter(const Vector<char>& vector) { m_vector.c = &vector; } 68 ConstSignedOrUnsignedCharVectorAdapter(const Vector<uint8_t>& vector) { m_vector.u = &vector; } 69 70 operator const Vector<char>&() { return *m_vector.c; } 71 const char* data() const { return m_vector.c->data(); } 72 size_t size() const { return m_vector.c->size(); } 73 74 private: 75 union { 76 const Vector<char>* c; 77 const Vector<uint8_t>* u; 78 } m_vector; 79 }; 80 81 WTF_EXPORT_PRIVATE void base64Encode(const void*, unsigned, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 82 WTF_EXPORT_PRIVATE void base64Encode(ConstSignedOrUnsignedCharVectorAdapter, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 51 83 WTF_EXPORT_PRIVATE void base64Encode(const CString&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 52 WTF_EXPORT_PRIVATE String base64Encode(const char*, unsigned, Base64EncodePolicy = Base64DoNotInsertLFs);53 WTF_EXPORT_PRIVATE String base64Encode( const Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);84 WTF_EXPORT_PRIVATE String base64Encode(const void*, unsigned, Base64EncodePolicy = Base64DoNotInsertLFs); 85 WTF_EXPORT_PRIVATE String base64Encode(ConstSignedOrUnsignedCharVectorAdapter, Base64EncodePolicy = Base64DoNotInsertLFs); 54 86 WTF_EXPORT_PRIVATE String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotInsertLFs); 55 87 56 WTF_EXPORT_PRIVATE bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);57 WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);58 WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter);88 WTF_EXPORT_PRIVATE bool base64Decode(const String&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter); 89 WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter); 90 WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter); 59 91 60 inline void base64Encode( const Vector<char>&in, Vector<char>& out, Base64EncodePolicy policy)92 inline void base64Encode(ConstSignedOrUnsignedCharVectorAdapter in, Vector<char>& out, Base64EncodePolicy policy) 61 93 { 62 94 base64Encode(in.data(), in.size(), out, policy); … … 68 100 } 69 101 70 inline String base64Encode( const Vector<char>&in, Base64EncodePolicy policy)102 inline String base64Encode(ConstSignedOrUnsignedCharVectorAdapter in, Base64EncodePolicy policy) 71 103 { 72 104 return base64Encode(in.data(), in.size(), policy); … … 83 115 // ====================================================================================== 84 116 85 WTF_EXPORT_PRIVATE void base64URLEncode(const char*, unsigned, Vector<char>&);86 WTF_EXPORT_PRIVATE void base64URLEncode( const Vector<char>&, Vector<char>&);117 WTF_EXPORT_PRIVATE void base64URLEncode(const void*, unsigned, Vector<char>&); 118 WTF_EXPORT_PRIVATE void base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter, Vector<char>&); 87 119 WTF_EXPORT_PRIVATE void base64URLEncode(const CString&, Vector<char>&); 88 WTF_EXPORT_PRIVATE String base64URLEncode(const char*, unsigned);89 WTF_EXPORT_PRIVATE String base64URLEncode( const Vector<char>&);120 WTF_EXPORT_PRIVATE String base64URLEncode(const void*, unsigned); 121 WTF_EXPORT_PRIVATE String base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter); 90 122 WTF_EXPORT_PRIVATE String base64URLEncode(const CString&); 91 123 92 WTF_EXPORT_PRIVATE bool base64URLDecode(const String&, Vector<char>&);93 WTF_EXPORT_PRIVATE bool base64URLDecode(const Vector<char>&, Vector<char>&);94 WTF_EXPORT_PRIVATE bool base64URLDecode(const char*, unsigned, Vector<char>&);124 WTF_EXPORT_PRIVATE bool base64URLDecode(const String&, SignedOrUnsignedCharVectorAdapter); 125 WTF_EXPORT_PRIVATE bool base64URLDecode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter); 126 WTF_EXPORT_PRIVATE bool base64URLDecode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter); 95 127 96 inline void base64URLEncode( const Vector<char>&in, Vector<char>& out)128 inline void base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter in, Vector<char>& out) 97 129 { 98 130 base64URLEncode(in.data(), in.size(), out); … … 104 136 } 105 137 106 inline String base64URLEncode( const Vector<char>&in)138 inline String base64URLEncode(ConstSignedOrUnsignedCharVectorAdapter in) 107 139 { 108 140 return base64URLEncode(in.data(), in.size()); -
trunk/Source/WebCore/ChangeLog
r159389 r159390 1 2013-11-16 Alexey Proskuryakov <ap@apple.com> 2 3 Use uint8_t vectors for WebCrypto data 4 https://bugs.webkit.org/show_bug.cgi?id=124466 5 6 Reviewed by Sam Weinig. 7 8 Using Vector<char> for crypto key data is somewhat non-idiomatic, and it gets simply 9 dangerous for bignums, because signed arithmetic is not appropriate for bignum digits. 10 11 * Modules/websockets/WebSocketHandshake.cpp: 12 (WebCore::generateSecWebSocketKey): 13 (WebCore::WebSocketHandshake::getExpectedWebSocketAccept): 14 No longer need to cast data to char* here. 15 16 * bindings/js/JSCryptoKeySerializationJWK.cpp: 17 * bindings/js/JSCryptoKeySerializationJWK.h: 18 * crypto/CryptoDigest.h: 19 * crypto/CryptoKey.h: 20 * crypto/keys/CryptoKeyAES.cpp: 21 * crypto/keys/CryptoKeyAES.h: 22 * crypto/keys/CryptoKeyDataOctetSequence.h: 23 * crypto/keys/CryptoKeyDataRSAComponents.cpp: 24 * crypto/keys/CryptoKeyDataRSAComponents.h: 25 * crypto/keys/CryptoKeyHMAC.cpp: 26 * crypto/keys/CryptoKeyHMAC.h: 27 * crypto/keys/CryptoKeyRSA.h: 28 * crypto/keys/CryptoKeySerializationRaw.cpp: 29 * crypto/keys/CryptoKeySerializationRaw.h: 30 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 31 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 32 * crypto/mac/CryptoDigestMac.cpp: 33 * crypto/mac/CryptoKeyMac.cpp: 34 * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h: 35 Switched to Vector<uint8_t>. 36 37 * crypto/mac/CryptoKeyRSAMac.cpp: 38 (WebCore::getPublicKeyComponents): Extracted from buildAlgorithmDescription() and simplified. 39 (WebCore::CryptoKeyRSA::create): Switched to Vector<uint8_t>. 40 (WebCore::CryptoKeyRSA::buildAlgorithmDescription): No longer need to copy data just 41 to change type from Vector<char> to Vector<unsigned char>. 42 (WebCore::bigIntegerToUInt32): Ditto. No longer need to cast types when dealing with the bignum. 43 (WebCore::CryptoKeyRSA::generatePair): Improved an error message a little. 44 45 * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL): 46 * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest): 47 * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::archive): 48 * platform/graphics/cg/ImageBufferCG.cpp: (WebCore::CGImageToDataURL): 49 No longer need to cast data to char* here. 50 1 51 2013-11-17 Antti Koivisto <antti@apple.com> 2 52 -
trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
r156600 r159390 104 104 unsigned char key[nonceSize]; 105 105 cryptographicallyRandomValues(key, nonceSize); 106 return base64Encode( reinterpret_cast<char*>(key), nonceSize);106 return base64Encode(key, nonceSize); 107 107 } 108 108 … … 117 117 Vector<uint8_t, sha1HashSize> hash; 118 118 sha1.computeHash(hash); 119 return base64Encode( reinterpret_cast<const char*>(hash.data()), sha1HashSize);119 return base64Encode(hash.data(), sha1HashSize); 120 120 } 121 121 -
trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
r159377 r159390 110 110 } 111 111 112 static bool getBigIntegerVectorFromJSON(ExecState* exec, JSObject* json, const char* key, Vector< char>& result)112 static bool getBigIntegerVectorFromJSON(ExecState* exec, JSObject* json, const char* key, Vector<uint8_t>& result) 113 113 { 114 114 String base64urlEncodedNumber; … … 290 290 } 291 291 292 Vector< char> octetSequence;292 Vector<uint8_t> octetSequence; 293 293 if (!base64URLDecode(keyBase64URL, octetSequence)) { 294 294 throwTypeError(m_exec, "Cannot decode base64url key data in JWK"); … … 306 306 std::unique_ptr<CryptoKeyData> JSCryptoKeySerializationJWK::keyDataRSAComponents() const 307 307 { 308 Vector< char> modulus;309 Vector< char> exponent;310 Vector< char> privateExponent;308 Vector<uint8_t> modulus; 309 Vector<uint8_t> exponent; 310 Vector<uint8_t> privateExponent; 311 311 312 312 if (!getBigIntegerVectorFromJSON(m_exec, m_json.get(), "n", modulus)) { … … 417 417 } 418 418 419 void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector< char>& keyData, JSObject* result)419 void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector<uint8_t>& keyData, JSObject* result) 420 420 { 421 421 addToJSON(exec, result, "kty", "oct"); -
trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h
r159377 r159390 66 66 virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE; 67 67 68 static void buildJSONForOctetSequence(JSC::ExecState*, const Vector< char>&, JSC::JSObject* result);68 static void buildJSONForOctetSequence(JSC::ExecState*, const Vector<uint8_t>&, JSC::JSObject* result); 69 69 static void addJWKAlgorithmToJSON(JSC::ExecState*, JSC::JSObject*, const CryptoKey& key); 70 70 static void addJWKUseToJSON(JSC::ExecState*, JSC::JSObject*, CryptoKeyUsage); -
trunk/Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r159379 r159390 114 114 digest->addBytes(data.first, data.second); 115 115 116 Vector<u nsigned char> digestData = digest->computeHash();116 Vector<uint8_t> digestData = digest->computeHash(); 117 117 118 Vector<u nsigned char> signature(512);118 Vector<uint8_t> signature(512); 119 119 size_t signatureSize = signature.size(); 120 120 … … 153 153 digest->addBytes(data.first, data.second); 154 154 155 Vector<u nsigned char> digestData = digest->computeHash();155 Vector<uint8_t> digestData = digest->computeHash(); 156 156 157 157 CCCryptorStatus status = CCRSACryptorVerify(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second); -
trunk/Source/WebCore/crypto/CryptoDigest.h
r159292 r159390 44 44 45 45 void addBytes(const void* input, size_t length); 46 Vector<u nsigned char> computeHash();46 Vector<uint8_t> computeHash(); 47 47 48 48 private: -
trunk/Source/WebCore/crypto/CryptoKey.cpp
r158582 r159390 90 90 91 91 #if !PLATFORM(MAC) 92 Vector< char> CryptoKey::randomData(size_t size)92 Vector<uint8_t> CryptoKey::randomData(size_t size) 93 93 { 94 Vector< char> result(size);94 Vector<uint8_t> result(size); 95 95 cryptographicallyRandomValues(result.data(), result.size()); 96 96 return result; -
trunk/Source/WebCore/crypto/CryptoKey.h
r159377 r159390 65 65 virtual std::unique_ptr<CryptoKeyData> exportData() const = 0; 66 66 67 static Vector< char> randomData(size_t);67 static Vector<uint8_t> randomData(size_t); 68 68 69 69 private: -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp
r159310 r159390 36 36 namespace WebCore { 37 37 38 CryptoKeyAES::CryptoKeyAES(CryptoAlgorithmIdentifier algorithm, const Vector< char>& key, bool extractable, CryptoKeyUsage usage)38 CryptoKeyAES::CryptoKeyAES(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage) 39 39 : CryptoKey(algorithm, CryptoKeyType::Secret, extractable, usage) 40 40 , m_key(key) -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h
r159310 r159390 37 37 class CryptoKeyAES FINAL : public CryptoKey { 38 38 public: 39 static PassRefPtr<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector< char>& key, bool extractable, CryptoKeyUsage usage)39 static PassRefPtr<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage) 40 40 { 41 41 return adoptRef(new CryptoKeyAES(algorithm, key, extractable, usage)); … … 47 47 virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::AES; } 48 48 49 const Vector< char>& key() const { return m_key; }49 const Vector<uint8_t>& key() const { return m_key; } 50 50 51 51 private: 52 CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector< char>& key, bool extractable, CryptoKeyUsage);52 CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage); 53 53 54 54 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE; 55 55 virtual std::unique_ptr<CryptoKeyData> exportData() const OVERRIDE; 56 56 57 Vector< char> m_key;57 Vector<uint8_t> m_key; 58 58 }; 59 59 -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.cpp
r158943 r159390 31 31 namespace WebCore { 32 32 33 CryptoKeyDataOctetSequence::CryptoKeyDataOctetSequence(const Vector< char>& data)33 CryptoKeyDataOctetSequence::CryptoKeyDataOctetSequence(const Vector<uint8_t>& data) 34 34 : CryptoKeyData(CryptoKeyData::Format::OctetSequence) 35 35 , m_keyData(data) -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataOctetSequence.h
r159213 r159390 36 36 class CryptoKeyDataOctetSequence FINAL : public CryptoKeyData { 37 37 public: 38 static std::unique_ptr<CryptoKeyDataOctetSequence> create(const Vector< char>& keyData)38 static std::unique_ptr<CryptoKeyDataOctetSequence> create(const Vector<uint8_t>& keyData) 39 39 { 40 40 return std::unique_ptr<CryptoKeyDataOctetSequence>(new CryptoKeyDataOctetSequence(keyData)); … … 42 42 virtual ~CryptoKeyDataOctetSequence(); 43 43 44 const Vector< char>& octetSequence() const { return m_keyData; }44 const Vector<uint8_t>& octetSequence() const { return m_keyData; } 45 45 46 46 private: 47 CryptoKeyDataOctetSequence(const Vector< char>&);47 CryptoKeyDataOctetSequence(const Vector<uint8_t>&); 48 48 49 Vector< char> m_keyData;49 Vector<uint8_t> m_keyData; 50 50 }; 51 51 -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.cpp
r159180 r159390 31 31 namespace WebCore { 32 32 33 CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent)33 CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent) 34 34 : CryptoKeyData(CryptoKeyData::Format::RSAComponents) 35 35 , m_type(Type::Public) … … 39 39 } 40 40 41 CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent)41 CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent) 42 42 : CryptoKeyData(CryptoKeyData::Format::RSAComponents) 43 43 , m_type(Type::Private) … … 49 49 } 50 50 51 CryptoKeyDataRSAComponents::CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos)51 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) 52 52 : CryptoKeyData(CryptoKeyData::Format::RSAComponents) 53 53 , m_type(Type::Private) -
trunk/Source/WebCore/crypto/keys/CryptoKeyDataRSAComponents.h
r159213 r159390 42 42 43 43 struct PrimeInfo { 44 Vector< char> primeFactor;45 Vector< char> factorCRTExponent;46 Vector< char> factorCRTCoefficient;44 Vector<uint8_t> primeFactor; 45 Vector<uint8_t> factorCRTExponent; 46 Vector<uint8_t> factorCRTCoefficient; 47 47 }; 48 48 49 static std::unique_ptr<CryptoKeyDataRSAComponents> createPublic(const Vector< char>& modulus, const Vector<char>& exponent)49 static std::unique_ptr<CryptoKeyDataRSAComponents> createPublic(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent) 50 50 { 51 51 return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent)); 52 52 } 53 53 54 static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivate(const Vector< char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent)54 static std::unique_ptr<CryptoKeyDataRSAComponents> createPrivate(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent) 55 55 { 56 56 return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent, privateExponent)); 57 57 } 58 58 59 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)59 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) 60 60 { 61 61 return std::unique_ptr<CryptoKeyDataRSAComponents>(new CryptoKeyDataRSAComponents(modulus, exponent, privateExponent, firstPrimeInfo, secondPrimeInfo, otherPrimeInfos)); … … 67 67 68 68 // Private and public keys. 69 const Vector< char>& modulus() const { return m_modulus; }70 const Vector< char>& exponent() const { return m_exponent; }69 const Vector<uint8_t>& modulus() const { return m_modulus; } 70 const Vector<uint8_t>& exponent() const { return m_exponent; } 71 71 72 72 // Only private keys. 73 const Vector< char>& privateExponent() const { return m_privateExponent; }73 const Vector<uint8_t>& privateExponent() const { return m_privateExponent; } 74 74 bool hasAdditionalPrivateKeyParameters() const { return m_hasAdditionalPrivateKeyParameters; } 75 75 const PrimeInfo& firstPrimeInfo() const { return m_firstPrimeInfo; } … … 78 78 79 79 private: 80 CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent);81 CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent);82 CryptoKeyDataRSAComponents(const Vector< char>& modulus, const Vector<char>& exponent, const Vector<char>& privateExponent, const PrimeInfo& firstPrimeInfo, const PrimeInfo& secondPrimeInfo, const Vector<PrimeInfo>& otherPrimeInfos);80 CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent); 81 CryptoKeyDataRSAComponents(const Vector<uint8_t>& modulus, const Vector<uint8_t>& exponent, const Vector<uint8_t>& privateExponent); 82 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); 83 83 84 84 Type m_type; 85 85 86 86 // Private and public keys. 87 Vector< char> m_modulus;88 Vector< char> m_exponent;87 Vector<uint8_t> m_modulus; 88 Vector<uint8_t> m_exponent; 89 89 90 90 // Only private keys. 91 Vector< char> m_privateExponent;91 Vector<uint8_t> m_privateExponent; 92 92 bool m_hasAdditionalPrivateKeyParameters; 93 93 PrimeInfo m_firstPrimeInfo; -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
r159310 r159390 36 36 namespace WebCore { 37 37 38 CryptoKeyHMAC::CryptoKeyHMAC(const Vector< char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)38 CryptoKeyHMAC::CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage) 39 39 : CryptoKey(CryptoAlgorithmIdentifier::HMAC, CryptoKeyType::Secret, extractable, usage) 40 40 , m_hash(hash) -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h
r159377 r159390 36 36 class CryptoKeyHMAC FINAL : public CryptoKey { 37 37 public: 38 static PassRefPtr<CryptoKeyHMAC> create(const Vector< char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)38 static PassRefPtr<CryptoKeyHMAC> create(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage) 39 39 { 40 40 return adoptRef(new CryptoKeyHMAC(key, hash, extractable, usage)); … … 47 47 virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::HMAC; } 48 48 49 const Vector< char>& key() const { return m_key; }49 const Vector<uint8_t>& key() const { return m_key; } 50 50 51 51 CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; } 52 52 53 53 private: 54 CryptoKeyHMAC(const Vector< char>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);54 CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage); 55 55 56 56 virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const OVERRIDE; … … 58 58 59 59 CryptoAlgorithmIdentifier m_hash; 60 Vector< char> m_key;60 Vector<uint8_t> m_key; 61 61 }; 62 62 -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h
r159310 r159390 53 53 void restrictToHash(CryptoAlgorithmIdentifier); 54 54 55 static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector< char>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>);55 static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>); 56 56 57 57 virtual CryptoKeyClass keyClass() const OVERRIDE { return CryptoKeyClass::RSA; } -
trunk/Source/WebCore/crypto/keys/CryptoKeySerializationRaw.cpp
r159377 r159390 62 62 } 63 63 64 bool CryptoKeySerializationRaw::serialize(const CryptoKey& key, Vector<u nsigned char>& result)64 bool CryptoKeySerializationRaw::serialize(const CryptoKey& key, Vector<uint8_t>& result) 65 65 { 66 66 std::unique_ptr<CryptoKeyData> keyData = key.exportData(); -
trunk/Source/WebCore/crypto/keys/CryptoKeySerializationRaw.h
r159377 r159390 47 47 virtual ~CryptoKeySerializationRaw(); 48 48 49 static bool serialize(const CryptoKey&, Vector<u nsigned char>&);49 static bool serialize(const CryptoKey&, Vector<uint8_t>&); 50 50 51 51 private: … … 59 59 virtual std::unique_ptr<CryptoKeyData> keyData() const OVERRIDE; 60 60 61 Vector< char> m_data;61 Vector<uint8_t> m_data; 62 62 }; 63 63 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r159379 r159390 59 59 } 60 60 61 Vector<u nsigned char> result(CCCryptorGetOutputLength(cryptor, data.second, true));61 Vector<uint8_t> result(CCCryptorGetOutputLength(cryptor, data.second, true)); 62 62 63 63 size_t bytesWritten; … … 68 68 } 69 69 70 u nsigned char* p = result.data() + bytesWritten;70 uint8_t* p = result.data() + bytesWritten; 71 71 status = CCCryptorFinal(cryptor, p, result.end() - p, &bytesWritten); 72 72 p += bytesWritten; -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r159380 r159390 60 60 } 61 61 62 static Vector<u nsigned char> calculateSignature(CCHmacAlgorithm algorithm, const Vector<char>& key, const CryptoOperationData& data)62 static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const CryptoOperationData& data) 63 63 { 64 64 size_t digestLength; … … 81 81 default: 82 82 ASSERT_NOT_REACHED(); 83 return Vector<u nsigned char>();83 return Vector<uint8_t>(); 84 84 } 85 85 86 Vector<u nsigned char> result(digestLength);87 const char* keyData = key.data() ? key.data() : ""; // <rdar://problem/15467425> HMAC crashes when key pointer is null.86 Vector<uint8_t> result(digestLength); 87 const void* keyData = key.data() ? key.data() : reinterpret_cast<const uint8_t*>(""); // <rdar://problem/15467425> HMAC crashes when key pointer is null. 88 88 CCHmac(algorithm, keyData, key.size(), data.first, data.second, result.data()); 89 89 return result; … … 106 106 } 107 107 108 Vector<u nsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);108 Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data); 109 109 110 110 promise->fulfill(signature); … … 127 127 } 128 128 129 Vector<u nsigned char> signature = calculateSignature(algorithm, hmacKey.key(), data);129 Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data); 130 130 131 131 bool result = signature.size() == expectedSignature.second && !memcmp(signature.data(), expectedSignature.first, signature.size()); -
trunk/Source/WebCore/crypto/mac/CryptoDigestMac.cpp
r159292 r159390 157 157 } 158 158 159 Vector<u nsigned char> CryptoDigest::computeHash()159 Vector<uint8_t> CryptoDigest::computeHash() 160 160 { 161 Vector<u nsigned char> result;161 Vector<uint8_t> result; 162 162 switch (m_context->algorithm) { 163 163 case CryptoAlgorithmIdentifier::SHA_1: -
trunk/Source/WebCore/crypto/mac/CryptoKeyMac.cpp
r158945 r159390 41 41 namespace WebCore { 42 42 43 Vector< char> CryptoKey::randomData(size_t size)43 Vector<uint8_t> CryptoKey::randomData(size_t size) 44 44 { 45 Vector< char> result(size);45 Vector<uint8_t> result(size); 46 46 CCRandomCopyBytes(kCCRandomDefault, result.data(), result.size()); 47 47 return result; -
trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
r159310 r159390 59 59 namespace WebCore { 60 60 61 static CCCryptorStatus getPublicKeyComponents(CCRSACryptorRef rsaKey, Vector<uint8_t>& modulus, Vector<uint8_t>& publicExponent) 62 { 63 ASSERT(CCRSAGetKeyType(rsaKey) == ccRSAKeyPublic); 64 65 modulus.resize(16384); 66 size_t modulusLength = modulus.size(); 67 publicExponent.resize(16384); 68 size_t exponentLength = publicExponent.size(); 69 CCCryptorStatus status = CCRSAGetKeyComponents(rsaKey, modulus.data(), &modulusLength, publicExponent.data(), &exponentLength, 0, 0, 0, 0); 70 if (status) 71 return status; 72 73 modulus.shrink(modulusLength); 74 publicExponent.shrink(exponentLength); 75 return status; 76 } 77 61 78 CryptoKeyRSA::CryptoKeyRSA(CryptoAlgorithmIdentifier identifier, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage) 62 79 : CryptoKey(identifier, type, extractable, usage) … … 69 86 { 70 87 if (keyData.type() == CryptoKeyDataRSAComponents::Type::Private && !keyData.hasAdditionalPrivateKeyParameters()) { 88 // <rdar://problem/15452324> tracks adding support. 71 89 WTFLogAlways("Private keys without additional data are not supported"); 72 90 return nullptr; … … 113 131 CCRSACryptorRef publicKey = platformKeyIsPublic ? m_platformKey : CCRSACryptorGetPublicKeyFromPrivateKey(m_platformKey); 114 132 115 uint8_t modulus[16384]; 116 size_t modulusLength = sizeof(modulus); 117 uint8_t publicExponent[16384]; 118 size_t exponentLength = sizeof(16384); 119 uint8_t p[16384]; 120 size_t pLength = sizeof(p); 121 uint8_t q[16384]; 122 size_t qLength = sizeof(q); 123 CCCryptorStatus status = CCRSAGetKeyComponents(publicKey, modulus, &modulusLength, publicExponent, &exponentLength, p, &pLength, q, &qLength); 133 Vector<uint8_t> modulus; 134 Vector<uint8_t> publicExponent; 135 CCCryptorStatus status = getPublicKeyComponents(publicKey, modulus, publicExponent); 124 136 if (!platformKeyIsPublic) { 125 137 // CCRSACryptorGetPublicKeyFromPrivateKey has "Get" in the name, but its result needs to be released (see <rdar://problem/15449697>). … … 131 143 } 132 144 133 builder.add("modulusLength", modulusLength * 8); 134 135 Vector<unsigned char> publicExponentVector; 136 publicExponentVector.append(publicExponent, exponentLength); 137 builder.add("publicExponent", publicExponentVector); 145 builder.add("modulusLength", modulus.size() * 8); 146 builder.add("publicExponent", publicExponent); 138 147 139 148 if (m_restrictedToSpecificHash) { … … 151 160 } 152 161 153 static bool bigIntegerToUInt32(const Vector< char>& bigInteger, uint32_t& result)162 static bool bigIntegerToUInt32(const Vector<uint8_t>& bigInteger, uint32_t& result) 154 163 { 155 164 result = 0; … … 161 170 for (size_t i = bigInteger.size() > 4 ? bigInteger.size() - 4 : 0; i < bigInteger.size(); ++i) { 162 171 result <<= 8; 163 result += static_cast<unsigned char>(bigInteger[i]);172 result += bigInteger[i]; 164 173 } 165 174 return true; 166 175 } 167 176 168 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector< char>& publicExponent, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise)177 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise) 169 178 { 170 179 uint32_t e; 171 180 if (!bigIntegerToUInt32(publicExponent, e)) { 172 181 // Adding support is tracked as <rdar://problem/15444034>. 173 WTFLogAlways("Public exponent is too big, not supported by CommonCrypto");182 WTFLogAlways("Public exponent is too big, not supported"); 174 183 promise->reject(nullptr); 175 184 return; -
trunk/Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h
r159379 r159390 39 39 unsigned modulusLength; 40 40 // The RSA public exponent, encoded as BigInteger. 41 Vector< char> publicExponent;41 Vector<uint8_t> publicExponent; 42 42 43 43 virtual Class parametersClass() const OVERRIDE { return Class::RsaKeyGenParams; } -
trunk/Source/WebCore/fileapi/FileReaderLoader.cpp
r158956 r159390 342 342 343 343 Vector<char> out; 344 base64Encode( static_cast<const char*>(m_rawData->data()), m_bytesLoaded, out);344 base64Encode(m_rawData->data(), m_bytesLoaded, out); 345 345 out.append('\0'); 346 346 builder.append(out.data()); -
trunk/Source/WebCore/inspector/DOMPatchSupport.cpp
r157971 r159390 443 443 Vector<uint8_t, 20> attrsHash; 444 444 attrsSHA1.computeHash(attrsHash); 445 digest->m_attrsSHA1 = base64Encode( reinterpret_cast<const char*>(attrsHash.data()), 10);445 digest->m_attrsSHA1 = base64Encode(attrsHash.data(), 10); 446 446 addStringToSHA1(sha1, digest->m_attrsSHA1); 447 447 } … … 450 450 Vector<uint8_t, 20> hash; 451 451 sha1.computeHash(hash); 452 digest->m_sha1 = base64Encode( reinterpret_cast<const char*>(hash.data()), 10);452 digest->m_sha1 = base64Encode(hash.data(), 10); 453 453 if (unusedNodesMap) 454 454 unusedNodesMap->add(digest->m_sha1, digest); -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r159268 r159390 1285 1285 1286 1286 RetainPtr<CFDataRef> buffer = archive->rawDataRepresentation(); 1287 *data = base64Encode( reinterpret_cast<const char*>(CFDataGetBytePtr(buffer.get())), CFDataGetLength(buffer.get()));1287 *data = base64Encode(CFDataGetBytePtr(buffer.get()), CFDataGetLength(buffer.get())); 1288 1288 #else 1289 1289 UNUSED_PARAM(data); -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r159027 r159390 411 411 412 412 Vector<char> base64Data; 413 base64Encode( reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), base64Data);413 base64Encode(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()), base64Data); 414 414 415 415 return "data:" + mimeType + ";base64," + base64Data;
Note:
See TracChangeset
for help on using the changeset viewer.