{
    "Function": "pkcs1Sha256",
    "File": "packages/protocol/contracts/automata-attestation/utils/RsaVerify.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [
        "gas()",
        "staticcall(uint256,uint256,uint256,uint256,uint256,uint256)",
        "bytes.concat()",
        "pop(uint256)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function pkcs1Sha256(\n        bytes32 _sha256,\n        bytes memory _s,\n        bytes memory _e,\n        bytes memory _m\n    )\n        internal\n        view\n        returns (bool)\n    {\n        uint8[17] memory sha256ExplicitNullParam = [\n            0x30,\n            0x31,\n            0x30,\n            0x0d,\n            0x06,\n            0x09,\n            0x60,\n            0x86,\n            0x48,\n            0x01,\n            0x65,\n            0x03,\n            0x04,\n            0x02,\n            0x01,\n            0x05,\n            0x00\n        ];\n\n        uint8[15] memory sha256ImplicitNullParam = [\n            0x30,\n            0x2f,\n            0x30,\n            0x0b,\n            0x06,\n            0x09,\n            0x60,\n            0x86,\n            0x48,\n            0x01,\n            0x65,\n            0x03,\n            0x04,\n            0x02,\n            0x01\n        ];\n\n        // decipher\n\n        bytes memory input =\n            bytes.concat(bytes32(_s.length), bytes32(_e.length), bytes32(_m.length), _s, _e, _m);\n        uint256 inputlen = input.length;\n\n        uint256 decipherlen = _m.length;\n        bytes memory decipher = new bytes(decipherlen);\n        assembly {\n            pop(\n                staticcall(\n                    sub(gas(), 2000),\n                    5,\n                    add(input, 0x20),\n                    inputlen,\n                    add(decipher, 0x20),\n                    decipherlen\n                )\n            )\n        }\n\n        // Check that is well encoded:\n        //\n        // 0x00 || 0x01 || PS || 0x00 || DigestInfo\n        // PS is padding filled with 0xff\n        // DigestInfo ::= SEQUENCE {\n        //    digestAlgorithm AlgorithmIdentifier,\n        //      [optional algorithm parameters]\n        //    digest OCTET STRING\n        // }\n\n        bool hasNullParam;\n        uint256 digestAlgoWithParamLen;\n\n        if (uint8(decipher[decipherlen - 50]) == 0x31) {\n            hasNullParam = true;\n            digestAlgoWithParamLen = sha256ExplicitNullParam.length;\n        } else if (uint8(decipher[decipherlen - 48]) == 0x2f) {\n            hasNullParam = false;\n            digestAlgoWithParamLen = sha256ImplicitNullParam.length;\n        } else {\n            return false;\n        }\n\n        uint256 paddingLen = decipherlen - 5 - digestAlgoWithParamLen - 32;\n\n        if (decipher[0] != 0 || decipher[1] != 0x01) {\n            return false;\n        }\n        for (uint256 i = 2; i < 2 + paddingLen; ++i) {\n            if (decipher[i] != 0xff) {\n                return false;\n            }\n        }\n        if (decipher[2 + paddingLen] != 0) {\n            return false;\n        }\n\n        // check digest algorithm\n\n        if (digestAlgoWithParamLen == sha256ExplicitNullParam.length) {\n            for (uint256 i; i < digestAlgoWithParamLen; ++i) {\n                if (decipher[3 + paddingLen + i] != bytes1(sha256ExplicitNullParam[i])) {\n                    return false;\n                }\n            }\n        } else {\n            for (uint256 i; i < digestAlgoWithParamLen; ++i) {\n                if (decipher[3 + paddingLen + i] != bytes1(sha256ImplicitNullParam[i])) {\n                    return false;\n                }\n            }\n        }\n\n        // check digest\n\n        if (\n            decipher[3 + paddingLen + digestAlgoWithParamLen] != 0x04\n                || decipher[4 + paddingLen + digestAlgoWithParamLen] != 0x20\n        ) {\n            return false;\n        }\n\n        for (uint256 i; i < _sha256.length; ++i) {\n            if (decipher[5 + paddingLen + digestAlgoWithParamLen + i] != _sha256[i]) {\n                return false;\n            }\n        }\n\n        return true;\n    }"
}