”;
A general process for creating a family of block ciphers is called CAST. Names for individual ciphers include CAST-128 and CAST-256. The CAST cryptography algorithm is the main topic of discussion in this chapter.
What is CAST Ecnryption Algorithm?
Usually used for IP security, the CAST method refers to the Fiestal structure, which divides plain text into equal portions and performs encryption.
- Instead of using DES”s 6*4 S-boxes, they use larger 8*32 S-boxes.
- They are made to be used with software.
- Bent functions are used as columns in the CAST S-boxes.
- S-boxes satisfy the avalanche requirement, which states that each bit of input and each bit of round key effects every bit of round output and increases the probability of every given output bit changing by exactly 50%.
What is CAST5?
The most popular CAST cipher is CAST-128, also referred to as CAST5. It is a symmetric key block cipher that is the default cipher for both GPG and PGF versions and is utilised in a variety of products. The developers of it, make it accessible for both commercial and non-commercial use globally at no cost to users.
The CAST5 encryption technique is made to support key sizes ranging from 40 to 128 bits, in increments of 8 bits. This means that the key sizes that can be used are 40, 48, 56, 64,…, 112, 120, and 128 bits.
- It is a Feistel Cipher with 16 rounds and 64-bit blocks.
- The range of key sizes is 40 bits to 128 bits.
- Eight 8*32 S-boxes are present. Among these eight boxes, four are utilised for scheduling keys, while the remaining four are used for encryption.
- 37 bits are the round keys.
- The F function divides the output into bytes, XORs the input with 32 bits of round key, and then passes each byte through a separate S-box to get four 32-bit results.
- In different rounds, those are nonlinearly mixed using various combining functions.
- Five more round key bits are used to control the rotation of the output.
Implementation using Python
For implementing the CAST5 encryption algorithm we will use Crypto.Cipher submodule of Python which is used to implement for both encryption and decryption of a wide range of cryptographic techniques. To use this module we need to install the pycryptodome library first which provides various cryptographic algorithms.
The implementation of CAST5 Algorithm using Crypto.Cipher is as follows −
Example
from Crypto.Cipher import CAST #Encryption function def encrypt(plaintext, key): cipher = CAST.new(key, CAST.MODE_ECB) # Ensure plaintext is a multiple of 8 bytes (64 bits) if len(plaintext) % 8 != 0: plaintext += '' '' * (8 - len(plaintext) % 8) ciphertext = cipher.encrypt(plaintext.encode(''utf-8'')) return ciphertext.hex() #Decryption function def decrypt(ciphertext, key): cipher = CAST.new(key, CAST.MODE_ECB) decrypted = cipher.decrypt(bytes.fromhex(ciphertext)) return decrypted.decode(''utf-8'').rstrip() # Plaintext message: plaintext = "Hello, this is a test message for CAST5 encryption." key = b''0123456789abcdef'' # 16 bytes (128 bits) key encrypted_text = encrypt(plaintext, key) print("Encrypted:", encrypted_text) decrypted_text = decrypt(encrypted_text, key) print("Decrypted:", decrypted_text)
Following is the output of the above example −
Input/Output
Encrypted: c9c8791f5b73c78e5fbf3c47c7d43be7a773cf757c98d2b35073e2a4d5f454f9c9b9bce4416016b57a1872ef1c19e3f51a778be27a17f11 Decrypted: Hello, this is a test message for CAST5 encryption.
Advantages of CAST5
CAST5 has a number of advantages −
- It is thought that CAST5 is secure. Despite being an older algorithm, there are not many hacks or security breaches. It makes use of a Feistel network structure to increase security.
- For memory usage and computational capability, CAST5 offers a reasonable level of efficiency. Efficient data encryption and decryption make it suitable for scenarios where speed is important.
- CAST5 is not based on any specific hardware or software configuration. It can be used on a range of operating systems and architectures without change because it is implemented in software.
- CAST5 has key sizes ranging from 40 to 128 bits, allowing users to choose the degree of security appropriate for a particular application. By enabling encryption and decryption with a single key, it simplifies key management.
- One can view the details of CAST5 because it is an open algorithm. This makes it trustworthy by allowing the cryptography community to examine and review it with one another.
Disadvantages of CAST5
CAST5 also has some limitations and disadvantages −
- CAST5 supports keys with lengths ranging from 40 to 128 bits. This flexibility allows for different levels of security, however the 40-bit minimum key length is considered to be inadequate for modern cryptographic standards. Longer keys provide more resilience to brute-force attacks.
- CAST5 operates on 64-bit blocks. Even while this was reasonable at the time the method was developed, in comparison to more modern block ciphers with larger block sizes, it is now seen as relatively little. This may lead to security problems, especially when encrypting large volumes of data.
- CAST5 may not provide the same level of security as more current encryption algorithms like AES (Advanced Encryption Standard), even if it has not been compromised in reality. More computer power and advances in cryptography can make older methods more vulnerable to attacks.
”;