SEED modes: CBC, CFB, OFB, and ECB
[Hazmat Home][Home]
SEED is a block symmetric key encryption methods which was developed by KISA (Korea Information Security Agency). It uses a 128-bit key and has a 16-round Feistel structure - and which splits the data into two 64-bit blocks, and where a 64-bit subkey is used for each round. SEED is easy to implement in both harwdware and software, and is memory efficient, along with being robust against side channel attacks. It has, in the past, been used in South Korea in the privacy of financial transactions.
|
Coding
The coding is:
import os from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding import sys message="Hello" mode=0 iv = os.urandom(16) if (len(sys.argv)>1): message=str(sys.argv[1]) if (len(sys.argv)>2): mode=int(sys.argv[2]) keysize=16 key = os.urandom(keysize) padder = padding.PKCS7(128).padder() unpadder = padding.PKCS7(128).unpadder() try: cipher = Cipher(algorithms.SEED(key), modes.CBC(iv)) if (mode==0): cipher = Cipher(algorithms.SEED(key), modes.CBC(iv)) if (mode==1): cipher = Cipher(algorithms.SEED(key), modes.OFB(iv)) if (mode==2): cipher = Cipher(algorithms.SEED(key), modes.CFB(iv)) if (mode==3): cipher = Cipher(algorithms.SEED(key), modes.ECB()) encryptor = cipher.encryptor() str=padder.update(message.encode())+padder.finalize() ciphertext = encryptor.update(str ) + encryptor.finalize() # Now decrypt decryptor = cipher.decryptor() rtn=unpadder.update(decryptor.update(ciphertext) + decryptor.finalize())+unpadder.finalize() print("Type:\t\t\t",cipher.algorithm.name) print("Mode:\t\t\t",cipher.mode.name) print("Message:\t\t",message) print("Message with padding:\t",str) print("\nKey:\t\t\t",key.hex()) print("IV:\t\t\t",iv.hex()) print("\nCipher:\t\t\t",ciphertext.hex()) print("Decrypt:\t\t",rtn.decode()) except Exception as msg: print(msg)
and a sample run:
Type: SEED Mode: CBC Message: Hello Message with padding: b'Hello\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b' Key: 9d151dbc82027467f78decaaf73cd068 IV: ce5e4116c1439cc2dfe9826152b5d3a8 Cipher: 8b938b7baa1b38611e28fabc13ecfd54 Decrypt: Hello