M5Utility 0.0.9 git rev:d29fae5
Loading...
Searching...
No Matches
m5::utility::crypto::TripleDES Class Reference

Public Types

enum class  Mode : uint8_t { ECB , CBC }
 Operation mode. More...
 
enum class  Padding : uint8_t { None , Zero , PKCS7 }
 Padding mode.
 
using Key = std::array<uint8_t, 8>
 
using Key8 = Key
 
using Key16 = std::array<uint8_t, 16>
 
using Key24 = std::array<uint8_t, 24>
 

Public Member Functions

 TripleDES (const Mode mode, const Padding pad, const uint8_t iv[8]=nullptr)
 Constructor.
 
Encrypto
uint32_t encrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key)
 Encrypto 1-key 3DES.
 
uint32_t encrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key1, const Key &key2)
 Encrypto 2-key 3DES.
 
uint32_t encrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key16 &key)
 Encrypto 2-key 3DES.
 
uint32_t encrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key1, const Key &key2, const Key &key3)
 Encrypto 3-key 3DES.
 
uint32_t encrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key24 &key)
 Encrypto 3-key 3DES.
 
Decrypto
uint32_t decrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key)
 
uint32_t decrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key1, const Key &key2)
 
uint32_t decrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key &key1, const Key &key2, const Key &key3)
 
uint32_t decrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key16 &key)
 
uint32_t decrypt (uint8_t *out, const uint8_t *in, const uint32_t in_len, const Key24 &key)
 

Static Public Member Functions

static void encrypt_block (uint8_t out[8], const uint8_t in[8], const Key &key)
 
static void decrypt_block (uint8_t out[8], const uint8_t in[8], const Key &key)
 

Protected Member Functions

uint32_t encrypt_3key (uint8_t *out, const uint8_t *in, uint32_t in_len, const Key &k1, const Key &k2, const Key &k3)
 
uint32_t decrypt_3key (uint8_t *out, const uint8_t *in, uint32_t in_len, const Key &k1, const Key &k2, const Key &k3)
 

Static Protected Member Functions

static void key_schedule (uint64_t subkeys[16], const Key &key)
 
static uint32_t feistel (const uint32_t r, const uint64_t subkey)
 
static uint64_t permute_bits (const uint64_t in, const uint8_t *table, const uint32_t table_len, const uint32_t in_bits)
 
static void process_block (uint8_t out[8], const uint8_t in[8], const Key &key, bool encrypt)
 
static void encrypt_block_3key (uint8_t out[8], const uint8_t in[8], const Key8 &k1, const Key8 &k2, const Key8 &k3)
 
static void decrypt_block_3key (uint8_t out[8], const uint8_t in[8], const Key8 &k1, const Key8 &k2, const Key8 &k3)
 

Member Enumeration Documentation

◆ Mode

enum class m5::utility::crypto::TripleDES::Mode : uint8_t
strong

Operation mode.

Enumerator
ECB 

Electronic CodeBook.

CBC 

Cipher Block Chaining.

Constructor & Destructor Documentation

◆ TripleDES()

m5::utility::crypto::TripleDES::TripleDES ( const Mode mode,
const Padding pad,
const uint8_t iv[8] = nullptr )

Constructor.

Parameters
modeMode
padPadding
ivInitialization vector for CBC mode
Note
IV is 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 if iv is nullptr

Member Function Documentation

◆ encrypt() [1/5]

uint32_t m5::utility::crypto::TripleDES::encrypt ( uint8_t * out,
const uint8_t * in,
const uint32_t in_len,
const Key & key )
inline

Encrypto 1-key 3DES.

Parameters
[out]outOutput buffer
inInput
in_lenInput length
keyKey
Returns
Output length
Note
Same as single DES
out at leaset in_len if Padding::None
out at leaset (in_len + 7)/8+8 if Padding::Zero, PKCS7

◆ encrypt() [2/5]

uint32_t m5::utility::crypto::TripleDES::encrypt ( uint8_t * out,
const uint8_t * in,
const uint32_t in_len,
const Key & key1,
const Key & key2 )
inline

Encrypto 2-key 3DES.

Parameters
[out]outOutput buffer
inInput
in_lenInput length
key1Key1
key2Key2
Returns
Output length
Note
out at leaset in_len if Padding::None
out at leaset (in_len + 7)/8+8 if Padding::Zero, PKCS7

◆ encrypt() [3/5]

uint32_t m5::utility::crypto::TripleDES::encrypt ( uint8_t * out,
const uint8_t * in,
const uint32_t in_len,
const Key & key1,
const Key & key2,
const Key & key3 )
inline

Encrypto 3-key 3DES.

Parameters
[out]outOutput buffer
inInput
in_lenInput length
key1Key1
key2Key2
key3Key3
Returns
Output length
Note
out at leaset in_len if Padding::None
out at leaset (in_len + 7)/8+8 if Padding::Zero, PKCS7

◆ encrypt() [4/5]

uint32_t m5::utility::crypto::TripleDES::encrypt ( uint8_t * out,
const uint8_t * in,
const uint32_t in_len,
const Key16 & key )

Encrypto 2-key 3DES.

Parameters
[out]outOutput buffer
inInput
in_lenInput length
keyKey
Returns
Output length
Note
out at leaset in_len if Padding::None
out at leaset (in_len + 7)/8+8 if Padding::Zero, PKCS7

◆ encrypt() [5/5]

uint32_t m5::utility::crypto::TripleDES::encrypt ( uint8_t * out,
const uint8_t * in,
const uint32_t in_len,
const Key24 & key )

Encrypto 3-key 3DES.

Parameters
[out]outOutput buffer
inInput
in_lenInput length
keyKey
Returns
Output length
Note
out at leaset in_len if Padding::None
out at leaset (in_len + 7)/8+8 if Padding::Zero, PKCS7