Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::ANSI_X923_Padding Class Referencefinal

`#include <mode_pad.h>`

Inheritance diagram for Botan::ANSI_X923_Padding:

## Public Member Functions
void | add_padding (secure_vector< uint8_t > &buffer, size_t final_block_bytes, size_t block_size) const override
std::string | name () const override
size_t | unpad (const uint8_t[], size_t) const override
bool | valid_blocksize (size_t bs) const override

## Detailed Description

ANSI X9.23 Padding

Definition at line 86 of file mode_pad.h.

## Member Function Documentation

void Botan::ANSI_X923_Padding::add_padding | ( | secure_vector< uint8_t > & | buffer,
|  | size_t | final_block_bytes,
|  | size_t | block_size
| ) |  | const
| override virtual

Add padding bytes to buffer.

Parameters

  buffer | data to pad
  final_block_bytes | size of the final block in bytes
  block_size | size of each block in bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 89 of file mode_pad.cpp.

92 {
93 const uint8_t pad_value = static_cast<uint8_t>(block_size - last_byte_pos);
94
95 for(size_t i = last_byte_pos; i < block_size-1; ++i)
96 {
97 buffer.push_back(0);
98 }
99 buffer.push_back(pad_value);
100 }

std::string Botan::ANSI_X923_Padding::name | ( |  | ) | const
| inline override virtual

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 97 of file mode_pad.h.

97 { return "X9.23"; }

size_t Botan::ANSI_X923_Padding::unpad | ( | const uint8_t | block[],
|  | size_t | len
| ) |  | const
| override virtual

Remove padding bytes from block

Parameters

  block | the last block
  len | the size of the block in bytes

Returns
  number of data bytes, or if the padding is invalid returns len

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 105 of file mode_pad.cpp.

References Botan::CT::Mask< T >::expand(), Botan::CT::Mask< T >::is_gt(), Botan::CT::Mask< T >::is_gte(), Botan::CT::poison(), Botan::CT::unpoison(), and valid_blocksize().

106 {
107 if(!valid_blocksize(input_length))
108 return input_length;
109
110 CT::poison(input, input_length);
111
112 const size_t last_byte = input[input_length-1];
113
114 auto bad_input = CT::Mask<size_t>::is_gt(last_byte, input_length);
115
116 const size_t pad_pos = input_length - last_byte;
117
118 for(size_t i = 0; i != input_length - 1; ++i)
119 {
120 // Ignore values that are not part of the padding
121 const auto in_range = CT::Mask<size_t>::is_gte(i, pad_pos);
122 const auto pad_is_nonzero = CT::Mask<size_t>::expand(input[i]);
123 bad_input |= pad_is_nonzero & in_range;
124 }
125
126 CT::unpoison(input, input_length);
127
128 return bad_input.select_and_unpoison(input_length, pad_pos);
129 }
Botan::ANSI_X923_Padding::valid_blocksize
bool valid_blocksize(size_t bs) const override
Definition: mode_pad.h:95
Botan::CT::Mask::is_gte
static Mask< T > is_gte(T x, T y)
Definition: ct_utils.h:181
Botan::CT::poison
void poison(const T *p, size_t n)
Definition: ct_utils.h:48
Botan::CT::Mask::expand
static Mask< T > expand(T v)
Definition: ct_utils.h:123
Botan::CT::unpoison
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:59
Botan::CT::Mask::is_gt
static Mask< T > is_gt(T x, T y)
Definition: ct_utils.h:165

bool Botan::ANSI_X923_Padding::valid_blocksize | ( | size_t | block_size | ) | const
| inline override virtual

Parameters

  block_size | of the cipher

Returns
  valid block size for this padding mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 95 of file mode_pad.h.

Referenced by unpad().

95 { return (bs > 2 && bs < 256); }

The documentation for this class was generated from the following files:

- src/lib/modes/mode_pad/mode_pad.h
- src/lib/modes/mode_pad/mode_pad.cpp