Check RSA padding in TZ 36/297136/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 10 Aug 2023 18:27:44 +0000 (20:27 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 11 Aug 2023 08:10:44 +0000 (10:10 +0200)
The only supported padding method is PKCS1

Change-Id: I3cd769d68f67b3ee2afb959bca2e74db8e6295c4

src/manager/crypto/tz-backend/internals.cpp

index 2a5d83c..1d14e08 100644 (file)
@@ -733,6 +733,11 @@ RawBuffer sign(const RawBuffer &pkeyId,
        if (algo != AlgoType::RSA_SV && hash == HashAlgorithm::NONE)
                ThrowErr(Exc::Crypto::InputParam, "Only RSA supports no hash option");
 
+       RSAPaddingAlgorithm padding = RSAPaddingAlgorithm::NONE;
+       alg.getParam(ParamName::SV_RSA_PADDING, padding);
+       if (algo == AlgoType::RSA_SV && padding != RSAPaddingAlgorithm::PKCS1)
+               ThrowErr(Exc::Crypto::InputParam, "Only PKCS1 padding is supported");
+
        RawBuffer signature;
        TrustZoneContext::Instance().executeSign(getAlgType(algo),
                                                                                        getHashType(hash),
@@ -754,6 +759,11 @@ int verify(const RawBuffer &pkeyId,
        if (algo != AlgoType::RSA_SV && hash == HashAlgorithm::NONE)
                ThrowErr(Exc::Crypto::InputParam, "Only RSA supports no hash option");
 
+       RSAPaddingAlgorithm padding = RSAPaddingAlgorithm::NONE;
+       alg.getParam(ParamName::SV_RSA_PADDING, padding);
+       if (algo == AlgoType::RSA_SV && padding != RSAPaddingAlgorithm::PKCS1)
+               ThrowErr(Exc::Crypto::InputParam, "Only PKCS1 padding is supported");
+
        return TrustZoneContext::Instance().executeVerify(getAlgType(algo),
                                                                                                        getHashType(hash),
                                                                                                        pkeyId,