Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function computeDerivedKeys(self: CryptoFactory, serverNonce: Nonce, clientNonce: Nonce): DerivedKeys1 {
// calculate derived keys
if (clientNonce && serverNonce) {
const options = {
algorithm: self.symmetricEncryptionAlgorithm,
encryptingBlockSize: self.encryptingBlockSize,
encryptingKeyLength: self.derivedEncryptionKeyLength,
sha1or256: self.sha1or256,
signatureLength: self.signatureLength,
signingKeyLength: self.derivedSignatureKeyLength,
};
return {
algorithm: null,
derivedClientKeys: computeDerivedKeys_ext(serverNonce, clientNonce, options),
derivedServerKeys: computeDerivedKeys_ext(clientNonce, serverNonce, options),
};
} else {
return {derivedClientKeys: null, derivedServerKeys: null, algorithm: null};
}
}
// calculate derived keys
if (clientNonce && serverNonce) {
const options = {
algorithm: self.symmetricEncryptionAlgorithm,
encryptingBlockSize: self.encryptingBlockSize,
encryptingKeyLength: self.derivedEncryptionKeyLength,
sha1or256: self.sha1or256,
signatureLength: self.signatureLength,
signingKeyLength: self.derivedSignatureKeyLength,
};
return {
algorithm: null,
derivedClientKeys: computeDerivedKeys_ext(serverNonce, clientNonce, options),
derivedServerKeys: computeDerivedKeys_ext(clientNonce, serverNonce, options),
};
} else {
return {derivedClientKeys: null, derivedServerKeys: null, algorithm: null};
}
}
const secret = Buffer.from("My Little Secret");
const seed = Buffer.from("My Little Seed");
const globalOptions = {
signingKeyLength: 16,
encryptingKeyLength: 16,
encryptingBlockSize: 16,
signatureLength: 20,
algorithm: "aes-128-cbc"
};
export const derivedKeys = computeDerivedKeys(secret, seed, globalOptions);
export function iterateOnSymmetricEncryptedChunk(buffer: Buffer, callback: ChunkVisitorFunc) {
const options: any = {
chunkSize: 1024,
encryptBufferFunc: null,
plainBlockSize: 0,
requestId: 10,
signBufferFunc: null,
signatureLength: 0,
};
options.signatureLength = derivedKeys.signatureLength;
options.signBufferFunc = (chunk: Buffer) => makeMessageChunkSignatureWithDerivedKeys(chunk, derivedKeys);
options.plainBlockSize = derivedKeys.encryptingBlockSize;
msgChunkManager.write(buffer, buffer.length);
msgChunkManager.end();
}
exports.iterate_on_signed_and_encrypted_message_chunks = iterate_on_signed_and_encrypted_message_chunks;
const secret = Buffer.from("My Little Secret");
const seed = Buffer.from("My Little Seed");
const options = {
signingKeyLength: 16,
encryptingKeyLength: 16,
encryptingBlockSize: 16,
signatureLength: 20,
algorithm: "aes-128-cbc"
};
const derivedKeys = crypto_utils.computeDerivedKeys(secret, seed, options);
exports.derivedKeys = derivedKeys;
function iterate_on_symmetric_encrypted_chunk(buffer, callback) {
const options = {
requestId: 10,
chunkSize: 1024
};
options.signatureLength = derivedKeys.signatureLength;
options.signingFunc = function (chunk) {
return crypto_utils.makeMessageChunkSignatureWithDerivedKeys(chunk, derivedKeys);
};
options.plainBlockSize = derivedKeys.encryptingBlockSize;
options.cipherBlockSize = derivedKeys.encryptingBlockSize;
options.encrypt_buffer = function (chunk) {
const derivedKeys = {
derivedClientKeys: null,
derivedServerKeys: null,
algorithm: null
};
if (clientNonce && serverNonce) {
const options = {
signingKeyLength: self.derivedSignatureKeyLength,
encryptingKeyLength: self.derivedEncryptionKeyLength,
encryptingBlockSize: self.encryptingBlockSize,
signatureLength: self.signatureLength,
algorithm: self.symmetricEncryptionAlgorithm,
sha1or256: self.sha1or256
};
derivedKeys.derivedClientKeys = crypto_utils.computeDerivedKeys(serverNonce, clientNonce, options);
derivedKeys.derivedServerKeys = crypto_utils.computeDerivedKeys(clientNonce, serverNonce, options);
}
return derivedKeys;
}
derivedClientKeys: null,
derivedServerKeys: null,
algorithm: null
};
if (clientNonce && serverNonce) {
const options = {
signingKeyLength: self.derivedSignatureKeyLength,
encryptingKeyLength: self.derivedEncryptionKeyLength,
encryptingBlockSize: self.encryptingBlockSize,
signatureLength: self.signatureLength,
algorithm: self.symmetricEncryptionAlgorithm,
sha1or256: self.sha1or256
};
derivedKeys.derivedClientKeys = crypto_utils.computeDerivedKeys(serverNonce, clientNonce, options);
derivedKeys.derivedServerKeys = crypto_utils.computeDerivedKeys(clientNonce, serverNonce, options);
}
return derivedKeys;
}