/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once #include #include #include #include namespace vcl::pdf { /** Algorithm 2.B: Computing a hash (revision 6 and later) * * Described in ISO 32000-2:2020(E) - 7.6.4.3.4 */ VCL_DLLPUBLIC std::vector computeHashR6(const sal_uInt8* pPassword, size_t nPasswordLength, std::vector const& rValidationSalt, std::vector const& rUserKey = std::vector()); /** Algorithm 11: Authenticating the user password (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.10 */ VCL_DLLPUBLIC bool validateUserPassword(const sal_uInt8* pUserPass, size_t nPasswordLength, std::vector& U); /** Algorithm 12: Authenticating the owner password (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.11 */ VCL_DLLPUBLIC bool validateOwnerPassword(const sal_uInt8* pUserPass, size_t nPasswordLength, std::vector& U, std::vector& O); /** Generates the encryption key - random data 32-byte */ VCL_DLLPUBLIC std::vector generateKey(); /** Algorithm 8: U and UE * * Computing the encryption dictionary’s U (user password) and UE (user encryption) values * (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.7 */ VCL_DLLPUBLIC void generateUandUE(const sal_uInt8* pUserPass, size_t nPasswordLength, std::vector& rFileEncryptionKey, std::vector& U, std::vector& UE); /** Algorithm 9: O and OE * * Computing the encryption dictionary’s O (owner password) and OE (owner encryption) values * (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.8 */ VCL_DLLPUBLIC void generateOandOE(const sal_uInt8* pUserPass, size_t nPasswordLength, std::vector& rFileEncryptionKey, std::vector& U, std::vector& O, std::vector& OE); /** Algorithm 8 step b) in reverse * * Described in ISO 32000-2:2020(E) - 7.6.4.4.7 * * - compute the hash with password and user key salt * - decrypt with hash as key and zero IV */ VCL_DLLPUBLIC std::vector decryptKey(const sal_uInt8* pUserPass, size_t nPasswordLength, std::vector& U, std::vector& UE); /** Algorithm 13: Validating the permissions (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.12 */ VCL_DLLPUBLIC std::vector decryptPerms(std::vector& rPermsEncrypted, std::vector& rFileEncryptionKey); /** Algorithm 10 step f) * * Computing the encryption dictionary’s Perms (permissions) value (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.9 */ VCL_DLLPUBLIC std::vector encryptPerms(std::vector& rPerms, std::vector& rFileEncryptionKey); /** Algorithm 10 steps a) - e) * * Computing the encryption dictionary’s Perms (permissions) value (Security handlers of revision 6) * * Described in ISO 32000-2:2020(E) - 7.6.4.4.9 */ VCL_DLLPUBLIC std::vector createPerms(sal_Int32 nAccessPermissions, bool bEncryptMetadata); /** Padding as described in Internet RFC 8018 * * Described in ISO 32000-2:2020(E) - 7.6.3.1 */ VCL_DLLPUBLIC size_t addPaddingToVector(std::vector& rVector, size_t nBlockSize); } // end vcl::pdf /* vim:set shiftwidth=4 softtabstop=4 expandtab: */