AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?How can one securely generate an asymmetric key pair from a short passphrase?Key derivation functions (KDF): What are? Main purposes? How can they be used?Cryptography Implementation in softwareHashing - Digital Signing and Trivial StretchingReason for replacing mifare classicFast Forward Hash SignaturesApplication level encryption and key renewalPassword derived hash to encrypt known plaintext as password checkSecurity of non-standard use for AES-256-CTR?Basic encrypted custom protocolcipherText = aes-ctr(key, iv+1, (plainText)); & authTag= aes-ctr(key, iv, aes-ecb(key, sha-1(cipherText+authData+key+iv))); is it secure?What should I use for consequent AES key derivation?

How to take photos in burst mode, without vibration?

In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?

Reserved de-dupe rules

Arrow those variables!

Were any external disk drives stacked vertically?

I Accidentally Deleted a Stock Terminal Theme

Can I ask the recruiters in my resume to put the reason why I am rejected?

Is "remove commented out code" correct English?

Doing something right before you need it - expression for this?

Facing a paradox: Earnshaw's theorem in one dimension

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Does a druid starting with a bow start with no arrows?

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Western buddy movie with a supernatural twist where a woman turns into an eagle at the end

Is there a hemisphere-neutral way of specifying a season?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Can I make "comment-region" comment empty lines?

intersection of two sorted vectors in C++

Can a virus destroy the BIOS of a modern computer?

What's the point of deactivating Num Lock on login screens?

UK: Is there precedent for the governments e-petition site changing the direction of a government decision?

How do I find out when a node was added to an availability group?

Is it inappropriate for a student to attend their mentor's dissertation defense?

90's TV series where a boy goes to another dimension through portal near power lines



AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?


How can one securely generate an asymmetric key pair from a short passphrase?Key derivation functions (KDF): What are? Main purposes? How can they be used?Cryptography Implementation in softwareHashing - Digital Signing and Trivial StretchingReason for replacing mifare classicFast Forward Hash SignaturesApplication level encryption and key renewalPassword derived hash to encrypt known plaintext as password checkSecurity of non-standard use for AES-256-CTR?Basic encrypted custom protocolcipherText = aes-ctr(key, iv+1, (plainText)); & authTag= aes-ctr(key, iv, aes-ecb(key, sha-1(cipherText+authData+key+iv))); is it secure?What should I use for consequent AES key derivation?













3












$begingroup$


I'd like to encrypt Text with AES/CTR and a password defined by the user in java. I already checked the internet (and stackoverflow) for answers. The most used version is to hash the user pw with sha1 and take only the first 16bytes.



But I don't think this can be a good pratice.



  1. sha1 is weak

  2. taking only the first 16bytes makes the hash also weak
    and rise the chance for a collision (even with sha-256)

Is this really the best practice? Why? How can I do things better?



Some links to the articles I mentioned:



  • https://stackoverflow.com/questions/3451670/java-aes-and-using-my-own-key

  • https://howtodoinjava.com/security/java-aes-encryption-example/

  • https://blog.axxg.de/java-aes-verschluesselung-mit-beispiel/









share|improve this question









New contributor




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







$endgroup$











  • $begingroup$
    I added the links
    $endgroup$
    – firendlyQuestion
    3 hours ago










  • $begingroup$
    They are not good sources. Anyway I will call this question as dupe of this and this
    $endgroup$
    – kelalaka
    2 hours ago















3












$begingroup$


I'd like to encrypt Text with AES/CTR and a password defined by the user in java. I already checked the internet (and stackoverflow) for answers. The most used version is to hash the user pw with sha1 and take only the first 16bytes.



But I don't think this can be a good pratice.



  1. sha1 is weak

  2. taking only the first 16bytes makes the hash also weak
    and rise the chance for a collision (even with sha-256)

Is this really the best practice? Why? How can I do things better?



Some links to the articles I mentioned:



  • https://stackoverflow.com/questions/3451670/java-aes-and-using-my-own-key

  • https://howtodoinjava.com/security/java-aes-encryption-example/

  • https://blog.axxg.de/java-aes-verschluesselung-mit-beispiel/









share|improve this question









New contributor




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







$endgroup$











  • $begingroup$
    I added the links
    $endgroup$
    – firendlyQuestion
    3 hours ago










  • $begingroup$
    They are not good sources. Anyway I will call this question as dupe of this and this
    $endgroup$
    – kelalaka
    2 hours ago













3












3








3





$begingroup$


I'd like to encrypt Text with AES/CTR and a password defined by the user in java. I already checked the internet (and stackoverflow) for answers. The most used version is to hash the user pw with sha1 and take only the first 16bytes.



But I don't think this can be a good pratice.



  1. sha1 is weak

  2. taking only the first 16bytes makes the hash also weak
    and rise the chance for a collision (even with sha-256)

Is this really the best practice? Why? How can I do things better?



Some links to the articles I mentioned:



  • https://stackoverflow.com/questions/3451670/java-aes-and-using-my-own-key

  • https://howtodoinjava.com/security/java-aes-encryption-example/

  • https://blog.axxg.de/java-aes-verschluesselung-mit-beispiel/









share|improve this question









New contributor




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







$endgroup$




I'd like to encrypt Text with AES/CTR and a password defined by the user in java. I already checked the internet (and stackoverflow) for answers. The most used version is to hash the user pw with sha1 and take only the first 16bytes.



But I don't think this can be a good pratice.



  1. sha1 is weak

  2. taking only the first 16bytes makes the hash also weak
    and rise the chance for a collision (even with sha-256)

Is this really the best practice? Why? How can I do things better?



Some links to the articles I mentioned:



  • https://stackoverflow.com/questions/3451670/java-aes-and-using-my-own-key

  • https://howtodoinjava.com/security/java-aes-encryption-example/

  • https://blog.axxg.de/java-aes-verschluesselung-mit-beispiel/






encryption hash aes symmetric






share|improve this question









New contributor




firendlyQuestion 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




firendlyQuestion 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








edited 3 hours ago







firendlyQuestion













New contributor




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









asked 3 hours ago









firendlyQuestionfirendlyQuestion

162




162




New contributor




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





New contributor





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






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











  • $begingroup$
    I added the links
    $endgroup$
    – firendlyQuestion
    3 hours ago










  • $begingroup$
    They are not good sources. Anyway I will call this question as dupe of this and this
    $endgroup$
    – kelalaka
    2 hours ago
















  • $begingroup$
    I added the links
    $endgroup$
    – firendlyQuestion
    3 hours ago










  • $begingroup$
    They are not good sources. Anyway I will call this question as dupe of this and this
    $endgroup$
    – kelalaka
    2 hours ago















$begingroup$
I added the links
$endgroup$
– firendlyQuestion
3 hours ago




$begingroup$
I added the links
$endgroup$
– firendlyQuestion
3 hours ago












$begingroup$
They are not good sources. Anyway I will call this question as dupe of this and this
$endgroup$
– kelalaka
2 hours ago




$begingroup$
They are not good sources. Anyway I will call this question as dupe of this and this
$endgroup$
– kelalaka
2 hours ago










1 Answer
1






active

oldest

votes


















5












$begingroup$


Why is it a good practice to use only the first 16 bytes of a hash for encryption?




As you noted, it isn't.



But, the problem is not with the "16 bytes" part of the statement, or the concern for collisions. The problem is with the "hash" part.



16 bytes



As stated in one of the links you shared, AES only uses key sizes of 128, 192, and 256 bits (or 16, 24, and 32 bytes, respectively). So the key must be one of these sizes, because AES simply does not support other key sizes.



Trying to use a larger key could have a variety of possible outcomes depending on what the implementation chooses to do. It might raise an exception, or continue silently while only using the first N bits of the supplied key.



Hashing a password to use as an encryption key



Using a hash function such as MD5, SHA1, SHA2, SHA3, blake2, etc, would all be bad practice. The first two are obvious: MD5 and SHA1 are known to be weak in general.



But even using a strong cryptographic hash like SHA3 or blake2 would also be bad, because they were not designed to solve the problem of deriving a key from a password. Use of a cryptographic hash function is involved in this process, but it is not the entirety of it.



Good practice would be to use a dedicated key derivation function such as Argon2 that was designed to solve this problem. If your library doesn't support Argon2 but supports scrypt, bcrypt or PBKDF2, any of these three is also a reasonable choice.



Why/How



A normal hash function is designed to be fast and require little space.



A hash function designed for use on passwords is quite the opposite: it is a slow function that requires lots of memory access, in an attempt to try and optimize the function towards what a consumer CPU is good at, and minimize the potential for optimization with special hardware. Specialized hardware is usable by an attacker, but a legitimate user is limited to a commodity CPU; The goal is to try and use a function that cannot take advantage of special hardware to the extent possible.



Details about the hows and whys of password hashing are listed in this paper and quoted below (with minor modifications, e.g. removing citations and modified formatting):




Cryptographic Security: The scheme should be cryptographically secure and as such possess the following properties:



  • 1) Preimage resistance

  • 2) Second preimage resistance

  • 3) collision resistance.

In addition it should avoid other cryptographic weaknesses such as those present in (some)Merkle-Damgård constructions(e.g. length extension attacks, partial message collisions, etc)



Defense against lookup table /TMTOAttacks:



  • The scheme should aim to make TMTO attacks that allow for precomputed lookup table generation, such as Rainbow Tables, infeasible

Defense against CPU-optimized 'crackers':



  • The scheme should be ‘CPU-hard’, that is, it should require significant amounts of CPU processing in a manner that cannot be optimized away through either software or hardware. As such, cracking-optimized (multi-core) CPU software implementations (eg. written in assembly, testing multiple input sets in parallel) should offer only minimal speed-up improvements compared to those intended for validation (“slower for attackers, faster for defenders”).

Defense against hardware-optimized 'crackers':



  • The scheme should be 'memory-hard', that is, it should significant amounts of RAM capacity in a manner that cannot be optimized away through eg. TMTO attacks. As such cracking-optimized ASIC, FPGA and GPU implementations should offer only minimal speed up improvements (eg. in terms of time-area product) compared to those intended for validation. As noted by Aumasson one of the main scheme design challenges is ensuring minimized efficiency on GPUs, FPGAs and ASICs (in order to minimize benefits of cracking-optimized implementations) and maximized efficiency on general-purpose CPUs (in order to maintain regular use efficiency).

Defense against side-channel attacks:



  • Depending on the use-case (eg. for key derivation or authentication to a device seeking to protect against modification by the device owner) side-channel attacks might be a relevant avenue of attack. Password hashing schemes should aim to offer side-channel resilience. With regards to password hashing scheme security we will focus on security versus the cache-timing type of side-channel attacks given the existence of such attacks against the commonly used scrypt scheme. The second category of side-channel attacks we will take into consideration are so-called Garbage Collector Attacks (GCAs). GCAs have been discussed in literature as an instance of a 'memory leak' attack relevant to password hashing scheme security. GCAs consist of a scenario where an attacker has access to a target machine's internal memory either after termination of the hashing scheme or at some point where the password itself is still present in memory (the so-called WeakGCA variant)...






share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "281"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    firendlyQuestion 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%2fcrypto.stackexchange.com%2fquestions%2f68545%2faes-why-is-it-a-good-practice-to-use-only-the-first-16bytes-of-a-hash-for-encry%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5












    $begingroup$


    Why is it a good practice to use only the first 16 bytes of a hash for encryption?




    As you noted, it isn't.



    But, the problem is not with the "16 bytes" part of the statement, or the concern for collisions. The problem is with the "hash" part.



    16 bytes



    As stated in one of the links you shared, AES only uses key sizes of 128, 192, and 256 bits (or 16, 24, and 32 bytes, respectively). So the key must be one of these sizes, because AES simply does not support other key sizes.



    Trying to use a larger key could have a variety of possible outcomes depending on what the implementation chooses to do. It might raise an exception, or continue silently while only using the first N bits of the supplied key.



    Hashing a password to use as an encryption key



    Using a hash function such as MD5, SHA1, SHA2, SHA3, blake2, etc, would all be bad practice. The first two are obvious: MD5 and SHA1 are known to be weak in general.



    But even using a strong cryptographic hash like SHA3 or blake2 would also be bad, because they were not designed to solve the problem of deriving a key from a password. Use of a cryptographic hash function is involved in this process, but it is not the entirety of it.



    Good practice would be to use a dedicated key derivation function such as Argon2 that was designed to solve this problem. If your library doesn't support Argon2 but supports scrypt, bcrypt or PBKDF2, any of these three is also a reasonable choice.



    Why/How



    A normal hash function is designed to be fast and require little space.



    A hash function designed for use on passwords is quite the opposite: it is a slow function that requires lots of memory access, in an attempt to try and optimize the function towards what a consumer CPU is good at, and minimize the potential for optimization with special hardware. Specialized hardware is usable by an attacker, but a legitimate user is limited to a commodity CPU; The goal is to try and use a function that cannot take advantage of special hardware to the extent possible.



    Details about the hows and whys of password hashing are listed in this paper and quoted below (with minor modifications, e.g. removing citations and modified formatting):




    Cryptographic Security: The scheme should be cryptographically secure and as such possess the following properties:



    • 1) Preimage resistance

    • 2) Second preimage resistance

    • 3) collision resistance.

    In addition it should avoid other cryptographic weaknesses such as those present in (some)Merkle-Damgård constructions(e.g. length extension attacks, partial message collisions, etc)



    Defense against lookup table /TMTOAttacks:



    • The scheme should aim to make TMTO attacks that allow for precomputed lookup table generation, such as Rainbow Tables, infeasible

    Defense against CPU-optimized 'crackers':



    • The scheme should be ‘CPU-hard’, that is, it should require significant amounts of CPU processing in a manner that cannot be optimized away through either software or hardware. As such, cracking-optimized (multi-core) CPU software implementations (eg. written in assembly, testing multiple input sets in parallel) should offer only minimal speed-up improvements compared to those intended for validation (“slower for attackers, faster for defenders”).

    Defense against hardware-optimized 'crackers':



    • The scheme should be 'memory-hard', that is, it should significant amounts of RAM capacity in a manner that cannot be optimized away through eg. TMTO attacks. As such cracking-optimized ASIC, FPGA and GPU implementations should offer only minimal speed up improvements (eg. in terms of time-area product) compared to those intended for validation. As noted by Aumasson one of the main scheme design challenges is ensuring minimized efficiency on GPUs, FPGAs and ASICs (in order to minimize benefits of cracking-optimized implementations) and maximized efficiency on general-purpose CPUs (in order to maintain regular use efficiency).

    Defense against side-channel attacks:



    • Depending on the use-case (eg. for key derivation or authentication to a device seeking to protect against modification by the device owner) side-channel attacks might be a relevant avenue of attack. Password hashing schemes should aim to offer side-channel resilience. With regards to password hashing scheme security we will focus on security versus the cache-timing type of side-channel attacks given the existence of such attacks against the commonly used scrypt scheme. The second category of side-channel attacks we will take into consideration are so-called Garbage Collector Attacks (GCAs). GCAs have been discussed in literature as an instance of a 'memory leak' attack relevant to password hashing scheme security. GCAs consist of a scenario where an attacker has access to a target machine's internal memory either after termination of the hashing scheme or at some point where the password itself is still present in memory (the so-called WeakGCA variant)...






    share|improve this answer











    $endgroup$

















      5












      $begingroup$


      Why is it a good practice to use only the first 16 bytes of a hash for encryption?




      As you noted, it isn't.



      But, the problem is not with the "16 bytes" part of the statement, or the concern for collisions. The problem is with the "hash" part.



      16 bytes



      As stated in one of the links you shared, AES only uses key sizes of 128, 192, and 256 bits (or 16, 24, and 32 bytes, respectively). So the key must be one of these sizes, because AES simply does not support other key sizes.



      Trying to use a larger key could have a variety of possible outcomes depending on what the implementation chooses to do. It might raise an exception, or continue silently while only using the first N bits of the supplied key.



      Hashing a password to use as an encryption key



      Using a hash function such as MD5, SHA1, SHA2, SHA3, blake2, etc, would all be bad practice. The first two are obvious: MD5 and SHA1 are known to be weak in general.



      But even using a strong cryptographic hash like SHA3 or blake2 would also be bad, because they were not designed to solve the problem of deriving a key from a password. Use of a cryptographic hash function is involved in this process, but it is not the entirety of it.



      Good practice would be to use a dedicated key derivation function such as Argon2 that was designed to solve this problem. If your library doesn't support Argon2 but supports scrypt, bcrypt or PBKDF2, any of these three is also a reasonable choice.



      Why/How



      A normal hash function is designed to be fast and require little space.



      A hash function designed for use on passwords is quite the opposite: it is a slow function that requires lots of memory access, in an attempt to try and optimize the function towards what a consumer CPU is good at, and minimize the potential for optimization with special hardware. Specialized hardware is usable by an attacker, but a legitimate user is limited to a commodity CPU; The goal is to try and use a function that cannot take advantage of special hardware to the extent possible.



      Details about the hows and whys of password hashing are listed in this paper and quoted below (with minor modifications, e.g. removing citations and modified formatting):




      Cryptographic Security: The scheme should be cryptographically secure and as such possess the following properties:



      • 1) Preimage resistance

      • 2) Second preimage resistance

      • 3) collision resistance.

      In addition it should avoid other cryptographic weaknesses such as those present in (some)Merkle-Damgård constructions(e.g. length extension attacks, partial message collisions, etc)



      Defense against lookup table /TMTOAttacks:



      • The scheme should aim to make TMTO attacks that allow for precomputed lookup table generation, such as Rainbow Tables, infeasible

      Defense against CPU-optimized 'crackers':



      • The scheme should be ‘CPU-hard’, that is, it should require significant amounts of CPU processing in a manner that cannot be optimized away through either software or hardware. As such, cracking-optimized (multi-core) CPU software implementations (eg. written in assembly, testing multiple input sets in parallel) should offer only minimal speed-up improvements compared to those intended for validation (“slower for attackers, faster for defenders”).

      Defense against hardware-optimized 'crackers':



      • The scheme should be 'memory-hard', that is, it should significant amounts of RAM capacity in a manner that cannot be optimized away through eg. TMTO attacks. As such cracking-optimized ASIC, FPGA and GPU implementations should offer only minimal speed up improvements (eg. in terms of time-area product) compared to those intended for validation. As noted by Aumasson one of the main scheme design challenges is ensuring minimized efficiency on GPUs, FPGAs and ASICs (in order to minimize benefits of cracking-optimized implementations) and maximized efficiency on general-purpose CPUs (in order to maintain regular use efficiency).

      Defense against side-channel attacks:



      • Depending on the use-case (eg. for key derivation or authentication to a device seeking to protect against modification by the device owner) side-channel attacks might be a relevant avenue of attack. Password hashing schemes should aim to offer side-channel resilience. With regards to password hashing scheme security we will focus on security versus the cache-timing type of side-channel attacks given the existence of such attacks against the commonly used scrypt scheme. The second category of side-channel attacks we will take into consideration are so-called Garbage Collector Attacks (GCAs). GCAs have been discussed in literature as an instance of a 'memory leak' attack relevant to password hashing scheme security. GCAs consist of a scenario where an attacker has access to a target machine's internal memory either after termination of the hashing scheme or at some point where the password itself is still present in memory (the so-called WeakGCA variant)...






      share|improve this answer











      $endgroup$















        5












        5








        5





        $begingroup$


        Why is it a good practice to use only the first 16 bytes of a hash for encryption?




        As you noted, it isn't.



        But, the problem is not with the "16 bytes" part of the statement, or the concern for collisions. The problem is with the "hash" part.



        16 bytes



        As stated in one of the links you shared, AES only uses key sizes of 128, 192, and 256 bits (or 16, 24, and 32 bytes, respectively). So the key must be one of these sizes, because AES simply does not support other key sizes.



        Trying to use a larger key could have a variety of possible outcomes depending on what the implementation chooses to do. It might raise an exception, or continue silently while only using the first N bits of the supplied key.



        Hashing a password to use as an encryption key



        Using a hash function such as MD5, SHA1, SHA2, SHA3, blake2, etc, would all be bad practice. The first two are obvious: MD5 and SHA1 are known to be weak in general.



        But even using a strong cryptographic hash like SHA3 or blake2 would also be bad, because they were not designed to solve the problem of deriving a key from a password. Use of a cryptographic hash function is involved in this process, but it is not the entirety of it.



        Good practice would be to use a dedicated key derivation function such as Argon2 that was designed to solve this problem. If your library doesn't support Argon2 but supports scrypt, bcrypt or PBKDF2, any of these three is also a reasonable choice.



        Why/How



        A normal hash function is designed to be fast and require little space.



        A hash function designed for use on passwords is quite the opposite: it is a slow function that requires lots of memory access, in an attempt to try and optimize the function towards what a consumer CPU is good at, and minimize the potential for optimization with special hardware. Specialized hardware is usable by an attacker, but a legitimate user is limited to a commodity CPU; The goal is to try and use a function that cannot take advantage of special hardware to the extent possible.



        Details about the hows and whys of password hashing are listed in this paper and quoted below (with minor modifications, e.g. removing citations and modified formatting):




        Cryptographic Security: The scheme should be cryptographically secure and as such possess the following properties:



        • 1) Preimage resistance

        • 2) Second preimage resistance

        • 3) collision resistance.

        In addition it should avoid other cryptographic weaknesses such as those present in (some)Merkle-Damgård constructions(e.g. length extension attacks, partial message collisions, etc)



        Defense against lookup table /TMTOAttacks:



        • The scheme should aim to make TMTO attacks that allow for precomputed lookup table generation, such as Rainbow Tables, infeasible

        Defense against CPU-optimized 'crackers':



        • The scheme should be ‘CPU-hard’, that is, it should require significant amounts of CPU processing in a manner that cannot be optimized away through either software or hardware. As such, cracking-optimized (multi-core) CPU software implementations (eg. written in assembly, testing multiple input sets in parallel) should offer only minimal speed-up improvements compared to those intended for validation (“slower for attackers, faster for defenders”).

        Defense against hardware-optimized 'crackers':



        • The scheme should be 'memory-hard', that is, it should significant amounts of RAM capacity in a manner that cannot be optimized away through eg. TMTO attacks. As such cracking-optimized ASIC, FPGA and GPU implementations should offer only minimal speed up improvements (eg. in terms of time-area product) compared to those intended for validation. As noted by Aumasson one of the main scheme design challenges is ensuring minimized efficiency on GPUs, FPGAs and ASICs (in order to minimize benefits of cracking-optimized implementations) and maximized efficiency on general-purpose CPUs (in order to maintain regular use efficiency).

        Defense against side-channel attacks:



        • Depending on the use-case (eg. for key derivation or authentication to a device seeking to protect against modification by the device owner) side-channel attacks might be a relevant avenue of attack. Password hashing schemes should aim to offer side-channel resilience. With regards to password hashing scheme security we will focus on security versus the cache-timing type of side-channel attacks given the existence of such attacks against the commonly used scrypt scheme. The second category of side-channel attacks we will take into consideration are so-called Garbage Collector Attacks (GCAs). GCAs have been discussed in literature as an instance of a 'memory leak' attack relevant to password hashing scheme security. GCAs consist of a scenario where an attacker has access to a target machine's internal memory either after termination of the hashing scheme or at some point where the password itself is still present in memory (the so-called WeakGCA variant)...






        share|improve this answer











        $endgroup$




        Why is it a good practice to use only the first 16 bytes of a hash for encryption?




        As you noted, it isn't.



        But, the problem is not with the "16 bytes" part of the statement, or the concern for collisions. The problem is with the "hash" part.



        16 bytes



        As stated in one of the links you shared, AES only uses key sizes of 128, 192, and 256 bits (or 16, 24, and 32 bytes, respectively). So the key must be one of these sizes, because AES simply does not support other key sizes.



        Trying to use a larger key could have a variety of possible outcomes depending on what the implementation chooses to do. It might raise an exception, or continue silently while only using the first N bits of the supplied key.



        Hashing a password to use as an encryption key



        Using a hash function such as MD5, SHA1, SHA2, SHA3, blake2, etc, would all be bad practice. The first two are obvious: MD5 and SHA1 are known to be weak in general.



        But even using a strong cryptographic hash like SHA3 or blake2 would also be bad, because they were not designed to solve the problem of deriving a key from a password. Use of a cryptographic hash function is involved in this process, but it is not the entirety of it.



        Good practice would be to use a dedicated key derivation function such as Argon2 that was designed to solve this problem. If your library doesn't support Argon2 but supports scrypt, bcrypt or PBKDF2, any of these three is also a reasonable choice.



        Why/How



        A normal hash function is designed to be fast and require little space.



        A hash function designed for use on passwords is quite the opposite: it is a slow function that requires lots of memory access, in an attempt to try and optimize the function towards what a consumer CPU is good at, and minimize the potential for optimization with special hardware. Specialized hardware is usable by an attacker, but a legitimate user is limited to a commodity CPU; The goal is to try and use a function that cannot take advantage of special hardware to the extent possible.



        Details about the hows and whys of password hashing are listed in this paper and quoted below (with minor modifications, e.g. removing citations and modified formatting):




        Cryptographic Security: The scheme should be cryptographically secure and as such possess the following properties:



        • 1) Preimage resistance

        • 2) Second preimage resistance

        • 3) collision resistance.

        In addition it should avoid other cryptographic weaknesses such as those present in (some)Merkle-Damgård constructions(e.g. length extension attacks, partial message collisions, etc)



        Defense against lookup table /TMTOAttacks:



        • The scheme should aim to make TMTO attacks that allow for precomputed lookup table generation, such as Rainbow Tables, infeasible

        Defense against CPU-optimized 'crackers':



        • The scheme should be ‘CPU-hard’, that is, it should require significant amounts of CPU processing in a manner that cannot be optimized away through either software or hardware. As such, cracking-optimized (multi-core) CPU software implementations (eg. written in assembly, testing multiple input sets in parallel) should offer only minimal speed-up improvements compared to those intended for validation (“slower for attackers, faster for defenders”).

        Defense against hardware-optimized 'crackers':



        • The scheme should be 'memory-hard', that is, it should significant amounts of RAM capacity in a manner that cannot be optimized away through eg. TMTO attacks. As such cracking-optimized ASIC, FPGA and GPU implementations should offer only minimal speed up improvements (eg. in terms of time-area product) compared to those intended for validation. As noted by Aumasson one of the main scheme design challenges is ensuring minimized efficiency on GPUs, FPGAs and ASICs (in order to minimize benefits of cracking-optimized implementations) and maximized efficiency on general-purpose CPUs (in order to maintain regular use efficiency).

        Defense against side-channel attacks:



        • Depending on the use-case (eg. for key derivation or authentication to a device seeking to protect against modification by the device owner) side-channel attacks might be a relevant avenue of attack. Password hashing schemes should aim to offer side-channel resilience. With regards to password hashing scheme security we will focus on security versus the cache-timing type of side-channel attacks given the existence of such attacks against the commonly used scrypt scheme. The second category of side-channel attacks we will take into consideration are so-called Garbage Collector Attacks (GCAs). GCAs have been discussed in literature as an instance of a 'memory leak' attack relevant to password hashing scheme security. GCAs consist of a scenario where an attacker has access to a target machine's internal memory either after termination of the hashing scheme or at some point where the password itself is still present in memory (the so-called WeakGCA variant)...







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 35 mins ago









        Gilles

        8,27732755




        8,27732755










        answered 2 hours ago









        Ella RoseElla Rose

        16.8k44482




        16.8k44482




















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









            draft saved

            draft discarded


















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












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











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














            Thanks for contributing an answer to Cryptography Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcrypto.stackexchange.com%2fquestions%2f68545%2faes-why-is-it-a-good-practice-to-use-only-the-first-16bytes-of-a-hash-for-encry%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

            Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

            Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar