diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/foofs/blocks.clj | 21 | ||||
-rw-r--r-- | src/clojure/foofs/crypto.clj | 4 |
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] |