aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ocb.js8
-rw-r--r--crypto/ocb.py28
2 files changed, 36 insertions, 0 deletions
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)
+