[crypticl-cvs] CVS crypticl/src

tskogan tskogan at common-lisp.net
Mon Jan 22 22:45:32 UTC 2007


Update of /project/crypticl/cvsroot/crypticl/src
In directory clnet:/tmp/cvs-serv4482

Modified Files:
	utilities.lisp 
Log Message:
Add keyword option.


--- /project/crypticl/cvsroot/crypticl/src/utilities.lisp	2007/01/21 01:15:22	1.8
+++ /project/crypticl/cvsroot/crypticl/src/utilities.lisp	2007/01/22 22:45:32	1.9
@@ -35,13 +35,26 @@
       (setq integer (+ (* integer 256) (aref vector i))))
     integer))
 
-(defun integer-to-octet-vector (integer &key vector (start 0))
-  "Transforms positive integers to byte vector using big endian format. Assumes a byte is 8 bits. "      
+(defun integer-to-octet-vector (integer &key vector 
+                                             (start 0)
+                                             size)
+  "Transforms positive integers to byte vector using big endian/most
+significant byte first format.
+
+Parameters:
+size -- size of returned vector, prepadded with zero bytes if necessary.
+"      
+  (when (and size vector)
+    (assert (= size (length vector))))
   (let* ((required-length 
-	  ;; Special case for 0 because integer-length returns 0 then.
-	  (if (= integer 0)
-	      1   
-	    (ceiling (integer-length integer) 8)))
+          (cond 
+           (vector (length vector))
+           (size size)           
+           (t
+            ;; Special case for 0 because integer-length returns 0 then.
+            (if (= integer 0)
+                1   
+              (ceiling (integer-length integer) 8)))))
 	 (result (or vector
 		     (make-array required-length
 				 :element-type '(unsigned-byte 8)
@@ -59,6 +72,15 @@
     result))
 
 
+(defun int-as-octet-vector-add (ov n)
+  "Add n to octet vector ov."
+  (integer-to-octet-vector (+ (octet-vector-to-integer ov) n) :vector ov))
+
+(defun foo (data ctr)
+  (aes-crypt-octet-vector data #16(0) 'ctr nil ctr) 
+  (int-as-octet-vector-add ctr 1)
+  (hex data))
+
 (defun hex (ov)
   (octet-vector-to-hex-string ov))
 




More information about the Crypticl-cvs mailing list