[LON-CAPA-cvs] cvs: loncom /auth londes.js
www
lon-capa-cvs@mail.lon-capa.org
Sat, 23 Mar 2002 11:27:41 -0000
www Sat Mar 23 06:27:41 2002 EDT
Modified files:
/loncom/auth londes.js
Log:
Due to potentially buggy JavaScript implementations, need to bring back
self-test
Index: loncom/auth/londes.js
diff -u loncom/auth/londes.js:1.3 loncom/auth/londes.js:1.4
--- loncom/auth/londes.js:1.3 Sat Mar 23 05:34:48 2002
+++ loncom/auth/londes.js Sat Mar 23 06:27:41 2002
@@ -3,7 +3,7 @@
// Encryption Routines according to Data Encryption Standard DES
// Federal Information Processing Standards Publication 46-2 (1993 Dec 30)
//
-// $Id: londes.js,v 1.3 2002/03/23 10:34:48 www Exp $
+// $Id: londes.js,v 1.4 2002/03/23 11:27:41 www Exp $
//
// Copyright Michigan State University Board of Trustees
//
@@ -140,6 +140,104 @@
for (i=0;i<=47;i++) {
etarr[i]=parseInt(et.substring(i*2,i*2+2));
}
+
+// Selftest
+ window.status="Self test";
+
+// Primitive test, "Cryptography: A New Dimension in Computer Security"
+// C.H. Meyer, S.M. Matyas, John Wiley and Sons, 1982, pg. 160
+
+ uextkey=0x1234567;
+ lextkey=bit[31]|0x9abcdef;
+ ublock=uextkey;
+ lblock=lextkey;
+ ip();
+ if (hexstring(lv)!='cc00ccff') { alert("IP failed: lv."); }
+ if (hexstring(rv)!='f0aaf0aa') { alert("IP failed: rv."); }
+ initkeys();
+ if (hexstring(uk[1])!='000b0267') { alert("Key generation failed: uk"); }
+ if (hexstring(lk[1])!='009b49a5') { alert("Key generation failed: lk"); }
+ stage(1);
+ if (hexstring(uexpand)!='007a1555') { alert("E failed: u"); }
+ if (hexstring(lexpand)!='007a1555') { alert("E failed: l"); }
+ if (hexstring(rv)!='921c209c') { alert("Stage 1 failed"); }
+
+// According to National Bureau of Standards, Special Publication 500-20,
+// "Validating the Correctness of Hardware Implementations of the
+// NBS Data Encryption Standard", Rev. Sep. 1980.
+
+// PC-1 and PC-2 test
+ ublock=0;
+ lblock=0;
+ uextkey=0x1010101;
+ lextkey=0x1010102;
+ initkeys();
+ encrypt();
+ var st=hexstring(ublock);
+ st+=hexstring(lblock);
+ if (st!="869efd7f9f265a09") {
+ st+=": failed PC-1 and PC-2 test!";
+ alert(st);
+ }
+ window.status="Self test .";
+
+// According to NBS 500-20 IP and E test
+ ublock=bit[28]|0x66b40b4;
+ lblock=bit[30]|0xaba4bd6;
+ uextkey=0x1010101;
+ lextkey=0x1010101;
+ initkeys();
+ encrypt();
+ var st=hexstring(ublock);
+ st+=hexstring(lblock);
+ if (st!="0000000000000001") {
+ st+=": failed IP and E test!";
+ alert(st);
+ }
+ window.status="Self test ..";
+
+// According to NBS 500-20 ptest
+ ublock=0;
+ lblock=0;
+ uextkey=bit[28]|0x29116;
+ lextkey=bit[31]|bit[28]|0x8100101;
+ initkeys();
+ encrypt();
+ var st=hexstring(ublock);
+ st+=hexstring(lblock);
+ if (st!="1aeac39a61f0a464") {
+ st+=": failed ptest!";
+ alert(st);
+ }
+ window.status="Self test ...";
+
+// According to NBS 500-20 S-box test
+ ublock=bit[28]|bit[29]|0x553228;
+ lblock=bit[29]|bit[30]|0xd6f295a;
+ var orgu=ublock;
+ var orgl=lblock;
+ uextkey=bit[28]|0xc587f1c;
+ lextkey=bit[28]|0x3924fef;
+ initkeys();
+ encrypt();
+ var st=hexstring(ublock);
+ st+=hexstring(lblock);
+ if (st!="63fac0d034d9f793") {
+ st+=": failed S-box test!";
+ alert(st);
+ }
+ window.status="Self test ....";
+
+// Decryption test
+ decrypt();
+ if (ublock!=orgu) { alert("Decryption failed for ublock."); }
+ if (lblock!=orgl) { alert("Decryption failed for lblock."); }
+ window.status="Self test .....";
+
+// Reset keys
+
+ uextkey=0;
+ lextkey=0;
window.status="Ready.";
}