From 8e5552606447f74938b60b75e84526d59d7769af Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Tue, 19 Jun 2012 00:08:35 -0500 Subject: Implemented encode-block and decode-block. --- src/clojure/foofs/blocks.clj | 21 +++++++++++++++++++++ src/clojure/foofs/crypto.clj | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/clojure/foofs/blocks.clj (limited to 'src') 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] -- cgit v1.2.3-18-g5258