Changeset 220953 in webkit
- Timestamp:
- Aug 19, 2017 9:41:47 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220951 r220953 1 2017-08-19 Sam Weinig <sam@webkit.org> 2 3 [Mac] Change uint8_t* to Vector<uint8_t> type in all crypto algorithm implementation 4 https://bugs.webkit.org/show_bug.cgi?id=164939 5 6 Reviewed by Chris Dumez. 7 8 Address FIXMEs, replacing uint8_t*/size_t parameters with Vector<uint8_t>&. 9 10 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 11 (WebCore::transformAES_CBC): 12 (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt): 13 (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): 14 * crypto/mac/CryptoAlgorithmAES_KWMac.cpp: 15 (WebCore::wrapKeyAES_KW): 16 (WebCore::unwrapKeyAES_KW): 17 (WebCore::CryptoAlgorithmAES_KW::platformWrapKey): 18 (WebCore::CryptoAlgorithmAES_KW::platformUnwrapKey): 19 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 20 (WebCore::calculateSignature): 21 (WebCore::CryptoAlgorithmHMAC::platformSign): 22 (WebCore::CryptoAlgorithmHMAC::platformVerify): 23 * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp: 24 (WebCore::encryptRSAES_PKCS1_v1_5): 25 (WebCore::decryptRSAES_PKCS1_v1_5): 26 (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt): 27 (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt): 28 * crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: 29 (WebCore::signRSASSA_PKCS1_v1_5): 30 (WebCore::verifyRSASSA_PKCS1_v1_5): 31 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign): 32 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify): 33 * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: 34 (WebCore::encryptRSA_OAEP): 35 (WebCore::decryptRSA_OAEP): 36 (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt): 37 (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): 38 1 39 2017-08-18 Ryosuke Niwa <rniwa@webkit.org> 2 40 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r220941 r220953 36 36 namespace WebCore { 37 37 38 // FIXME: We should change iv and data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 39 // https://bugs.webkit.org/show_bug.cgi?id=164939 40 static ExceptionOr<Vector<uint8_t>> transformAES_CBC(CCOperation operation, const uint8_t* iv, const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength) 38 static ExceptionOr<Vector<uint8_t>> transformAES_CBC(CCOperation operation, const Vector<uint8_t>& iv, const Vector<uint8_t>& key, const Vector<uint8_t>& data) 41 39 { 42 40 CCCryptorRef cryptor; 43 CCCryptorStatus status = CCCryptorCreate(operation, kCCAlgorithmAES, kCCOptionPKCS7Padding, key.data(), key.size(), iv , &cryptor);41 CCCryptorStatus status = CCCryptorCreate(operation, kCCAlgorithmAES, kCCOptionPKCS7Padding, key.data(), key.size(), iv.data(), &cryptor); 44 42 if (status) 45 43 return Exception { OperationError }; 46 44 47 Vector<uint8_t> result(CCCryptorGetOutputLength(cryptor, data Length, true));45 Vector<uint8_t> result(CCCryptorGetOutputLength(cryptor, data.size(), true)); 48 46 49 47 size_t bytesWritten; 50 status = CCCryptorUpdate(cryptor, data , dataLength, result.data(), result.size(), &bytesWritten);48 status = CCCryptorUpdate(cryptor, data.data(), data.size(), result.data(), result.size(), &bytesWritten); 51 49 if (status) 52 50 return Exception { OperationError }; … … 73 71 auto& aesKey = downcast<CryptoKeyAES>(key.get()); 74 72 ASSERT(aesParameters.ivVector().size() == kCCBlockSizeAES128); 75 auto result = transformAES_CBC(kCCEncrypt, aesParameters.ivVector() .data(), aesKey.key(), plainText.data(), plainText.size());73 auto result = transformAES_CBC(kCCEncrypt, aesParameters.ivVector(), aesKey.key(), plainText); 76 74 if (result.hasException()) { 77 75 // We should only dereference callbacks after being back to the Document/Worker threads. … … 97 95 auto& aesKey = downcast<CryptoKeyAES>(key.get()); 98 96 assert(aesParameters.ivVector().size() == kCCBlockSizeAES128); 99 auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector() .data(), aesKey.key(), cipherText.data(), cipherText.size());97 auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector(), aesKey.key(), cipherText); 100 98 if (result.hasException()) { 101 99 // We should only dereference callbacks after being back to the Document/Worker threads. -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_KWMac.cpp
r220941 r220953 34 34 namespace WebCore { 35 35 36 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 37 // https://bugs.webkit.org/show_bug.cgi?id=164939 38 static ExceptionOr<Vector<uint8_t>> wrapKeyAES_KW(const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength) 36 static ExceptionOr<Vector<uint8_t>> wrapKeyAES_KW(const Vector<uint8_t>& key, const Vector<uint8_t>& data) 39 37 { 40 Vector<uint8_t> result(CCSymmetricWrappedSize(kCCWRAPAES, data Length));38 Vector<uint8_t> result(CCSymmetricWrappedSize(kCCWRAPAES, data.size())); 41 39 size_t resultSize = result.size(); 42 if (CCSymmetricKeyWrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.data(), key.size(), data , dataLength, result.data(), &resultSize))40 if (CCSymmetricKeyWrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.data(), key.size(), data.data(), data.size(), result.data(), &resultSize)) 43 41 return Exception { OperationError }; 44 42 … … 47 45 } 48 46 49 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 50 // https://bugs.webkit.org/show_bug.cgi?id=164939 51 static ExceptionOr<Vector<uint8_t>> unwrapKeyAES_KW(const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength) 47 static ExceptionOr<Vector<uint8_t>> unwrapKeyAES_KW(const Vector<uint8_t>& key, const Vector<uint8_t>& data) 52 48 { 53 Vector<uint8_t> result(CCSymmetricUnwrappedSize(kCCWRAPAES, data Length));49 Vector<uint8_t> result(CCSymmetricUnwrappedSize(kCCWRAPAES, data.size())); 54 50 size_t resultSize = result.size(); 55 51 … … 57 53 return Exception { OperationError }; 58 54 59 if (CCSymmetricKeyUnwrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.data(), key.size(), data , dataLength, result.data(), &resultSize))55 if (CCSymmetricKeyUnwrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.data(), key.size(), data.data(), data.size(), result.data(), &resultSize)) 60 56 return Exception { OperationError }; 61 57 … … 67 63 { 68 64 auto& aesKey = downcast<CryptoKeyAES>(key.get()); 69 auto result = wrapKeyAES_KW(aesKey.key(), data .data(), data.size());65 auto result = wrapKeyAES_KW(aesKey.key(), data); 70 66 if (result.hasException()) { 71 67 exceptionCallback(result.releaseException().code()); … … 78 74 { 79 75 auto& aesKey = downcast<CryptoKeyAES>(key.get()); 80 auto result = unwrapKeyAES_KW(aesKey.key(), data .data(), data.size());76 auto result = unwrapKeyAES_KW(aesKey.key(), data); 81 77 if (result.hasException()) { 82 78 exceptionCallback(result.releaseException().code()); -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r220941 r220953 54 54 } 55 55 56 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 57 // https://bugs.webkit.org/show_bug.cgi?id=164939 58 static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const uint8_t* data, size_t dataLength) 56 static Vector<uint8_t> calculateSignature(CCHmacAlgorithm algorithm, const Vector<uint8_t>& key, const Vector<uint8_t>& data) 59 57 { 60 58 size_t digestLength; … … 81 79 82 80 Vector<uint8_t> result(digestLength); 83 CCHmac(algorithm, key.data(), key.size(), data , dataLength, result.data());81 CCHmac(algorithm, key.data(), key.size(), data.data(), data.size(), result.data()); 84 82 return result; 85 83 } … … 99 97 return; 100 98 } 101 auto result = calculateSignature(*algorithm, hmacKey.key(), data .data(), data.size());99 auto result = calculateSignature(*algorithm, hmacKey.key(), data); 102 100 // We should only dereference callbacks after being back to the Document/Worker threads. 103 101 context.postTask([callback = WTFMove(callback), result = WTFMove(result), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) { … … 123 121 return; 124 122 } 125 auto expectedSignature = calculateSignature(*algorithm, hmacKey.key(), data .data(), data.size());123 auto expectedSignature = calculateSignature(*algorithm, hmacKey.key(), data); 126 124 // Using a constant time comparison to prevent timing attacks. 127 125 bool result = signature.size() == expectedSignature.size() && !constantTimeMemcmp(expectedSignature.data(), signature.data(), expectedSignature.size()); -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp
r220941 r220953 35 35 namespace WebCore { 36 36 37 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 38 // https://bugs.webkit.org/show_bug.cgi?id=164939 39 static ExceptionOr<Vector<uint8_t>> encryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 37 static ExceptionOr<Vector<uint8_t>> encryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data) 40 38 { 41 39 Vector<uint8_t> cipherText(keyLength / 8); // Per Step 3.c of https://tools.ietf.org/html/rfc3447#section-7.2.1 42 40 size_t cipherTextLength = cipherText.size(); 43 if (CCRSACryptorEncrypt(key, ccPKCS1Padding, data , dataLength, cipherText.data(), &cipherTextLength, 0, 0, kCCDigestNone))41 if (CCRSACryptorEncrypt(key, ccPKCS1Padding, data.data(), data.size(), cipherText.data(), &cipherTextLength, 0, 0, kCCDigestNone)) 44 42 return Exception { OperationError }; 45 43 … … 47 45 } 48 46 49 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 50 // https://bugs.webkit.org/show_bug.cgi?id=164939 51 static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 47 static ExceptionOr<Vector<uint8_t>> decryptRSAES_PKCS1_v1_5(const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data) 52 48 { 53 49 Vector<uint8_t> plainText(keyLength / 8); // Per Step 1 of https://tools.ietf.org/html/rfc3447#section-7.2.1 54 50 size_t plainTextLength = plainText.size(); 55 if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data , dataLength, plainText.data(), &plainTextLength, 0, 0, kCCDigestNone))51 if (CCRSACryptorDecrypt(key, ccPKCS1Padding, data.data(), data.size(), plainText.data(), &plainTextLength, 0, 0, kCCDigestNone)) 56 52 return Exception { OperationError }; 57 53 … … 65 61 workQueue.dispatch([key = WTFMove(key), plainText = WTFMove(plainText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 66 62 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 67 auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText .data(), plainText.size());63 auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText); 68 64 if (result.hasException()) { 69 65 // We should only dereference callbacks after being back to the Document/Worker threads. … … 87 83 workQueue.dispatch([key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 88 84 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 89 auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText .data(), cipherText.size());85 auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText); 90 86 if (result.hasException()) { 91 87 // We should only dereference callbacks after being back to the Document/Worker threads. -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r220941 r220953 36 36 namespace WebCore { 37 37 38 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 39 // https://bugs.webkit.org/show_bug.cgi?id=164939 40 static ExceptionOr<Vector<uint8_t>> signRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 38 static ExceptionOr<Vector<uint8_t>> signRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data) 41 39 { 42 40 CCDigestAlgorithm digestAlgorithm; … … 50 48 if (!digest) 51 49 return Exception { OperationError }; 52 digest->addBytes(data , dataLength);50 digest->addBytes(data.data(), data.size()); 53 51 auto digestData = digest->computeHash(); 54 52 … … 63 61 } 64 62 65 // FIXME: We should change signature, data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 66 // https://bugs.webkit.org/show_bug.cgi?id=164939 67 static ExceptionOr<bool> verifyRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, const uint8_t* signature, size_t signatureLength, const uint8_t* data, size_t dataLength) 63 static ExceptionOr<bool> verifyRSASSA_PKCS1_v1_5(CryptoAlgorithmIdentifier hash, const PlatformRSAKey key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data) 68 64 { 69 65 CCDigestAlgorithm digestAlgorithm; … … 77 73 if (!digest) 78 74 return Exception { OperationError }; 79 digest->addBytes(data , dataLength);75 digest->addBytes(data.data(), data.size()); 80 76 auto digestData = digest->computeHash(); 81 77 82 auto status = CCRSACryptorVerify(key, ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature , signatureLength);78 auto status = CCRSACryptorVerify(key, ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), signature.size()); 83 79 if (!status) 84 80 return true; … … 94 90 workQueue.dispatch([key = WTFMove(key), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 95 91 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 96 auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data .data(), data.size());92 auto result = signRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), rsaKey.keySizeInBits(), data); 97 93 if (result.hasException()) { 98 94 // We should only dereference callbacks after being back to the Document/Worker threads. … … 116 112 workQueue.dispatch([key = WTFMove(key), signature = WTFMove(signature), data = WTFMove(data), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 117 113 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 118 auto result = verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature .data(), signature.size(), data.data(), data.size());114 auto result = verifyRSASSA_PKCS1_v1_5(rsaKey.hashAlgorithmIdentifier(), rsaKey.platformKey(), signature, data); 119 115 if (result.hasException()) { 120 116 // We should only dereference callbacks after being back to the Document/Worker threads. -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp
r220941 r220953 36 36 namespace WebCore { 37 37 38 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 39 // https://bugs.webkit.org/show_bug.cgi?id=164939 40 static ExceptionOr<Vector<uint8_t>> encryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 38 static ExceptionOr<Vector<uint8_t>> encryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data) 41 39 { 42 40 CCDigestAlgorithm digestAlgorithm; … … 46 44 Vector<uint8_t> cipherText(keyLength / 8); // Per Step 3.c of https://tools.ietf.org/html/rfc3447#section-7.1.1 47 45 size_t cipherTextLength = cipherText.size(); 48 if (CCRSACryptorEncrypt(key, ccOAEPPadding, data , dataLength, cipherText.data(), &cipherTextLength, label.data(), label.size(), digestAlgorithm))46 if (CCRSACryptorEncrypt(key, ccOAEPPadding, data.data(), data.size(), cipherText.data(), &cipherTextLength, label.data(), label.size(), digestAlgorithm)) 49 47 return Exception { OperationError }; 50 48 … … 52 50 } 53 51 54 // FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. 55 // https://bugs.webkit.org/show_bug.cgi?id=164939 56 static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) 52 static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const Vector<uint8_t>& data) 57 53 { 58 54 CCDigestAlgorithm digestAlgorithm; … … 62 58 Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1 63 59 size_t plainTextLength = plainText.size(); 64 if (CCRSACryptorDecrypt(key, ccOAEPPadding, data , dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm))60 if (CCRSACryptorDecrypt(key, ccOAEPPadding, data.data(), data.size(), plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm)) 65 61 return Exception { OperationError }; 66 62 … … 75 71 auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters); 76 72 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 77 auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText .data(), plainText.size());73 auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText); 78 74 if (result.hasException()) { 79 75 // We should only dereference callbacks after being back to the Document/Worker threads. … … 98 94 auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters); 99 95 auto& rsaKey = downcast<CryptoKeyRSA>(key.get()); 100 auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText .data(), cipherText.size());96 auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText); 101 97 if (result.hasException()) { 102 98 // We should only dereference callbacks after being back to the Document/Worker threads.
Note: See TracChangeset
for help on using the changeset viewer.