Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cryptographic hash functions in Python

I am writing a program in Python for elliptic curve cryptography (for school and out of interest). I am currently working on the digital signature algorithm. I am currently looking for a good and secure hashing function which is either standard in Python or can easily be downloaded and imported. I thought about SHA256, since that's the only one I know which hasn't been broken yet (as far as I know). However, I have also read that SHA shouldn't be used for cryptography. Is SHA256 appropriate for a digital signature algorithm? Or should a different hashing function be used? If so, which one would be a good choice?

like image 242
Dasherman Avatar asked Dec 04 '14 17:12

Dasherman


People also ask

Which are cryptographic hash functions?

A cryptographic hash function is an algorithm that takes an arbitrary amount of data input—a credential—and produces a fixed-size output of enciphered text called a hash value, or just “hash.” That enciphered text can then be stored instead of the password itself, and later used to verify the user.

Which hash function is used in Python?

Python hash() function is a built-in function and returns the hash value of an object if it has one. The hash value is an integer which is used to quickly compare dictionary keys while looking at a dictionary.

Is Python hash () secure?

A “cryptographic” hash function is one that makes finding hash collisions very difficult, and thus prevents attackers from landing collision attacks. So, there you have it: Python uses SipHash because it's a trusted, cryptographic hash function that should prevent collision attacks.


1 Answers

I use SHA-512 for a similar purpose, I think you'd be hard pressed to get much more secure than that. SHA-512 is available in python's hashlib, and can be used like so:

import hashlib
hashGen = hashlib.sha512()
hashGen.update("What you want to hash")
hash = hashGen.hexdigest()
print "your hash is: ", hash
like image 183
Patrick T Nelson Avatar answered Sep 18 '22 04:09

Patrick T Nelson