BB10/gseCrypto/sample_application/js/katSHA.js
function katSHA() {
	var which = Array("raw", "hex", "b64");

	var testVectors = katSHAvector;

	var message = "";

	message += "<h2>SHA KAT</h2>";
	message += "<table>";

	for ( var i = 0; i < testVectors.length; ++i) {
		var suite = testVectors[i];
		for ( var j = 0; j < which.length; ++j) {
			var encoding = which[j];
			var toHash = suite[encoding];

			var params = { input: {} };
			params.input[encoding] = toHash;

			var results = suite.results;
			for ( var k = 0; k < results.length; ++k) {
				var kat = results[k];
				var alg = kat.alg;
				params.alg = alg;
				
				var live = community.gseCrypto.hash(params).output;

				var match = kat.hex == live.hex;
				message += ("<tr>");
				message += ("<td class='" + (match ? "pass" : "fail") + "'>"
						+ match + "</td>");

				match = kat.b64 == live.b64;
				message += ("<td class='" + (match ? "pass" : "fail") + "'>"
						+ match + "</td>");

				message += ("<td>" + JSON.stringify(params) + "</td>");

				message += ("<td>" + kat.hex + "<br />" + live.hex + "</td>");
				message += ("<td>" + kat.b64 + "<br />" + live.b64 + "</td>");

				message += ("</tr>");
			}
		}
	}
	message += ("</table>");

	log(message);
}
function katSHA() {
	var which = Array("raw", "hex", "b64");

	var testVectors = katSHAvector;

	var message = "";

	message += "<h2>SHA KAT</h2>";
	message += "<table>";

	for ( var i = 0; i < testVectors.length; ++i) {
		var suite = testVectors[i];
		for ( var j = 0; j < which.length; ++j) {
			var encoding = which[j];
			var toHash = suite[encoding];

			var params = { input: {} };
			params.input[encoding] = toHash;

			var results = suite.results;
			for ( var k = 0; k < results.length; ++k) {
				var kat = results[k];
				var alg = kat.alg;
				params.alg = alg;
				
				var live = community.gseCrypto.hash(params).output;

				var match = kat.hex == live.hex;
				message += ("<tr>");
				message += ("<td class='" + (match ? "pass" : "fail") + "'>"
						+ match + "</td>");

				match = kat.b64 == live.b64;
				message += ("<td class='" + (match ? "pass" : "fail") + "'>"
						+ match + "</td>");

				message += ("<td>" + JSON.stringify(params) + "</td>");

				message += ("<td>" + kat.hex + "<br />" + live.hex + "</td>");
				message += ("<td>" + kat.b64 + "<br />" + live.b64 + "</td>");

				message += ("</tr>");
			}
		}
	}
	message += ("</table>");

	log(message);
}
/*
Copyright 2013 Research In Motion Limited.

Licensed 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.