Diff
Modified: trunk/Source/WebCore/ChangeLog (231045 => 231046)
--- trunk/Source/WebCore/ChangeLog 2018-04-26 15:04:16 UTC (rev 231045)
+++ trunk/Source/WebCore/ChangeLog 2018-04-26 16:14:37 UTC (rev 231046)
@@ -1,3 +1,21 @@
+2018-04-15 Darin Adler <[email protected]>
+
+ [Cocoa] Adopt CCRSAGetCRTComponents and stop using CCBigNum
+ https://bugs.webkit.org/show_bug.cgi?id=184637
+
+ Reviewed by Alexey Proskuryakov.
+
+ * crypto/CommonCryptoUtilities.cpp: Compile out WebCore::CCBigNum class if
+ HAVE(CCRSAGetCRTComponents) is true.
+
+ * crypto/CommonCryptoUtilities.h: Define HAVE(CCRSAGetCRTComponents) on new
+ enough versions of iOS and macOS that have it and add declarations of the
+ function for the non-Apple-internal-SDK case. Also don't define the
+ WebCore::CCBigNum class if HAVE(CCRSAGetCRTComponents) is true.
+
+ * crypto/mac/CryptoKeyRSAMac.cpp:
+ (WebCore::getPrivateKeyComponents): Use CCRSAGetCRTComponents if present.
+
2018-04-26 Per Arne Vollan <[email protected]>
Add lazy initialization of caption display mode for videos.
Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.cpp (231045 => 231046)
--- trunk/Source/WebCore/crypto/CommonCryptoUtilities.cpp 2018-04-26 15:04:16 UTC (rev 231045)
+++ trunk/Source/WebCore/crypto/CommonCryptoUtilities.cpp 2018-04-26 16:14:37 UTC (rev 231046)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,11 +28,12 @@
#if ENABLE(SUBTLE_CRYPTO)
+#if !HAVE(CCRSAGetCRTComponents)
+
#if USE(APPLE_INTERNAL_SDK)
#include <CommonCrypto/CommonBigNum.h>
#endif
-typedef CCCryptorStatus CCStatus;
extern "C" CCBigNumRef CCBigNumFromData(CCStatus *status, const void *s, size_t len);
extern "C" size_t CCBigNumToData(CCStatus *status, const CCBigNumRef bn, void *to);
extern "C" uint32_t CCBigNumByteCount(const CCBigNumRef bn);
@@ -43,6 +44,8 @@
extern "C" CCStatus CCBigNumMod(CCBigNumRef result, CCBigNumRef dividend, CCBigNumRef modulus);
extern "C" CCStatus CCBigNumInverseMod(CCBigNumRef result, const CCBigNumRef a, const CCBigNumRef modulus);
+#endif
+
namespace WebCore {
bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCDigestAlgorithm& algorithm)
@@ -68,6 +71,8 @@
}
}
+#if !HAVE(CCRSAGetCRTComponents)
+
CCBigNum::CCBigNum(CCBigNumRef number)
: m_number(number)
{
@@ -168,6 +173,8 @@
return result;
}
+#endif
+
} // namespace WebCore
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.h (231045 => 231046)
--- trunk/Source/WebCore/crypto/CommonCryptoUtilities.h 2018-04-26 15:04:16 UTC (rev 231045)
+++ trunk/Source/WebCore/crypto/CommonCryptoUtilities.h 2018-04-26 16:14:37 UTC (rev 231046)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,6 +25,10 @@
#pragma once
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+#define HAVE_CCRSAGetCRTComponents 1
+#endif
+
#if ENABLE(SUBTLE_CRYPTO)
#include "CryptoAlgorithmIdentifier.h"
@@ -40,6 +44,10 @@
#include <CommonCrypto/CommonRandomSPI.h>
#endif
+#if USE(APPLE_INTERNAL_SDK) && HAVE(CCRSAGetCRTComponents)
+#include <CommonCrypto/CommonRSACryptorSPI.h>
+#endif
+
#ifndef _CC_RSACRYPTOR_H_
enum {
kCCDigestNone = 0,
@@ -88,6 +96,11 @@
extern "C" CCCryptorStatus CCRSACryptorImport(const void *keyPackage, size_t keyPackageLen, CCRSACryptorRef *key);
extern "C" CCCryptorStatus CCRSACryptorExport(CCRSACryptorRef key, void *out, size_t *outLen);
+#if HAVE(CCRSAGetCRTComponents)
+extern "C" CCCryptorStatus CCRSAGetCRTComponentsSizes(CCRSACryptorRef rsaKey, size_t *dpSize, size_t *dqSize, size_t *qinvSize);
+extern "C" CCCryptorStatus CCRSAGetCRTComponents(CCRSACryptorRef rsaKey, void *dp, size_t dpSize, void *dq, size_t dqSize, void *qinv, size_t qinvSize);
+#endif
+
#ifndef _CC_ECCRYPTOR_H_
enum {
ccECKeyPublic = 0,
@@ -113,8 +126,6 @@
extern "C" CCCryptorStatus CCECCryptorSignHash(CCECCryptorRef privateKey, const void *hashToSign, size_t hashSignLen, void *signedData, size_t *signedDataLen);
extern "C" CCCryptorStatus CCECCryptorVerifyHash(CCECCryptorRef publicKey, const void *hash, size_t hashLen, const void *signedData, size_t signedDataLen, uint32_t *valid);
-
-
#ifndef CommonCrypto_CommonNistKeyDerivation_h
enum {
kCCKDFAlgorithmHKDF = 6
@@ -131,6 +142,9 @@
namespace WebCore {
+#if !HAVE(CCRSAGetCRTComponents)
+
+// Only need CCBigNum for the code used when we don't have CCRSAGetCRTComponents.
class CCBigNum {
public:
CCBigNum(const uint8_t*, size_t);
@@ -153,6 +167,8 @@
CCBigNumRef m_number;
};
+#endif
+
bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier, CCDigestAlgorithm&);
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp (231045 => 231046)
--- trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2018-04-26 15:04:16 UTC (rev 231045)
+++ trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2018-04-26 16:14:37 UTC (rev 231046)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -102,6 +102,23 @@
firstPrimeInfo.primeFactor.shrink(pLength);
secondPrimeInfo.primeFactor.shrink(qLength);
+#if HAVE(CCRSAGetCRTComponents)
+ size_t dpSize;
+ size_t dqSize;
+ size_t qinvSize;
+ if (auto status = CCRSAGetCRTComponentsSizes(rsaKey, &dpSize, &dqSize, &qinvSize))
+ return status;
+
+ Vector<uint8_t> dp(dpSize);
+ Vector<uint8_t> dq(dqSize);
+ Vector<uint8_t> qinv(qinvSize);
+ if (auto status = CCRSAGetCRTComponents(rsaKey, dp.data(), dpSize, dq.data(), dqSize, qinv.data(), qinvSize))
+ return status;
+
+ firstPrimeInfo.factorCRTExponent = WTFMove(dp);
+ secondPrimeInfo.factorCRTExponent = WTFMove(dq);
+ secondPrimeInfo.factorCRTCoefficient = WTFMove(qinv);
+#else
CCBigNum d(privateExponent.data(), privateExponent.size());
CCBigNum p(firstPrimeInfo.primeFactor.data(), firstPrimeInfo.primeFactor.size());
CCBigNum q(secondPrimeInfo.primeFactor.data(), secondPrimeInfo.primeFactor.size());
@@ -113,6 +130,7 @@
firstPrimeInfo.factorCRTExponent = dp.data();
secondPrimeInfo.factorCRTExponent = dq.data();
secondPrimeInfo.factorCRTCoefficient = qi.data();
+#endif
return status;
}