[Nym3-commit] r8 - trunk/crypto

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Thu, 29 Apr 2004 19:46:08 +0200


Author: dybbuk
Date: 2004-04-29 19:46:07 +0200 (Thu, 29 Apr 2004)
New Revision: 8

Modified:
   trunk/crypto/test.ml
Log:
Ah, the tests now correctly parse the new test vector format, and now we can try to find my OAEP encoding bug.  (Would it be faster to scrap all of this and write OpenSSL bindings?  Perhaps.  Would it be as painfully fun?  Never!)


Modified: trunk/crypto/test.ml
===================================================================
--- trunk/crypto/test.ml	2004-04-29 16:44:54 UTC (rev 7)
+++ trunk/crypto/test.ml	2004-04-29 17:46:07 UTC (rev 8)
@@ -33,9 +33,17 @@
    encoded data in RSA Security's test vectors. *)
 
 let reader is =
-  try
-    Some (input_line is)
-  with _ -> None
+  let prune_cr str =
+    let last_idx = (String.length str) - 1 in
+      if str.[last_idx] = '\r' then
+        String.sub str 0 last_idx
+      else
+        str
+  in
+    try
+      Some (prune_cr (input_line is))
+    with
+        End_of_file -> None
 
 let wipe_key key size =
   key.size <- size;
@@ -113,6 +121,7 @@
      val read_number: in_channel -> string
      val decipher_line: string -> in_channel -> temp_key -> unit
    end) = struct
+
     let rec process_file accu is =
       match reader is with
 	  Some(line) ->
@@ -138,9 +147,9 @@
       aux ""
 	
   let nk_regx = Str.regexp 
-		  "^# Example +\\([0-9]+\\): A \\([0-9]+\\)-bit RSA Key Pair"
+		  "^# Example +\\([0-9]+\\): A \\([0-9]+\\)-bit RSA key pair"
   let ex_regx = Str.regexp 
-		  "^# RSAES-OAEP Encryption Example \\(.*\\)"
+		  "^# OAEP Example \\(.*\\)"
 
   let decipher_line line is key =
     if (Str.string_match nk_regx line 0) then (
@@ -154,32 +163,34 @@
       if (String.length key.cipher) > 0 then
 	run_tests key
       else ();
-      Printf.printf "# Tests for example %s\n" (Str.matched_group 1 line);
+      Printf.printf "# Tests for example %s (%d-bit)\n" (Str.matched_group 1 line) key.size;
     )
     else
       match line with
-	  "# CRT coefficient qInv: " ->
-	    key.qinv <- read_number is;
+        (* First set matches our test message *)
 	| "# Encryption:" ->
 	    key.cipher <- read_number is
-	| "# Message to be encrypted:" ->
+	| "# Message:" ->
 	    key.message <- read_number is
-	| "# Prime p: " ->
+	| "# Seed:" -> 
+	    key.seed <- read_number is
+        (* This set matches our test key. *)
+	| "# Modulus: " ->
+	    key.n <- read_number is
+	| "# Public exponent: " ->
+	    key.e <- read_number is
+        | "# Exponent: " ->
+            key.d <- read_number is
+	| "# Prime 1: " ->
 	    key.p <- read_number is
-	| "# Prime q: " ->
+	| "# Prime 2: " ->
 	    key.q <- read_number is
-	| "# RSA modulus n:" ->
-	    key.n <- read_number is
-	| "# RSA private exponent d: " ->
-	    key.d <- read_number is
-	| "# RSA public exponent e: " ->
-	    key.e <- read_number is
-	| "# Seed:" -> 
-	    key.seed <- read_number is
-	| "# p's CRT exponent dP: " ->
+	| "# Prime exponent 1: " ->
 	    key.dp <- read_number is
-	| "# q's CRT exponent dQ: " ->
+	| "# Prime exponent 2: " ->
 	    key.dq <- read_number is
+	| "# Coefficient: " ->
+	    key.qinv <- read_number is;
 	| _ -> ()
 
 end