From 015e2d2492519c96dda7a310d888b29984e9fead Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 18 Feb 2012 19:07:39 -0500 Subject: Implementation of aes-ocb in python and javascript We can know easily encrypt directories in python, and generate objects in the alias format. --- crypto/ocb.js | 8 ++++++++ crypto/ocb.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 crypto/ocb.js create mode 100644 crypto/ocb.py (limited to 'crypto') diff --git a/crypto/ocb.js b/crypto/ocb.js new file mode 100644 index 0000000..d7d53aa --- /dev/null +++ b/crypto/ocb.js @@ -0,0 +1,8 @@ +load('sjcl.js') +var aeskey = sjcl.codec.hex.toBits('12538243c49f1c58e6f7b0687bbd65b2') +var iv = sjcl.codec.hex.toBits('250c3041c00a605a4100e264abbc588b') +plaintext = "La chaire est triste, hélas ! et j'ai lu tous les livres." +var secret = sjcl.encrypt(aeskey, plaintext,{mode:'ocb2', iv:iv, adata:"", tag:128}) +var secret2 = sjcl.json.decode(secret) +print(secret) +print(sjcl.codec.hex.fromBits(secret2.ct)) diff --git a/crypto/ocb.py b/crypto/ocb.py new file mode 100644 index 0000000..08814c7 --- /dev/null +++ b/crypto/ocb.py @@ -0,0 +1,28 @@ +#-*- coding: utf-8 -*- +from aespython import key_expander, aes_cipher, ocb_mode +import json +import base64 +def hex2byte(hexstring): + return map(ord, hexstring.decode("hex")) +def byte2hex(byteslist): + return str(bytearray(byteslist)).encode("hex") + +if __name__=="__main__": + KE = key_expander.KeyExpander(128) + key = hex2byte('12538243c49f1c58e6f7b0687bbd65b2') + expanded_key = KE.expand(key) + aes_cipher_128 = aes_cipher.AESCipher(expanded_key) + aes_ocb_128 = ocb_mode.OCBMode(aes_cipher_128, 16) + iv = hex2byte('250c3041c00a605a4100e264abbc588b') + aes_ocb_128.set_iv(iv) + plaintext = "La chaire est triste, hélas ! et j'ai lu tous les livres.".encode("hex") + header = "".encode("hex") + (tag,ciphertext) = aes_ocb_128.encrypt_block(hex2byte(plaintext), hex2byte(header)) + sjcl_object = {"iv": base64.b64encode(bytearray(iv)).rstrip("="), + "mode": "ocb2", + "tag": 128, + "ct": base64.b64encode(bytearray(ciphertext) + + bytearray(tag)).rstrip("=") + } + print json.dumps(sjcl_object) + -- cgit v1.2.3-70-g09d2