|  | 
|  |  
| | 
| 
| 
|  |  
| 
Joined:  Jan 2004 Posts: 2,081 Hoopy frood |  
| OP   Hoopy frood Joined:  Jan 2004 Posts: 2,081 | 
2 issues related to invalid key lengths: #1) When key is longer than 56 bytes (not necessarily same as $len() = 56), Blowfish should either reject as invalid length or chop at 56 bytes so it can repeat a minimum 16 bytes while expanding key to 72 bytes. %badkey returns the same test vector as in the link above, but should have returned the same string as %goodkey because both share the same 1st 56 bytes, and therefore should have expanded to the same 72-byte pattern. 
alias Test_e {
  var %badkey $left($str(abcdefghijklmnopqrstuvwxyz,3),72) | var %goodkey $left(%badkey,56)
  bset -t &data1 1 BLOWFISH | noop $encode(&data1,bme,%badkey ) | noop $decode(&data1,bm) | echo 4 -a Wrong: $bvar(&data1,1-8)
  bset -t &data2 1 BLOWFISH | noop $encode(&data2,bme,%goodkey) | noop $decode(&data2,bm) | echo 3 -a Correct: $bvar(&data2,1-8)
}
#2) el and cl correctly give UTF-8 $utfencode strings to Blowfish, but incorrectly validate the $utfdecode length, accepting 57-72 byte keys because $len() is 56, but rejecting 56-byte key which have $len() shorter. I got 'el' and 'cl' to both return the same vector by having cl's XOR of lower-case plaintext and IV of eight 0x20 spaces cancel each other out. 'cl' should have either rejected %badkey as having 57 bytes or used key containing the 56 bytes of $bvar(&bad57,1-56) and should have accepted $len() 55 %goodkey as a valid key containing 56 bytes. Correct ciphertext for key being first 56 bytes of $bvar(&bad57,1-56) is: hex: 43 37 A2 45 17 96 A3 01 decimal: 67 55 162 69 23 150 163 1 
alias Test_cl {
  var %badkey  $str(a,55) $+ $chr(233)
  var %goodkey $str(a,54) $+ $chr(233)
  bset -t &data1 1 BLOWFISH | noop $encode(&data1,bmel ,%badkey                 ) | noop $decode(&data1,bm) | echo 4 -a 57-byte key: $bvar(&data1,1-8)
  bset -t &data2 1 blowfish | noop $encode(&data2,bmcli,%badkey,$str($chr(32),8)) | noop $decode(&data2,bm) | echo 4 -a 57-byte key: $bvar(&data2,1-8)
  bset -t &bad57  1 %badkey  | echo -a Above Accepts $bvar(&bad57 ,0) bytes: $bvar(&bad57 ,1-)
  bset -t &good56 1 %goodkey | echo -a Below Rejects $bvar(&good56,0) bytes: $bvar(&good56,1-)
  echo -a Next 2 lines should return same vector, key has 56 UTF-8 bytes but 'cli' rejects as invalid parameter:
  bset -t &data1 1 BLOWFISH | noop $encode(&data1,bme  ,%goodkey                 ) | noop $decode(&data1,bm) | echo 3 -a 56-byte key: $bvar(&data1,1-8)
  bset -t &data2 1 blowfish | noop $encode(&data2,bmcli,%goodkey,$str($chr(32),8)) | noop $decode(&data2,bm) | echo 3 -a 56-byte key: $bvar(&data2,1-8)
}
I don't know how 'c' without 'l' hashes the key, but I expect that it correctly inputs the UTF-8 bytes to the hash, and returns the correct hash output. Since the hash output is shorter than 56, there will not be an issue of invalid key length there. |  |  |  
| 
| Entire Thread |  
 
|    Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 07/12/17 07:46 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 17/12/17 09:03 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 17/12/17 12:30 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 17/12/17 05:22 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 18/12/17 02:05 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 18/12/17 05:29 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 24/12/17 06:33 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 29/12/17 10:18 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 05/01/18 04:26 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 07/01/18 05:34 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 06/03/19 10:07 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 21/03/19 09:51 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 28/03/19 09:59 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 29/03/19 11:51 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 12/04/19 04:58 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 12/04/19 06:39 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 13/04/19 08:02 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Raccoon | 13/04/19 11:16 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 13/04/19 11:46 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 14/04/19 12:00 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 14/04/19 10:59 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 25/04/19 06:11 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 27/04/19 10:22 AM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | Khaled | 29/03/19 12:16 PM |  
|    Re: Invalid key lengths in $encode(data,<e[l]|cl>,key) | maroon | 31/03/19 10:57 PM |  |  | 
 |  
| 
 |  |  |