Thread: SHA1 hash in C

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    77

    SHA1 hash in C

    I have a C project in Visual Studio 2017.
    I need to hash as SHA1 string a message to generate a session ID. Looking for a hash function I've been driven to OpenSSL library but I have the feeling to kill a fly with a hammer. Is there any other simple SHA1 standard library available?
    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    This is too easy, surely.
    sha1 source code - Google Search
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    It might not matter for your project, but if security is of any concern at all, SHA1 is the wrong tool for the job.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    77
    Thanks, interesting. What would be the options, knowing that my C app is server and the client is Angular. This said, what would be the appropriate C solution/library?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Are you fully aware of just how difficult it is to make a secure internet-facing application in C?

    Assuming Angular doesn't care how you generate your session tokens (only that they're represented as printable strings), you should go for the most secure hashing algorithm you can find. Your aim should be to minimise the possibility of attackers being able to say 'spoof' or 'replay' sessions with stolen tokens.

    > Looking for a hash function I've been driven to OpenSSL library but I have the feeling to kill a fly with a hammer
    How so?
    Surely you could use OpenSSL to provide other services as well, for example doing the heavy lifting of negotiating an https connection.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    77
    Thanks again, useful exchange, I'm on the same page with you. To clarify, OpenSSL does more than I need, but I found the solution.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Opariti View Post
    OpenSSL does more than I need
    In the same way that the C standard library does more than you need, most of the time. It's unreasonable to expect to use all, or even a majority of a particular library's functionality in any given project.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash function to hash key into geographic coordinate
    By dominic_tran201 in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2011, 10:03 AM
  2. Putting several hashes together. Better than md5/sha1?
    By idleman in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2009, 12:42 PM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. sha1
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 07-17-2004, 11:13 AM

Tags for this Thread