fix(QMCv2): overflow error in js decoder
This commit is contained in:
@@ -18,7 +18,7 @@ function loadTestDataDecoder(name: string): {
|
||||
}
|
||||
|
||||
test('qmc: real file', async () => {
|
||||
const cases = ['mflac0_rc4', 'mflac_map', 'mgg_map', 'qmc0_static'];
|
||||
const cases = ['mflac0_rc4', 'mflac_rc4', 'mflac_map', 'mgg_map', 'qmc0_static'];
|
||||
for (const name of cases) {
|
||||
const { clearText, cipherText } = loadTestDataDecoder(name);
|
||||
const c = new QmcDecoder(cipherText);
|
||||
|
@@ -69,7 +69,7 @@ test('map cipher: real file', async () => {
|
||||
});
|
||||
|
||||
test('rc4 cipher: real file', async () => {
|
||||
const cases = ['mflac0_rc4'];
|
||||
const cases = ['mflac0_rc4', 'mflac_rc4'];
|
||||
for (const name of cases) {
|
||||
const { key, clearText, cipherText } = loadTestDataCipher(name);
|
||||
const c = new QmcRC4Cipher(key);
|
||||
@@ -81,7 +81,7 @@ test('rc4 cipher: real file', async () => {
|
||||
});
|
||||
|
||||
test('rc4 cipher: first segment', async () => {
|
||||
const cases = ['mflac0_rc4'];
|
||||
const cases = ['mflac0_rc4', 'mflac_rc4'];
|
||||
for (const name of cases) {
|
||||
const { key, clearText, cipherText } = loadTestDataCipher(name);
|
||||
const c = new QmcRC4Cipher(key);
|
||||
@@ -93,7 +93,7 @@ test('rc4 cipher: first segment', async () => {
|
||||
});
|
||||
|
||||
test('rc4 cipher: align block (128~5120)', async () => {
|
||||
const cases = ['mflac0_rc4'];
|
||||
const cases = ['mflac0_rc4', 'mflac_rc4'];
|
||||
for (const name of cases) {
|
||||
const { key, clearText, cipherText } = loadTestDataCipher(name);
|
||||
const c = new QmcRC4Cipher(key);
|
||||
@@ -105,7 +105,7 @@ test('rc4 cipher: align block (128~5120)', async () => {
|
||||
});
|
||||
|
||||
test('rc4 cipher: simple block (5120~10240)', async () => {
|
||||
const cases = ['mflac0_rc4'];
|
||||
const cases = ['mflac0_rc4', 'mflac_rc4'];
|
||||
for (const name of cases) {
|
||||
const { key, clearText, cipherText } = loadTestDataCipher(name);
|
||||
const c = new QmcRC4Cipher(key);
|
||||
|
@@ -119,7 +119,7 @@ export class QmcRC4Cipher implements QmcStreamCipher {
|
||||
// ignore if key char is '\x00'
|
||||
if (!value) continue;
|
||||
|
||||
const next_hash = (this.hash * value) & 0xffffffff;
|
||||
const next_hash = (this.hash * value) >>> 0;
|
||||
if (next_hash == 0 || next_hash <= this.hash) break;
|
||||
|
||||
this.hash = next_hash;
|
||||
@@ -174,7 +174,8 @@ export class QmcRC4Cipher implements QmcStreamCipher {
|
||||
|
||||
// Calculate the number of bytes to skip.
|
||||
// The initial "key" derived from segment id, plus the current offset.
|
||||
const skipLen = (offset % QmcRC4Cipher.SEGMENT_SIZE) + this.getSegmentKey(offset / QmcRC4Cipher.SEGMENT_SIZE);
|
||||
const skipLen =
|
||||
(offset % QmcRC4Cipher.SEGMENT_SIZE) + this.getSegmentKey(Math.floor(offset / QmcRC4Cipher.SEGMENT_SIZE));
|
||||
|
||||
// decrypt the block
|
||||
let j = 0;
|
||||
@@ -192,7 +193,7 @@ export class QmcRC4Cipher implements QmcStreamCipher {
|
||||
|
||||
private getSegmentKey(id: number): number {
|
||||
const seed = this.key[id % this.N];
|
||||
const idx = ((this.hash / ((id + 1) * seed)) * 100.0) | 0;
|
||||
const idx = Math.floor((this.hash / ((id + 1) * seed)) * 100.0);
|
||||
return idx % this.N;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ function loadTestDataKeyDecrypt(name: string): {
|
||||
}
|
||||
|
||||
test('key dec: real file', async () => {
|
||||
const cases = ['mflac_map', 'mgg_map', 'mflac0_rc4'];
|
||||
const cases = ['mflac_map', 'mgg_map', 'mflac0_rc4', 'mflac_rc4'];
|
||||
for (const name of cases) {
|
||||
const { clearText, cipherText } = loadTestDataKeyDecrypt(name);
|
||||
const buf = QmcDeriveKey(cipherText);
|
||||
|
Reference in New Issue
Block a user