pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by Paranoia on Tue 16th Mar 21:27
download | new post

  1. ################################################
  2. ##
  3. ##  Specified in section B.2.1 of http://dl.dropbox.com/u/4326/pkcs-1v2-1d3.pdf
  4. ##
  5. ##  Example is input: (dcd87d5c68f1eea8f55267c31b2e8bb4251f84d7e0b2c04626f5aff93edcfb25c9c2b3ff8ae10e839a2ddb4cdcfe4ff47728b4a1b7c1362baad29ab48d2869d5024121435811591be392f982fb3e87d095aeb40448db972f3ac14f7bc275195281ce32d2f1b76d4d353e2d,20)
  6. ##
  7. ##  which should give output of: 41870b5ab029e657d95750b54c283c08725dbea9
  8. ##
  9. ##  My understanding of the psuedocode, means that it should basically return the sha-1 hash of:
  10. ##
  11. ##  dcd87d5c68f1eea8f55267c31b2e8bb4251f84d7e0b2c04626f5aff93edcfb25c9c2b3ff8ae10e839a2ddb4cdcfe4ff47728b4a1b7c1362baad29ab48d2869d5024121435811591be392f982fb3e87d095aeb40448db972f3ac14f7bc275195281ce32d2f1b76d4d353e2d00000000
  12. ##
  13. ##  which I get to be: 5f9c34b65ea02ce2ce5930624badf313f4a8f20d
  14. ##
  15. ##  which this agrees with: http://www.movable-type.co.uk/scripts/sha1.html
  16. ##
  17. ##  which makes me thing my interpretation of the psuedocode might be incorrect, but it seems so simple!
  18. ##
  19. ##  Thaannnkkkssss
  20. #############################################
  21.  
  22.  
  23.  
  24. def mgf1_sha1(mgfSeed, maskLen):
  25.  
  26.   result = ""
  27.  
  28.   if maskLen > (2**32)*sha.digest_size:
  29.     return "mask too long"
  30.  
  31.   print int(math.ceil(maskLen / sha.digest_size))
  32.  
  33.   for i in range(int(math.ceil(maskLen / sha.digest_size))):
  34.     counter = hex(i)[2:].zfill(8)
  35.     if counter[len(counter)-1] == 'L':
  36.       counter = counter[:len(counter)-1]
  37.     hash = sha.new(mgfSeed+counter)
  38.     result = result + hash.hexdigest()
  39.  
  40.   return result[:(maskLen*2)]

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings