File indexing completed on 2024-06-16 03:53:03
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 BLOCKCIPHER_H 0009 #define BLOCKCIPHER_H 0010 0011 #include "kwalletbackend_export.h" 0012 0013 /* @internal 0014 */ 0015 class KWALLETBACKEND_EXPORT BlockCipher 0016 { 0017 public: 0018 BlockCipher(); 0019 virtual ~BlockCipher(); 0020 0021 /* 0022 * Return the current blocksize in bytes. 0023 */ 0024 int blockSize() const; 0025 0026 /* 0027 * Set the encryption key to key. Return true on success. 0028 */ 0029 virtual bool setKey(void *key, int bitlength) = 0; 0030 0031 /* 0032 * Get the required (or if it's variable, then the maximum) key 0033 * length for this cipher in bits. 0034 */ 0035 virtual int keyLen() const = 0; 0036 0037 /* 0038 * True if the key is of a variable length. In this case, 0039 * getKeyLen() will return the maximum length. 0040 */ 0041 virtual bool variableKeyLen() const = 0; 0042 0043 /* 0044 * True if all settings are good and we are ready to encrypt. 0045 */ 0046 virtual bool readyToGo() const = 0; 0047 0048 /* 0049 * Encrypt the block. Returns the number of bytes successfully 0050 * encrypted. Can return -1 on error. 0051 */ 0052 virtual int encrypt(void *block, int len) = 0; 0053 0054 /* 0055 * Decrypt the block. Returns as does encrypt(); 0056 */ 0057 virtual int decrypt(void *block, int len) = 0; 0058 0059 protected: 0060 int _blksz; 0061 int _keylen; // in bits 0062 }; 0063 0064 #endif // BLOCKCIPHER_H