summaryrefslogtreecommitdiff
path: root/threefish.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-05-17 14:38:37 -0400
committerJeffrey Walton <noloader@gmail.com>2017-05-17 14:38:37 -0400
commit03a6a8fb7328d619f84292bf96b81df02aaa121d (patch)
tree2abca8752492c409120240ae3d4f5817a8bf33f1 /threefish.h
parent5b81b5c66c6b14cf9aa120100a9ddfb2b356cbee (diff)
downloadcryptopp-git-03a6a8fb7328d619f84292bf96b81df02aaa121d.tar.gz
Add separate Enc and Dec classes to Threefish
The change speeds up benchmarks for Threefish-256 and Threefish-512 by about 10 MiB/s on a 6th gen Skylake
Diffstat (limited to 'threefish.h')
-rw-r--r--threefish.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/threefish.h b/threefish.h
index 422da93f..087e52a0 100644
--- a/threefish.h
+++ b/threefish.h
@@ -68,7 +68,8 @@ public:
{
public:
std::string AlgorithmName() const {
- return m_blocksize ? "Threefish-" + IntToString(m_blocksize*8) + "(" + IntToString((m_rkey.size()-1)*8) + ")" : StaticAlgorithmName();
+ // Key length is the same as blocksize
+ return m_blocksize ? "Threefish-" + IntToString(m_blocksize*8) : StaticAlgorithmName();
}
unsigned int OptimalDataAlignment() const {
@@ -77,22 +78,36 @@ public:
protected:
void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &params);
+
+ typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
+ mutable AlignedSecBlock64 m_wspace; // workspace
+ AlignedSecBlock64 m_rkey; // keys
+ AlignedSecBlock64 m_tweak;
+ };
+
+ class CRYPTOPP_NO_VTABLE Enc : public Base
+ {
+ protected:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
void ProcessAndXorBlock_256(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
void ProcessAndXorBlock_512(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
void ProcessAndXorBlock_1024(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ };
- private:
- typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
- mutable AlignedSecBlock64 m_wspace; // workspace
- AlignedSecBlock64 m_rkey; // keys
- AlignedSecBlock64 m_tweak;
+ class CRYPTOPP_NO_VTABLE Dec : public Base
+ {
+ protected:
+ void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+
+ void ProcessAndXorBlock_256(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ void ProcessAndXorBlock_512(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
+ void ProcessAndXorBlock_1024(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
};
public:
- typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
- typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
+ typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
+ typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
};
typedef Threefish::Encryption ThreefishEncryption;