File indexing completed on 2024-06-16 03:53:04

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 George Staikos <staikos@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef __CBC__KO__H
0009 #define __CBC__KO__H
0010 
0011 #include "blockcipher.h"
0012 
0013 /* @internal
0014  *   Initialize this class with a pointer to a valid, uninitialized BlockCipher
0015  *   and it will apply that cipher using CBC.  You may want to make the
0016  *   initial block a full block of random data.  Do not change the block size
0017  *   at any time!!  You must pad it yourself.  Also, you can only encrypt or
0018  *   decrypt.  You can't do both with a given instance.  After you call one,
0019  *   calls to the other will fail in this instance.
0020  */
0021 
0022 class CipherBlockChain : public BlockCipher
0023 {
0024 public:
0025     CipherBlockChain(BlockCipher *cipher, bool useECBforReading = false);
0026     ~CipherBlockChain() override;
0027 
0028     bool setKey(void *key, int bitlength) override;
0029 
0030     int keyLen() const override;
0031 
0032     bool variableKeyLen() const override;
0033 
0034     bool readyToGo() const override;
0035 
0036     int encrypt(void *block, int len) override;
0037 
0038     int decrypt(void *block, int len) override;
0039 
0040 private:
0041     void initRegister();
0042     int decryptECB(void *block, int len);
0043 
0044     BlockCipher *_cipher;
0045     void *_register;
0046     void *_next;
0047     int _len;
0048     int _reader, _writer;
0049     bool _useECBforReading;
0050 };
0051 
0052 #endif