Truncating the output of AES-128












3












$begingroup$


I'd like to use the output of a pseudorandom function (PRF) as a one time pad.



I want to use AES-128 (as it's commonly used as a PRF). As we know AES-128 output 128 bits.



Question: Would be secure to truncate the output of AES-128 and get only 32 or 64 bits of it as one time pad to mask some 32 or 64 bits value respectively?










share|improve this question









$endgroup$








  • 3




    $begingroup$
    Why don't you use AES in CTR mode? Which doesn't need a padding?
    $endgroup$
    – kelalaka
    Feb 20 at 15:14










  • $begingroup$
    Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
    $endgroup$
    – Natanael
    Feb 20 at 15:48










  • $begingroup$
    @Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
    $endgroup$
    – Ay.
    Feb 20 at 15:54












  • $begingroup$
    @Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
    $endgroup$
    – Natanael
    Feb 20 at 16:40






  • 1




    $begingroup$
    @Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
    $endgroup$
    – Squeamish Ossifrage
    Feb 21 at 0:54


















3












$begingroup$


I'd like to use the output of a pseudorandom function (PRF) as a one time pad.



I want to use AES-128 (as it's commonly used as a PRF). As we know AES-128 output 128 bits.



Question: Would be secure to truncate the output of AES-128 and get only 32 or 64 bits of it as one time pad to mask some 32 or 64 bits value respectively?










share|improve this question









$endgroup$








  • 3




    $begingroup$
    Why don't you use AES in CTR mode? Which doesn't need a padding?
    $endgroup$
    – kelalaka
    Feb 20 at 15:14










  • $begingroup$
    Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
    $endgroup$
    – Natanael
    Feb 20 at 15:48










  • $begingroup$
    @Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
    $endgroup$
    – Ay.
    Feb 20 at 15:54












  • $begingroup$
    @Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
    $endgroup$
    – Natanael
    Feb 20 at 16:40






  • 1




    $begingroup$
    @Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
    $endgroup$
    – Squeamish Ossifrage
    Feb 21 at 0:54
















3












3








3


1



$begingroup$


I'd like to use the output of a pseudorandom function (PRF) as a one time pad.



I want to use AES-128 (as it's commonly used as a PRF). As we know AES-128 output 128 bits.



Question: Would be secure to truncate the output of AES-128 and get only 32 or 64 bits of it as one time pad to mask some 32 or 64 bits value respectively?










share|improve this question









$endgroup$




I'd like to use the output of a pseudorandom function (PRF) as a one time pad.



I want to use AES-128 (as it's commonly used as a PRF). As we know AES-128 output 128 bits.



Question: Would be secure to truncate the output of AES-128 and get only 32 or 64 bits of it as one time pad to mask some 32 or 64 bits value respectively?







aes pseudo-random-function






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 20 at 14:47









Ay.Ay.

1817




1817








  • 3




    $begingroup$
    Why don't you use AES in CTR mode? Which doesn't need a padding?
    $endgroup$
    – kelalaka
    Feb 20 at 15:14










  • $begingroup$
    Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
    $endgroup$
    – Natanael
    Feb 20 at 15:48










  • $begingroup$
    @Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
    $endgroup$
    – Ay.
    Feb 20 at 15:54












  • $begingroup$
    @Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
    $endgroup$
    – Natanael
    Feb 20 at 16:40






  • 1




    $begingroup$
    @Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
    $endgroup$
    – Squeamish Ossifrage
    Feb 21 at 0:54
















  • 3




    $begingroup$
    Why don't you use AES in CTR mode? Which doesn't need a padding?
    $endgroup$
    – kelalaka
    Feb 20 at 15:14










  • $begingroup$
    Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
    $endgroup$
    – Natanael
    Feb 20 at 15:48










  • $begingroup$
    @Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
    $endgroup$
    – Ay.
    Feb 20 at 15:54












  • $begingroup$
    @Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
    $endgroup$
    – Natanael
    Feb 20 at 16:40






  • 1




    $begingroup$
    @Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
    $endgroup$
    – Squeamish Ossifrage
    Feb 21 at 0:54










3




3




$begingroup$
Why don't you use AES in CTR mode? Which doesn't need a padding?
$endgroup$
– kelalaka
Feb 20 at 15:14




$begingroup$
Why don't you use AES in CTR mode? Which doesn't need a padding?
$endgroup$
– kelalaka
Feb 20 at 15:14












$begingroup$
Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
$endgroup$
– Natanael
Feb 20 at 15:48




$begingroup$
Or a XOF such as SHAKE256, which doesn't require the seed to be in any particular format
$endgroup$
– Natanael
Feb 20 at 15:48












$begingroup$
@Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
$endgroup$
– Ay.
Feb 20 at 15:54






$begingroup$
@Natanael it seems AES is faster than SHA, look at here, page 11: fc14.ifca.ai/papers/fc14_submission_52.pdf
$endgroup$
– Ay.
Feb 20 at 15:54














$begingroup$
@Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
$endgroup$
– Natanael
Feb 20 at 16:40




$begingroup$
@Ay. SHAKE256 is based on SHA3, not SHA1, and should be much faster than SHA1. Perhaps even KangarooTwelve from the same team for more speed. keccak.team/kangarootwelve.html
$endgroup$
– Natanael
Feb 20 at 16:40




1




1




$begingroup$
@Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
$endgroup$
– Squeamish Ossifrage
Feb 21 at 0:54






$begingroup$
@Natanael If any of the SHA-3 functions performed better than SHA-1 in a fair comparison (hardware SHA-3 vs. software SHA-1 being unfair), I would be rather surprised. See bench.cr.yp.to/results-hash.html for a large collection of measurements. Heuristically: SHA-3 was engineered to have a much higher security margin than SHA-1, not to run faster; both of them pay the high cost of collision resistance, while AES does not. (But of course AES also invites timing side channels in software, which none of the SHAs do.)
$endgroup$
– Squeamish Ossifrage
Feb 21 at 0:54












3 Answers
3






active

oldest

votes


















9












$begingroup$

What you describe is exactly using AES-CTR to encrypt a 32-bit or 64-bit message. So, yes.






share|improve this answer









$endgroup$













  • $begingroup$
    Even, from 1 bit to 128.
    $endgroup$
    – kelalaka
    Feb 20 at 18:45






  • 2




    $begingroup$
    AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
    $endgroup$
    – Squeamish Ossifrage
    Feb 20 at 18:46



















6












$begingroup$

AES-128 instantiates a pseudorandom permutation (PRP) (and a PRP is also a PRF). Theoretically, truncating AES-128's output does not weaken its security, which depends only on its key size. Intuitively, an attacker gets less information from, say, a 64-bit output than from a 128-bit output. So, for example, distinguishing the truncated 64-bit output from a random 64-bit string is at least as hard as distinguishing AES-128's 128-bit output from a random 128-bit string.






share|improve this answer









$endgroup$





















    2












    $begingroup$

    A true one-time-pad requires a true random number generator to generate the pads. However, let's assume that what you really want to have is a cipher that simulates a one-time-pad. Such a cipher, which creates a key stream is called a stream cipher. So what you want is a stream cipher with limited output, based on AES.



    As written in other answers there are known ways of generating a stream cipher from a block cipher. Probably the best known one is counter mode or CTR. There are other modes possible, but note that some of these streaming modes depend on the plaintext and are therefore different from how an OTP is used. So lets focus on counter mode.



    Counter mode depends as the name suggests on a counter which is generated starting from an initial counter value. This value is commonly generated from a nonce, which is either deterministically generated or random. If the nonce is indeed unique then you can use AES to generate the key stream, take as many bits you want from it, and then XOR them with the plaintext message of 32 or 64 bit.



    The problem occurs if you want to encrypt more 32 or 64 bit values. In that case you need a new nonce, or you would generate a many time pad or Vigenère cipher, which is obviously not secure. You can simply store a random nonce with the encrypted bits, but then you would expand the ciphertext possibly by a large margin compared to the plaintext (depending on the size of the nonce); probably at least by 64 bits.



    It may be that you need Format Preserving Encryption (FPE) or a block cipher with small small sized blocks instead. This is deterministic encryption, so identical plaintext will lead to identical ciphertext, leaking information. The advantage is that it doesn't leak any actual bits of the plaintext, like CTR does when it generates the Vigenère cipher / many-time-pad. Depending on the information in the plaintext, the many-time-pad will likely completely compromise security including confidentiality.



    Beware that neither of the options given provides integrity / authenticity. This will be particularly hard to achieve anyway if you want to keep the ciphertext near the size of the plaintext. Probably best to use FPE with a few bits set to a checksum to that there is at least a high chance of detecting integrity issues (especially if multiple ciphertext are altered).






    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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcrypto.stackexchange.com%2fquestions%2f67463%2ftruncating-the-output-of-aes-128%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9












      $begingroup$

      What you describe is exactly using AES-CTR to encrypt a 32-bit or 64-bit message. So, yes.






      share|improve this answer









      $endgroup$













      • $begingroup$
        Even, from 1 bit to 128.
        $endgroup$
        – kelalaka
        Feb 20 at 18:45






      • 2




        $begingroup$
        AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
        $endgroup$
        – Squeamish Ossifrage
        Feb 20 at 18:46
















      9












      $begingroup$

      What you describe is exactly using AES-CTR to encrypt a 32-bit or 64-bit message. So, yes.






      share|improve this answer









      $endgroup$













      • $begingroup$
        Even, from 1 bit to 128.
        $endgroup$
        – kelalaka
        Feb 20 at 18:45






      • 2




        $begingroup$
        AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
        $endgroup$
        – Squeamish Ossifrage
        Feb 20 at 18:46














      9












      9








      9





      $begingroup$

      What you describe is exactly using AES-CTR to encrypt a 32-bit or 64-bit message. So, yes.






      share|improve this answer









      $endgroup$



      What you describe is exactly using AES-CTR to encrypt a 32-bit or 64-bit message. So, yes.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Feb 20 at 18:28









      Squeamish OssifrageSqueamish Ossifrage

      21k13197




      21k13197












      • $begingroup$
        Even, from 1 bit to 128.
        $endgroup$
        – kelalaka
        Feb 20 at 18:45






      • 2




        $begingroup$
        AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
        $endgroup$
        – Squeamish Ossifrage
        Feb 20 at 18:46


















      • $begingroup$
        Even, from 1 bit to 128.
        $endgroup$
        – kelalaka
        Feb 20 at 18:45






      • 2




        $begingroup$
        AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
        $endgroup$
        – Squeamish Ossifrage
        Feb 20 at 18:46
















      $begingroup$
      Even, from 1 bit to 128.
      $endgroup$
      – kelalaka
      Feb 20 at 18:45




      $begingroup$
      Even, from 1 bit to 128.
      $endgroup$
      – kelalaka
      Feb 20 at 18:45




      2




      2




      $begingroup$
      AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
      $endgroup$
      – Squeamish Ossifrage
      Feb 20 at 18:46




      $begingroup$
      AES-CTR works on any number of bits. Obviously you can't reduce the adversary's probability of correctly guessing what one-bit message was below $1/2$, but that's not AES's fault.
      $endgroup$
      – Squeamish Ossifrage
      Feb 20 at 18:46











      6












      $begingroup$

      AES-128 instantiates a pseudorandom permutation (PRP) (and a PRP is also a PRF). Theoretically, truncating AES-128's output does not weaken its security, which depends only on its key size. Intuitively, an attacker gets less information from, say, a 64-bit output than from a 128-bit output. So, for example, distinguishing the truncated 64-bit output from a random 64-bit string is at least as hard as distinguishing AES-128's 128-bit output from a random 128-bit string.






      share|improve this answer









      $endgroup$


















        6












        $begingroup$

        AES-128 instantiates a pseudorandom permutation (PRP) (and a PRP is also a PRF). Theoretically, truncating AES-128's output does not weaken its security, which depends only on its key size. Intuitively, an attacker gets less information from, say, a 64-bit output than from a 128-bit output. So, for example, distinguishing the truncated 64-bit output from a random 64-bit string is at least as hard as distinguishing AES-128's 128-bit output from a random 128-bit string.






        share|improve this answer









        $endgroup$
















          6












          6








          6





          $begingroup$

          AES-128 instantiates a pseudorandom permutation (PRP) (and a PRP is also a PRF). Theoretically, truncating AES-128's output does not weaken its security, which depends only on its key size. Intuitively, an attacker gets less information from, say, a 64-bit output than from a 128-bit output. So, for example, distinguishing the truncated 64-bit output from a random 64-bit string is at least as hard as distinguishing AES-128's 128-bit output from a random 128-bit string.






          share|improve this answer









          $endgroup$



          AES-128 instantiates a pseudorandom permutation (PRP) (and a PRP is also a PRF). Theoretically, truncating AES-128's output does not weaken its security, which depends only on its key size. Intuitively, an attacker gets less information from, say, a 64-bit output than from a 128-bit output. So, for example, distinguishing the truncated 64-bit output from a random 64-bit string is at least as hard as distinguishing AES-128's 128-bit output from a random 128-bit string.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 20 at 18:25









          Shan ChenShan Chen

          1,905613




          1,905613























              2












              $begingroup$

              A true one-time-pad requires a true random number generator to generate the pads. However, let's assume that what you really want to have is a cipher that simulates a one-time-pad. Such a cipher, which creates a key stream is called a stream cipher. So what you want is a stream cipher with limited output, based on AES.



              As written in other answers there are known ways of generating a stream cipher from a block cipher. Probably the best known one is counter mode or CTR. There are other modes possible, but note that some of these streaming modes depend on the plaintext and are therefore different from how an OTP is used. So lets focus on counter mode.



              Counter mode depends as the name suggests on a counter which is generated starting from an initial counter value. This value is commonly generated from a nonce, which is either deterministically generated or random. If the nonce is indeed unique then you can use AES to generate the key stream, take as many bits you want from it, and then XOR them with the plaintext message of 32 or 64 bit.



              The problem occurs if you want to encrypt more 32 or 64 bit values. In that case you need a new nonce, or you would generate a many time pad or Vigenère cipher, which is obviously not secure. You can simply store a random nonce with the encrypted bits, but then you would expand the ciphertext possibly by a large margin compared to the plaintext (depending on the size of the nonce); probably at least by 64 bits.



              It may be that you need Format Preserving Encryption (FPE) or a block cipher with small small sized blocks instead. This is deterministic encryption, so identical plaintext will lead to identical ciphertext, leaking information. The advantage is that it doesn't leak any actual bits of the plaintext, like CTR does when it generates the Vigenère cipher / many-time-pad. Depending on the information in the plaintext, the many-time-pad will likely completely compromise security including confidentiality.



              Beware that neither of the options given provides integrity / authenticity. This will be particularly hard to achieve anyway if you want to keep the ciphertext near the size of the plaintext. Probably best to use FPE with a few bits set to a checksum to that there is at least a high chance of detecting integrity issues (especially if multiple ciphertext are altered).






              share|improve this answer











              $endgroup$


















                2












                $begingroup$

                A true one-time-pad requires a true random number generator to generate the pads. However, let's assume that what you really want to have is a cipher that simulates a one-time-pad. Such a cipher, which creates a key stream is called a stream cipher. So what you want is a stream cipher with limited output, based on AES.



                As written in other answers there are known ways of generating a stream cipher from a block cipher. Probably the best known one is counter mode or CTR. There are other modes possible, but note that some of these streaming modes depend on the plaintext and are therefore different from how an OTP is used. So lets focus on counter mode.



                Counter mode depends as the name suggests on a counter which is generated starting from an initial counter value. This value is commonly generated from a nonce, which is either deterministically generated or random. If the nonce is indeed unique then you can use AES to generate the key stream, take as many bits you want from it, and then XOR them with the plaintext message of 32 or 64 bit.



                The problem occurs if you want to encrypt more 32 or 64 bit values. In that case you need a new nonce, or you would generate a many time pad or Vigenère cipher, which is obviously not secure. You can simply store a random nonce with the encrypted bits, but then you would expand the ciphertext possibly by a large margin compared to the plaintext (depending on the size of the nonce); probably at least by 64 bits.



                It may be that you need Format Preserving Encryption (FPE) or a block cipher with small small sized blocks instead. This is deterministic encryption, so identical plaintext will lead to identical ciphertext, leaking information. The advantage is that it doesn't leak any actual bits of the plaintext, like CTR does when it generates the Vigenère cipher / many-time-pad. Depending on the information in the plaintext, the many-time-pad will likely completely compromise security including confidentiality.



                Beware that neither of the options given provides integrity / authenticity. This will be particularly hard to achieve anyway if you want to keep the ciphertext near the size of the plaintext. Probably best to use FPE with a few bits set to a checksum to that there is at least a high chance of detecting integrity issues (especially if multiple ciphertext are altered).






                share|improve this answer











                $endgroup$
















                  2












                  2








                  2





                  $begingroup$

                  A true one-time-pad requires a true random number generator to generate the pads. However, let's assume that what you really want to have is a cipher that simulates a one-time-pad. Such a cipher, which creates a key stream is called a stream cipher. So what you want is a stream cipher with limited output, based on AES.



                  As written in other answers there are known ways of generating a stream cipher from a block cipher. Probably the best known one is counter mode or CTR. There are other modes possible, but note that some of these streaming modes depend on the plaintext and are therefore different from how an OTP is used. So lets focus on counter mode.



                  Counter mode depends as the name suggests on a counter which is generated starting from an initial counter value. This value is commonly generated from a nonce, which is either deterministically generated or random. If the nonce is indeed unique then you can use AES to generate the key stream, take as many bits you want from it, and then XOR them with the plaintext message of 32 or 64 bit.



                  The problem occurs if you want to encrypt more 32 or 64 bit values. In that case you need a new nonce, or you would generate a many time pad or Vigenère cipher, which is obviously not secure. You can simply store a random nonce with the encrypted bits, but then you would expand the ciphertext possibly by a large margin compared to the plaintext (depending on the size of the nonce); probably at least by 64 bits.



                  It may be that you need Format Preserving Encryption (FPE) or a block cipher with small small sized blocks instead. This is deterministic encryption, so identical plaintext will lead to identical ciphertext, leaking information. The advantage is that it doesn't leak any actual bits of the plaintext, like CTR does when it generates the Vigenère cipher / many-time-pad. Depending on the information in the plaintext, the many-time-pad will likely completely compromise security including confidentiality.



                  Beware that neither of the options given provides integrity / authenticity. This will be particularly hard to achieve anyway if you want to keep the ciphertext near the size of the plaintext. Probably best to use FPE with a few bits set to a checksum to that there is at least a high chance of detecting integrity issues (especially if multiple ciphertext are altered).






                  share|improve this answer











                  $endgroup$



                  A true one-time-pad requires a true random number generator to generate the pads. However, let's assume that what you really want to have is a cipher that simulates a one-time-pad. Such a cipher, which creates a key stream is called a stream cipher. So what you want is a stream cipher with limited output, based on AES.



                  As written in other answers there are known ways of generating a stream cipher from a block cipher. Probably the best known one is counter mode or CTR. There are other modes possible, but note that some of these streaming modes depend on the plaintext and are therefore different from how an OTP is used. So lets focus on counter mode.



                  Counter mode depends as the name suggests on a counter which is generated starting from an initial counter value. This value is commonly generated from a nonce, which is either deterministically generated or random. If the nonce is indeed unique then you can use AES to generate the key stream, take as many bits you want from it, and then XOR them with the plaintext message of 32 or 64 bit.



                  The problem occurs if you want to encrypt more 32 or 64 bit values. In that case you need a new nonce, or you would generate a many time pad or Vigenère cipher, which is obviously not secure. You can simply store a random nonce with the encrypted bits, but then you would expand the ciphertext possibly by a large margin compared to the plaintext (depending on the size of the nonce); probably at least by 64 bits.



                  It may be that you need Format Preserving Encryption (FPE) or a block cipher with small small sized blocks instead. This is deterministic encryption, so identical plaintext will lead to identical ciphertext, leaking information. The advantage is that it doesn't leak any actual bits of the plaintext, like CTR does when it generates the Vigenère cipher / many-time-pad. Depending on the information in the plaintext, the many-time-pad will likely completely compromise security including confidentiality.



                  Beware that neither of the options given provides integrity / authenticity. This will be particularly hard to achieve anyway if you want to keep the ciphertext near the size of the plaintext. Probably best to use FPE with a few bits set to a checksum to that there is at least a high chance of detecting integrity issues (especially if multiple ciphertext are altered).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 21 at 16:43

























                  answered Feb 21 at 14:52









                  Maarten BodewesMaarten Bodewes

                  55.4k679196




                  55.4k679196






























                      draft saved

                      draft discarded




















































                      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%2f67463%2ftruncating-the-output-of-aes-128%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

                      Index of /

                      Tribalistas

                      Listed building