Skip to content

Commit 8647b50

Browse files
authored
Merge pull request #933 from cbeuw/blowfish-keyfix
2 parents 21dc5d9 + 81605b2 commit 8647b50

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/core/operations/BlowfishDecrypt.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ class BlowfishDecrypt extends Operation {
7070
inputType = args[3],
7171
outputType = args[4];
7272

73-
if (key.length !== 8) {
73+
if (key.length < 4 || key.length > 56) {
7474
throw new OperationError(`Invalid key length: ${key.length} bytes
7575
76-
Blowfish uses a key length of 8 bytes (64 bits).`);
76+
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
77+
}
78+
79+
if (iv.length !== 8) {
80+
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`);
7781
}
7882

7983
input = Utils.convertToByteString(input, inputType);

src/core/operations/BlowfishEncrypt.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ class BlowfishEncrypt extends Operation {
7070
inputType = args[3],
7171
outputType = args[4];
7272

73-
if (key.length !== 8) {
73+
if (key.length < 4 || key.length > 56) {
7474
throw new OperationError(`Invalid key length: ${key.length} bytes
75+
76+
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
77+
}
7578

76-
Blowfish uses a key length of 8 bytes (64 bits).`);
79+
if (iv.length !== 8) {
80+
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`);
7781
}
7882

7983
input = Utils.convertToByteString(input, inputType);

tests/operations/tests/Crypt.mjs

+34
Original file line numberDiff line numberDiff line change
@@ -1948,4 +1948,38 @@ DES uses a key length of 8 bytes (64 bits).`,
19481948
}
19491949
],
19501950
},
1951+
{
1952+
name: "Blowfish Encrypt with variable key length: CBC, ASCII, 4 bytes",
1953+
input: "The quick brown fox jumps over the lazy dog.",
1954+
expectedOutput: "823f337a53ecf121aa9ec1b111bd5064d1d7586abbdaaa0c8fd0c6cc43c831c88bf088ee3e07287e3f36cf2e45f9c7e6",
1955+
recipeConfig: [
1956+
{
1957+
"op": "Blowfish Encrypt",
1958+
"args": [
1959+
{"option": "Hex", "string": "00112233"}, // Key
1960+
{"option": "Hex", "string": "0000000000000000"}, // IV
1961+
"CBC", // Mode
1962+
"Raw", // Input
1963+
"Hex" // Output
1964+
]
1965+
}
1966+
],
1967+
},
1968+
{
1969+
name: "Blowfish Encrypt with variable key length: CBC, ASCII, 42 bytes",
1970+
input: "The quick brown fox jumps over the lazy dog.",
1971+
expectedOutput: "19f5a68145b34321cfba72226b0f33922ce44dd6e7869fe328db64faae156471216f12ed2a37fd0bdd7cebf867b3cff0",
1972+
recipeConfig: [
1973+
{
1974+
"op": "Blowfish Encrypt",
1975+
"args": [
1976+
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdead"}, // Key
1977+
{"option": "Hex", "string": "0000000000000000"}, // IV
1978+
"CBC", // Mode
1979+
"Raw", // Input
1980+
"Hex" // Output
1981+
]
1982+
}
1983+
],
1984+
}
19511985
]);

0 commit comments

Comments
 (0)