Botan 2.1.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::OneAndZeros_Padding Class Referencefinal

`#include <mode_pad.h>`

Inheritance diagram for Botan::OneAndZeros_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

One And Zeros Padding (ISO/IEC 9797-1, padding method 2)

Definition at line 102 of file mode_pad.h.

## Member Function Documentation

void Botan::OneAndZeros_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 119 of file mode_pad.cpp.

122 {
123 buffer.push_back(0x80);
124
125 for(size_t i = last_byte_pos + 1; i % block_size; ++i)
126 buffer.push_back(0x00);
127 }

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

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 113 of file mode_pad.h.

113 { return "OneAndZeros"; }

size_t Botan::OneAndZeros_Padding::unpad | ( | const uint8_t | block[],
|  | size_t | size
| ) |  | const
| override virtual

Remove padding bytes from block

Parameters

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

Returns
  number of padding bytes

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 132 of file mode_pad.cpp.

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

133 {
134 CT::poison(block, size);
135 uint8_t bad_input = 0;
136 uint8_t seen_one = 0;
137 size_t pad_pos = size - 1;
138 size_t i = size;
139
140 while(i)
141 {
142 seen_one |= CT::is_equal<uint8_t>(block[i-1],0x80);
143 pad_pos -= CT::select<uint8_t>(~seen_one, 1, 0);
144 bad_input |= ~CT::is_zero<uint8_t>(block[i-1]) & ~seen_one;
145 i--;
146 }
147 bad_input |= ~seen_one;
148
149 CT::conditional_copy_mem(size_t(bad_input),&pad_pos,&size,&pad_pos,1);
150 CT::unpoison(block, size);
151 CT::unpoison(pad_pos);
152
153 return pad_pos;
154 }
Botan::CT::conditional_copy_mem
void conditional_copy_mem(T value, T *to, const T *from0, const T *from1, size_t elems)
Definition: ct_utils.h:138
Botan::CT::poison
void poison(const T *p, size_t n)
Definition: ct_utils.h:46
Botan::CT::unpoison
void unpoison(const T *p, size_t n)
Definition: ct_utils.h:57

bool Botan::OneAndZeros_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 111 of file mode_pad.h.

111 { return (bs > 0); }

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