What is the benefit of having a cryptographically secure hash algorithm in hashmaps?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












I recently read the Rust language documentation and saw this:




By default, HashMap uses a cryptographically secure hashing function that can provide resistance to Denial of Service (DoS) attacks. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it.




As someone with no background in systems languages, I've never heard of in memory attacks based on the wrong hashing algorithm. So I got some questions:



How does the secure has algorithm prevent a DoS or any other attacks?



When should I opt for a more secure hash over a faster one?










share|improve this question







New contributor




Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    3
    down vote

    favorite












    I recently read the Rust language documentation and saw this:




    By default, HashMap uses a cryptographically secure hashing function that can provide resistance to Denial of Service (DoS) attacks. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it.




    As someone with no background in systems languages, I've never heard of in memory attacks based on the wrong hashing algorithm. So I got some questions:



    How does the secure has algorithm prevent a DoS or any other attacks?



    When should I opt for a more secure hash over a faster one?










    share|improve this question







    New contributor




    Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I recently read the Rust language documentation and saw this:




      By default, HashMap uses a cryptographically secure hashing function that can provide resistance to Denial of Service (DoS) attacks. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it.




      As someone with no background in systems languages, I've never heard of in memory attacks based on the wrong hashing algorithm. So I got some questions:



      How does the secure has algorithm prevent a DoS or any other attacks?



      When should I opt for a more secure hash over a faster one?










      share|improve this question







      New contributor




      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I recently read the Rust language documentation and saw this:




      By default, HashMap uses a cryptographically secure hashing function that can provide resistance to Denial of Service (DoS) attacks. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it.




      As someone with no background in systems languages, I've never heard of in memory attacks based on the wrong hashing algorithm. So I got some questions:



      How does the secure has algorithm prevent a DoS or any other attacks?



      When should I opt for a more secure hash over a faster one?







      hash memory rust






      share|improve this question







      New contributor




      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 26 mins ago









      Greaka

      1183




      1183




      New contributor




      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Greaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Sometimes applications use untrusted data as the key in a hash map. A simple implementation can allow the untrusted data to cause a denial of service attack.



          Hash maps are fast - O(1) - in the best case, but slow - O(n) - in the worst case. This is because keys are normally in separate buckets, but some values can result in the same hash - a collision - which are handled by a slower linked list. With random data, collisions will be uncommon. However, some implementation have a vulnerability where malicious data can cause many collisions, which makes the hash map slow. Some years ago there was a Linux kernel DoS due to this.



          The root cause of the Linux vulnerability was that hashing was predictable. It was fixed by introducing a key into the hash function that a remote user would not know. I don't know exactly how Rust hash maps work, but I expect they use a similar kind of keyed hash.



          You should opt for a more secure hash any time you're using untrusted data as a key.






          share|improve this answer



























            up vote
            3
            down vote













            I agree that's a little vague and it's going to heavily depend on how the hashmaps are used.



            Here's my guess: say you're taking some input from users, say [Firstname.Lastname] and using that as the lookup value in your hash table. Let's say you're building your hash table using the simple hash function that takes initials so that [Firstname.Lastname] --> FL then it would be easy for an attacker to submit loads of values that all hash to the same thing. That would essentially turn your hashtable into a list which negates all the performance gains of using a hashtable. Slow lookups = denial of service.



            AA -> [ ]
            AB -> [ ]
            ...
            FK -> [ ]
            FL -> [First.Last, F1.F2, F1.F2, Fanotheu.Lonteuh, ...]
            FM -> [ ]
            ...
            ZZ -> [ ]


            Cryptographic hash functions are specifically designed to prevent this because it's very hard to construct two different inputs that have the same hash value (called collisions).





            When should I opt for a more secure hash over a faster one?




            The answer is simple: opt for a cryptographic hash any time the lookup value is supplied by users and could be maliciously crafted. If the lookup values are coming from some internal source that you trust to be non-malicious and evenly distributed, then you can use a faster hash.






            share|improve this answer
















            • 1




              +1 for same answer as me, at the exact same time! A collision :)
              – paj28
              4 mins ago










            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "162"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Greaka is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f195134%2fwhat-is-the-benefit-of-having-a-cryptographically-secure-hash-algorithm-in-hashm%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Sometimes applications use untrusted data as the key in a hash map. A simple implementation can allow the untrusted data to cause a denial of service attack.



            Hash maps are fast - O(1) - in the best case, but slow - O(n) - in the worst case. This is because keys are normally in separate buckets, but some values can result in the same hash - a collision - which are handled by a slower linked list. With random data, collisions will be uncommon. However, some implementation have a vulnerability where malicious data can cause many collisions, which makes the hash map slow. Some years ago there was a Linux kernel DoS due to this.



            The root cause of the Linux vulnerability was that hashing was predictable. It was fixed by introducing a key into the hash function that a remote user would not know. I don't know exactly how Rust hash maps work, but I expect they use a similar kind of keyed hash.



            You should opt for a more secure hash any time you're using untrusted data as a key.






            share|improve this answer
























              up vote
              3
              down vote



              accepted










              Sometimes applications use untrusted data as the key in a hash map. A simple implementation can allow the untrusted data to cause a denial of service attack.



              Hash maps are fast - O(1) - in the best case, but slow - O(n) - in the worst case. This is because keys are normally in separate buckets, but some values can result in the same hash - a collision - which are handled by a slower linked list. With random data, collisions will be uncommon. However, some implementation have a vulnerability where malicious data can cause many collisions, which makes the hash map slow. Some years ago there was a Linux kernel DoS due to this.



              The root cause of the Linux vulnerability was that hashing was predictable. It was fixed by introducing a key into the hash function that a remote user would not know. I don't know exactly how Rust hash maps work, but I expect they use a similar kind of keyed hash.



              You should opt for a more secure hash any time you're using untrusted data as a key.






              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                Sometimes applications use untrusted data as the key in a hash map. A simple implementation can allow the untrusted data to cause a denial of service attack.



                Hash maps are fast - O(1) - in the best case, but slow - O(n) - in the worst case. This is because keys are normally in separate buckets, but some values can result in the same hash - a collision - which are handled by a slower linked list. With random data, collisions will be uncommon. However, some implementation have a vulnerability where malicious data can cause many collisions, which makes the hash map slow. Some years ago there was a Linux kernel DoS due to this.



                The root cause of the Linux vulnerability was that hashing was predictable. It was fixed by introducing a key into the hash function that a remote user would not know. I don't know exactly how Rust hash maps work, but I expect they use a similar kind of keyed hash.



                You should opt for a more secure hash any time you're using untrusted data as a key.






                share|improve this answer












                Sometimes applications use untrusted data as the key in a hash map. A simple implementation can allow the untrusted data to cause a denial of service attack.



                Hash maps are fast - O(1) - in the best case, but slow - O(n) - in the worst case. This is because keys are normally in separate buckets, but some values can result in the same hash - a collision - which are handled by a slower linked list. With random data, collisions will be uncommon. However, some implementation have a vulnerability where malicious data can cause many collisions, which makes the hash map slow. Some years ago there was a Linux kernel DoS due to this.



                The root cause of the Linux vulnerability was that hashing was predictable. It was fixed by introducing a key into the hash function that a remote user would not know. I don't know exactly how Rust hash maps work, but I expect they use a similar kind of keyed hash.



                You should opt for a more secure hash any time you're using untrusted data as a key.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 10 mins ago









                paj28

                25k366102




                25k366102






















                    up vote
                    3
                    down vote













                    I agree that's a little vague and it's going to heavily depend on how the hashmaps are used.



                    Here's my guess: say you're taking some input from users, say [Firstname.Lastname] and using that as the lookup value in your hash table. Let's say you're building your hash table using the simple hash function that takes initials so that [Firstname.Lastname] --> FL then it would be easy for an attacker to submit loads of values that all hash to the same thing. That would essentially turn your hashtable into a list which negates all the performance gains of using a hashtable. Slow lookups = denial of service.



                    AA -> [ ]
                    AB -> [ ]
                    ...
                    FK -> [ ]
                    FL -> [First.Last, F1.F2, F1.F2, Fanotheu.Lonteuh, ...]
                    FM -> [ ]
                    ...
                    ZZ -> [ ]


                    Cryptographic hash functions are specifically designed to prevent this because it's very hard to construct two different inputs that have the same hash value (called collisions).





                    When should I opt for a more secure hash over a faster one?




                    The answer is simple: opt for a cryptographic hash any time the lookup value is supplied by users and could be maliciously crafted. If the lookup values are coming from some internal source that you trust to be non-malicious and evenly distributed, then you can use a faster hash.






                    share|improve this answer
















                    • 1




                      +1 for same answer as me, at the exact same time! A collision :)
                      – paj28
                      4 mins ago














                    up vote
                    3
                    down vote













                    I agree that's a little vague and it's going to heavily depend on how the hashmaps are used.



                    Here's my guess: say you're taking some input from users, say [Firstname.Lastname] and using that as the lookup value in your hash table. Let's say you're building your hash table using the simple hash function that takes initials so that [Firstname.Lastname] --> FL then it would be easy for an attacker to submit loads of values that all hash to the same thing. That would essentially turn your hashtable into a list which negates all the performance gains of using a hashtable. Slow lookups = denial of service.



                    AA -> [ ]
                    AB -> [ ]
                    ...
                    FK -> [ ]
                    FL -> [First.Last, F1.F2, F1.F2, Fanotheu.Lonteuh, ...]
                    FM -> [ ]
                    ...
                    ZZ -> [ ]


                    Cryptographic hash functions are specifically designed to prevent this because it's very hard to construct two different inputs that have the same hash value (called collisions).





                    When should I opt for a more secure hash over a faster one?




                    The answer is simple: opt for a cryptographic hash any time the lookup value is supplied by users and could be maliciously crafted. If the lookup values are coming from some internal source that you trust to be non-malicious and evenly distributed, then you can use a faster hash.






                    share|improve this answer
















                    • 1




                      +1 for same answer as me, at the exact same time! A collision :)
                      – paj28
                      4 mins ago












                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    I agree that's a little vague and it's going to heavily depend on how the hashmaps are used.



                    Here's my guess: say you're taking some input from users, say [Firstname.Lastname] and using that as the lookup value in your hash table. Let's say you're building your hash table using the simple hash function that takes initials so that [Firstname.Lastname] --> FL then it would be easy for an attacker to submit loads of values that all hash to the same thing. That would essentially turn your hashtable into a list which negates all the performance gains of using a hashtable. Slow lookups = denial of service.



                    AA -> [ ]
                    AB -> [ ]
                    ...
                    FK -> [ ]
                    FL -> [First.Last, F1.F2, F1.F2, Fanotheu.Lonteuh, ...]
                    FM -> [ ]
                    ...
                    ZZ -> [ ]


                    Cryptographic hash functions are specifically designed to prevent this because it's very hard to construct two different inputs that have the same hash value (called collisions).





                    When should I opt for a more secure hash over a faster one?




                    The answer is simple: opt for a cryptographic hash any time the lookup value is supplied by users and could be maliciously crafted. If the lookup values are coming from some internal source that you trust to be non-malicious and evenly distributed, then you can use a faster hash.






                    share|improve this answer












                    I agree that's a little vague and it's going to heavily depend on how the hashmaps are used.



                    Here's my guess: say you're taking some input from users, say [Firstname.Lastname] and using that as the lookup value in your hash table. Let's say you're building your hash table using the simple hash function that takes initials so that [Firstname.Lastname] --> FL then it would be easy for an attacker to submit loads of values that all hash to the same thing. That would essentially turn your hashtable into a list which negates all the performance gains of using a hashtable. Slow lookups = denial of service.



                    AA -> [ ]
                    AB -> [ ]
                    ...
                    FK -> [ ]
                    FL -> [First.Last, F1.F2, F1.F2, Fanotheu.Lonteuh, ...]
                    FM -> [ ]
                    ...
                    ZZ -> [ ]


                    Cryptographic hash functions are specifically designed to prevent this because it's very hard to construct two different inputs that have the same hash value (called collisions).





                    When should I opt for a more secure hash over a faster one?




                    The answer is simple: opt for a cryptographic hash any time the lookup value is supplied by users and could be maliciously crafted. If the lookup values are coming from some internal source that you trust to be non-malicious and evenly distributed, then you can use a faster hash.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 10 mins ago









                    Mike Ounsworth

                    36.3k1485128




                    36.3k1485128







                    • 1




                      +1 for same answer as me, at the exact same time! A collision :)
                      – paj28
                      4 mins ago












                    • 1




                      +1 for same answer as me, at the exact same time! A collision :)
                      – paj28
                      4 mins ago







                    1




                    1




                    +1 for same answer as me, at the exact same time! A collision :)
                    – paj28
                    4 mins ago




                    +1 for same answer as me, at the exact same time! A collision :)
                    – paj28
                    4 mins ago










                    Greaka is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    Greaka is a new contributor. Be nice, and check out our Code of Conduct.












                    Greaka is a new contributor. Be nice, and check out our Code of Conduct.











                    Greaka is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f195134%2fwhat-is-the-benefit-of-having-a-cryptographically-secure-hash-algorithm-in-hashm%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    One-line joke