| 1 |
/* |
| 2 |
* ECB Mode |
| 3 |
* (C) 1999-2009,2013 Jack Lloyd |
| 4 |
* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity |
| 5 |
* |
| 6 |
* Botan is released under the Simplified BSD License (see license.txt) |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef SOFTHSM_BOTAN_MODE_ECB_H_ |
| 10 |
#define SOFTHSM_BOTAN_MODE_ECB_H_ |
| 11 |
|
| 12 |
#include <botan/version.h> |
| 13 |
// ECB cipher mode was dropped in Botan 2.0.0 |
| 14 |
// so including this code in SoftHSM for continued support |
| 15 |
// for e.g. CKA_VALUE_CHECK |
| 16 |
|
| 17 |
#include <botan/cipher_mode.h> |
| 18 |
#include <botan/block_cipher.h> |
| 19 |
|
| 20 |
namespace Botan { |
| 21 |
|
| 22 |
/** |
| 23 |
* ECB mode |
| 24 |
*/ |
| 25 |
class BOTAN_DLL ECB_Mode : public Cipher_Mode |
| 26 |
{ |
| 27 |
public: |
| 28 |
std::string name() const override; |
| 29 |
|
| 30 |
size_t update_granularity() const override; |
| 31 |
|
| 32 |
Key_Length_Specification key_spec() const override; |
| 33 |
|
| 34 |
size_t default_nonce_length() const override; |
| 35 |
|
| 36 |
bool valid_nonce_length(size_t n) const override; |
| 37 |
|
| 38 |
void clear() override; |
| 39 |
|
| 40 |
void reset() override; |
| 41 |
|
| 42 |
protected: |
| 43 |
ECB_Mode(BlockCipher* cipher, bool with_pkcs7_padding); |
| 44 |
|
| 45 |
const BlockCipher& cipher() const { return *m_cipher; } |
| 46 |
|
| 47 |
bool with_pkcs7_padding() const { return m_with_pkcs7_padding; } |
| 48 |
|
| 49 |
private: |
| 50 |
void start_msg(const byte nonce[], size_t nonce_len) override; |
| 51 |
void key_schedule(const byte key[], size_t length) override; |
| 52 |
|
| 53 |
std::unique_ptr<BlockCipher> m_cipher; |
| 54 |
bool m_with_pkcs7_padding; |
| 55 |
}; |
| 56 |
|
| 57 |
/** |
| 58 |
* ECB Encryption |
| 59 |
*/ |
| 60 |
class BOTAN_DLL ECB_Encryption final : public ECB_Mode |
| 61 |
{ |
| 62 |
public: |
| 63 |
/** |
| 64 |
* @param cipher block cipher to use |
| 65 |
*/ |
| 66 |
ECB_Encryption(BlockCipher* cipher, bool with_pkcs7_padding) : |
| 67 |
ECB_Mode(cipher, with_pkcs7_padding) {} |
| 68 |
|
| 69 |
size_t process(uint8_t buf[], size_t size) override; |
| 70 |
|
| 71 |
void finish(secure_vector<byte>& final_block, size_t offset = 0) override; |
| 72 |
|
| 73 |
size_t output_length(size_t input_length) const override; |
| 74 |
|
| 75 |
size_t minimum_final_size() const override; |
| 76 |
}; |
| 77 |
|
| 78 |
/** |
| 79 |
* ECB Decryption |
| 80 |
*/ |
| 81 |
class BOTAN_DLL ECB_Decryption final : public ECB_Mode |
| 82 |
{ |
| 83 |
public: |
| 84 |
/** |
| 85 |
* @param cipher block cipher to use |
| 86 |
* @param padding padding method to use |
| 87 |
*/ |
| 88 |
ECB_Decryption(BlockCipher* cipher, bool with_pkcs7_padding) : |
| 89 |
ECB_Mode(cipher, with_pkcs7_padding) {} |
| 90 |
|
| 91 |
size_t process(uint8_t buf[], size_t size) override; |
| 92 |
|
| 93 |
void finish(secure_vector<byte>& final_block, size_t offset = 0) override; |
| 94 |
|
| 95 |
size_t output_length(size_t input_length) const override; |
| 96 |
|
| 97 |
size_t minimum_final_size() const override; |
| 98 |
}; |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
#endif |