HSL 2.0 framework Description of the framework

Public Member Functions |Static Public Member Functions |List of all members
hsl20_4_crypto.hsl20_4_crypto.AESCipher Class Reference

Class for data encryption using AES. More..

## Public Member Functions
def | __init__ (self)
| Constructor. More...
def | init (self, key, iv=None)
| Initialize. More...
def | use_ecb (self)
| Uses the ECB (Electronic Code Book) mode for encryption More...
def | use_cbc (self)
| Uses the CBC (Cipher Block Chaining) mode for encryption
def | use_cfb (self)
| Uses the CFB (Cipher FeedBack) mode for encryption
def | use_ofb (self)
| Uses the OFB (Output FeedBack) mode for encryption
def | use_ctr (self)
| Uses the CTR (Counter Mode) for encryption
def | encrypt (self, data)
| Encrypts the transmitted data block. More...
def | decrypt (self, data)
| Decrypts the transferred data block. More...

## Static Public Member Functions
def | generate_init_vector ()
| Generates a 16 characters long string. More...

## Detailed Description

Class for encrypting data using AES

Part of the packet for encryption.

The methods encrypt (encrypt) and decrypt (decrypt) are used to process whole strings. By default CBC (Cipher-Block Chaining) is used

class Crypto_AES(hsl20_4.BaseModule):
def __init__(self, homeserver_context):
....
def on_input_value(self, index, value):
if index == self.PIN_I_DO_CRYPTO:
data = "val_with_16_char
vector = "abcdefghijklmnop"
aes_1 = self.FRAMEWORK.create_aes()
aes_1.init("key_with_16_char" , vector)
aes_1.use_cbc()
encrypted = aes_1.encrypt(data)
aes_2 = self.FRAMEWORK.create_aes()
aes_2.init("key_with_16_char" , vector)
aes_2.use_cbc()
decrypted = aes_2.decrypt(encrypted)

If a telegram is received at input PIN_I_DO_CRYPTO, the data block data is encrypted with the static vector vector (aes_1) and stored in the variable encrypted.
The encrypted data block encrypted is then decrypted again with the same vector (aes_2) and stored in the variable decrypted.
In both cases the method CBC is used.

Note
  The data blocks decrypted and data are identical!
  The same AES object cannot be used for encryption and decryption!

## Constructor & Destructor Documentation

## ◆ __init__()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.__init__ | ( |  | self | ) |

Constructor

Warning
  This class should not be instantiated directly

## Member Function Documentation

## ◆ decrypt()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.decrypt | ( |  | self,
|  |  | data
| ) |  |

Decrypts the transferred data block

Note
  The complete data packet to be encrypted must always be transferred: decrypt(a)+decrypt(b) != decrypt(a+b)
  Depending on the mode, the transferred data packet must be a multiple of the block size

Parameters

  data | string Data block

Exceptions

  AttributeError | It's triggered when... ...no key was specified ...the key has an invalid length ...an init vector has been specified which is not 16 characters long
  ValueError | It's triggered when... ...the size of the data packet is not correct

## ◆ encrypt()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.encrypt | ( |  | self,
|  |  | data
| ) |  |

Encrypts the transferred data block

The entire packet to be encrypted must be transferred

Note
  The complete data packet to be encrypted must always be transferred: encrypt(a)+encrypt(b) != encrypt(a+b)
  Depending on the mode, the transferred data packet must be a multiple of the block size

Parameters

  data | string Data block

Exceptions

  AttributesError | It's triggered when... ...no key was specified ...the key has an invalid length ...an init vector has been specified which is not 16 characters long
  ValueError | It's triggered when... ...the size of the data packet is not correct

## ◆ generate_init_vector()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.generate_init_vector | ( |  | ) |
| static

Generates a 16 character long string

This can be used as an init vector

Returns
  string
  Init vector

## ◆ init()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.init | ( |  | self,
|  |  | key,
|  |  | iv = `None`
| ) |  |

Initialize

Parameters

  key | string Key. Must be 16, 24 or 32 in length
  iv | string Optional. Init vector, must be 16 characters long

## ◆ use_ecb()

def hsl20_4_crypto.hsl20_4_crypto.AESCipher.use_ecb | ( |  | self | ) |

Uses the ECB (Electronic Code Book) mode for encryption

Note
  This method does not require an init vector!

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

- hsl20_4_crypto.py