Botan  2.7.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::ANSI_X923_Padding Class Referencefinal

#include <mode_pad.h>

Inheritance diagram for Botan::ANSI_X923_Padding:
Botan::BlockCipherModePaddingMethod

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 85 of file mode_pad.h.

Member Function Documentation

◆ add_padding()

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

Add padding bytes to buffer.

Parameters
bufferdata to pad
final_block_bytessize of the final block in bytes
block_sizesize of each block in bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 79 of file mode_pad.cpp.

82  {
83  const uint8_t pad_value = static_cast<uint8_t>(block_size - last_byte_pos);
84 
85  for(size_t i = last_byte_pos; i < block_size-1; ++i)
86  {
87  buffer.push_back(0);
88  }
89  buffer.push_back(pad_value);
90  }

◆ name()

std::string Botan::ANSI_X923_Padding::name ( ) const
inlineoverridevirtual
Returns
name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 96 of file mode_pad.h.

96 { return "X9.23"; }

◆ unpad()

size_t Botan::ANSI_X923_Padding::unpad ( const uint8_t  block[],
size_t  size 
) const
overridevirtual

Remove padding bytes from block

Parameters
blockthe last block
sizethe size of the block in bytes
Returns
number of padding bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 95 of file mode_pad.cpp.

References Botan::CT::conditional_copy_mem(), Botan::CT::is_zero(), Botan::CT::poison(), and Botan::CT::unpoison().

96  {
97  CT::poison(block,size);
98  size_t bad_input = 0;
99  const size_t last_byte = block[size-1];
100 
101  bad_input |= CT::expand_mask<size_t>(last_byte > size);
102 
103  size_t pad_pos = size - last_byte;
104  size_t i = size - 2;
105  while(i)
106  {
107  bad_input |= (~CT::is_zero(block[i])) & CT::expand_mask<uint8_t>(i >= pad_pos);
108  --i;
109  }
110  CT::conditional_copy_mem(bad_input,&pad_pos,&size,&pad_pos,1);
111  CT::unpoison(block,size);
112  CT::unpoison(pad_pos);
113  return pad_pos;
114  }
void poison(const T *p, size_t n)
Definition: ct_utils.h:46
T conditional_copy_mem(T value, T *to, const T *from0, const T *from1, size_t elems)
Definition: ct_utils.h:154
T is_zero(T x)
Definition: ct_utils.h:130
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:57

◆ valid_blocksize()

bool Botan::ANSI_X923_Padding::valid_blocksize ( size_t  block_size) const
inlineoverridevirtual
Parameters
block_sizeof the cipher
Returns
valid block size for this padding mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 94 of file mode_pad.h.

94 { return (bs > 0 && bs < 256); }

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