Results 1 to 4 of 4

Thread: What is a hash and how do I make and use one in Ubuntu?

  1. #1
    Join Date
    May 2009
    Ubuntu Development Release

    What is a hash and how do I make and use one in Ubuntu?

    Hey all this might be in the wrong forum area, but it sounds security-ish so if its not I apologize. But in light of the whole PS3 lawsuit thing againt a guy who released a hash of a PS3 key, I'm sorta wondering what a hash is and how its different from a key? how is it used? How do I make one in ubuntu?

    Thanks in advanced!
    Echo "Your thoughts" > /dev/null

  2. #2
    Join Date
    Feb 2010
    Land of Confusion
    Ubuntu 14.04 Trusty Tahr

    Re: What is a hash and how do I make and use one in Ubuntu?

    Here is a link to the wiki on hashes.
    Thank you for your contributions. "So long and thanks for the fish!"

  3. #3
    Join Date
    May 2008
    Ubuntu 10.10 Maverick Meerkat

    Re: What is a hash and how do I make and use one in Ubuntu?

    That article looks a bit abstract, so here's a more practical explanation:
    A hash is a value generated by a one way transformation of some data.

    The main use of a hash is to verify you have the right data, as even a single bit changed in the source will change the entire thing.

    Lets say you are downloading randomrootutil.tar.gz
    Your ISP is hacked and it inserts the source of evilrootkit.c into rootutil_main.c

    You blindly compile and install the source, run the program and now evilrootkit.c running.

    However, if you had a hash, you could get the hash.
    When the hijacked randomrootutil.tar.gz downloads, you hash it yourself(with md5sum <file> or shasum <file>, depending on the hash algorithm), and see that it's changed.

    A more secure variant of this is combining it with public key.
    Alice writes a message "I decide to let the AI out of the box", hashes it, and encrypts it with his private key.

    Bob reads the message and decrypts Alice's hash with her public key(reminder, the public key can only decrypt things written with Bob's private key).

    Another use of hashes is in your password file.
    Your password isn't stored as plain text, so if your computer is compromised, it's harder to get your passwords.

    When you set a new password, any sane Linux distro generates a random salt, adds it to the end of the password, hashes and stores it.
    When you login, the salt is added to the end, hashed and compared.

    The salt is present to prevent reversing the hash(it's sort of a forced way of making the password stronger, without actually having to deal with stronger passwords).

    I don't see why a hash of a key would cause an uproar though, it's hard to reverse a hash(you have to randomly generate every possible input, and see if it matches up).

  4. #4
    Join Date
    May 2007
    STL, MO
    Kubuntu Karmic Koala (testing)

    Re: What is a hash and how do I make and use one in Ubuntu?

    There's no difference between the two when they are created. Hashes and keys are both outputs of a hashing function which accepts arbitrary data and performs a (ideally) one way function that creates a unique, fixed-length message. The whole point is the "one way" aspect. Let's say that you and I both know f(), and I give you y, which is the output of f(x) (i.e. f(x) = y), then there is no way that you can derive f^-1() (the inverse of f()) and thus calculate f^-1(y) = x. In this example, f() is a hashing function like sha1 or md5, x is input data (random or not), and y is the fixed-length output.

    The difference between a key and hash actually have to do with what the input is (x above). Valuable data is hashed. If I produce a file called book-report.txt and I give my teacher a hash of it, then the teacher knows exactly which file is mine. Hashes (hopefully) prove uniqueness. When you download a Linux iso, you often see md5 hashes posted with them. The point is that if I trust that I'm provided the with the correct hash, then I can download an ubuntu iso from a really shady website, and as long as I can run the hashing function on that file (like md5sum) and it matches, then that software is (hopefully) guaranteed to be Ubuntu without a single modification. All bits are identical.
    On the other hand, keys are used quite differently. Keys are created the same that hashes are: some data is provided to a hashing function and a fixed-length message is outputed(f(x) = y).
    The difference is what x is. In a hash, the input data is valuable; it's the data that I'm signing to be unique. In a key, it's usually just random garbage. I don't care what the input is when I make a key, as long as its quite random. Hashes are used to prove the uniqueness of data, but keys are used in a secondary crypto function. Hashes provide for data to be distributed in possibly insecure manners (like over the internet). Keys are used to secure the distribution method (like on encrypted web pages).

    You might have noticed that I've included "(hopefully)" several times. The idea is that if I put in x and get y, then out of all possible mathematical combinations of data, there is no way that I can get f(x) = y and f(z) = y where z is any other arbitrary data. That is that y represents only a single piece of data that is possible. This is obviously false. Remember that y is a fixed-length, but I can put in an infinitely long piece of data. There are infinite values for x, but finite values for y, so there are many possible Xs that produce y. Okay, we can't guarantee mathematical perfection, but hopefully the hashing function is very, very hard to reverse and useless if you could. (Finding two or more Xs that produce the same y is called a collision). Let's go back to the book report situation. Let's say that someone wants to sabotage me, and wants to submit a terrible book report that has the same hash as mine (since the teacher has the correct hash). If they could create a file that looks reasonably like a book report that matched my hash, then they have found a serious collision, and the hashing function is broken. People should stop using the hashing function immediately because it may be easy to make a valid-looking collision.
    With all modern hashes, this is basically impossible. The fake book report would likely be data that could never be mistaken for a book report; it might be like 80GB and just random data. This is where md5 is. There are known collisions, but they wouldn't be mistaken for valid data. Furthermore, there are some known Xs that produce the same y, but there is no reverse function (f^-1()), so an attacker cannot create imposter data given a hash.

    It's import to realize that the actual hash and key (and not what they represent, just the actual output data) are the same. They are created with the same process, although there are lots of processes (rsa, dsa, md5, blowfish, twofish, etc.).

    The PS3 uses keys to sign all the software that runs on the machines. It has keys that are used to secure the distribution (data stored on hard drive, discs, etc.) of data, even when it's being executed.
    Keys play into a larger situation with certificates and trust hierarchies. Basically, there are certain trusted authorities (like Versign), and anyone can be one; all it means is that I trust some entity to trust others. That trusted entity gives me a special hash called a certificate. Then agents go to that trusted authority and ask to be trusted. The trusted entity "signs" (another special hashing function) the agent's key, and the agent distributes some data to me. We have created a chain of trust. I trust the agent because I trust the entity that trusts agents. Sony will provide keys to a game studio to sign the GTA game, then when that runs on the PS3, the actual console knows that its okay to run the code because it trusts Sony's key.

    This whole system is very dependent on the trusted entity's "private key" secure. If anyone figures out what it is, then the whole chain is broken. Unauthorized agents can pose as legitmate ones, and users can't do anything about this. Hackers have basically gained f^-1(), although specifically it's sort of different. With the PS3, this means that any game distributor (studio, website, torrent, etc.) can sign their software with Sony's key and basically give it the official "Sony seal of approve," and the console will play the game as if nothing is wrong.

    Well, Sony was careless in the way that keys were exchanged on the PS3, and some hackers reversed engineered the private key. Anyone with that key can sign software and make it look legitimate. The problem, for Sony, is that since it's the root private key, they can't revoke it or change it without your PS3 taking a trip back to Sony headquarters for a software update (can't do it over the net since that could be faked with software that is signed by the very key that Sony is trying to erase).

    I have no intention of getting into an ideological debate about whether it's right that these keys have been leaked. I will discuss the cryptographical systems used, failures, and cryptographical theory, and keys/hashes/PKI/etc.

    It's also worth noting that, at least in the USA, the possession of these keys and the tools used to produce them are illegal. I would concede that it is extraordinarily unlikely that the FBI would come after you, but there is no doubt the possession of copy protection circumvention tools for game consoles is a violation of the "DMCA" 17 USC 1201(a)(1).

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts