Commit f37f9b40 authored by ap@apple.com's avatar ap@apple.com

Use uint8_t vectors for WebCrypto data

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: http://svn.webkit.org/repository/webkit/trunk@159390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f6525067
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
......
......@@ -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);
}
......
/*
* 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());
}
......
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
......
......@@ -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)
......
......@@ -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));
......
......@@ -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);
......
......@@ -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)
......
......@@ -43,7 +43,7 @@ public:
~CryptoDigest();
void addBytes(const void* input, size_t length);
Vector<unsigned char> computeHash();
Vector<uint8_t> computeHash();
private:
CryptoDigest();
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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)
......
......@@ -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;
......
......@@ -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)
......
......@@ -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)