<!-- Utilities for manipulating ABVs -->
<script src="util.js"></script>
<!-- A simple wrapper around IndexedDB -->
<script src="simpledb.js"></script>
<!-- Test vectors drawn from the literature -->
<script src="./test-vectors.js"></script>
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/* <![CDATA[*/ "use strict";
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key",
function() { var that = this; var alg = "PBKDF2"; var key = new TextEncoder().encode("password");
// -----------------------------------------------------------------------------
TestArray.addTest( "Unwrapping a PBKDF2 key in PKCS8 format should fail",
function() { var that = this; var pbkdf2Key = new TextEncoder().encode("password"); var alg = {name: "AES-GCM", length: 256, iv: new Uint8Array(16)}; var wrappingKey;
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key and derive bits using HMAC-SHA-1",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha1.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Import a PBKDF2 key in JWK format and derive bits using HMAC-SHA-1",
function() { var that = this; var alg = "PBKDF2";
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key and derive a new key using HMAC-SHA-1",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha1.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key and derive a new key using HMAC-SHA-1 with custom length",
function() { var that = this;
function doDerive(x) { var alg = {
name: "PBKDF2",
hash: "SHA-1",
salt: tv.pbkdf2_sha1.salt,
iterations: tv.pbkdf2_sha1.iterations,
};
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key and derive bits using HMAC-SHA-256",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha256.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 zero-length key and derive bits using HMAC-SHA-256",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha256_no_pwd.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Import raw PBKDF2 key and derive bits using HMAC-SHA-256 with zero-length salt",
function() { var that = this; var importAlg = { name: "PBKDF2", hash: "SHA-256" }; var key = tv.pbkdf2_sha256_no_salt.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
var deriveAlg = {
name: "PBKDF2",
hash: "SHA-256",
salt: new Uint8Array(0),
iterations: tv.pbkdf2_sha256_no_salt.iterations,
};
return crypto.subtle.deriveBits(deriveAlg, x, tv.pbkdf2_sha256_no_salt.length);
}
function fail(x) { console.log("failing"); error(that)(x); }
// -----------------------------------------------------------------------------
TestArray.addTest( "Fail while deriving key with bad hash name",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha256.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Fail while deriving bits given null length",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha256.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
// -----------------------------------------------------------------------------
TestArray.addTest( "Fail while deriving key of null length",
function() { var that = this; var alg = "PBKDF2"; var key = tv.pbkdf2_sha256.password;
function doDerive(x) {
if (!hasKeyFields(x)) {
throw new Error("Invalid key; missing field(s)");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.