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 _BLOWFISH_H
0009 #define _BLOWFISH_H
0010 
0011 #include <config-kwalletbackend.h>
0012 
0013 #if HAVE_STDINT_H
0014 #include <stdint.h>
0015 #endif
0016 #include <sys/types.h>
0017 #if HAVE_SYS_BITYPES_H
0018 #include <sys/bitypes.h> /* For uintXX_t on Tru64 */
0019 #endif
0020 
0021 #include "blockcipher.h"
0022 #include "kwalletbackend_export.h"
0023 
0024 /* @internal
0025  */
0026 class KWALLETBACKEND_EXPORT BlowFish : public BlockCipher
0027 {
0028 public:
0029     BlowFish();
0030     ~BlowFish() override;
0031 
0032     bool setKey(void *key, int bitlength) override;
0033 
0034     int keyLen() const override;
0035 
0036     bool variableKeyLen() const override;
0037 
0038     bool readyToGo() const override;
0039 
0040     int encrypt(void *block, int len) override;
0041 
0042     int decrypt(void *block, int len) override;
0043 
0044 private:
0045     uint32_t m_S[4][256];
0046     uint32_t m_P[18];
0047 
0048     void *m_key;
0049     int m_keylen; // in bits
0050 
0051     bool m_initialized;
0052 
0053     bool init();
0054     uint32_t F(uint32_t x);
0055     void encipher(uint32_t *xl, uint32_t *xr);
0056     void decipher(uint32_t *xl, uint32_t *xr);
0057 };
0058 
0059 #endif