Botan 3.9.0
Crypto and TLS for C&
blowfish.h
Go to the documentation of this file.
1/*
2* Blowfish
3* (C) 1999-2011 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_BLOWFISH_H_
9#define BOTAN_BLOWFISH_H_
10
11#include <botan/block_cipher.h>
12#include <botan/secmem.h>
13
14namespace Botan {
15
16/**
17* Blowfish
18*/
19class BOTAN_TEST_API Blowfish final : public Block_Cipher_Fixed_Params<8, 1, 56> {
20 public:
21 void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
22 void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
23
24 /**
25 * Modified EKSBlowfish key schedule, used for bcrypt password hashing
26 */
27 void salted_set_key(const uint8_t key[],
28 size_t key_length,
29 const uint8_t salt[],
30 size_t salt_length,
31 size_t workfactor,
32 bool salt_first = false);
33
34 void clear() override;
35
36 std::string name() const override { return "Blowfish"; }
37
38 std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<Blowfish>(); }
39
40 bool has_keying_material() const override;
41
42 private:
43 void key_schedule(std::span<const uint8_t> key) override;
44
45 void key_expansion(const uint8_t key[], size_t key_length, const uint8_t salt[], size_t salt_length);
46
47 void generate_sbox(secure_vector<uint32_t>& box,
48 uint32_t& L,
49 uint32_t& R,
50 const uint8_t salt[],
51 size_t salt_length,
52 size_t salt_off) const;
53
55};
56
57} // namespace Botan
58
59#endif
#define BOTAN_TEST_API
Definition api.h:41
std::unique_ptr< BlockCipher > new_object() const override
Definition blowfish.h:38
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition blowfish.cpp:156
std::string name() const override
Definition blowfish.h:36
void clear() override
Definition blowfish.cpp:402
void salted_set_key(const uint8_t key[], size_t key_length, const uint8_t salt[], size_t salt_length, size_t workfactor, bool salt_first=false)
Definition blowfish.cpp:339
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition blowfish.cpp:231
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69