LCOV - code coverage report
Current view: top level - include/oox/crypto - CryptTools.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 2 0.0 %
Date: 2014-11-03 Functions: 0 4 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
      21             : #define INCLUDED_OOX_CRYPTO_CRYPTTOOLS_HXX
      22             : 
      23             : #include <config_oox.h>
      24             : 
      25             : #include <rtl/ustring.hxx>
      26             : 
      27             : #if USE_TLS_OPENSSL
      28             : #include <openssl/evp.h>
      29             : #include <openssl/sha.h>
      30             : #endif // USE_TLS_OPENSSL
      31             : 
      32             : #if USE_TLS_NSS
      33             : #include <nss.h>
      34             : #include <pk11pub.h>
      35             : #include <sechash.h>
      36             : #endif // USE_TLS_NSS
      37             : 
      38             : #include <rtl/digest.h>
      39             : #include <vector>
      40             : 
      41             : namespace oox {
      42             : namespace core {
      43             : 
      44             : class Crypto
      45             : {
      46             : public:
      47             :     enum CryptoType
      48             :     {
      49             :         UNKNOWN,
      50             :         AES_128_ECB,
      51             :         AES_128_CBC,
      52             :         AES_256_CBC,
      53             :     };
      54             : 
      55             : protected:
      56             :     CryptoType mType;
      57             : #if USE_TLS_OPENSSL
      58             :     EVP_CIPHER_CTX mContext;
      59             : #endif
      60             : #if USE_TLS_NSS
      61             :     PK11Context* mContext;
      62             :     SECItem*     mSecParam;
      63             :     PK11SymKey*  mSymKey;
      64             : #endif
      65             : 
      66             : #if USE_TLS_OPENSSL
      67             :     const EVP_CIPHER* getCipher(CryptoType type);
      68             : #endif
      69             : #if USE_TLS_NSS
      70             :     void setupContext(
      71             :             std::vector<sal_uInt8>& key,
      72             :             std::vector<sal_uInt8>& iv,
      73             :             CryptoType type,
      74             :             CK_ATTRIBUTE_TYPE operation);
      75             : #endif
      76             : 
      77             : protected:
      78             :     Crypto(CryptoType type);
      79             : 
      80             : public:
      81             :     virtual ~Crypto();
      82             : 
      83             :     virtual sal_uInt32 update(
      84             :                     std::vector<sal_uInt8>& output,
      85             :                     std::vector<sal_uInt8>& input,
      86             :                     sal_uInt32 inputLength = 0) = 0;
      87             : };
      88             : 
      89           0 : class Decrypt : public Crypto
      90             : {
      91             : public:
      92             :     Decrypt(std::vector<sal_uInt8>& key, CryptoType type);
      93             :     Decrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
      94             : 
      95             :     virtual sal_uInt32 update(
      96             :                     std::vector<sal_uInt8>& output,
      97             :                     std::vector<sal_uInt8>& input,
      98             :                     sal_uInt32 inputLength = 0) SAL_OVERRIDE;
      99             : 
     100             : 
     101             :     static sal_uInt32 aes128ecb(
     102             :                     std::vector<sal_uInt8>& output,
     103             :                     std::vector<sal_uInt8>& input,
     104             :                     std::vector<sal_uInt8>& key );
     105             : 
     106             : };
     107             : 
     108           0 : class Encrypt : public Crypto
     109             : {
     110             : public:
     111             :     Encrypt(std::vector<sal_uInt8>& key, CryptoType type);
     112             :     Encrypt(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& iv, CryptoType type);
     113             : 
     114             :     virtual sal_uInt32 update(
     115             :                     std::vector<sal_uInt8>& output,
     116             :                     std::vector<sal_uInt8>& input,
     117             :                     sal_uInt32 inputLength = 0) SAL_OVERRIDE;
     118             : };
     119             : 
     120             : class Digest
     121             : {
     122             : public:
     123             :     enum DigestType
     124             :     {
     125             :         UNKNOWN,
     126             :         SHA1,
     127             :         SHA512
     128             :     };
     129             : 
     130             :     static const sal_uInt32 DIGEST_LENGTH_SHA1;
     131             :     static const sal_uInt32 DIGEST_LENGTH_SHA512;
     132             : 
     133             : private:
     134             :     DigestType meType;
     135             : 
     136             : #if USE_TLS_OPENSSL
     137             :     EVP_MD_CTX* mpContext;
     138             : #endif
     139             : 
     140             : #if USE_TLS_NSS
     141             :     HASHContext* mpContext;
     142             : #endif
     143             : 
     144             : public:
     145             :     Digest(DigestType eType);
     146             :     virtual ~Digest();
     147             : 
     148             :     bool update(std::vector<sal_uInt8>& input);
     149             :     bool finalize(std::vector<sal_uInt8>& digest);
     150             : 
     151             :     sal_uInt32 getLength();
     152             : 
     153             :     static bool sha1(  std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
     154             :     static bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
     155             : };
     156             : 
     157             : bool sha1(  std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
     158             : bool sha512(std::vector<sal_uInt8>& digest, std::vector<sal_uInt8>& input);
     159             : 
     160             : } // namespace core
     161             : } // namespace oox
     162             : 
     163             : #endif
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10