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...
definit (self, key, iv=None)
Initialize. More...
defuse_ecb (self)
Uses the ECB (Electronic Code Book) mode for encryption More...
defuse_cbc (self)
Uses the CBC (Cipher Block Chaining) mode for encryption
defuse_cfb (self)
Uses the CFB (Cipher FeedBack) mode for encryption
defuse_ofb (self)
Uses the OFB (Output FeedBack) mode for encryption
defuse_ctr (self)
Uses the CTR (Counter Mode) for encryption
defencrypt (self, data)
Encrypts the transmitted data block. More...
defdecrypt (self, data)
Decrypts the transferred data block. More...

Static Public Member Functions

defgenerate_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
datastring
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
datastring
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
keystring
Key. Must be 16, 24 or 32 in length
ivstring
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: