aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2012-06-19 00:08:35 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2012-06-19 00:08:35 -0500
commit8e5552606447f74938b60b75e84526d59d7769af (patch)
treec1b6120a0c3b864fa9e9f50419219ee94db3a492 /src
parentf8cc00d3a2dcbd8752fca1add8a6667d8f1c9179 (diff)
Implemented encode-block and decode-block.
Diffstat (limited to 'src')
-rw-r--r--src/clojure/foofs/blocks.clj21
-rw-r--r--src/clojure/foofs/crypto.clj4
2 files changed, 23 insertions, 2 deletions
diff --git a/src/clojure/foofs/blocks.clj b/src/clojure/foofs/blocks.clj
new file mode 100644
index 0000000..01cea6d
--- /dev/null
+++ b/src/clojure/foofs/blocks.clj
@@ -0,0 +1,21 @@
+(ns foofs.blocks
+ (:use foofs.crypto))
+
+(def aes-key-size 32)
+(def aes-iv-size 16)
+
+(defn encode-block
+ [f-block seed]
+ (let [e-key (sha-512 f-block)
+ aes-key (make-aes-key (take aes-key-size e-key))
+ iv (make-aes-iv (take aes-iv-size (concat seed (repeat 0))))
+ e-block (aes-encrypt aes-key iv f-block)
+ e-hash (sha-512 e-block)]
+ [e-key e-hash e-block]))
+
+(defn decode-block
+ [e-block e-key seed]
+ (let [aes-key (make-aes-key (take aes-key-size e-key))
+ iv (make-aes-iv (take aes-iv-size (concat seed (repeat 0))))
+ f-block (aes-decrypt aes-key iv e-block)]
+ f-block))
diff --git a/src/clojure/foofs/crypto.clj b/src/clojure/foofs/crypto.clj
index 976b421..a7fd60e 100644
--- a/src/clojure/foofs/crypto.clj
+++ b/src/clojure/foofs/crypto.clj
@@ -1,8 +1,8 @@
(ns foofs.crypto
- (:use foofs.bytebuffer)
+ (:use foofs.fuse.bytebuffer)
(:import java.security.MessageDigest
javax.crypto.Cipher
- (javax.crypto.spec IVParameterSpec SecretKeySpec)))
+ (javax.crypto.spec IvParameterSpec SecretKeySpec)))
(defn sha-512
[message]