daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BLOG ON CRYPTOGRAPHY
  2. Today, people in general relate to cryptography mostly in regard to the security of their passwords. The passwords are worthless if others have resources to know it.
  3.  
  4. Today most of the websites dont simply use cryptographic hash functions like SHA256, MD5 etc. directly on the password. Instead random bits ( salt ) is added while encrypting them so that even when two users enter the same password the hashes that are generated are different from each other.
  5. Hashes like SHA1 , SHA256, MD5 etc. are general purpose hashes. They have been designed to hash a large amount of data as quickly as possible.
  6. An encryption algorithm for securely storing your password should have the following characteristics:
  7. 1. preimage resistance: Given h, it should be hard to find any value x with h = H(x).
  8. 2. second preimage resistance: Given x1, it should be hard to find x2 != x1 with H(x1) = H                         (x2).
  9. 3. collision resistance: It should be hard to find two values x1 != x2 with H(x1) = H(x2).
  10.  
  11. Another desirable characteristic of a secure hash algorithm should be  slow execution speed.  To calculate the value of a string x it should take some minimum amount of resources to calculate H(x).
  12.  
  13. There is a fundamental difference between collision attack and preimage attack:
  14. Collision attack: the attacker computes two messages m and m', distinct from each other, such that m and m' hash to the same value.
  15. Preimage: the attacker is given a goal (a hash value h) and finds a message m which hashes to h.
  16.  
  17. A secure hash is intended to prevent collisions, even when an effort is being made to cause collisions.  A slow hashing function would make a dictionary attack difficult because of the amount of time it takes.
  18. Taking into account the above characteristics of a good hashing algorithm,  one would expect that if the input is changed even slightly ( like flipping of a single bit ), the output changes significantly. This is called the 'avalanche effect'. If a hash function does not exhibit avalanche effect to a significant degree(50% of the bits change ), then it has poor randomization and given enough time a cryptoanalyst would be able to predict the input given only the output. The avalanche effect is one of the primary design objectives. It is also the reason why hash functions have large data blocks.
  19.  
  20. Avalanche effect is helpful when one needs to use only a specific portion of the hash.
  21.  
  22. For an appropriately good hashing function removing some output bits demonstrably does not weaken it beyond the limit imposed by the number of remaining bits, with regards to collision resistance and preimage resistance and other useful properties. Collisions start are likely to occur when you have 2 to half the number of bits in the hash, but can occur at much earlier. So if you take a 256-bit hash with the avalanche effect like sha256 and take the 8 characters from its hex-digest (232 bits), you'll have a 50% chance of collision with 77,000 entries (roughly 216), a 1% chance of collision once you have about 9300 entries, 0.1% chance with 2900 entries etc, despite your hash about 4 billion different possible values of 232 bits.
  23.  
  24. Looking at other properties of hash functions, there is no proof that every output of the hash functuions is reachable for some input, but it is expected to be true. About 2134.5 (for MD5) or 2166.8 (for SHA-1) distinct messages are expected to be required to reach all output values, on the assumption that these hashes behave as random functions. If you found that it didn't generate some outputs, then this would be a flaw. It is at least a distinguisher, and most likely is indicative of some larger flaw, but how large the flaw is depends on many, many things.
  25.  
  26. These properties of hash functions have led us to decide how passwords should be stored. One should keep in mind that the space against which the attackers would be acting is not the output space of the hashing algorithm but only the password space. The most recommended hashing algorithm for storing passwords is 'bcrypt' which is typically slow.
  27. Bcrypt uses a variant of the Blowfish encryption algorithm’s keying schedule, and introduces a work factor, which allows you to determine how expensive the hash function will be. Because of this, bcrypt can keep up with Moore’s law. As computers get faster you can increase the work factor and the hash will get slower.
  28.  
  29. In usual scenarios a salted hash should be used. A salt is stored with the password in the database and is hashed together with the password to produce the hash. One can also use secret salt to be more secure. Secret salts are not stored in the same database but at a location not accessible by the potential attacker.
  30. Another possibility would be to use some kind of cryptographic hardware (a token) attached on the server with an embedded key, which does some hashing operation on salt, key and password to produce the hash.It should not have an interface to retrieve the secret key, otherwise your attacker (if he succeeds to gain execute access on the server) can use this, too.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top