How to use the crypt.Mode function in crypt

To help you get started, we’ve selected a few crypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Moddable-OpenSource / moddable / modules / crypt / ssl / ssl_setup.js View on Github external
throw new Error("SSL: SetupCipher: unkown encryption algorithm");
	}
	switch (cipher.encryptionMode) {
	case CBC:
	case NONE:
		switch (cipher.hashAlgorithm) {
		case MD5: h = "MD5"; break;
		case SHA1: h = "SHA1"; break;
		case SHA256: h = "SHA256"; break;
		case SHA384: h = "SHA384"; break;
		default:
			throw new Error("SSL: SetupCipher: unknown hash algorithm");
		}
		o.hmac = new HMAC(new Digest(h), o.macSecret);
		if (cipher.encryptionMode == CBC)
			o.enc = new Mode("CBC", enc, o.iv);	// no padding -- SSL 3.2 requires padding process beyond RFC2630
		else
			o.enc = enc;
		break;
	case GCM:
		o.enc = new Gcm(enc);
		o.nonce = BigInt(1);
		break;
	default:
		o.enc = enc;
		break;
	}
}
github Moddable-OpenSource / moddable / examples / crypt / cryptblockcipher / main.js View on Github external
function testCipherMode(name, direction, cipher, iv, padding, data, expected)
{
	let mode, result;
	if (name == "GCM") {
		mode = new GCM(cipher);
		result = mode.process(data, undefined, iv, padding /* AAD */, direction == "encrypt");
	}
	else {
		mode = new Mode(name, cipher, iv, padding);
		result = mode[direction](data);
	}

	if (Bin.comp(result, expected) != 0) {
		trace(`${name}.${direction} FAIL\n`);
		trace("result = " + Hex.toString(result) + "\n");
		trace("expected = " + Hex.toString(expected) + "\n");
	}
	else
		trace(`${name}.${direction} pass\n`);
}
github Moddable-OpenSource / moddable / modules / crypt / etc / gcm.js View on Github external
constructor(cipher, tagLength = 16) {
		this.block = cipher;
		this.ctr = new Mode("CTR", this.block);
		this.tagLength = tagLength;
	};
	init(iv, aad) {