aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ocb.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2012-02-18 19:07:39 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2012-02-18 19:07:39 -0500
commit015e2d2492519c96dda7a310d888b29984e9fead (patch)
treeb199b61932450a047a7f10ddac30b32086ee131b /crypto/ocb.py
parent96dd59f2a302495387999c09ced5e70e85dd82f3 (diff)
downloadalias-015e2d2492519c96dda7a310d888b29984e9fead.tar.gz
Implementation of aes-ocb in python and javascript
We can know easily encrypt directories in python, and generate objects in the alias format.
Diffstat (limited to 'crypto/ocb.py')
-rw-r--r--crypto/ocb.py28
1 files changed, 28 insertions, 0 deletions
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)
+