Botan: src/filters/modes/mode_pad/mode_pad.h Source File

Botan 1.10.16

mode_pad.h
Go to the documentation of this file.
1 /*
2 * CBC Padding Methods
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_CBC_PADDING_H__
9 #define BOTAN_CBC_PADDING_H__
10
11 #include <botan/types.h>
12 #include <string>
13
14 namespace Botan {
15
16 /**
17 * Block Cipher Mode Padding Method
18 * This class is pretty limited, it cannot deal well with
19 * randomized padding methods, or any padding method that
20 * wants to add more than one block. For instance, it should
21 * be possible to define cipher text stealing mode as simply
22 * a padding mode for CBC, which happens to consume the last
23 * two block (and requires use of the block cipher).
24 */
25 class BOTAN_DLL BlockCipherModePaddingMethod
26 {
27 public:
28 /**
29 * @param block output buffer
30 * @param size of the block
31 * @param current_position in the last block
32 */
33 virtual void pad(byte block[],
34 size_t size,
35 size_t current_position) const = 0;
36
37 /**
38 * @param block the last block
39 * @param size the of the block
40 */
41 virtual size_t unpad(const byte block[],
42 size_t size) const = 0;
43
44 /**
45 * @param block_size of the cipher
46 * @param position in the current block
47 * @return number of padding bytes that will be appended
48 */
49 virtual size_t pad_bytes(size_t block_size,
50 size_t position) const;
51
52 /**
53 * @param block_size of the cipher
54 * @return valid block size for this padding mode
55 */
56 virtual bool valid_blocksize(size_t block_size) const = 0;
57
58 /**
59 * @return name of the mode
60 */
61 virtual std::string name() const = 0;
62
63 /**
64 * virtual destructor
65 */
66 virtual ~BlockCipherModePaddingMethod() {}
67 };
68
69 /**
70 * PKCS#7 Padding
71 */
72 class BOTAN_DLL PKCS7_Padding : public BlockCipherModePaddingMethod
73 {
74 public:
75 void pad(byte[], size_t, size_t) const;
76 size_t unpad(const byte[], size_t) const;
77 bool valid_blocksize(size_t) const;
78 std::string name() const { return "PKCS7"; }
79 };
80
81 /**
82 * ANSI X9.23 Padding
83 */
84 class BOTAN_DLL ANSI_X923_Padding : public BlockCipherModePaddingMethod
85 {
86 public:
87 void pad(byte[], size_t, size_t) const;
88 size_t unpad(const byte[], size_t) const;
89 bool valid_blocksize(size_t) const;
90 std::string name() const { return "X9.23"; }
91 };
92
93 /**
94 * One And Zeros Padding
95 */
96 class BOTAN_DLL OneAndZeros_Padding : public BlockCipherModePaddingMethod
97 {
98 public:
99 void pad(byte[], size_t, size_t) const;
100 size_t unpad(const byte[], size_t) const;
101 bool valid_blocksize(size_t) const;
102 std::string name() const { return "OneAndZeros"; }
103 };
104
105 /**
106 * Null Padding
107 */
108 class BOTAN_DLL Null_Padding : public BlockCipherModePaddingMethod
109 {
110 public:
111 void pad(byte[], size_t, size_t) const { return; }
112 size_t unpad(const byte[], size_t size) const { return size; }
113 size_t pad_bytes(size_t, size_t) const { return 0; }
114 bool valid_blocksize(size_t) const { return true; }
115 std::string name() const { return "NoPadding"; }
116 };
117
118 }
119
120 #endif
Botan::Null_Padding::name
std::string name() const
Definition: mode_pad.h:115
Botan::BlockCipherModePaddingMethod::~BlockCipherModePaddingMethod
virtual ~BlockCipherModePaddingMethod()
Definition: mode_pad.h:66
Botan::PKCS7_Padding::name
std::string name() const
Definition: mode_pad.h:78
Botan::Null_Padding
Definition: mode_pad.h:108
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Null_Padding::unpad
size_t unpad(const byte[], size_t size) const
Definition: mode_pad.h:112
Botan::Null_Padding::valid_blocksize
bool valid_blocksize(size_t) const
Definition: mode_pad.h:114
Botan
Definition: algo_base.h:14
Botan::OneAndZeros_Padding
Definition: mode_pad.h:96
Botan::BlockCipherModePaddingMethod
Definition: mode_pad.h:25
Botan::ANSI_X923_Padding
Definition: mode_pad.h:84
Botan::ANSI_X923_Padding::name
std::string name() const
Definition: mode_pad.h:90
Botan::PKCS7_Padding
Definition: mode_pad.h:72
Botan::OneAndZeros_Padding::name
std::string name() const
Definition: mode_pad.h:102
Botan::Null_Padding::pad
void pad(byte[], size_t, size_t) const
Definition: mode_pad.h:111
Botan::Null_Padding::pad_bytes
size_t pad_bytes(size_t, size_t) const
Definition: mode_pad.h:113