How to Implement Deterministic Encryption Safely in .NET Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Using HMAC as a nonce with AES-CTR encrypt-and-MACWhat Are the Risks of AES-GCM [Key, Nonce, Message] where Nonce = MessageCan I Achieve Deterministic Encryption Using AES-GCM with Nonce = HMAC [ message ]Deterministic nonces in CTR modeWhich gives better deterministic encryption SIV or Plain ECB mode?Security of this deterministic encryption scheme(Re-)Using deterministic IV in CTR mode / How to: deterministic AESWhy is synthetic IV (SIV) mode considered deterministic authenticated encryption (DAE)?Deterministic encryption for a limited space: using HMAC as IVIs deterministic encryption appropriate for low entropy plaintext when CPA is not a concern?Are there any misuse-resistant asymmetric encryption schemes?What Are the Risks of AES-GCM [Key, Nonce, Message] where Nonce = MessageDeterministic Authenticated Encryption with AES-OFB and HMAC

Is there a "higher Segal conjecture"?

What is the musical term for a note that continously plays through a melody?

How to recreate this effect in Photoshop?

How does cp -a work

Models of set theory where not every set can be linearly ordered

If a contract sometimes uses the wrong name, is it still valid?

Single word antonym of "flightless"

Output the ŋarâþ crîþ alphabet song without using (m)any letters

How to assign captions for two tables in LaTeX?

Bonus calculation: Am I making a mountain out of a molehill?

When is phishing education going too far?

Should I discuss the type of campaign with my players?

Does surprise arrest existing movement?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

What's the purpose of writing one's academic bio in 3rd person?

What are the pros and cons of Aerospike nosecones?

Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?

Doubts about chords

Disable hyphenation for an entire paragraph

What does the "x" in "x86" represent?

When -s is used with third person singular. What's its use in this context?

Antler Helmet: Can it work?

Is there a service that would inform me whenever a new direct route is scheduled from a given airport?

Gastric acid as a weapon



How to Implement Deterministic Encryption Safely in .NET



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Using HMAC as a nonce with AES-CTR encrypt-and-MACWhat Are the Risks of AES-GCM [Key, Nonce, Message] where Nonce = MessageCan I Achieve Deterministic Encryption Using AES-GCM with Nonce = HMAC [ message ]Deterministic nonces in CTR modeWhich gives better deterministic encryption SIV or Plain ECB mode?Security of this deterministic encryption scheme(Re-)Using deterministic IV in CTR mode / How to: deterministic AESWhy is synthetic IV (SIV) mode considered deterministic authenticated encryption (DAE)?Deterministic encryption for a limited space: using HMAC as IVIs deterministic encryption appropriate for low entropy plaintext when CPA is not a concern?Are there any misuse-resistant asymmetric encryption schemes?What Are the Risks of AES-GCM [Key, Nonce, Message] where Nonce = MessageDeterministic Authenticated Encryption with AES-OFB and HMAC










4












$begingroup$


I am trying to implement a deterministic encryption scheme in .NET. This link suggests I use AES-SIV mode encryption. An alternative is to use AES-CTR [ k1, nonce, message] mode with HMAC[ k2, message] as the nonce. This is effectively the same as AES-SIV.



In .NET, there is no implementation of AES-SIV. AES-CTR mode is also not available in .NET. The only .NET compatible library which implements AES-SIV I can find is Miscreant .NET. This is not FIPS validated.



Does anyone have any suggestions on how to implement a deterministic encryption scheme in .NET?



This post is a continuation of a previous post.



My Project: I have several bankers who will send the balance information for thousands of bank accounts to a server. The account numbers will be encrypted using this scheme prior to sending to the server for security purposes. The server deliberately will not have the private key [I'm setting up a zero-knowledge encryption scheme]. On the client side, Banker1 and Banker2 must be able to encrypt the account number in a deterministic way that allows any Banker to decrypt account numbers returned from the server. For this reason, I decided to use HMAC(message) as the nonce for my encryption scheme and append it to the ciphertext. AES-CTR[ k1, nonce, message] || HMAC[ k2, message] where nonce = HMAC[ k2, message].



Thank you!










share|improve this question











$endgroup$
















    4












    $begingroup$


    I am trying to implement a deterministic encryption scheme in .NET. This link suggests I use AES-SIV mode encryption. An alternative is to use AES-CTR [ k1, nonce, message] mode with HMAC[ k2, message] as the nonce. This is effectively the same as AES-SIV.



    In .NET, there is no implementation of AES-SIV. AES-CTR mode is also not available in .NET. The only .NET compatible library which implements AES-SIV I can find is Miscreant .NET. This is not FIPS validated.



    Does anyone have any suggestions on how to implement a deterministic encryption scheme in .NET?



    This post is a continuation of a previous post.



    My Project: I have several bankers who will send the balance information for thousands of bank accounts to a server. The account numbers will be encrypted using this scheme prior to sending to the server for security purposes. The server deliberately will not have the private key [I'm setting up a zero-knowledge encryption scheme]. On the client side, Banker1 and Banker2 must be able to encrypt the account number in a deterministic way that allows any Banker to decrypt account numbers returned from the server. For this reason, I decided to use HMAC(message) as the nonce for my encryption scheme and append it to the ciphertext. AES-CTR[ k1, nonce, message] || HMAC[ k2, message] where nonce = HMAC[ k2, message].



    Thank you!










    share|improve this question











    $endgroup$














      4












      4








      4


      2



      $begingroup$


      I am trying to implement a deterministic encryption scheme in .NET. This link suggests I use AES-SIV mode encryption. An alternative is to use AES-CTR [ k1, nonce, message] mode with HMAC[ k2, message] as the nonce. This is effectively the same as AES-SIV.



      In .NET, there is no implementation of AES-SIV. AES-CTR mode is also not available in .NET. The only .NET compatible library which implements AES-SIV I can find is Miscreant .NET. This is not FIPS validated.



      Does anyone have any suggestions on how to implement a deterministic encryption scheme in .NET?



      This post is a continuation of a previous post.



      My Project: I have several bankers who will send the balance information for thousands of bank accounts to a server. The account numbers will be encrypted using this scheme prior to sending to the server for security purposes. The server deliberately will not have the private key [I'm setting up a zero-knowledge encryption scheme]. On the client side, Banker1 and Banker2 must be able to encrypt the account number in a deterministic way that allows any Banker to decrypt account numbers returned from the server. For this reason, I decided to use HMAC(message) as the nonce for my encryption scheme and append it to the ciphertext. AES-CTR[ k1, nonce, message] || HMAC[ k2, message] where nonce = HMAC[ k2, message].



      Thank you!










      share|improve this question











      $endgroup$




      I am trying to implement a deterministic encryption scheme in .NET. This link suggests I use AES-SIV mode encryption. An alternative is to use AES-CTR [ k1, nonce, message] mode with HMAC[ k2, message] as the nonce. This is effectively the same as AES-SIV.



      In .NET, there is no implementation of AES-SIV. AES-CTR mode is also not available in .NET. The only .NET compatible library which implements AES-SIV I can find is Miscreant .NET. This is not FIPS validated.



      Does anyone have any suggestions on how to implement a deterministic encryption scheme in .NET?



      This post is a continuation of a previous post.



      My Project: I have several bankers who will send the balance information for thousands of bank accounts to a server. The account numbers will be encrypted using this scheme prior to sending to the server for security purposes. The server deliberately will not have the private key [I'm setting up a zero-knowledge encryption scheme]. On the client side, Banker1 and Banker2 must be able to encrypt the account number in a deterministic way that allows any Banker to decrypt account numbers returned from the server. For this reason, I decided to use HMAC(message) as the nonce for my encryption scheme and append it to the ciphertext. AES-CTR[ k1, nonce, message] || HMAC[ k2, message] where nonce = HMAC[ k2, message].



      Thank you!







      ctr nonce deterministic-encryption siv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 31 at 21:41









      kelalaka

      8,79532351




      8,79532351










      asked Mar 31 at 19:55









      user67091user67091

      211




      211




















          1 Answer
          1






          active

          oldest

          votes


















          7












          $begingroup$

          You can safely use HMAC-SHA256 instead of the SIV mode custom PRF to derive the nonce/authentication tag. There's some caveats:



          • HMAC-SHA256 gives a 256-bit output; you'll have to truncate it to the nonce size.


          • HMAC-SHA256 takes in a single bit string, so it can't distinguish the boundary between a header (unencrypted associated data) and payload (encrypted message); the SIV mode custom PRF is defined on a tuple of bit strings. So make sure that if you compute HMAC over more than just a ciphertext, you uniquely encode the tuple of $(a, c)$ as a bit string you pass to HMAC-SHA256.



          • Beware limits on total volume of data for AES-SIV or similar! For example, if your ‘AES-CTR’ takes a 96-bit nonce (as AES-GCM uses), you must limit your total volume of data to well below $2^48$ messages, so that there is no danger of nonce collision. For example, you might limit it to a billion messages, $2^30$.



            AES-SIV internally uses $operatornameAES_k(n) mathbin| operatornameAES_k(n + 1) mathbin| operatornameAES_k(n + 2) mathbin| cdots$ with a 128-bit nonce $n$, instead of what is usually meant by AES-CTR, which is $operatornameAES_k(n mathbin| 0) mathbin| operatornameAES_k(n mathbin| 1) mathbin| operatornameAES_k(n mathbin| 2) mathbin| cdots$ with a (say) 96-bit nonce $n$ and 32-bit block counter like AES-GCM uses. The details don't matter that much as long as you pay close attention to the advertised adversary advantage and data volume limits.



          • Make sure to write known-answer test vectors for the system you think you're implementing, using another tool or another library, so that you can do quick self-tests to confirm interoperability.



          • Avoid the term ‘zero-knowledge’ unless you're actually doing cryptography involving zero-knowledge proofs, which are a specific technical concept involving provers, verifiers, extractors, and simulators. Saying ‘zero-knowledge encryption’ proudly announces that you have more money for a marketing department than for a cryptography engineering department.



            • Even if you encrypt identifiers, there's lots of information to be learned from network structures and databases with ‘anonymized’ (really, pseudonymized) identifiers. So ‘zero-knowledge’ is especially inappropriate here if you're only concealing the labels, not the structure of the database.


            • In this scenario, I would advise you to either (a) persuade your management to invest more money in cryptography engineering including hiring competent implementors and auditors, or (b) start polishing your CV, because this job is doomed. This is not a comment on your value or intelligence as a person! Obviously you're working hard to learn. But it is not confidence-inspiring to hear that your management are tasking someone who has to ask a pseudonymous forum of strangers on the internet for help with cryptographic basics in order to handle private banking information for thousands of clients over the internet.







          share|improve this answer











          $endgroup$












          • $begingroup$
            1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
            $endgroup$
            – user67091
            Mar 31 at 22:16











          • $begingroup$
            Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
            $endgroup$
            – user67091
            Mar 31 at 22:18






          • 1




            $begingroup$
            Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:37






          • 1




            $begingroup$
            I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:40











          • $begingroup$
            Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
            $endgroup$
            – user67091
            Apr 1 at 2:24











          Your Answer








          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%2f68443%2fhow-to-implement-deterministic-encryption-safely-in-net%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









          7












          $begingroup$

          You can safely use HMAC-SHA256 instead of the SIV mode custom PRF to derive the nonce/authentication tag. There's some caveats:



          • HMAC-SHA256 gives a 256-bit output; you'll have to truncate it to the nonce size.


          • HMAC-SHA256 takes in a single bit string, so it can't distinguish the boundary between a header (unencrypted associated data) and payload (encrypted message); the SIV mode custom PRF is defined on a tuple of bit strings. So make sure that if you compute HMAC over more than just a ciphertext, you uniquely encode the tuple of $(a, c)$ as a bit string you pass to HMAC-SHA256.



          • Beware limits on total volume of data for AES-SIV or similar! For example, if your ‘AES-CTR’ takes a 96-bit nonce (as AES-GCM uses), you must limit your total volume of data to well below $2^48$ messages, so that there is no danger of nonce collision. For example, you might limit it to a billion messages, $2^30$.



            AES-SIV internally uses $operatornameAES_k(n) mathbin| operatornameAES_k(n + 1) mathbin| operatornameAES_k(n + 2) mathbin| cdots$ with a 128-bit nonce $n$, instead of what is usually meant by AES-CTR, which is $operatornameAES_k(n mathbin| 0) mathbin| operatornameAES_k(n mathbin| 1) mathbin| operatornameAES_k(n mathbin| 2) mathbin| cdots$ with a (say) 96-bit nonce $n$ and 32-bit block counter like AES-GCM uses. The details don't matter that much as long as you pay close attention to the advertised adversary advantage and data volume limits.



          • Make sure to write known-answer test vectors for the system you think you're implementing, using another tool or another library, so that you can do quick self-tests to confirm interoperability.



          • Avoid the term ‘zero-knowledge’ unless you're actually doing cryptography involving zero-knowledge proofs, which are a specific technical concept involving provers, verifiers, extractors, and simulators. Saying ‘zero-knowledge encryption’ proudly announces that you have more money for a marketing department than for a cryptography engineering department.



            • Even if you encrypt identifiers, there's lots of information to be learned from network structures and databases with ‘anonymized’ (really, pseudonymized) identifiers. So ‘zero-knowledge’ is especially inappropriate here if you're only concealing the labels, not the structure of the database.


            • In this scenario, I would advise you to either (a) persuade your management to invest more money in cryptography engineering including hiring competent implementors and auditors, or (b) start polishing your CV, because this job is doomed. This is not a comment on your value or intelligence as a person! Obviously you're working hard to learn. But it is not confidence-inspiring to hear that your management are tasking someone who has to ask a pseudonymous forum of strangers on the internet for help with cryptographic basics in order to handle private banking information for thousands of clients over the internet.







          share|improve this answer











          $endgroup$












          • $begingroup$
            1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
            $endgroup$
            – user67091
            Mar 31 at 22:16











          • $begingroup$
            Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
            $endgroup$
            – user67091
            Mar 31 at 22:18






          • 1




            $begingroup$
            Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:37






          • 1




            $begingroup$
            I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:40











          • $begingroup$
            Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
            $endgroup$
            – user67091
            Apr 1 at 2:24















          7












          $begingroup$

          You can safely use HMAC-SHA256 instead of the SIV mode custom PRF to derive the nonce/authentication tag. There's some caveats:



          • HMAC-SHA256 gives a 256-bit output; you'll have to truncate it to the nonce size.


          • HMAC-SHA256 takes in a single bit string, so it can't distinguish the boundary between a header (unencrypted associated data) and payload (encrypted message); the SIV mode custom PRF is defined on a tuple of bit strings. So make sure that if you compute HMAC over more than just a ciphertext, you uniquely encode the tuple of $(a, c)$ as a bit string you pass to HMAC-SHA256.



          • Beware limits on total volume of data for AES-SIV or similar! For example, if your ‘AES-CTR’ takes a 96-bit nonce (as AES-GCM uses), you must limit your total volume of data to well below $2^48$ messages, so that there is no danger of nonce collision. For example, you might limit it to a billion messages, $2^30$.



            AES-SIV internally uses $operatornameAES_k(n) mathbin| operatornameAES_k(n + 1) mathbin| operatornameAES_k(n + 2) mathbin| cdots$ with a 128-bit nonce $n$, instead of what is usually meant by AES-CTR, which is $operatornameAES_k(n mathbin| 0) mathbin| operatornameAES_k(n mathbin| 1) mathbin| operatornameAES_k(n mathbin| 2) mathbin| cdots$ with a (say) 96-bit nonce $n$ and 32-bit block counter like AES-GCM uses. The details don't matter that much as long as you pay close attention to the advertised adversary advantage and data volume limits.



          • Make sure to write known-answer test vectors for the system you think you're implementing, using another tool or another library, so that you can do quick self-tests to confirm interoperability.



          • Avoid the term ‘zero-knowledge’ unless you're actually doing cryptography involving zero-knowledge proofs, which are a specific technical concept involving provers, verifiers, extractors, and simulators. Saying ‘zero-knowledge encryption’ proudly announces that you have more money for a marketing department than for a cryptography engineering department.



            • Even if you encrypt identifiers, there's lots of information to be learned from network structures and databases with ‘anonymized’ (really, pseudonymized) identifiers. So ‘zero-knowledge’ is especially inappropriate here if you're only concealing the labels, not the structure of the database.


            • In this scenario, I would advise you to either (a) persuade your management to invest more money in cryptography engineering including hiring competent implementors and auditors, or (b) start polishing your CV, because this job is doomed. This is not a comment on your value or intelligence as a person! Obviously you're working hard to learn. But it is not confidence-inspiring to hear that your management are tasking someone who has to ask a pseudonymous forum of strangers on the internet for help with cryptographic basics in order to handle private banking information for thousands of clients over the internet.







          share|improve this answer











          $endgroup$












          • $begingroup$
            1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
            $endgroup$
            – user67091
            Mar 31 at 22:16











          • $begingroup$
            Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
            $endgroup$
            – user67091
            Mar 31 at 22:18






          • 1




            $begingroup$
            Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:37






          • 1




            $begingroup$
            I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:40











          • $begingroup$
            Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
            $endgroup$
            – user67091
            Apr 1 at 2:24













          7












          7








          7





          $begingroup$

          You can safely use HMAC-SHA256 instead of the SIV mode custom PRF to derive the nonce/authentication tag. There's some caveats:



          • HMAC-SHA256 gives a 256-bit output; you'll have to truncate it to the nonce size.


          • HMAC-SHA256 takes in a single bit string, so it can't distinguish the boundary between a header (unencrypted associated data) and payload (encrypted message); the SIV mode custom PRF is defined on a tuple of bit strings. So make sure that if you compute HMAC over more than just a ciphertext, you uniquely encode the tuple of $(a, c)$ as a bit string you pass to HMAC-SHA256.



          • Beware limits on total volume of data for AES-SIV or similar! For example, if your ‘AES-CTR’ takes a 96-bit nonce (as AES-GCM uses), you must limit your total volume of data to well below $2^48$ messages, so that there is no danger of nonce collision. For example, you might limit it to a billion messages, $2^30$.



            AES-SIV internally uses $operatornameAES_k(n) mathbin| operatornameAES_k(n + 1) mathbin| operatornameAES_k(n + 2) mathbin| cdots$ with a 128-bit nonce $n$, instead of what is usually meant by AES-CTR, which is $operatornameAES_k(n mathbin| 0) mathbin| operatornameAES_k(n mathbin| 1) mathbin| operatornameAES_k(n mathbin| 2) mathbin| cdots$ with a (say) 96-bit nonce $n$ and 32-bit block counter like AES-GCM uses. The details don't matter that much as long as you pay close attention to the advertised adversary advantage and data volume limits.



          • Make sure to write known-answer test vectors for the system you think you're implementing, using another tool or another library, so that you can do quick self-tests to confirm interoperability.



          • Avoid the term ‘zero-knowledge’ unless you're actually doing cryptography involving zero-knowledge proofs, which are a specific technical concept involving provers, verifiers, extractors, and simulators. Saying ‘zero-knowledge encryption’ proudly announces that you have more money for a marketing department than for a cryptography engineering department.



            • Even if you encrypt identifiers, there's lots of information to be learned from network structures and databases with ‘anonymized’ (really, pseudonymized) identifiers. So ‘zero-knowledge’ is especially inappropriate here if you're only concealing the labels, not the structure of the database.


            • In this scenario, I would advise you to either (a) persuade your management to invest more money in cryptography engineering including hiring competent implementors and auditors, or (b) start polishing your CV, because this job is doomed. This is not a comment on your value or intelligence as a person! Obviously you're working hard to learn. But it is not confidence-inspiring to hear that your management are tasking someone who has to ask a pseudonymous forum of strangers on the internet for help with cryptographic basics in order to handle private banking information for thousands of clients over the internet.







          share|improve this answer











          $endgroup$



          You can safely use HMAC-SHA256 instead of the SIV mode custom PRF to derive the nonce/authentication tag. There's some caveats:



          • HMAC-SHA256 gives a 256-bit output; you'll have to truncate it to the nonce size.


          • HMAC-SHA256 takes in a single bit string, so it can't distinguish the boundary between a header (unencrypted associated data) and payload (encrypted message); the SIV mode custom PRF is defined on a tuple of bit strings. So make sure that if you compute HMAC over more than just a ciphertext, you uniquely encode the tuple of $(a, c)$ as a bit string you pass to HMAC-SHA256.



          • Beware limits on total volume of data for AES-SIV or similar! For example, if your ‘AES-CTR’ takes a 96-bit nonce (as AES-GCM uses), you must limit your total volume of data to well below $2^48$ messages, so that there is no danger of nonce collision. For example, you might limit it to a billion messages, $2^30$.



            AES-SIV internally uses $operatornameAES_k(n) mathbin| operatornameAES_k(n + 1) mathbin| operatornameAES_k(n + 2) mathbin| cdots$ with a 128-bit nonce $n$, instead of what is usually meant by AES-CTR, which is $operatornameAES_k(n mathbin| 0) mathbin| operatornameAES_k(n mathbin| 1) mathbin| operatornameAES_k(n mathbin| 2) mathbin| cdots$ with a (say) 96-bit nonce $n$ and 32-bit block counter like AES-GCM uses. The details don't matter that much as long as you pay close attention to the advertised adversary advantage and data volume limits.



          • Make sure to write known-answer test vectors for the system you think you're implementing, using another tool or another library, so that you can do quick self-tests to confirm interoperability.



          • Avoid the term ‘zero-knowledge’ unless you're actually doing cryptography involving zero-knowledge proofs, which are a specific technical concept involving provers, verifiers, extractors, and simulators. Saying ‘zero-knowledge encryption’ proudly announces that you have more money for a marketing department than for a cryptography engineering department.



            • Even if you encrypt identifiers, there's lots of information to be learned from network structures and databases with ‘anonymized’ (really, pseudonymized) identifiers. So ‘zero-knowledge’ is especially inappropriate here if you're only concealing the labels, not the structure of the database.


            • In this scenario, I would advise you to either (a) persuade your management to invest more money in cryptography engineering including hiring competent implementors and auditors, or (b) start polishing your CV, because this job is doomed. This is not a comment on your value or intelligence as a person! Obviously you're working hard to learn. But it is not confidence-inspiring to hear that your management are tasking someone who has to ask a pseudonymous forum of strangers on the internet for help with cryptographic basics in order to handle private banking information for thousands of clients over the internet.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 31 at 20:33

























          answered Mar 31 at 20:14









          Squeamish OssifrageSqueamish Ossifrage

          22.6k132102




          22.6k132102











          • $begingroup$
            1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
            $endgroup$
            – user67091
            Mar 31 at 22:16











          • $begingroup$
            Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
            $endgroup$
            – user67091
            Mar 31 at 22:18






          • 1




            $begingroup$
            Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:37






          • 1




            $begingroup$
            I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:40











          • $begingroup$
            Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
            $endgroup$
            – user67091
            Apr 1 at 2:24
















          • $begingroup$
            1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
            $endgroup$
            – user67091
            Mar 31 at 22:16











          • $begingroup$
            Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
            $endgroup$
            – user67091
            Mar 31 at 22:18






          • 1




            $begingroup$
            Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:37






          • 1




            $begingroup$
            I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
            $endgroup$
            – Squeamish Ossifrage
            Apr 1 at 1:40











          • $begingroup$
            Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
            $endgroup$
            – user67091
            Apr 1 at 2:24















          $begingroup$
          1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
          $endgroup$
          – user67091
          Mar 31 at 22:16





          $begingroup$
          1.) I'll truncate the nonce size appropriately. I was aware of this need. 2.) I will never approach 2^30 accounts. My limits will be between ~1M - 10M. 3.) I will bear this in mind once I test. I will also hire a consultant for testing. 4.) There is a file encryption service known as BoxCryptor that labels itself a 'Zero Knowledge Provider'. This may be false advertising but my system is similar to theirs. I will be safe not to over-advertise what we offer, though. I'm an entrepreneur without a budget. I admit encryption is difficult but not impossible thanks to this forum.
          $endgroup$
          – user67091
          Mar 31 at 22:16













          $begingroup$
          Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
          $endgroup$
          – user67091
          Mar 31 at 22:18




          $begingroup$
          Any advice on how to implement the above within .NET given SIV is not implemented and CTR mode is not available within the System.Security.Cryptography namespace?
          $endgroup$
          – user67091
          Mar 31 at 22:18




          1




          1




          $begingroup$
          Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
          $endgroup$
          – Squeamish Ossifrage
          Apr 1 at 1:37




          $begingroup$
          Boxcryptor appears to have more money for marketing than cryptography. They're abusing the term ‘zero-knowledge’. Their technical overview doesn't even mention authenticating data, which suggests they really don't know what they're doing. They are also apparently too embarrassed at their own security to share source code. They seem to respond with weasel words and deflection when confronted about audits.
          $endgroup$
          – Squeamish Ossifrage
          Apr 1 at 1:37




          1




          1




          $begingroup$
          I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
          $endgroup$
          – Squeamish Ossifrage
          Apr 1 at 1:40





          $begingroup$
          I missed the sentence where you said you don't even have AES-CTR. In principle you could use an alternative like AES-CBC (make sure to pad then MAC then encrypt here, and decrypt then verify then unpad) or AES-OFB instead of AES-CTR. But you're in over your head here. You need to find someone who is experienced in cryptography engineering for your startup. It's one thing to use this site to learn about little questions at a time; it's quite another to build the foundation of a product that people might rely on for banking privacy as an exercise in learning cryptography basics.
          $endgroup$
          – Squeamish Ossifrage
          Apr 1 at 1:40













          $begingroup$
          Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
          $endgroup$
          – user67091
          Apr 1 at 2:24




          $begingroup$
          Thanks for your help! I understand your concerns. I spend 2 - 3 hours each night after work to finish this product and can see many obstacles. I'm pushed forward by words from Bill Gates who said most people over-estimate what they can accomplish in a few months but underestimate what they can accomplish in a year. Elon Musk was also discouraged by others given his lack of experience not to say I'm Elon Musk. You helped me on my original post where I concluded there was no answer. With perseverance, however, I found the solution we are discussing now. Onwards, I say. I'm no quitter.
          $endgroup$
          – user67091
          Apr 1 at 2:24

















          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%2f68443%2fhow-to-implement-deterministic-encryption-safely-in-net%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

          Triangular numbers and gcdProving sum of a set is $0 pmod n$ if $n$ is odd, or $fracn2 pmod n$ if $n$ is even?Is greatest common divisor of two numbers really their smallest linear combination?GCD, LCM RelationshipProve a set of nonnegative integers with greatest common divisor 1 and closed under addition has all but finite many nonnegative integers.all pairs of a and b in an equation containing gcdTriangular Numbers Modulo $k$ - Hit All Values?Understanding the Existence and Uniqueness of the GCDGCD and LCM with logical symbolsThe greatest common divisor of two positive integers less than 100 is equal to 3. Their least common multiple is twelve times one of the integers.Suppose that for all integers $x$, $x|a$ and $x|b$ if and only if $x|c$. Then $c = gcd(a,b)$Which is the gcd of 2 numbers which are multiplied and the result is 600000?

          Ingelân Ynhâld Etymology | Geografy | Skiednis | Polityk en bestjoer | Ekonomy | Demografy | Kultuer | Klimaat | Sjoch ek | Keppelings om utens | Boarnen, noaten en referinsjes Navigaasjemenuwww.gov.ukOffisjele webside fan it regear fan it Feriene KeninkrykOffisjele webside fan it Britske FerkearsburoNederlânsktalige ynformaasje fan it Britske FerkearsburoOffisjele webside fan English Heritage, de organisaasje dy't him ynset foar it behâld fan it Ingelske kultuergoedYnwennertallen fan alle Britske stêden út 'e folkstelling fan 2011Notes en References, op dizze sideEngland

          Հադիս Բովանդակություն Անվանում և նշանակություն | Դասակարգում | Աղբյուրներ | Նավարկման ցանկ