Bitcoin Forum
April 18, 2024, 10:54:42 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: the goxsh script is zero-padding the secret and then encrypting in ECB mode  (Read 996 times)
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
February 27, 2013, 08:27:34 PM
 #1

hello!

I am not a crypto-guru, so I might be wrong but this seems highly suspicious to me:


      password = password[0:32]
      aes = AES.new(password, AES.MODE_ECB)
      secret = str.zfill(secret, 128)
      secret = aes.encrypt(secret)


It turns out that before zero padding the length of secret is 88 bytes and after it is 128 bytes, so there is more than one complete block (key length = 32 bytes) of known plaintext and because of ECB mode all other 32 byte blocks will be encoded with the very same key! Isn't this danegrous? Shouldn't it be padded with random bytes instead and also the ECB mode be completely avoided?

1713480882
Hero Member
*
Offline Offline

Posts: 1713480882

View Profile Personal Message (Offline)

Ignore
1713480882
Reply with quote  #2

1713480882
Report to moderator
1713480882
Hero Member
*
Offline Offline

Posts: 1713480882

View Profile Personal Message (Offline)

Ignore
1713480882
Reply with quote  #2

1713480882
Report to moderator
"With e-currency based on cryptographic proof, without the need to trust a third party middleman, money can be secure and transactions effortless." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713480882
Hero Member
*
Offline Offline

Posts: 1713480882

View Profile Personal Message (Offline)

Ignore
1713480882
Reply with quote  #2

1713480882
Report to moderator
1713480882
Hero Member
*
Offline Offline

Posts: 1713480882

View Profile Personal Message (Offline)

Ignore
1713480882
Reply with quote  #2

1713480882
Report to moderator
1713480882
Hero Member
*
Offline Offline

Posts: 1713480882

View Profile Personal Message (Offline)

Ignore
1713480882
Reply with quote  #2

1713480882
Report to moderator
Zeilap
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
February 27, 2013, 09:31:21 PM
Last edit: February 27, 2013, 09:44:22 PM by Zeilap
 #2

hello!

I am not a crypto-guru, so I might be wrong but this seems highly suspicious to me:


      password = password[0:32]
      aes = AES.new(password, AES.MODE_ECB)
      secret = str.zfill(secret, 128)
      secret = aes.encrypt(secret)


It turns out that before zero padding the length of secret is 88 bytes and after it is 128 bytes, so there is more than one complete block (key length = 32 bytes) of known plaintext and because of ECB mode all other 32 byte blocks will be encoded with the very same key! Isn't this danegrous? Shouldn't it be padded with random bytes instead and also the ECB mode be completely avoided?
I'm no crypto guru either, but here is a simple attack:

Code:
# passwords is a large list of common passwords
passwords = ['querty', 'password', ... ]

# map of encrypted null block (i.e. result of encrypting zero) => password
zeroCiphers = {}

# fill the zeroCiphers
for password in passwords:
    aes = AES.new(password, AES.MODE_ECB)
    zeroCiphers[aes.encrypt(0)] = password


def decrypt(ciphertext):
    # get the last block (we're hoping it's from encrypting the zero padding)
    lastBlock = cipertext[-16:]

    # look up this encrypted zero byte in our table to get the password
    password = zeroCiphers[lastBlock]

    if(password !== null):
        # BINGO!
        aes = AES.new(password, AES.MODE_ECB)
        return aes.decrypt(ciphertext)
    else:
        return '';

Quick fix is to change to Cipher Block Chaining, so that the cipher changes every block, you don't know block were originally zero padding.


Please send a share of any stolen bitcoins to the address in my sig Wink
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!