Skip to content

Commit

Permalink
Fix gchq#930 by allowing variable key sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Jan 9, 2020
1 parent f7be8d7 commit c689cf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/core/operations/BlowfishDecrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ class BlowfishDecrypt extends Operation {
inputType = args[3],
outputType = args[4];

if (key.length !== 8) {
if (key.length < 4 || key.length > 56) {
throw new OperationError(`Invalid key length: ${key.length} bytes
Blowfish uses a key length of 8 bytes (64 bits).`);
Blowfish's key length needs to between 4 and 56 bytes (32-448 bits).`);
}

if (iv.length !== 8) {
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`);
}

input = Utils.convertToByteString(input, inputType);
Expand Down
8 changes: 6 additions & 2 deletions src/core/operations/BlowfishEncrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ class BlowfishEncrypt extends Operation {
inputType = args[3],
outputType = args[4];

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

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

input = Utils.convertToByteString(input, inputType);
Expand Down

0 comments on commit c689cf7

Please sign in to comment.