This is an automated email from the ASF dual-hosted git repository. kmccusker pushed a commit to branch issue7 in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-js.git
commit 65f4b6bc0b3d327c0716a9606fac8872882eb298 Author: Kealan McCusker <[email protected]> AuthorDate: Wed Jun 26 14:43:04 2019 +0100 removed some brower tests --- examples/browser/example_AES_ENCRYPTION.html | 149 ----------- examples/browser/example_DVS_BLS381.html | 162 ------------ examples/browser/example_ECC_BLS381_NIST521.html | 217 ---------------- examples/browser/example_ECC_NIST256.html | 201 --------------- examples/browser/example_HASH.html | 115 --------- examples/browser/example_MPIN_BLS381.html | 224 ----------------- examples/browser/example_MPIN_FULL_BLS381.html | 272 --------------------- examples/browser/example_MPIN_ONE_PASS_BLS381.html | 228 ----------------- examples/browser/example_MPIN_TP_BLS381.html | 210 ---------------- .../browser/example_RSA2048_ECDSA_NIST256.html | 211 ---------------- examples/browser/example_RSA2048_GENKEY.html | 176 ------------- 11 files changed, 2165 deletions(-) diff --git a/examples/browser/example_AES_ENCRYPTION.html b/examples/browser/example_AES_ENCRYPTION.html deleted file mode 100644 index 288ce63..0000000 --- a/examples/browser/example_AES_ENCRYPTION.html +++ /dev/null @@ -1,149 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test HASH function - test driver and function exerciser for SHA256, SHA384, SHA512 API Functions */ - - -var ctx = new CTX(); - -var bytestostring = function(b) { - var s = ""; - var len = b.length; - var ch; - - for (var i = 0; i < len; i++) { - ch = b[i]; - s += ((ch >>> 4) & 15).toString(16); - s += (ch & 15).toString(16); - } - - return s; -}; - -var hextobytes = function(value_hex) { - // "use strict"; - var len, byte_value, i; - - len = value_hex.length; - byte_value = []; - - for (i = 0; i < len; i += 2) { - byte_value[(i / 2)] = parseInt(value_hex.substr(i, 2), 16); - } - - return byte_value; -}; - -var AES_ENCRYPT = function(mode, K, M) { - /* Input is from an octet string M, output is to an octet string C */ - /* Input is padded as necessary to make up a full final block */ - var a = new ctx.AES(); - var fin; - var i, j, ipt, opt; - var buff = []; - /*var clen=16+(Math.floor(M.length/16))*16;*/ - - var C = []; - var padlen; - - a.init(mode, K.length, K, null); - - ipt = opt = 0; - fin = false; - for (;;) { - for (i = 0; i < 16; i++) { - if (ipt < M.length) { - buff[i] = M[ipt++]; - } else { - fin = true; - break; - } - } - if (fin) { - break; - } - a.encrypt(buff); - for (i = 0; i < 16; i++) { - C[opt++] = buff[i]; - } - } - - /* last block, filled up to i-th index */ - - padlen = 16 - i; - for (j = i; j < 16; j++) { - buff[j] = padlen; - } - a.encrypt(buff); - for (i = 0; i < 16; i++) { - C[opt++] = buff[i]; - } - a.end(); - return C; -}; - -var KEY = "edfdb257cb37cdf182c5455b0c0efebb"; - -console.log("Encryption Key: ", KEY); - -var PLAINTEXT = "1695fe475421cace3557daca01f445ff"; - -console.log("Plaintext: ", PLAINTEXT); - -var Cout = AES_ENCRYPT(ctx.AES.ECB, hextobytes(KEY), hextobytes(PLAINTEXT)); - -console.log("Ciphertext: ", bytestostring(Cout)); -</script> -</body> -</html> diff --git a/examples/browser/example_DVS_BLS381.html b/examples/browser/example_DVS_BLS381.html deleted file mode 100644 index ad11117..0000000 --- a/examples/browser/example_DVS_BLS381.html +++ /dev/null @@ -1,162 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test DVS - test driver and function exerciser for Designated Verifier Signature API Functions */ - - -var ctx = new CTX("BLS381"); - -var RAW = []; -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var res; - -var S = []; -var SST = []; -var TOKEN = []; -var SEC = []; -var xID = []; -var X = []; -var Y1 = []; -var Y2 = []; -var Z = []; -var Pa = []; -var U = []; - -var sha = ctx.ECP.HASH_TYPE; - -/* Trusted Authority set-up */ -ctx.MPIN.RANDOM_GENERATE(rng, S); -console.log("M-Pin Master Secret s: 0x" + ctx.MPIN.bytestostring(S)); - -/* Create Client Identity */ -var IDstr = "[email protected]"; -var CLIENT_ID = ctx.MPIN.stringtobytes(IDstr); - -console.log("Client ID= " + ctx.MPIN.bytestostring(CLIENT_ID)); - -/* Generate random public key and z */ -res = ctx.MPIN.GET_DVS_KEYPAIR(rng, Z, Pa); -if (res != 0) { - console.log("Can't generate DVS keypair, error ", res); -} - -console.log("Z: 0x" + ctx.MPIN.bytestostring(Z)); -console.log("Pa: 0x" + ctx.MPIN.bytestostring(Pa)); - -/* Append Pa to ID */ -for (var i = 0; i < Pa.length; i++) { - CLIENT_ID.push(Pa[i]); -} -console.log("ID|Pa: 0x" + ctx.MPIN.bytestostring(CLIENT_ID)); -/* Hash Client ID */ -var HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - -/* Client and Server are issued secrets by DTA */ -ctx.MPIN.GET_SERVER_SECRET(S, SST); -console.log("Server Secret SS: 0x" + ctx.MPIN.bytestostring(SST)); - -ctx.MPIN.GET_CLIENT_SECRET(S, HCID, TOKEN); -console.log("Client Secret CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Compute client secret for key escrow less scheme z.CS */ -res = ctx.MPIN.GET_G1_MULTIPLE(null, 0, Z, TOKEN, TOKEN); -if (res != 0) { - console.log("Failed to compute z.CS, error ", res); -} -console.log("z.CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Client extracts PIN from secret to create Token */ -var pin = 1234; -console.log("Client extracts PIN= " + pin); -res = ctx.MPIN.EXTRACT_PIN(sha, CLIENT_ID, pin, TOKEN); -if (res != 0) { - console.log("Failed to extract PIN, Error: ", res); -} - -console.log("Client Token TK: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -var timeValue = ctx.MPIN.GET_TIME(); - -var message = "Message to sign"; - -res = ctx.MPIN.CLIENT(sha, 0, CLIENT_ID, rng, X, pin, TOKEN, SEC, U, null, null, timeValue, Y1, message); -if (res != 0) { - console.log("Failed to extract PIN, error ", res); -} - -console.log("U: 0x" + ctx.MPIN.bytestostring(U)); - -console.log("Y1: 0x" + ctx.MPIN.bytestostring(Y1)); -console.log("V: 0x" + ctx.MPIN.bytestostring(SEC)); - -/* Server */ -res = ctx.MPIN.SERVER(sha, 0, xID, null, Y2, SST, U, null, SEC, null, null, CLIENT_ID, timeValue, message, Pa); -console.log("Y2: 0x" + ctx.MPIN.bytestostring(Y2)); - -if (res != 0) { - console.log("FAILURE Signature Verification, error", res); -} else { - console.log("SUCCESS Error Code ", res); -} - -</script> -</body> -</html> diff --git a/examples/browser/example_ECC_BLS381_NIST521.html b/examples/browser/example_ECC_BLS381_NIST521.html deleted file mode 100644 index 43a4057..0000000 --- a/examples/browser/example_ECC_BLS381_NIST521.html +++ /dev/null @@ -1,217 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - - -/* Test ECC - test driver and function exerciser for ECDH/ECIES/ECDSA API Functions */ - - -var ctx1 = new CTX("BLS381"); -var ctx2 = new CTX("NIST521"); - -console.log("Start testing BLS381"); - -var pp = "M0ng00se", - res, - i; - -var S1 = []; -var W0 = []; -var W1 = []; -var Z0 = []; -var Z1 = []; -var RAW = []; -var SALT = []; - -var rng = new ctx1.RAND(); - -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - - -for (i = 0; i < 8; i++) { - SALT[i] = (i + 1); -} // set Salt - -console.log("Alice's Passphrase= " + pp); - -var PW = ctx1.ECDH.stringtobytes(pp); -// private key S0 of size EGS bytes derived from Password and Salt -var S0 = ctx1.ECDH.PBKDF2(ctx1.ECP.HASH_TYPE, PW, SALT, 1000, ctx1.ECP.AESKEY); - -console.log("Alice's private key= 0x" + ctx1.ECDH.bytestostring(S0)); -// Generate Key pair S/W -ctx1.ECDH.KEY_PAIR_GENERATE(null, S0, W0); - -//console.log("Alice's public key= 0x" + ctx1.ECDH.bytestostring(W0)); - -res = ctx1.ECDH.PUBLIC_KEY_VALIDATE(W0); -if (res != 0) { - console.error("ECP_ZZZ Public Key is invalid!"); -} -// Random private key for other party -ctx1.ECDH.KEY_PAIR_GENERATE(rng, S1, W1); - -console.log("Servers private key= 0x" + ctx1.ECDH.bytestostring(S1)); -//console.log("Servers public key= 0x" + ctx1.ECDH.bytestostring(W1)); - -res = ctx1.ECDH.PUBLIC_KEY_VALIDATE(W1); -if (res != 0) { - console.error("ECP_ZZZ Public Key is invalid!"); -} - -// Calculate common key using DH - IEEE 1363 method - -ctx1.ECDH.ECPSVDP_DH(S0, W1, Z0); -ctx1.ECDH.ECPSVDP_DH(S1, W0, Z1); - -var same = true; -for (i = 0; i < ctx1.ECDH.EFS; i++) { - if (Z0[i] != Z1[i]) { - same = false; - } -} - -if (!same) { - console.error("ECP_ZZZSVDP-DH Failed"); -} - -var KEY = ctx1.ECDH.KDF2(ctx1.ECP.HASH_TYPE, Z0, null, ctx1.ECP.AESKEY); - -console.log("Alice's ECDH Key= 0x" + ctx1.ECDH.bytestostring(KEY)); -console.log("Servers ECDH Key= 0x" + ctx1.ECDH.bytestostring(KEY)); - - -console.log("\ntart testing NIST251"); - -var i, - res; -var pp = "M0ng00se"; - -var S1 = []; -var W0 = []; -var W1 = []; -var Z0 = []; -var Z1 = []; -var RAW = []; -var SALT = []; - -var rng = new ctx2.RAND(); - -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -for (i = 0; i < 8; i++) { - SALT[i] = (i + 1); -} // set Salt - -console.log("Alice's Passphrase= " + pp); - -var PW = ctx2.ECDH.stringtobytes(pp); -// private key S0 of size EGS bytes derived from Password and Salt -var S0 = ctx2.ECDH.PBKDF2(ctx2.ECP.HASH_TYPE, PW, SALT, 1000, ctx1.ECDH.EGS); - -console.log("Alice's private key= 0x" + ctx2.ECDH.bytestostring(S0)); -// Generate Key pair S/W -ctx2.ECDH.KEY_PAIR_GENERATE(null, S0, W0); - -//console.log("Alice's public key= 0x" + ctx2.ECDH.bytestostring(W0)); - -res = ctx2.ECDH.PUBLIC_KEY_VALIDATE(W0); -if (res != 0) { - console.error("ECP_ZZZ Public Key is invalid!"); -} -// Random private key for other party -ctx2.ECDH.KEY_PAIR_GENERATE(rng, S1, W1); - -console.log("Servers private key= 0x" + ctx2.ECDH.bytestostring(S1)); -//console.log("Servers public key= 0x" + ctx2.ECDH.bytestostring(W1)); - -res = ctx2.ECDH.PUBLIC_KEY_VALIDATE(W1); -if (res != 0) { - console.error("ECP_ZZZ Public Key is invalid!"); -} - -// Calculate common key using DH - IEEE 1363 method - -ctx2.ECDH.ECPSVDP_DH(S0, W1, Z0); -ctx2.ECDH.ECPSVDP_DH(S1, W0, Z1); - -var same = true; -for (i = 0; i < ctx2.ECDH.EFS; i++) { - if (Z0[i] != Z1[i]) { - same = false; - } -} - -if (!same) { - console.error("ECP_ZZZSVDP-DH Failed"); -} - -var KEY = ctx2.ECDH.KDF2(ctx2.ECP.HASH_TYPE, Z0, null, ctx2.ECP.AESKEY); - -console.log("Alice's ECDH Key= 0x" + ctx2.ECDH.bytestostring(KEY)); -console.log("Servers ECDH Key= 0x" + ctx2.ECDH.bytestostring(KEY)); - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_ECC_NIST256.html b/examples/browser/example_ECC_NIST256.html deleted file mode 100644 index fec675f..0000000 --- a/examples/browser/example_ECC_NIST256.html +++ /dev/null @@ -1,201 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - - -/* Test ECC - test driver and function exerciser for ECDH/ECIES/ECDSA API Functions */ - - -console.log("Start testing ECDH with NIST256"); - -var ctx = new CTX("NIST256"); - -var i, - res; -var pp = "M0ng00se"; - -var EGS = ctx.ECP.AESKEY; -var sha = ctx.ECP.HASH_TYPE; - -var S1 = []; -var W0 = []; -var W1 = []; -var Z0 = []; -var Z1 = []; -var RAW = []; -var SALT = []; -var P1 = []; -var P2 = []; -var V = []; -var M = []; -var T = new Array(12); // must specify required length -var CS = []; -var DS = []; - -var rng = new ctx.RAND(); - -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - - -for (i = 0; i < 8; i++) { - SALT[i] = (i + 1); -} // set Salt - -console.log("Alice's Passphrase= " + pp); - -var PW = ctx.ECDH.stringtobytes(pp); -// private key S0 of size EGS bytes derived from Password and Salt -var S0 = ctx.ECDH.PBKDF2(sha, PW, SALT, 1000, EGS); - -console.log("Alice's private key= 0x" + ctx.ECDH.bytestostring(S0)); -// Generate Key pair S/W -ctx.ECDH.KEY_PAIR_GENERATE(null, S0, W0); - -console.log("Alice's public key= 0x" + ctx.ECDH.bytestostring(W0)); - -res = ctx.ECDH.PUBLIC_KEY_VALIDATE(W0); -if (res != 0) { - console.error("ECP Public Key is invalid!"); -} -// Random private key for other party -ctx.ECDH.KEY_PAIR_GENERATE(rng, S1, W1); - -console.log("Servers private key= 0x" + ctx.ECDH.bytestostring(S1)); -console.log("Servers public key= 0x" + ctx.ECDH.bytestostring(W1)); - -res = ctx.ECDH.PUBLIC_KEY_VALIDATE(W1); -if (res != 0) { - console.error("ECP Public Key is invalid!"); -} - -// Calculate common key using DH - IEEE 1363 method - -ctx.ECDH.ECPSVDP_DH(S0, W1, Z0); -ctx.ECDH.ECPSVDP_DH(S1, W0, Z1); - -var same = true; -for (i = 0; i < ctx.ECDH.EFS; i++) { - if (Z0[i] != Z1[i]) { - same = false; - } -} - -if (!same) { - console.error("ECPSVDP-DH Failed"); -} - -var KEY = ctx.ECDH.KDF2(sha, Z0, null, ctx.ECDH.EAS); - -console.log("Alice's ECDH Key= 0x" + ctx.ECDH.bytestostring(KEY)); -console.log("Servers ECDH Key= 0x" + ctx.ECDH.bytestostring(KEY)); - -if (ctx.ECP.CURVETYPE != ctx.ECP.MONTGOMERY) { - console.log("Testing ECIES"); - - P1[0] = 0x0; - P1[1] = 0x1; - P1[2] = 0x2; - P2[0] = 0x0; - P2[1] = 0x1; - P2[2] = 0x2; - P2[3] = 0x3; - - for (i = 0; i <= 16; i++) { - M[i] = i; - } - - var C = ctx.ECDH.ECIES_ENCRYPT(sha, P1, P2, rng, W1, M, V, T); - - console.log("Ciphertext= "); - console.log("V= 0x" + ctx.ECDH.bytestostring(V)); - console.log("C= 0x" + ctx.ECDH.bytestostring(C)); - console.log("T= 0x" + ctx.ECDH.bytestostring(T)); - - - M = ctx.ECDH.ECIES_DECRYPT(sha, P1, P2, V, C, T, S1); - if (M.length == 0) { - console.error("ECIES Decryption Failed"); - } else { - console.log("Decryption succeeded"); - } - - console.log("Message is 0x" + ctx.ECDH.bytestostring(M)); - - console.log("Testing ECDSA"); - - if (ctx.ECDH.ECPSP_DSA(sha, rng, S0, M, CS, DS) != 0) { - console.error("ECDSA Signature Failed"); - } - - console.log("Signature= "); - console.log("C= 0x" + ctx.ECDH.bytestostring(CS)); - console.log("D= 0x" + ctx.ECDH.bytestostring(DS)); - - if (ctx.ECDH.ECPVP_DSA(sha, W0, M, CS, DS) != 0) { - console.error("ECDSA Verification Failed"); - } else { - console.log("ECDSA Signature/Verification succeeded"); - } -} - -rng.clean(); - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_HASH.html b/examples/browser/example_HASH.html deleted file mode 100644 index 60754a4..0000000 --- a/examples/browser/example_HASH.html +++ /dev/null @@ -1,115 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Example Hash functions */ - - -var ctx = new CTX(); - -var bytestostring = function(b) { - var s = ""; - var len = b.length; - var ch; - - for (var i = 0; i < len; i++) { - ch = b[i]; - s += ((ch >>> 4) & 15).toString(16); - s += (ch & 15).toString(16); - } - return s; -}; - -var stringtobytes = function(s) { - var b = []; - for (var i = 0; i < s.length; i++) { - b.push(s.charCodeAt(i)); - } - return b; -}; - -var hashit = function(sha, B) { - var R = [], - H; - - if (sha == ctx.HASH256.len) { - H = new ctx.HASH256(); - } else if (sha == ctx.HASH384.len) { - H = new ctx.HASH384(); - } else if (sha == ctx.HASH512.len) { - H = new ctx.HASH512(); - } - - H.process_array(B); - R = H.hash(); - - if (R.length == 0) { - return null; - } - - return R; -}; - -var to_hash = "test hash"; - -console.log("String to hash: ", to_hash); - -var hashed = hashit(ctx.HASH256.len, stringtobytes(to_hash)); -console.log("SHA256: ", bytestostring(hashed)); -hashed = hashit(ctx.HASH384.len, stringtobytes(to_hash)); -console.log("SHA384: ", bytestostring(hashed)); -hashed = hashit(ctx.HASH512.len, stringtobytes(to_hash)); -console.log("SHA512: ", bytestostring(hashed)); -</script> -</body> -</html> diff --git a/examples/browser/example_MPIN_BLS381.html b/examples/browser/example_MPIN_BLS381.html deleted file mode 100644 index 08d54cd..0000000 --- a/examples/browser/example_MPIN_BLS381.html +++ /dev/null @@ -1,224 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test MPIN - test driver and function exerciser for MPIN API Functions */ - - -var ctx = new CTX("BLS381"); - -/* Test M-Pin */ - -var RAW = []; -var i; -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var sha = ctx.ECP.HASH_TYPE; - -var S = []; -var SST = []; -var TOKEN = []; -var PERMIT = []; -var SEC = []; -var xID = []; -var xCID = []; -var X = []; -var Y = []; -var E = []; -var F = []; -var HCID = []; -var HID = []; -var HTID = []; - -/* Set configuration */ -var PINERROR = true; -var ONE_PASS = false; - -/* Trusted Authority set-up */ -ctx.MPIN.RANDOM_GENERATE(rng, S); -console.log("M-Pin Master Secret s: 0x" + ctx.MPIN.bytestostring(S)); - -/* Create Client Identity */ -var IDstr = "[email protected]"; -var CLIENT_ID = ctx.MPIN.stringtobytes(IDstr); -HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); /* Either Client or TA calculates Hash(ID) - you decide! */ - -console.log("Client ID= " + ctx.MPIN.bytestostring(CLIENT_ID)); - -/* Client and Server are issued secrets by DTA */ -ctx.MPIN.GET_SERVER_SECRET(S, SST); -console.log("Server Secret SS: 0x" + ctx.MPIN.bytestostring(SST)); - -ctx.MPIN.GET_CLIENT_SECRET(S, HCID, TOKEN); -console.log("Client Secret CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Client extracts PIN from secret to create Token */ -var pin = 1234; -console.log("Client extracts PIN= " + pin); -var rtn = ctx.MPIN.EXTRACT_PIN(sha, CLIENT_ID, pin, TOKEN); -if (rtn != 0) { - console.log("Failed to extract PIN "); -} - -console.log("Client Token TK: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -var date = 0; - -pin = 1234; - -/* Set date=0 and PERMIT=null if time permits not in use - -Client First pass: Inputs CLIENT_ID, optional RNG, pin, TOKEN and PERMIT. Output xID = x.H(CLIENT_ID) and re-combined secret SEC -If PERMITS are is use, then date!=0 and PERMIT is added to secret and xCID = x.(H(CLIENT_ID)+H_T(date|H(CLIENT_ID))) -ctx.RANDom value x is supplied externally if RNG=null, otherwise generated and passed out by RNG - -If Time Permits OFF set xCID = null, HTID=null and use xID and HID only -If Time permits are ON, AND pin error detection is required then all of xID, xCID, HID and HTID are required -If Time permits are ON, AND pin error detection is NOT required, set xID=null, HID=null and use xCID and HTID only. - - -*/ -var pxID = xID; -var pxCID = xCID; -var pHID = HID; -var pHTID = HTID; -var pE = E; -var pF = F; -var pPERMIT = PERMIT; - -if (date != 0) { - if (!PINERROR) { - pxID = null; - // pHID=null; - } -} else { - pPERMIT = null; - pxCID = null; - pHTID = null; -} - -if (!PINERROR) { - pE = null; - pF = null; -} - -if (ONE_PASS) { - console.log("MPIN Single Pass "); - var timeValue = ctx.MPIN.GET_TIME(); - console.log("Epoch " + timeValue); - - rtn = ctx.MPIN.CLIENT(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT, timeValue, Y); - - if (rtn != 0) { - console.error("FAILURE: CLIENT rtn: " + rtn); - process.exit(-1); - } - rtn = ctx.MPIN.SERVER(sha, date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF, CLIENT_ID, timeValue); - if (rtn != 0) { - console.error("FAILURE: SERVER rtn: " + rtn); - process.exit(-1); - } -} else { - console.log("MPIN Multi Pass "); - rtn = ctx.MPIN.CLIENT_1(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT); - if (rtn != 0) { - console.error("FAILURE: CLIENT_1 rtn: " + rtn); - process.exit(-1); - } - - /* Server calculates H(ID) and H(T|H(ID)) (if time permits enabled), and maps them to points on the curve HID and HTID resp. */ - ctx.MPIN.SERVER_1(sha, date, CLIENT_ID, pHID, pHTID); - - /* Server generates ctx.RANDom number Y and sends it to Client */ - ctx.MPIN.RANDOM_GENERATE(rng, Y); - - /* Client Second Pass: Inputs Client secret SEC, x and y. Outputs -(x+y)*SEC */ - rtn = ctx.MPIN.CLIENT_2(X, Y, SEC); - if (rtn != 0) { - console.error("FAILURE: CLIENT_2 rtn: " + rtn); - process.exit(-1); - } - /* Server Second pass. Inputs hashed client id, ctx.RANDom Y, -(x+y)*SEC, xID and xCID and Server secret SST. E and F help kangaroos to find error. */ - /* If PIN error not required, set E and F = NULL */ - rtn = ctx.MPIN.SERVER_2(date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF); - - if (rtn != 0) { - console.log("FAILURE: SERVER_1 rtn: " + rtn); - process.exit(-1); - } -} - - -if (rtn == ctx.MPIN.BAD_PIN) { - console.log("Server says - Bad Pin."); - if (PINERROR) { - var err = ctx.MPIN.KANGAROO(E, F); - if (err != 0) { - console.log("(Client PIN is out by " + err + ")"); - process.exit(-1); - } - } -} else { - console.log("Server says - PIN is good! You really are " + IDstr); -} - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_MPIN_FULL_BLS381.html b/examples/browser/example_MPIN_FULL_BLS381.html deleted file mode 100644 index d95979f..0000000 --- a/examples/browser/example_MPIN_FULL_BLS381.html +++ /dev/null @@ -1,272 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test MPIN - test driver and function exerciser for MPIN API Functions */ - - -var ctx = new CTX("BLS381"); - -/* Test M-Pin */ - -var RAW = []; -var i; -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} -rng.seed(100, RAW); - -var sha = ctx.ECP.HASH_TYPE; - -var S = []; -var SST = []; -var TOKEN = []; -var PERMIT = []; -var SEC = []; -var xID = []; -var xCID = []; -var X = []; -var Y = []; -var E = []; -var F = []; -var HCID = []; -var HID = []; -var HTID = []; - -var G1 = []; -var G2 = []; -var R = []; -var Z = []; -var W = []; -var T = []; -var CK = []; -var SK = []; - -var HSID = []; - -/* Set configuration */ -var PERMITS = true; -var PINERROR = true; -var ONE_PASS = false; - - -/* Trusted Authority set-up */ -ctx.MPIN.RANDOM_GENERATE(rng, S); -console.log("M-Pin Master Secret s: 0x" + ctx.MPIN.bytestostring(S)); - -/* Create Client Identity */ -var IDstr = "[email protected]"; -var CLIENT_ID = ctx.MPIN.stringtobytes(IDstr); -HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); /* Either Client or TA calculates Hash(ID) - you decide! */ - -console.log("Client ID= " + ctx.MPIN.bytestostring(CLIENT_ID)); - -/* Client and Server are issued secrets by DTA */ -ctx.MPIN.GET_SERVER_SECRET(S, SST); -console.log("Server Secret SS: 0x" + ctx.MPIN.bytestostring(SST)); - -ctx.MPIN.GET_CLIENT_SECRET(S, HCID, TOKEN); -console.log("Client Secret CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Client extracts PIN from secret to create Token */ -var pin = 1234; -console.log("Client extracts PIN= " + pin); -var rtn = ctx.MPIN.EXTRACT_PIN(sha, CLIENT_ID, pin, TOKEN); -if (rtn != 0) { - console.log("Failed to extract PIN "); -} - -console.log("Client Token TK: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -ctx.MPIN.PRECOMPUTE(TOKEN, HCID, G1, G2); - -var date; -if (PERMITS) { - date = ctx.MPIN.today(); - /* Client gets "Time Token" permit from DTA */ - ctx.MPIN.GET_CLIENT_PERMIT(sha, date, S, HCID, PERMIT); - console.log("Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); - - /* This encoding makes Time permit look ctx.RANDom - Elligator squared */ - ctx.MPIN.ENCODING(rng, PERMIT); - console.log("Encoded Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); - ctx.MPIN.DECODING(PERMIT); - console.log("Decoded Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); -} else { - date = 0; -} - -pin = 1234; - -/* Set date=0 and PERMIT=null if time permits not in use - -Client First pass: Inputs CLIENT_ID, optional RNG, pin, TOKEN and PERMIT. Output xID = x.H(CLIENT_ID) and re-combined secret SEC -If PERMITS are is use, then date!=0 and PERMIT is added to secret and xCID = x.(H(CLIENT_ID)+H_T(date|H(CLIENT_ID))) -ctx.RANDom value x is supplied externally if RNG=null, otherwise generated and passed out by RNG - -If Time Permits OFF set xCID = null, HTID=null and use xID and HID only -If Time permits are ON, AND pin error detection is required then all of xID, xCID, HID and HTID are required -If Time permits are ON, AND pin error detection is NOT required, set xID=null, HID=null and use xCID and HTID only. - - -*/ -var pxID = xID; -var pxCID = xCID; -var pHID = HID; -var pHTID = HTID; -var pE = E; -var pF = F; -var pPERMIT = PERMIT; -var prHID; - -if (date != 0) { - prHID = pHTID; - if (!PINERROR) { - pxID = null; - // pHID=null; - } -} else { - prHID = pHID; - pPERMIT = null; - pxCID = null; - pHTID = null; -} -if (!PINERROR) { - pE = null; - pF = null; -} - -if (ONE_PASS) { - console.log("MPIN Single Pass "); - var timeValue = ctx.MPIN.GET_TIME(); - console.log("Epoch " + timeValue); - - rtn = ctx.MPIN.CLIENT(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT, timeValue, Y); - - if (rtn != 0) { - console.error("FAILURE: CLIENT rtn: " + rtn); - process.exit(-1); - } - HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 1, R, HCID, Z); /* Also Send Z=r.ID to Server, remember ctx.RANDom r */ - - rtn = ctx.MPIN.SERVER(sha, date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF, CLIENT_ID, timeValue); - if (rtn != 0) { - console.error("FAILURE: SERVER rtn: " + rtn); - process.exit(-1); - } - HSID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 0, W, prHID, T); /* Also send T=w.ID to client, remember ctx.RANDom w */ -} else { - console.log("MPIN Multi Pass "); - rtn = ctx.MPIN.CLIENT_1(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT); - if (rtn != 0) { - console.error("FAILURE: CLIENT_1 rtn: " + rtn); - process.exit(-1); - } - HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 1, R, HCID, Z); /* Also Send Z=r.ID to Server, remember ctx.RANDom r */ - - /* Server calculates H(ID) and H(T|H(ID)) (if time permits enabled), and maps them to points on the curve HID and HTID resp. */ - ctx.MPIN.SERVER_1(sha, date, CLIENT_ID, pHID, pHTID); - - /* Server generates ctx.RANDom number Y and sends it to Client */ - ctx.MPIN.RANDOM_GENERATE(rng, Y); - - HSID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 0, W, prHID, T); /* Also send T=w.ID to client, remember ctx.RANDom w */ - - /* Client Second Pass: Inputs Client secret SEC, x and y. Outputs -(x+y)*SEC */ - rtn = ctx.MPIN.CLIENT_2(X, Y, SEC); - if (rtn != 0) { - console.error("FAILURE: CLIENT_2 rtn: " + rtn); - process.exit(-1); - } - /* Server Second pass. Inputs hashed client id, ctx.RANDom Y, -(x+y)*SEC, xID and xCID and Server secret SST. E and F help kangaroos to find error. */ - /* If PIN error not required, set E and F = NULL */ - rtn = ctx.MPIN.SERVER_2(date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF); - - if (rtn != 0) { - console.error("FAILURE: SERVER_1 rtn: " + rtn); - process.exit(-1); - } -} - - -if (rtn == ctx.MPIN.BAD_PIN) { - console.log("Server says - Bad Pin."); - if (PINERROR) { - var err = ctx.MPIN.KANGAROO(E, F); - if (err != 0) { - console.error("(Client PIN is out by " + err + ")"); - process.exit(-1); - } - } -} else { - console.log("Server says - PIN is good! You really are " + IDstr); - - var H = ctx.MPIN.HASH_ALL(sha, HCID, pxID, pxCID, SEC, Y, Z, T); - ctx.MPIN.CLIENT_KEY(sha, G1, G2, pin, R, X, H, T, CK); - - console.log("Client Key = 0x" + ctx.MPIN.bytestostring(CK)); - H = ctx.MPIN.HASH_ALL(sha, HSID, pxID, pxCID, SEC, Y, Z, T); - ctx.MPIN.SERVER_KEY(sha, Z, SST, W, H, pHID, pxID, pxCID, SK); - console.log("Server Key = 0x" + ctx.MPIN.bytestostring(SK)); -} - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_MPIN_ONE_PASS_BLS381.html b/examples/browser/example_MPIN_ONE_PASS_BLS381.html deleted file mode 100644 index 9d43ab6..0000000 --- a/examples/browser/example_MPIN_ONE_PASS_BLS381.html +++ /dev/null @@ -1,228 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test MPIN - test driver and function exerciser for MPIN API Functions */ - - -var ctx = new CTX("BLS381"); - -/* Test M-Pin */ - -var RAW = []; -var i; -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var sha = ctx.ECP.HASH_TYPE; - -var S = []; -var SST = []; -var TOKEN = []; -var PERMIT = []; -var SEC = []; -var xID = []; -var xCID = []; -var X = []; -var Y = []; -var E = []; -var F = []; -var HCID = []; -var HID = []; -var HTID = []; - -var G1 = []; -var G2 = []; -var R = []; -var Z = []; -var W = []; -var T = []; -var CK = []; -var SK = []; - -var HSID = []; - -/* Set configuration */ -var PINERROR = true; -var FULL = true; - -/* Trusted Authority set-up */ -ctx.MPIN.RANDOM_GENERATE(rng, S); -console.log("M-Pin Master Secret s: 0x" + ctx.MPIN.bytestostring(S)); - -/* Create Client Identity */ -var IDstr = "[email protected]"; -var CLIENT_ID = ctx.MPIN.stringtobytes(IDstr); -HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); /* Either Client or TA calculates Hash(ID) - you decide! */ - -console.log("Client ID= " + ctx.MPIN.bytestostring(CLIENT_ID)); - -/* Client and Server are issued secrets by DTA */ -ctx.MPIN.GET_SERVER_SECRET(S, SST); -console.log("Server Secret SS: 0x" + ctx.MPIN.bytestostring(SST)); - -ctx.MPIN.GET_CLIENT_SECRET(S, HCID, TOKEN); -console.log("Client Secret CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Client extracts PIN from secret to create Token */ -var pin = 1234; -console.log("Client extracts PIN= " + pin); -var rtn = ctx.MPIN.EXTRACT_PIN(sha, CLIENT_ID, pin, TOKEN); -if (rtn != 0) { - console.log("Failed to extract PIN "); -} - -console.log("Client Token TK: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -if (FULL) { - ctx.MPIN.PRECOMPUTE(TOKEN, HCID, G1, G2); -} - -var date = 0; - -pin = 1234; - -/* Set date=0 and PERMIT=null if time permits not in use - -Client First pass: Inputs CLIENT_ID, optional RNG, pin, TOKEN and PERMIT. Output xID = x.H(CLIENT_ID) and re-combined secret SEC -If PERMITS are is use, then date!=0 and PERMIT is added to secret and xCID = x.(H(CLIENT_ID)+H_T(date|H(CLIENT_ID))) -ctx.RANDom value x is supplied externally if RNG=null, otherwise generated and passed out by RNG - -If Time Permits OFF set xCID = null, HTID=null and use xID and HID only -If Time permits are ON, AND pin error detection is required then all of xID, xCID, HID and HTID are required -If Time permits are ON, AND pin error detection is NOT required, set xID=null, HID=null and use xCID and HTID only. - - -*/ -var pxID = xID; -var pxCID = xCID; -var pHID = HID; -var pHTID = HTID; -var pE = E; -var pF = F; -var pPERMIT = PERMIT; -var prHID; - -if (date != 0) { - prHID = pHTID; - if (!PINERROR) { - pxID = null; - // pHID=null; - } -} else { - prHID = pHID; - pPERMIT = null; - pxCID = null; - pHTID = null; -} -if (!PINERROR) { - pE = null; - pF = null; -} - -console.log("MPIN Single Pass "); -var timeValue = ctx.MPIN.GET_TIME(); -console.log("Epoch " + timeValue); - -rtn = ctx.MPIN.CLIENT(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT, timeValue, Y); - -if (rtn != 0) { - console.error("FAILURE: CLIENT rtn: " + rtn); - process.exit(-1); -} -if (FULL) { - HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 1, R, HCID, Z); /* Also Send Z=r.ID to Server, remember ctx.RANDom r */ -} - -rtn = ctx.MPIN.SERVER(sha, date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF, CLIENT_ID, timeValue); -if (rtn != 0) { - console.error("FAILURE: SERVER rtn: " + rtn); - process.exit(-1); -} - -if (FULL) { - HSID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); - ctx.MPIN.GET_G1_MULTIPLE(rng, 0, W, prHID, T); /* Also send T=w.ID to client, remember ctx.RANDom w */ -} - -if (rtn == ctx.MPIN.BAD_PIN) { - console.log("Server says - Bad Pin."); - if (PINERROR) { - var err = ctx.MPIN.KANGAROO(E, F); - if (err != 0) { - console.log("(Client PIN is out by " + err + ")"); - process.exit(-1); - } - } -} else { - console.log("Server says - PIN is good! You really are " + IDstr); - if (FULL) { - var H = ctx.MPIN.HASH_ALL(sha, HCID, pxID, pxCID, SEC, Y, Z, T); - ctx.MPIN.CLIENT_KEY(sha, G1, G2, pin, R, X, H, T, CK); - - console.log("Client Key = 0x" + ctx.MPIN.bytestostring(CK)); - H = ctx.MPIN.HASH_ALL(sha, HSID, pxID, pxCID, SEC, Y, Z, T); - ctx.MPIN.SERVER_KEY(sha, Z, SST, W, H, pHID, pxID, pxCID, SK); - console.log("Server Key = 0x" + ctx.MPIN.bytestostring(SK)); - } -} -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_MPIN_TP_BLS381.html b/examples/browser/example_MPIN_TP_BLS381.html deleted file mode 100644 index c29c250..0000000 --- a/examples/browser/example_MPIN_TP_BLS381.html +++ /dev/null @@ -1,210 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test MPIN - test driver and function exerciser for MPIN API Functions */ - - -var ctx = new CTX("BLS381"); - -/* Test M-Pin */ - -var RAW = []; -var i; - -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var sha = ctx.ECP.HASH_TYPE; - -var S = []; -var SST = []; -var TOKEN = []; -var PERMIT = []; -var SEC = []; -var xID = []; -var xCID = []; -var X = []; -var Y = []; -var E = []; -var F = []; -var HCID = []; -var HID = []; -var HTID = []; - -/* Set configuration */ -var PINERROR = true; - -/* Trusted Authority set-up */ -ctx.MPIN.RANDOM_GENERATE(rng, S); -console.log("M-Pin Master Secret s: 0x" + ctx.MPIN.bytestostring(S)); - -/* Create Client Identity */ -var IDstr = "[email protected]"; -var CLIENT_ID = ctx.MPIN.stringtobytes(IDstr); -HCID = ctx.MPIN.HASH_ID(sha, CLIENT_ID); /* Either Client or TA calculates Hash(ID) - you decide! */ - -console.log("Client ID= " + ctx.MPIN.bytestostring(CLIENT_ID)); - -/* Client and Server are issued secrets by DTA */ -ctx.MPIN.GET_SERVER_SECRET(S, SST); -console.log("Server Secret SS: 0x" + ctx.MPIN.bytestostring(SST)); - -ctx.MPIN.GET_CLIENT_SECRET(S, HCID, TOKEN); -console.log("Client Secret CS: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -/* Client extracts PIN from secret to create Token */ -var pin = 1234; -console.log("Client extracts PIN= " + pin); -var rtn = ctx.MPIN.EXTRACT_PIN(sha, CLIENT_ID, pin, TOKEN); -if (rtn != 0) { - console.log("Failed to extract PIN "); -} - -console.log("Client Token TK: 0x" + ctx.MPIN.bytestostring(TOKEN)); - -var date = ctx.MPIN.today(); -/* Client gets "Time Token" permit from DTA */ -ctx.MPIN.GET_CLIENT_PERMIT(sha, date, S, HCID, PERMIT); -console.log("Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); - -/* This encoding makes Time permit look ctx.RANDom - Elligator squared */ -ctx.MPIN.ENCODING(rng, PERMIT); -console.log("Encoded Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); -ctx.MPIN.DECODING(PERMIT); -console.log("Decoded Time Permit TP: 0x" + ctx.MPIN.bytestostring(PERMIT)); - -pin = 1234; - -/* Set date=0 and PERMIT=null if time permits not in use - -Client First pass: Inputs CLIENT_ID, optional RNG, pin, TOKEN and PERMIT. Output xID = x.H(CLIENT_ID) and re-combined secret SEC -If PERMITS are is use, then date!=0 and PERMIT is added to secret and xCID = x.(H(CLIENT_ID)+H_T(date|H(CLIENT_ID))) -ctx.RANDom value x is supplied externally if RNG=null, otherwise generated and passed out by RNG - -If Time Permits OFF set xCID = null, HTID=null and use xID and HID only -If Time permits are ON, AND pin error detection is required then all of xID, xCID, HID and HTID are required -If Time permits are ON, AND pin error detection is NOT required, set xID=null, HID=null and use xCID and HTID only. - - -*/ -var pxID = xID; -var pxCID = xCID; -var pHID = HID; -var pHTID = HTID; -var pE = E; -var pF = F; -var pPERMIT = PERMIT; - -if (date != 0) { - if (!PINERROR) { - pxID = null; - // pHID=null; - } -} else { - pPERMIT = null; - pxCID = null; - pHTID = null; -} -if (!PINERROR) { - pE = null; - pF = null; -} - -console.log("MPIN Multi Pass "); -rtn = ctx.MPIN.CLIENT_1(sha, date, CLIENT_ID, rng, X, pin, TOKEN, SEC, pxID, pxCID, pPERMIT); -if (rtn != 0) { - console.error("FAILURE: CLIENT_1 rtn: " + rtn); - process.exit(-1); -} -/* Server calculates H(ID) and H(T|H(ID)) (if time permits enabled), and maps them to points on the curve HID and HTID resp. */ -ctx.MPIN.SERVER_1(sha, date, CLIENT_ID, pHID, pHTID); - -/* Server generates ctx.RANDom number Y and sends it to Client */ -ctx.MPIN.RANDOM_GENERATE(rng, Y); - -/* Client Second Pass: Inputs Client secret SEC, x and y. Outputs -(x+y)*SEC */ -rtn = ctx.MPIN.CLIENT_2(X, Y, SEC); -if (rtn != 0) { - console.error("FAILURE: CLIENT_2 rtn: " + rtn); - process.exit(-1); -} -/* Server Second pass. Inputs hashed client id, ctx.RANDom Y, -(x+y)*SEC, xID and xCID and Server secret SST. E and F help kangaroos to find error. */ -/* If PIN error not required, set E and F = NULL */ -rtn = ctx.MPIN.SERVER_2(date, pHID, pHTID, Y, SST, pxID, pxCID, SEC, pE, pF); - -if (rtn != 0) { - console.error("FAILURE: SERVER_1 rtn: " + rtn); - process.exit(-1); -} -if (rtn == ctx.MPIN.BAD_PIN) { - console.log("Server says - Bad Pin."); - if (PINERROR) { - var err = ctx.MPIN.KANGAROO(E, F); - if (err != 0) { - console.log("(Client PIN is out by " + err + ")"); - } - } -} else { - console.log("Server says - PIN is good! You really are " + IDstr); -} - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_RSA2048_ECDSA_NIST256.html b/examples/browser/example_RSA2048_ECDSA_NIST256.html deleted file mode 100644 index 6836342..0000000 --- a/examples/browser/example_RSA2048_ECDSA_NIST256.html +++ /dev/null @@ -1,211 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -'License'); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test RSA - test driver and function exerciser for RSA_2048 and ECDSA with NIST256 */ - - -var ctx1 = new CTX("RSA2048"); - -console.log("Start test RSA2048"); - -var i, j = 0; - -var RAW = []; -var rng = new ctx1.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var sha = ctx1.RSA.HASH_TYPE; -var message = "Hello World\n"; -var pub = new ctx1.rsa_public_key(ctx1.FF.FFLEN); -var priv = new ctx1.rsa_private_key(ctx1.FF.HFLEN); - -var ML = []; -var C = []; -var S = []; -var SALT = []; -var pp = "M0ng00se"; -var CS = []; -var DS = []; -var S0 = []; -var W0 = []; - -var start, end, time; -start = new Date().getTime(); -console.log("Generate RSA public/private key pair"); - -ctx1.RSA.KEY_PAIR(rng, 65537, priv, pub); - -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -var M = ctx1.RSA.stringtobytes(message); -console.log("Encrypting test string"); - -var E = ctx1.RSA.OAEP_ENCODE(sha, M, rng, null); /* OAEP encode message m to e */ -console.log("Encoding= 0x" + ctx1.RSA.bytestohex(E)); - -console.log("Public key= 0x" + pub.n.toString()); - -start = new Date().getTime(); -ctx1.RSA.ENCRYPT(pub, E, C); /* encrypt encoded message */ -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -console.log("Ciphertext= 0x" + ctx1.RSA.bytestohex(C)); - -console.log("Decrypting test string"); -start = new Date().getTime(); -ctx1.RSA.DECRYPT(priv, C, ML); -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -var cmp = true; -if (E.length != ML.length) { - cmp = false; -} else { - for (j = 0; j < E.length; j++) { - if (E[j] != ML[j]) { - cmp = false; - } - } -} -if (cmp) { - console.log("Decryption is OK"); -} else { - console.error("Decryption Failed"); - process.exit(-1); -} - -var MS = ctx1.RSA.OAEP_DECODE(sha, null, ML); /* OAEP decode message */ -console.log("Decoding= 0x" + ctx1.RSA.bytestohex(MS)); - -console.log("message= " + ctx1.RSA.bytestostring(MS)); - -console.log("Start test RSA signature"); - -ctx1.RSA.PKCS15(sha, M, C); - -ctx1.RSA.DECRYPT(priv, C, S); /* create signature in S */ - -console.log("Signature= 0x" + ctx1.RSA.bytestohex(S)); - -ctx1.RSA.ENCRYPT(pub, S, ML); - -cmp = true; -if (C.length != ML.length) { - cmp = false; -} else { - for (j = 0; j < C.length; j++) { - if (C[j] != ML[j]) { - cmp = false; - } - } -} -if (cmp) { - console.log("Signature is valid"); -} else { - console.error("Signature is INVALID"); - process.exit(-1); -} -ctx1.RSA.PRIVATE_KEY_KILL(priv); - -console.log("SUCCESS"); - - -var ctx2 = new CTX("NIST256"); - -console.log("\n\nStart test ECDSA NIST256"); - -for (i = 0; i < 8; i++) { - SALT[i] = (i + 1); -} // set Salt - -console.log("Alice's Passphrase= " + pp); - -// Random private key for other party -ctx2.ECDH.KEY_PAIR_GENERATE(rng, S0, W0); - -// message -for (i = 0; i <= 16; i++) { - M[i] = i; -} - -if (ctx2.ECDH.ECPSP_DSA(sha, rng, S0, M, CS, DS) != 0) { - console.error("ECDSA Signature Failed"); -} - -console.log("Signature= "); -console.log("C= 0x" + ctx2.ECDH.bytestostring(CS)); -console.log("D= 0x" + ctx2.ECDH.bytestostring(DS)); - -if (ctx2.ECDH.ECPVP_DSA(sha, W0, M, CS, DS) != 0) { - console.error("ECDSA Verification Failed"); -} else { - console.log("ECDSA Signature/Verification succeeded"); -} - -rng.clean(); - -console.log("SUCCESS"); -</script> -</body> -</html> diff --git a/examples/browser/example_RSA2048_GENKEY.html b/examples/browser/example_RSA2048_GENKEY.html deleted file mode 100644 index 6ffa893..0000000 --- a/examples/browser/example_RSA2048_GENKEY.html +++ /dev/null @@ -1,176 +0,0 @@ -<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> -<html> -<head> -<title>Browser test</title> -<script src="src/rand.js"></script> -<script src="src/rom_curve.js"></script> -<script src="src/rom_field.js"></script> -<script src="src/uint64.js"></script> -<script src="src/aes.js"></script> -<script src="src/big.js"></script> -<script src="src/gcm.js"></script> -<script src="src/hash256.js"></script> -<script src="src/hash384.js"></script> -<script src="src/hash512.js"></script> -<script src="src/sha3.js"></script> -<script src="src/newhope.js"></script> -<script src="src/nhs.js"></script> -<script src="src/fp.js"></script> -<script src="src/fp2.js"></script> -<script src="src/fp4.js"></script> -<script src="src/fp12.js"></script> -<script src="src/ff.js"></script> -<script src="src/rsa.js"></script> -<script src="src/ecp.js"></script> -<script src="src/ecp2.js"></script> -<script src="src/ecdh.js"></script> -<script src="src/pair.js"></script> -<script src="src/mpin.js"></script> -<script src="src/ctx.js"></script> -</head> - -<body> -<h1>Browser test</h1> - -<script type="text/javascript"> -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -'License'); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -/* Test RSA - test driver and function exerciser for RSA_2048 API Functions */ - - -var ctx = new CTX("RSA2048"); - -console.log("Start test RSA 2048 with key generation"); - -var i, j = 0; - -var RAW = []; -var rng = new ctx.RAND(); -rng.clean(); -for (i = 0; i < 100; i++) { - RAW[i] = i; -} - -rng.seed(100, RAW); - -var sha = ctx.RSA.HASH_TYPE; -var message = "Hello World\n"; -var pub = new ctx.rsa_public_key(ctx.FF.FFLEN); -var priv = new ctx.rsa_private_key(ctx.FF.HFLEN); - -var ML = []; -var C = []; -var S = []; - -var start, end, time; -start = new Date().getTime(); -console.log("Generating RSA public/private key pair (slow!)"); -ctx.RSA.KEY_PAIR(rng, 65537, priv, pub); -console.log("PR.p: " + priv.p.toString()); -console.log("PR.q: " + priv.q.toString()); -console.log("PR.dp: " + priv.dp.toString()); -console.log("PR.dq: " + priv.dq.toString()); -console.log("PR.c: " + priv.c.toString()); -console.log("PUB.n: " + pub.n.toString()); - - -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -var M = ctx.RSA.stringtobytes(message); -console.log("Encrypting test string"); - -var E = ctx.RSA.OAEP_ENCODE(sha, M, rng, null); /* OAEP encode message m to e */ -console.log("Encoding= 0x" + ctx.RSA.bytestohex(E)); - -console.log("Public key= 0x" + pub.n.toString()); - -start = new Date().getTime(); -ctx.RSA.ENCRYPT(pub, E, C); /* encrypt encoded message */ -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -console.log("Ciphertext= 0x" + ctx.RSA.bytestohex(C)); - -console.log("Decrypting test string"); -start = new Date().getTime(); -ctx.RSA.DECRYPT(priv, C, ML); -end = new Date().getTime(); -time = end - start; -console.log("Time in ms= " + time); - -var cmp = true; -if (E.length != ML.length) { - cmp = false; -} else { - for (j = 0; j < E.length; j++) { - if (E[j] != ML[j]) { - cmp = false; - } - } -} - -if (cmp) { - console.log("Decryption is OK"); -} else { - console.error("Decryption Failed"); - process.exit(-1); -} - -var MS = ctx.RSA.OAEP_DECODE(sha, null, ML); /* OAEP decode message */ -console.log("Decoding= 0x" + ctx.RSA.bytestohex(MS)); - -console.log("message= " + ctx.RSA.bytestostring(MS)); - -console.log("Start test RSA signature"); - -ctx.RSA.PKCS15(sha, M, C); - -ctx.RSA.DECRYPT(priv, C, S); /* create signature in S */ - -console.log("Signature= 0x" + ctx.RSA.bytestohex(S)); - -ctx.RSA.ENCRYPT(pub, S, ML); - -cmp = true; -if (C.length != ML.length) { - cmp = false; -} else { - for (j = 0; j < C.length; j++) { - if (C[j] != ML[j]) { - cmp = false; - } - } -} - -if (cmp) { - console.log("Signature is valid"); -} else { - console.error("Signature is INVALID"); - process.exit(-1); -} -ctx.RSA.PRIVATE_KEY_KILL(priv); - -console.log("SUCCESS"); -</script> -</body> -</html>
