LCOV - code coverage report
Current view: top level - include/oox/crypto - Standard2007Engine.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1 0.0 %
Date: 2014-04-14 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  */
      10             : 
      11             : #ifndef INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
      12             : #define INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
      13             : 
      14             : #include <oox/crypto/CryptTools.hxx>
      15             : #include <oox/crypto/CryptoEngine.hxx>
      16             : 
      17             : namespace oox {
      18             : namespace core {
      19             : 
      20             : const sal_uInt32 ENCRYPTINFO_CRYPTOAPI      = 0x00000004;
      21             : const sal_uInt32 ENCRYPTINFO_DOCPROPS       = 0x00000008;
      22             : const sal_uInt32 ENCRYPTINFO_EXTERNAL       = 0x00000010;
      23             : const sal_uInt32 ENCRYPTINFO_AES            = 0x00000020;
      24             : 
      25             : const sal_uInt32 ENCRYPT_ALGO_AES128        = 0x0000660E;
      26             : const sal_uInt32 ENCRYPT_ALGO_AES192        = 0x0000660F;
      27             : const sal_uInt32 ENCRYPT_ALGO_AES256        = 0x00006610;
      28             : const sal_uInt32 ENCRYPT_ALGO_RC4           = 0x00006801;
      29             : 
      30             : const sal_uInt32 ENCRYPT_HASH_SHA1          = 0x00008004;
      31             : 
      32             : const sal_uInt32 ENCRYPT_KEY_SIZE_AES_128   = 0x00000080;
      33             : const sal_uInt32 ENCRYPT_KEY_SIZE_AES_192   = 0x000000C0;
      34             : const sal_uInt32 ENCRYPT_KEY_SIZE_AES_256   = 0x00000100;
      35             : 
      36             : const sal_uInt32 ENCRYPT_PROVIDER_TYPE_AES  = 0x00000018;
      37             : const sal_uInt32 ENCRYPT_PROVIDER_TYPE_RC4  = 0x00000001;
      38             : 
      39             : // version of encryption info used in MS Office 2007 (major = 3, minor = 2)
      40             : const sal_uInt32 VERSION_INFO_2007_FORMAT       = 0x00020003;
      41             : // version of encryption info used in MS Office 2007 SP2 and older (major = 4, minor = 2)
      42             : const sal_uInt32 VERSION_INFO_2007_FORMAT_SP2   = 0x00020004;
      43             : 
      44             : // version of encryption info - agile (major = 4, minor = 4)
      45             : const sal_uInt32 VERSION_INFO_AGILE         = 0x00040004;
      46             : 
      47             : const sal_uInt32 SALT_LENGTH                    = 16;
      48             : const sal_uInt32 ENCRYPTED_VERIFIER_LENGTH      = 16;
      49             : const sal_uInt32 ENCRYPTED_VERIFIER_HASH_LENGTH = 32;
      50             : 
      51             : struct EncryptionStandardHeader
      52             : {
      53             :     sal_uInt32 flags;
      54             :     sal_uInt32 sizeExtra;       // 0
      55             :     sal_uInt32 algId;           // if flag AES && CRYPTOAPI this defaults to 128-bit AES
      56             :     sal_uInt32 algIdHash;       // 0: determine by flags - defaults to SHA-1 if not external
      57             :     sal_uInt32 keyBits;         // key size in bits: 0 (determine by flags), 128, 192, 256
      58             :     sal_uInt32 providedType;    // AES or RC4
      59             :     sal_uInt32 reserved1;       // 0
      60             :     sal_uInt32 reserved2;       // 0
      61             : 
      62             :     EncryptionStandardHeader();
      63             : };
      64             : 
      65             : struct EncryptionVerifierAES
      66             : {
      67             :     sal_uInt32 saltSize;                                                // must be 0x00000010
      68             :     sal_uInt8  salt[SALT_LENGTH];                                       // random generated salt value
      69             :     sal_uInt8  encryptedVerifier[ENCRYPTED_VERIFIER_LENGTH];            // randomly generated verifier value
      70             :     sal_uInt32 encryptedVerifierHashSize;                               // actually written hash size - depends on algorithm
      71             :     sal_uInt8  encryptedVerifierHash[ENCRYPTED_VERIFIER_HASH_LENGTH];   // verifier value hash - itself also encrypted
      72             : 
      73             :     EncryptionVerifierAES();
      74             : };
      75             : 
      76           0 : struct StandardEncryptionInfo
      77             : {
      78             :     EncryptionStandardHeader header;
      79             :     EncryptionVerifierAES    verifier;
      80             : };
      81             : 
      82             : class Standard2007Engine : public CryptoEngine
      83             : {
      84             :     StandardEncryptionInfo mInfo;
      85             : 
      86             :     bool generateVerifier();
      87             :     bool calculateEncryptionKey(const OUString& rPassword);
      88             : 
      89             : public:
      90             :     Standard2007Engine();
      91             :     virtual ~Standard2007Engine();
      92             : 
      93             :     StandardEncryptionInfo& getInfo();
      94             : 
      95             :     virtual bool generateEncryptionKey(const OUString& rPassword) SAL_OVERRIDE;
      96             : 
      97             :     virtual bool writeEncryptionInfo(
      98             :                     const OUString& rPassword,
      99             :                     BinaryXOutputStream& rStream) SAL_OVERRIDE;
     100             : 
     101             :     virtual bool decrypt(
     102             :                     BinaryXInputStream& aInputStream,
     103             :                     BinaryXOutputStream& aOutputStream) SAL_OVERRIDE;
     104             : 
     105             :     virtual bool encrypt(
     106             :                     BinaryXInputStream& aInputStream,
     107             :                     BinaryXOutputStream& aOutputStream) SAL_OVERRIDE;
     108             : 
     109             : };
     110             : 
     111             : } // namespace core
     112             : } // namespace oox
     113             : 
     114             : #endif
     115             : 
     116             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10