NTRU 1.0.0.1 → 1.1.0.0
raw patch · 18 files changed
+641/−647 lines, 18 filesdep +integer-gmpdep +polydep −arithmoidep −polynomialdep ~SHAdep ~basedep ~bytestringnew-uploader
Dependencies added: integer-gmp, poly
Dependencies removed: arithmoi, polynomial
Dependency ranges changed: SHA, base, bytestring, containers, crypto-api, random, split
Files
- LICENSE +169/−169
- NTRU.cabal +47/−70
- README.md +5/−5
- examples/sampleGeneralNTRU.hs +13/−12
- examples/sampleSpecificNTRU.hs +12/−11
- src/Math/NTRU.hs +191/−176
- src/Math/NTRU/EES1087EP1.hs +17/−17
- src/Math/NTRU/EES1087EP2.hs +17/−17
- src/Math/NTRU/EES1171EP1.hs +17/−17
- src/Math/NTRU/EES1499EP1.hs +17/−17
- src/Math/NTRU/EES401EP1.hs +17/−17
- src/Math/NTRU/EES449EP1.hs +17/−17
- src/Math/NTRU/EES541EP1.hs +17/−17
- src/Math/NTRU/EES613EP1.hs +17/−17
- src/Math/NTRU/EES659EP1.hs +17/−17
- src/Math/NTRU/EES677EP1.hs +17/−17
- src/Math/NTRU/EES761EP1.hs +17/−17
- src/Math/NTRU/EES887EP1.hs +17/−17
LICENSE view
@@ -6,253 +6,253 @@ Version 2, June 1991 -Copyright (C) 1989, 1991 Free Software Foundation, Inc. +Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -Everyone is permitted to copy and distribute verbatim copies of this license +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble -The licenses for most software are designed to take away your freedom to share -and change it. By contrast, the GNU General Public License is intended to -guarantee your freedom to share and change free software--to make sure the -software is free for all its users. This General Public License applies to most -of the Free Software Foundation's software and to any other program whose -authors commit to using it. (Some other Free Software Foundation software is -covered by the GNU Lesser General Public License instead.) You can apply it to +The licenses for most software are designed to take away your freedom to share+and change it. By contrast, the GNU General Public License is intended to+guarantee your freedom to share and change free software--to make sure the+software is free for all its users. This General Public License applies to most+of the Free Software Foundation's software and to any other program whose+authors commit to using it. (Some other Free Software Foundation software is+covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. -When we speak of free software, we are referring to freedom, not price. Our -General Public Licenses are designed to make sure that you have the freedom to -distribute copies of free software (and charge for this service if you wish), -that you receive source code or can get it if you want it, that you can change -the software or use pieces of it in new free programs; and that you know you +When we speak of free software, we are referring to freedom, not price. Our+General Public Licenses are designed to make sure that you have the freedom to+distribute copies of free software (and charge for this service if you wish),+that you receive source code or can get it if you want it, that you can change+the software or use pieces of it in new free programs; and that you know you can do these things. -To protect your rights, we need to make restrictions that forbid anyone to deny -you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies of the +To protect your rights, we need to make restrictions that forbid anyone to deny+you these rights or to ask you to surrender the rights. These restrictions+translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. -For example, if you distribute copies of such a program, whether gratis or for -a fee, you must give the recipients all the rights that you have. You must make -sure that they, too, receive or can get the source code. And you must show them +For example, if you distribute copies of such a program, whether gratis or for+a fee, you must give the recipients all the rights that you have. You must make+sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. -We protect your rights with two steps: (1) copyright the software, and (2) -offer you this license which gives you legal permission to copy, distribute +We protect your rights with two steps: (1) copyright the software, and (2)+offer you this license which gives you legal permission to copy, distribute and/or modify the software. -Also, for each author's protection and ours, we want to make certain that -everyone understands that there is no warranty for this free software. If the -software is modified by someone else and passed on, we want its recipients to -know that what they have is not the original, so that any problems introduced +Also, for each author's protection and ours, we want to make certain that+everyone understands that there is no warranty for this free software. If the+software is modified by someone else and passed on, we want its recipients to+know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. -Finally, any free program is threatened constantly by software patents. We wish -to avoid the danger that redistributors of a free program will individually -obtain patent licenses, in effect making the program proprietary. To prevent -this, we have made it clear that any patent must be licensed for everyone's +Finally, any free program is threatened constantly by software patents. We wish+to avoid the danger that redistributors of a free program will individually+obtain patent licenses, in effect making the program proprietary. To prevent+this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. -The precise terms and conditions for copying, distribution and modification +The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -0. This License applies to any program or other work which contains a notice -placed by the copyright holder saying it may be distributed under the terms of -this General Public License. The "Program", below, refers to any such program -or work, and a "work based on the Program" means either the Program or any -derivative work under copyright law: that is to say, a work containing the -Program or a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is included without +0. This License applies to any program or other work which contains a notice+placed by the copyright holder saying it may be distributed under the terms of+this General Public License. The "Program", below, refers to any such program+or work, and a "work based on the Program" means either the Program or any+derivative work under copyright law: that is to say, a work containing the+Program or a portion of it, either verbatim or with modifications and/or+translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". -Activities other than copying, distribution and modification are not covered by -this License; they are outside its scope. The act of running the Program is not -restricted, and the output from the Program is covered only if its contents -constitute a work based on the Program (independent of having been made by +Activities other than copying, distribution and modification are not covered by+this License; they are outside its scope. The act of running the Program is not+restricted, and the output from the Program is covered only if its contents+constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. -1. You may copy and distribute verbatim copies of the Program's source code as -you receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice and -disclaimer of warranty; keep intact all the notices that refer to this License -and to the absence of any warranty; and give any other recipients of the +1. You may copy and distribute verbatim copies of the Program's source code as+you receive it, in any medium, provided that you conspicuously and+appropriately publish on each copy an appropriate copyright notice and+disclaimer of warranty; keep intact all the notices that refer to this License+and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. -You may charge a fee for the physical act of transferring a copy, and you may +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. -2. You may modify your copy or copies of the Program or any portion of it, thus -forming a work based on the Program, and copy and distribute such modifications -or work under the terms of Section 1 above, provided that you also meet all of +2. You may modify your copy or copies of the Program or any portion of it, thus+forming a work based on the Program, and copy and distribute such modifications+or work under the terms of Section 1 above, provided that you also meet all of these conditions: -a) You must cause the modified files to carry prominent notices stating that +a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.-b) You must cause any work that you distribute or publish, that in whole or in -part contains or is derived from the Program or any part thereof, to be -licensed as a whole at no charge to all third parties under the terms of this +b) You must cause any work that you distribute or publish, that in whole or in+part contains or is derived from the Program or any part thereof, to be+licensed as a whole at no charge to all third parties under the terms of this License.-c) If the modified program normally reads commands interactively when run, you -must cause it, when started running for such interactive use in the most -ordinary way, to print or display an announcement including an appropriate -copyright notice and a notice that there is no warranty (or else, saying that -you provide a warranty) and that users may redistribute the program under these -conditions, and telling the user how to view a copy of this License. -(Exception: if the Program itself is interactive but does not normally print -such an announcement, your work based on the Program is not required to print +c) If the modified program normally reads commands interactively when run, you+must cause it, when started running for such interactive use in the most+ordinary way, to print or display an announcement including an appropriate+copyright notice and a notice that there is no warranty (or else, saying that+you provide a warranty) and that users may redistribute the program under these+conditions, and telling the user how to view a copy of this License.+(Exception: if the Program itself is interactive but does not normally print+such an announcement, your work based on the Program is not required to print an announcement.)-These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Program, and can be reasonably -considered independent and separate works in themselves, then this License, and -its terms, do not apply to those sections when you distribute them as separate -works. But when you distribute the same sections as part of a whole which is a -work based on the Program, the distribution of the whole must be on the terms -of this License, whose permissions for other licensees extend to the entire +These requirements apply to the modified work as a whole. If identifiable+sections of that work are not derived from the Program, and can be reasonably+considered independent and separate works in themselves, then this License, and+its terms, do not apply to those sections when you distribute them as separate+works. But when you distribute the same sections as part of a whole which is a+work based on the Program, the distribution of the whole must be on the terms+of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. -Thus, it is not the intent of this section to claim rights or contest your -rights to work written entirely by you; rather, the intent is to exercise the -right to control the distribution of derivative or collective works based on +Thus, it is not the intent of this section to claim rights or contest your+rights to work written entirely by you; rather, the intent is to exercise the+right to control the distribution of derivative or collective works based on the Program. -In addition, mere aggregation of another work not based on the Program with the -Program (or with a work based on the Program) on a volume of a storage or -distribution medium does not bring the other work under the scope of this +In addition, mere aggregation of another work not based on the Program with the+Program (or with a work based on the Program) on a volume of a storage or+distribution medium does not bring the other work under the scope of this License. -3. You may copy and distribute the Program (or a work based on it, under -Section 2) in object code or executable form under the terms of Sections 1 and +3. You may copy and distribute the Program (or a work based on it, under+Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: -a) Accompany it with the complete corresponding machine-readable source code, -which must be distributed under the terms of Sections 1 and 2 above on a medium +a) Accompany it with the complete corresponding machine-readable source code,+which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,-b) Accompany it with a written offer, valid for at least three years, to give -any third party, for a charge no more than your cost of physically performing -source distribution, a complete machine-readable copy of the corresponding -source code, to be distributed under the terms of Sections 1 and 2 above on a +b) Accompany it with a written offer, valid for at least three years, to give+any third party, for a charge no more than your cost of physically performing+source distribution, a complete machine-readable copy of the corresponding+source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,-c) Accompany it with the information you received as to the offer to distribute -corresponding source code. (This alternative is allowed only for noncommercial -distribution and only if you received the program in object code or executable +c) Accompany it with the information you received as to the offer to distribute+corresponding source code. (This alternative is allowed only for noncommercial+distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)-The source code for a work means the preferred form of the work for making -modifications to it. For an executable work, complete source code means all the -source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the executable. However, as a special exception, the source code distributed -need not include anything that is normally distributed (in either source or -binary form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component itself +The source code for a work means the preferred form of the work for making+modifications to it. For an executable work, complete source code means all the+source code for all modules it contains, plus any associated interface+definition files, plus the scripts used to control compilation and installation+of the executable. However, as a special exception, the source code distributed+need not include anything that is normally distributed (in either source or+binary form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component itself accompanies the executable. -If distribution of executable or object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the source -code from the same place counts as distribution of the source code, even though +If distribution of executable or object code is made by offering access to copy+from a designated place, then offering equivalent access to copy the source+code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. -4. You may not copy, modify, sublicense, or distribute the Program except as -expressly provided under this License. Any attempt otherwise to copy, modify, -sublicense or distribute the Program is void, and will automatically terminate -your rights under this License. However, parties who have received copies, or -rights, from you under this License will not have their licenses terminated so +4. You may not copy, modify, sublicense, or distribute the Program except as+expressly provided under this License. Any attempt otherwise to copy, modify,+sublicense or distribute the Program is void, and will automatically terminate+your rights under this License. However, parties who have received copies, or+rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. -5. You are not required to accept this License, since you have not signed it. -However, nothing else grants you permission to modify or distribute the Program -or its derivative works. These actions are prohibited by law if you do not -accept this License. Therefore, by modifying or distributing the Program (or -any work based on the Program), you indicate your acceptance of this License to -do so, and all its terms and conditions for copying, distributing or modifying +5. You are not required to accept this License, since you have not signed it.+However, nothing else grants you permission to modify or distribute the Program+or its derivative works. These actions are prohibited by law if you do not+accept this License. Therefore, by modifying or distributing the Program (or+any work based on the Program), you indicate your acceptance of this License to+do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. -6. Each time you redistribute the Program (or any work based on the Program), -the recipient automatically receives a license from the original licensor to -copy, distribute or modify the Program subject to these terms and conditions. -You may not impose any further restrictions on the recipients' exercise of the -rights granted herein. You are not responsible for enforcing compliance by +6. Each time you redistribute the Program (or any work based on the Program),+the recipient automatically receives a license from the original licensor to+copy, distribute or modify the Program subject to these terms and conditions.+You may not impose any further restrictions on the recipients' exercise of the+rights granted herein. You are not responsible for enforcing compliance by third parties to this License. -7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), conditions -are imposed on you (whether by court order, agreement or otherwise) that -contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot distribute so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not distribute the Program at all. -For example, if a patent license would not permit royalty-free redistribution -of the Program by all those who receive copies directly or indirectly through -you, then the only way you could satisfy both it and this License would be to +7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues), conditions+are imposed on you (whether by court order, agreement or otherwise) that+contradict the conditions of this License, they do not excuse you from the+conditions of this License. If you cannot distribute so as to satisfy+simultaneously your obligations under this License and any other pertinent+obligations, then as a consequence you may not distribute the Program at all.+For example, if a patent license would not permit royalty-free redistribution+of the Program by all those who receive copies directly or indirectly through+you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply and +If any portion of this section is held invalid or unenforceable under any+particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. -It is not the purpose of this section to induce you to infringe any patents or -other property right claims or to contest validity of any such claims; this -section has the sole purpose of protecting the integrity of the free software -distribution system, which is implemented by public license practices. Many -people have made generous contributions to the wide range of software -distributed through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing to -distribute software through any other system and a licensee cannot impose that +It is not the purpose of this section to induce you to infringe any patents or+other property right claims or to contest validity of any such claims; this+section has the sole purpose of protecting the integrity of the free software+distribution system, which is implemented by public license practices. Many+people have made generous contributions to the wide range of software+distributed through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing to+distribute software through any other system and a licensee cannot impose that choice. -This section is intended to make thoroughly clear what is believed to be a +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. -8. If the distribution and/or use of the Program is restricted in certain -countries either by patents or by copyrighted interfaces, the original -copyright holder who places the Program under this License may add an explicit -geographical distribution limitation excluding those countries, so that -distribution is permitted only in or among countries not thus excluded. In such -case, this License incorporates the limitation as if written in the body of +8. If the distribution and/or use of the Program is restricted in certain+countries either by patents or by copyrighted interfaces, the original+copyright holder who places the Program under this License may add an explicit+geographical distribution limitation excluding those countries, so that+distribution is permitted only in or among countries not thus excluded. In such+case, this License incorporates the limitation as if written in the body of this License. -9. The Free Software Foundation may publish revised and/or new versions of the -General Public License from time to time. Such new versions will be similar in -spirit to the present version, but may differ in detail to address new problems +9. The Free Software Foundation may publish revised and/or new versions of the+General Public License from time to time. Such new versions will be similar in+spirit to the present version, but may differ in detail to address new problems or concerns. -Each version is given a distinguishing version number. If the Program specifies -a version number of this License which applies to it and "any later version", -you have the option of following the terms and conditions either of that -version or of any later version published by the Free Software Foundation. If -the Program does not specify a version number of this License, you may choose +Each version is given a distinguishing version number. If the Program specifies+a version number of this License which applies to it and "any later version",+you have the option of following the terms and conditions either of that+version or of any later version published by the Free Software Foundation. If+the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. -10. If you wish to incorporate parts of the Program into other free programs -whose distribution conditions are different, write to the author to ask for -permission. For software which is copyrighted by the Free Software Foundation, -write to the Free Software Foundation; we sometimes make exceptions for this. -Our decision will be guided by the two goals of preserving the free status of -all derivatives of our free software and of promoting the sharing and reuse of +10. If you wish to incorporate parts of the Program into other free programs+whose distribution conditions are different, write to the author to ask for+permission. For software which is copyrighted by the Free Software Foundation,+write to the Free Software Foundation; we sometimes make exceptions for this.+Our decision will be guided by the two goals of preserving the free status of+all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR -THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE -STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE -PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND -PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR+THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE+STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE+PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND+FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND+PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL -ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE -PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR -INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA -BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL+ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE+PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR+INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA+BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A+FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
NTRU.cabal view
@@ -1,73 +1,50 @@--- Initial NTRU.cabal generated by cabal init. For further documentation, --- see http://haskell.org/cabal/users-guide/---- The name of the package.-name: NTRU---- The package version. See the Haskell package versioning policy (PVP) --- for standards guiding when and how versions should be incremented.--- http://www.haskell.org/haskellwiki/Package_versioning_policy--- PVP summary: +-+------- breaking API changes--- | | +----- non-breaking API additions--- | | | +--- code changes with no API change-version: 1.0.0.1---- A short (one-line) description of the package.-synopsis: NTRU Cryptography ---- A longer description of the package.-description: A Haskell implementation of the NTRU cryptographic system, following the IEEE Standard Specification for Public Key Crpytographic Techniques Based on Hard Problems over Lattices (IEEE Std 1363.1-2008)---- The license under which the package is released.-license: GPL---- The file containing the license text.-license-file: LICENSE---- The package author(s).-author: Theo Levine, Tom Cornelius, Elizabeth Hughes, CyberPoint International LLC. ---- An email address to which users can send suggestions, bug reports, and --- patches.-maintainer: opensource@cyberpointllc.com---- A copyright notice.-copyright: 2014, CyberPoint International, LLC --category: Cryptography, Math--build-type: Simple--extra-source-files: README.md, examples/sampleGeneralNTRU.hs, examples/sampleSpecificNTRU.hs---- Constraint on the version of Cabal needed to build this package.-cabal-version: >=1.8+name: NTRU+version: 1.1.0.0+license: GPL+license-file: LICENSE+copyright: 2014, CyberPoint International, LLC+maintainer: opensource@cyberpointllc.com, andrew.lelechenko@gmail.com+author: Theo Levine, Tom Cornelius, Elizabeth Hughes, CyberPoint International LLC.+synopsis: NTRU Cryptography+description:+ A Haskell implementation of the NTRU cryptographic system, following the IEEE Standard Specification for Public Key Cryptographic Techniques Based on Hard Problems over Lattices (IEEE Std 1363.1-2008)+category: Cryptography, Math+build-type: Simple+cabal-version: >=1.8+extra-source-files:+ README.md+ examples/sampleGeneralNTRU.hs+ examples/sampleSpecificNTRU.hs+tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1 +source-repository head+ type: git+ location: https://github.com/Bodigrim/ntru library-- hs-source-dirs: src-- ghc-options: -Wall-- -- Modules exported by the library.- exposed-modules: Math.NTRU- Math.NTRU.EES401EP1- Math.NTRU.EES449EP1- Math.NTRU.EES677EP1- Math.NTRU.EES1087EP2- Math.NTRU.EES541EP1- Math.NTRU.EES613EP1- Math.NTRU.EES887EP1- Math.NTRU.EES1171EP1- Math.NTRU.EES659EP1- Math.NTRU.EES761EP1- Math.NTRU.EES1087EP1- Math.NTRU.EES1499EP1 -- -- Modules included in this library but not exported.- -- other-modules: - - -- Other library packages from which modules are imported.- build-depends: base ==4.6.*, SHA ==1.6.*, split ==0.2.*, containers ==0.5.*, crypto-api ==0.13.*, random ==1.1.*, polynomial ==0.7.*, arithmoi ==0.4.*, bytestring ==0.10.*- + exposed-modules:+ Math.NTRU+ Math.NTRU.EES401EP1+ Math.NTRU.EES449EP1+ Math.NTRU.EES677EP1+ Math.NTRU.EES1087EP2+ Math.NTRU.EES541EP1+ Math.NTRU.EES613EP1+ Math.NTRU.EES887EP1+ Math.NTRU.EES1171EP1+ Math.NTRU.EES659EP1+ Math.NTRU.EES761EP1+ Math.NTRU.EES1087EP1+ Math.NTRU.EES1499EP1+ hs-source-dirs: src+ ghc-options: -Wall+ build-depends:+ base >=4.9 && <5,+ bytestring >=0.10,+ containers >=0.5,+ crypto-api >=0.13,+ integer-gmp >=1.0,+ poly >=0.3,+ random >=1.1,+ SHA >=1.6,+ split >=0.2
README.md view
@@ -9,17 +9,17 @@ cabal install NTRU ``` -or by downloading it and then running: +or by downloading it and then running: ``` cabal configure cabal build-cabal install +cabal install ```-You can ignore the warnings from the build. +You can ignore the warnings from the build. -A prebuilt hackage is available at http://hackage.haskell.org/package/NTRU. You may need to install some dependencies, such as llvm. +A prebuilt hackage is available at http://hackage.haskell.org/package/NTRU. You may need to install some dependencies, such as llvm. -Please contact opensource@cyberpointllc.com with any questions. +Please contact opensource@cyberpointllc.com with any questions. Copyright 2013 CyberPoint International LLC.
examples/sampleGeneralNTRU.hs view
@@ -7,20 +7,21 @@ import Data.Char import Data.Maybe -main = do - --- let params = genParams "EES401EP1" - let params = ParamSet {getN = 401, getP = 3, getQ = 2048, getDf = 113, getDg = 133, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 60, getBufferLenBits = 600, getBufferLenTrits = 400, getDm0 = 113, getShaLvl = 1, getDr = 113, getC = 11, getMinCallsR = 32, getMinCallsMask = 9, getOID = [0,2,4], getPkLen = 114, getBitLvl = 112}+main :: IO ()+main = do - (publicKey, privateKey) <- keyGen params- - let msg = map (fromIntegral . ord) "Hello, World" :: [Integer]+ -- let params = genParams "EES401EP1"+ let params = ParamSet {getN = 401, getP = 3, getQ = 2048, getDf = 113, getDg = 133, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 60, getBufferLenBits = 600, getBufferLenTrits = 400, getDm0 = 113, getShaLvl = 1, getDr = 113, getC = 11, getMinCallsR = 32, getMinCallsMask = 9, getOID = [0,2,4], getPkLen = 114, getBitLvl = 112} - ct <- encrypt params msg publicKey+ (publicKey, privateKey) <- keyGen params - let unencrypted = decrypt params privateKey publicKey ct + let msg = map (fromIntegral . ord) "Hello, World" :: [Integer] - if (isNothing unencrypted)- then print "Encryption Failed"- else print $ map (chr . fromIntegral) (fromJust unencrypted)+ ct <- encrypt params msg publicKey++ let unencrypted = decrypt params privateKey publicKey ct++ if (isNothing unencrypted)+ then print "Encryption Failed"+ else print $ map (chr . fromIntegral) (fromJust unencrypted)
examples/sampleSpecificNTRU.hs view
@@ -4,21 +4,22 @@ -} -- Paramter Set EES401EP1-import Math.NTRU.EES401EP1 +import Math.NTRU.EES401EP1 import Data.Char import Data.Maybe -main = do - - (publicKey, privateKey) <- keyGen- - let msg = map (fromIntegral . ord) "Hello, World" :: [Integer]+main :: IO ()+main = do - ct <- encrypt msg publicKey+ (publicKey, privateKey) <- keyGen - let unencrypted = decrypt privateKey publicKey ct + let msg = map (fromIntegral . ord) "Hello, World" :: [Integer] - if (isNothing unencrypted)- then print "Encryption Failed"- else print $ map (chr . fromIntegral) (fromJust unencrypted)+ ct <- encrypt msg publicKey++ let unencrypted = decrypt privateKey publicKey ct++ if (isNothing unencrypted)+ then print "Encryption Failed"+ else print $ map (chr . fromIntegral) (fromJust unencrypted)
src/Math/NTRU.hs view
@@ -1,140 +1,155 @@-{- | +{- | Module : NTRU Description : NTRU cryptographic system implementation Maintainer : julrich@cyberpointllc.com Stability : Experimental License : GPL -This is an implementation of the NTRU cryptographic system, following the standard set forth -by the IEEE in the document entitled IEEE Standard Specification for Public Key Cryptographic +This is an implementation of the NTRU cryptographic system, following the standard set forth+by the IEEE in the document entitled IEEE Standard Specification for Public Key Cryptographic Techniques Based on Hard Problems over Lattices (IEEE Std 1363.1-2008). It is designed to be compatible with the implementation-of SecurityInnovations, available <https://www.securityinnovation.com/products/encryption-libraries/ntru-crypto/ here>. +of SecurityInnovations, available <https://www.securityinnovation.com/products/encryption-libraries/ntru-crypto/ here>. -} -+{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-matches -fno-warn-unused-local-binds -fno-warn-incomplete-patterns -fno-warn-type-defaults #-} module Math.NTRU (keyGen, encrypt, decrypt, genParams, ParamSet(..)) where import Data.Digest.Pure.SHA import Data.List.Split-import Data.Sequence as Seq (index, update, fromList, Seq)-import Data.Foldable as L (toList)+import Data.Sequence as Seq (index, update, Seq) import Crypto.Random import System.Random-import Math.Polynomial-import Math.NumberTheory.Moduli +import Data.Poly hiding (toPoly)+import qualified Data.Poly as Poly+import GHC.Exts+import GHC.Integer.GMP.Internals import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL +{- Compatibility layer -} -{- Polynomial Operations -} +powPoly :: VPoly Integer -> Int -> VPoly Integer+powPoly = (^) --- | Poly to List-fromPoly :: Poly Integer -> [Integer]-fromPoly = polyCoeffs LE +x :: VPoly Integer+x = X --- | List to Poly-toPoly :: [Integer] -> Poly Integer -toPoly = poly LE +polyDegree :: VPoly Integer -> Int+polyDegree xs = case leading xs of+ Nothing -> minBound+ Just (k, _) -> fromIntegral k --- | Retrive the coefficient of p corresponding to the (x^i) term -polyCoef :: Poly Integer -> Int -> Integer-polyCoef p i = fromPoly p !! i +zero :: VPoly Integer+zero = 0 --- | Useful for syntax. Allows for poly + poly or poly * poly. --- | Note that for ring multiplication, reduceDegree must be called-instance (Num a, Eq a) => Num (Poly a) where- f + g = addPoly f g- f * g = multPoly f g- negate = negatePoly- abs = undefined- signum = undefined- fromInteger = undefined+one :: VPoly Integer+one = 1 +scalePoly :: Integer -> VPoly Integer -> VPoly Integer+scalePoly n = scale 0 n++polyIsZero :: VPoly Integer -> Bool+polyIsZero = (== 0)++{- Polynomial Operations -}++-- | VPoly to List+fromPoly :: VPoly Integer -> [Integer]+fromPoly = toList . unPoly++-- | List to VPoly+toPoly :: [Integer] -> VPoly Integer+toPoly = Poly.toPoly . fromList++-- | Retrive the coefficient of p corresponding to the (x^i) term+polyCoef :: VPoly Integer -> Int -> Integer+polyCoef p i = fromPoly p !! i+ -- | Allows for polynomial multipliction in the ring of size n: reduceDegree n (a * b) = a * b in the ring. Assumes: (degree f) <= 2n-reduceDegree :: Int -> Poly Integer -> Poly Integer +reduceDegree :: Int -> VPoly Integer -> VPoly Integer reduceDegree n f =- let (f1,f2) = splitAt n (fromPoly f) - in toPoly f1 + toPoly f2 + let (f1,f2) = splitAt n (fromPoly f)+ in toPoly f1 + toPoly f2 -- | Reduces all of the polynomial's coefficents mod q-polyMod :: Integer -> Poly Integer -> Poly Integer+polyMod :: Integer -> VPoly Integer -> VPoly Integer polyMod q f = toPoly $ map (`mod` q) (fromPoly f) -- | Same as polyMod, but chooses representative group values in Z/nZ to be in (-q/2, q/2] instead of [0,q-1]-polyModInterval :: Integer -> Poly Integer -> Poly Integer-polyModInterval q f = toPoly $ map (\x' -> intervalReduce $ x' `mod` q) (fromPoly f) +polyModInterval :: Integer -> VPoly Integer -> VPoly Integer+polyModInterval q f = toPoly $ map (\x' -> intervalReduce $ x' `mod` q) (fromPoly f) where intervalReduce x' = if x' <= (q `div` 2) then x' else x' - q --- | PolyMod when q is big -polyBigMod :: Integer -> Poly Integer -> Poly Integer-polyBigMod q p = toPoly $ map fromIntegral $ fromPoly $ polyMod q $ toPoly $ map fromIntegral $ fromPoly p +-- | PolyMod when q is big+polyBigMod :: Integer -> VPoly Integer -> VPoly Integer+polyBigMod q p = toPoly $ map fromIntegral $ fromPoly $ polyMod q $ toPoly $ map fromIntegral $ fromPoly p -- | Creates the polynomial x^n-xPow :: Int -> Poly Integer +xPow :: Int -> VPoly Integer xPow = powPoly x {- Key Generation -} -- | 6.3.3.1 Divides one polynomial by another mod p: let (q,r) = divPolyMod p a b; ((b * q) + r) `mod` p = a; (degree r) < (degree b)-divPolyMod :: Integer -> Poly Integer -> Poly Integer -> (Poly Integer, Poly Integer)-divPolyMod p a b = - let n = polyDegree b in - let u = inverseMod (polyCoef b n) p in +divPolyMod :: Integer -> VPoly Integer -> VPoly Integer -> (VPoly Integer, VPoly Integer)+divPolyMod p a b =+ let n = polyDegree b in+ let u = inverseMod (polyCoef b n) p in divLoop p b n u zero a- where + where divLoop p' b' n' u' q r =- let d = polyDegree r in + let d = polyDegree r in if d < n' then (polyMod p' q, polyMod p r) else- let v = scalePoly (u' * polyCoef r d) (xPow (d - n')) in - let r' = polyMod p' $ r - (v * b') in - let q' = polyMod p' $ q + v in + let v = scalePoly (u' * polyCoef r d) (xPow (d - n')) in+ let r' = polyMod p' $ r - (v * b') in+ let q' = polyMod p' $ q + v in divLoop p' b' n' u' q' r' --- | 6.3.3.2 Finds the extended GCD mod p: let (d,u) = extendedEuclidean p a b; if d == 1, then (u * a) `mod` p = 1 -extendedEuclidean :: Integer -> Poly Integer -> Poly Integer -> (Poly Integer, Poly Integer)+-- | 6.3.3.2 Finds the extended GCD mod p: let (d,u) = extendedEuclidean p a b; if d == 1, then (u * a) `mod` p = 1+extendedEuclidean :: Integer -> VPoly Integer -> VPoly Integer -> (VPoly Integer, VPoly Integer) extendedEuclidean p a b = extendedEuclideanLoop p one a zero b- where + where extendedEuclideanLoop p' u d v1 v3 | polyIsZero v3 = (d,u)- | otherwise = - let (q,t3) = divPolyMod p' d v3 in - let t1 = polyMod p' $ u - q * v1 in - extendedEuclideanLoop p' v1 v3 t1 t3 + | otherwise =+ let (q,t3) = divPolyMod p' d v3 in+ let t1 = polyMod p' $ u - q * v1 in+ extendedEuclideanLoop p' v1 v3 t1 t3 --- | Generates Polynomials and Attempts to Find Inverses Until Success: let (a,u) = findInvertible params; (a * u) `mod` 2 = 1 -findInvertible :: ParamSet -> IO (Poly Integer, Poly Integer)-findInvertible params = do - let n = getN params - let df = getDf params - a' <- genRandPoly n df df +-- | Generates Polynomials and Attempts to Find Inverses Until Success: let (a,u) = findInvertible params; (a * u) `mod` 2 = 1+findInvertible :: ParamSet -> IO (VPoly Integer, VPoly Integer)+findInvertible params = do+ let n = getN params+ let df = getDf params+ a' <- genRandPoly n df df let a = scalePoly (getP params) a' + one let b = xPow n - one- let (d, u) = extendedEuclidean 2 a b - if d == one then return (a, u) else findInvertible params + let (d, u) = extendedEuclidean 2 a b+ if d == one then return (a, u) else findInvertible params --- | 6.3.3.4 Raises Polynomial Inverse mod 2 to mod 2^11; let (a, b) = findInvertible; (a * (inverseLift a b (degree a))) `mod` 2048 = 1 -inverseLift :: Poly Integer -> Poly Integer -> Int -> Integer -> Poly Integer-inverseLift a b deg = inverseLift' a b deg (2 :: Integer) (11 :: Integer) where - inverseLift' a b deg n e q +-- | 6.3.3.4 Raises Polynomial Inverse mod 2 to mod 2^11; let (a, b) = findInvertible; (a * (inverseLift a b (degree a))) `mod` 2048 = 1+inverseLift :: VPoly Integer -> VPoly Integer -> Int -> Integer -> VPoly Integer+inverseLift a b deg = inverseLift' a b deg (2 :: Integer) (11 :: Integer) where+ inverseLift' a b deg n e q | e == 0 = polyMod (2 ^ q) b- | otherwise = - let b' = polyBigMod (2 ^ n) $ scalePoly 2 b - (reduceDegree deg $! a * (reduceDegree deg $! (b * b))) - in inverseLift' a b' deg (2 * n) (e `div` 2) q + | otherwise =+ let b' = polyBigMod (2 ^ n) $ scalePoly 2 b - (reduceDegree deg $! a * (reduceDegree deg $! (b * b)))+ in inverseLift' a b' deg (2 * n) (e `div` 2) q --- | Generates a random PublicKey-PrivateKey Pair +-- | Generates a random PublicKey-PrivateKey Pair keyGen :: ParamSet -- ^ Parameter set, most likely the output of 'genParams' -> IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enhancement #2>.-keyGen params = do - let n = getN params +keyGen params = do+ let n = getN params dg = getDg params- q = getQ params - (f, u) <- findInvertible params - let fq = inverseLift f u n (fromIntegral q) - g <- genRandPoly n dg (dg - 1) + q = getQ params+ (f, u) <- findInvertible params+ let fq = inverseLift f u n (fromIntegral q)+ g <- genRandPoly n dg (dg - 1) let pk = polyMod q $! reduceDegree n $! scalePoly (getP params) $! fq * g return (fromPoly pk, fromPoly f) @@ -143,22 +158,22 @@ -- | Creates seed for bpgm. h is the public key, b is the random string of bits prefixed to the message genSData :: [Integer] -> [Integer] -> [Integer] -> ParamSet -> [Integer]-genSData h msg b params = - let bh = concatMap bigIntToBits h in - let pkLen = getPkLen params in - let bhTrunc = take (pkLen - (pkLen `mod` 8)) bh in - let hTrunc = map (fromIntegral . bitsToInt) (chunksOf 8 bhTrunc) in - let sData = map fromIntegral (getOID params) ++ msg ++ b ++ hTrunc in +genSData h msg b params =+ let bh = concatMap bigIntToBits h in+ let pkLen = getPkLen params in+ let bhTrunc = take (pkLen - (pkLen `mod` 8)) bh in+ let hTrunc = map (fromIntegral . bitsToInt) (chunksOf 8 bhTrunc) in+ let sData = map fromIntegral (getOID params) ++ msg ++ b ++ hTrunc in sData -- | 8.3.2.2 Generates the blinding polynomial using the given seed bpgm :: [Integer] -> ParamSet -> [Integer] bpgm seed params = let (i, s) = igf ([], [], 0) seed params in- let r = Seq.update i 1 $ Seq.fromList $ replicate (getN params) 0 in+ let r = Seq.update i 1 $ fromList $ replicate (getN params) 0 in let t = getDr params in let r' = rlooper s 1 r (t - 1) params in- L.toList $ rlooper s (-1) r' t params+ toList $ rlooper s (-1) r' t params -- | Creates the sequence with the proper -1's and 1's rlooper :: ([Integer], [Integer], Integer) -> Integer -> Seq.Seq Integer -> Int -> ParamSet -> Seq.Seq Integer@@ -172,23 +187,23 @@ -- | 8.4.2.1 Given a state or a seed, generates the next index to be used igf :: ([Integer], [Integer], Integer) -> [Integer] -> ParamSet -> (Int, ([Integer], [Integer], Integer)) igf state seed params =- let (z, buf, counter) = extractVariables state seed params + let (z, buf, counter) = extractVariables state seed params (i, buf', counter') = genIndex counter buf z params s = (z, buf', counter')- n = getN params + n = getN params in (i `mod` n, s) --- | Either initializes the state, or uses the already created one -extractVariables :: ([Integer], [Integer], Integer) -> [Integer] -> ParamSet -> ([Integer], [Integer], Integer) +-- | Either initializes the state, or uses the already created one+extractVariables :: ([Integer], [Integer], Integer) -> [Integer] -> ParamSet -> ([Integer], [Integer], Integer) extractVariables state [] _ = state-extractVariables _ seed params = igfinit seed params +extractVariables _ seed params = igfinit seed params -- | Initialization of state igfinit :: [Integer] -> ParamSet -> ([Integer], [Integer], Integer)-igfinit seed params = - let minCallsR = getMinCallsR params - shaFn = getSHA params - z = shaFn seed +igfinit seed params =+ let minCallsR = getMinCallsR params+ shaFn = getSHA params+ z = shaFn seed buf = buildM 0 minCallsR z shaFn [] in (z, buf, minCallsR) @@ -196,35 +211,35 @@ genIndex :: Integer -> [Integer] -> [Integer] -> ParamSet -> (Int, [Integer], Integer) genIndex counter buf z params = let remLen = length buf- c = getC params - n = getN params + c = getC params+ n = getN params shaFn = getSHA params- hLen = getHLen params + hLen = getHLen params tmpLen = (c - remLen) cThreshold = counter + fromIntegral (ceiling (fromIntegral tmpLen / fromIntegral hLen))- (m, counter') = if remLen >= c + (m, counter') = if remLen >= c then (buf, counter) else (buildM counter cThreshold z shaFn buf, cThreshold) (b, buf') = splitAt c (buf ++ m)- i = fromIntegral $ bitsToInt b + i = fromIntegral $ bitsToInt b in if i >= (2^c - (2^c `mod` n))- then genIndex counter' buf' z params + then genIndex counter' buf' z params else (i, buf', counter') --- | Builds out the buffer +-- | Builds out the buffer buildM :: Integer -> Integer -> [Integer] -> ([Integer]->[Integer]) -> [Integer] -> [Integer] buildM count cThreshold z shaFn buf- | count >= cThreshold = buf - | otherwise = - let c = i2osp count 3 - h = shaFn (z ++ c) + | count >= cThreshold = buf+ | otherwise =+ let c = i2osp count 3+ h = shaFn (z ++ c) m = buf ++ intsToBits h- in buildM (count + 1) cThreshold z shaFn m + in buildM (count + 1) cThreshold z shaFn m -- | Converts counter to 4 bytes... Not exactly the same as documentation but in practice counter does not exceed the bounds i2osp :: Integer -> Integer -> [Integer]-i2osp i n - | n == 0 = [i] +i2osp i n+ | n == 0 = [i] | otherwise = 0:i2osp i (n-1) @@ -243,24 +258,24 @@ sha256Octets input = map fromIntegral $ B.unpack $ bToStrict $ bytestringDigest $ sha256 $ BL.pack $ map fromIntegral input -{- Mask Generation -} -- Much of this code is similar to blinding polynomial generation, but we implemented separately +{- Mask Generation -} -- Much of this code is similar to blinding polynomial generation, but we implemented separately --- | 8.4.1.1 Generates the mask based on the given seed +-- | 8.4.1.1 Generates the mask based on the given seed mgf :: [Integer] -> ParamSet -> [Integer] mgf seed params = let n = getN params in- let shaFn = getSHA params in - let z = shaFn seed in - let buf = buildBuffer 0 (getMinCallsR params) z shaFn [] in + let shaFn = getSHA params in+ let z = shaFn seed in+ let buf = buildBuffer 0 (getMinCallsR params) z shaFn [] in let i = formatI buf in take n $ finishI i n (getMinCallsR params) z shaFn --- | Builds out the buffer +-- | Builds out the buffer buildBuffer :: Integer -> Integer -> [Integer] -> ([Integer]->[Integer]) -> [Integer] -> [Integer] buildBuffer counter minCallsR z shaFn buffer | counter >= minCallsR = buffer- | otherwise = let octet_c = i2osp counter 3 in - let h = shaFn (z ++ octet_c) in + | otherwise = let octet_c = i2osp counter 3 in+ let h = shaFn (z ++ octet_c) in buildBuffer (counter + 1) minCallsR z shaFn (buffer ++ h) -- | Step I Converts octets to trits@@ -272,10 +287,10 @@ -- | Builds out buffer when needed finishI :: [Integer] -> Int -> Integer -> [Integer] -> ([Integer] -> [Integer]) -> [Integer] finishI i n counter z shaFn- | fromIntegral (length i) >= n = i - | otherwise = let buf = buildBuffer counter (counter + 1) z shaFn [] in - let i' = formatI buf in - finishI i' n (counter + 1) z shaFn + | fromIntegral (length i) >= n = i+ | otherwise = let buf = buildBuffer counter (counter + 1) z shaFn [] in+ let i' = formatI buf in+ finishI i' n (counter + 1) z shaFn -- | Formats buffer formatI :: [Integer] -> [Integer]@@ -284,40 +299,40 @@ {- Encrypt -} -- | Encrypts a message using the given parameter set-encrypt :: ParamSet -- ^ Parameter set, most likely the output of 'genParams' +encrypt :: ParamSet -- ^ Parameter set, most likely the output of 'genParams' -> [Integer] -- ^ A list of ASCII values representing the message -> [Integer] -- ^ A list of numbers representing the public key -> IO [Integer] -- ^ A list of numbers representing the ciphertext-encrypt params msg h = +encrypt params msg h = let l = fromIntegral $ length msg maxLength = getMaxMsgLenBytes params in if l > maxLength then error "message too long"- else do - let bLen = getDb params `div` 8 - dr = getDr params + else do+ let bLen = getDb params `div` 8+ dr = getDr params n = getN params q = getQ params- p = getP params + p = getP params b <- randByteString bLen let p0 = replicate (fromIntegral $ maxLength - l) 0- m = b ++ [fromIntegral l] ++ msg ++ p0 - mBin = addPadding $ intsToBits m + m = b ++ [fromIntegral l] ++ msg ++ p0+ mBin = addPadding $ intsToBits m mTrin = concatMap binToTern $ chunksOf 3 mBin sData = genSData h msg b params r = bpgm sData params r' = polyMod q $ reduceDegree n $ toPoly r * toPoly h r4 = polyMod 4 r' or4 = toOctets $ fromPoly r4- mask = mgf or4 params + mask = mgf or4 params m' = polyModInterval p $ toPoly mask + toPoly mTrin- e = polyMod q $ r' + m' + e = polyMod q $ r' + m' return $ fromPoly e {- Decrypt -} --- | 9.3.3 Decrypts e using the private key f and verifies it using the public key h. -decrypt :: ParamSet -- ^ Parameter set, most likely the output of 'genParams' +-- | 9.3.3 Decrypts e using the private key f and verifies it using the public key h.+decrypt :: ParamSet -- ^ Parameter set, most likely the output of 'genParams' -> [Integer] -- ^ A list of numbers representing the private key -> [Integer] -- ^ A list of numbers representing the public key -> [Integer] -- ^ A list of numbers representing the ciphertext@@ -325,55 +340,55 @@ decrypt params f h e = let n = getN params p = getP params- q = getQ params + q = getQ params bLen = getDb params `div` 8 ci = polyMod p $ polyModInterval q $ reduceDegree n $ toPoly f * toPoly e cR = polyMod q $ toPoly e - polyModInterval p ci cR4 = polyMod 4 cR coR4 = toOctets $ fromPoly cR4 cMask = polyMod p $ toPoly $ mgf coR4 params- cMTrin = polyModInterval p $ ci - cMask + cMTrin = polyModInterval p $ ci - cMask cMTrin' = improperPolynomial n $ fromPoly cMTrin cMBin = concatMap ternToBin $ chunksOf 2 $ take (length cMTrin' - (length cMTrin' `mod` 2)) cMTrin' cM = map bitsToInt $ chunksOf 8 $ take (length cMBin - (length cMBin `mod` 8)) cMBin (cb, rest) = splitAt bLen cM ([cl], rest') = splitAt (getLLen params) rest (cm, rest'') = splitAt (fromIntegral cl) rest'- sData = genSData h cm cb params + sData = genSData h cm cb params cr = bpgm sData params cR' = polyMod q $ reduceDegree n $ toPoly cr * toPoly h validR = cR' == cR validRemainder = all (==0) rest''- in checkValid cm validR validRemainder + in checkValid cm validR validRemainder -- | Checks results of verification steps checkValid :: [Integer] -> Bool -> Bool -> Maybe [Integer] checkValid _ _ False = Nothing checkValid _ False _ = Nothing-checkValid m _ _ = Just m +checkValid m _ _ = Just m {- Other Operations -} --- | Calculate the modular inverse of x and y: ((inverseMod x y) * x) `mod` y = 1 +-- | Calculate the modular inverse of x and y: ((inverseMod x y) * x) `mod` y = 1 inverseMod :: Integer -> Integer -> Integer-inverseMod x y = case invertMod (fromIntegral x) (fromIntegral y) of- Just n -> fromIntegral n - _ -> error "Could not calculate inverseMod"+inverseMod x y = case recipModInteger (fromIntegral x) (fromIntegral y) of+ 0 -> error "Could not calculate inverseMod"+ n -> n -- | Generate a random ByteString randByteString :: Int -> IO [Integer] randByteString size = do g <- newGenIO :: IO SystemRandom- case genBytes size g of + case genBytes size g of Left err -> error $ show err Right (result, g2) -> return (unpackByteString result) --- | Converts a bytestring to a list of ascii values +-- | Converts a bytestring to a list of ascii values unpackByteString :: BC.ByteString -> [Integer]-unpackByteString str = map fromIntegral (B.unpack str) +unpackByteString str = map fromIntegral (B.unpack str) --- | Used to encode bits of a message from binary to trinary representation +-- | Used to encode bits of a message from binary to trinary representation binToTern :: [Integer] -> [Integer] binToTern [0,0,0] = [0,0] binToTern [0,0,1] = [0,1]@@ -408,7 +423,7 @@ -- | Converts a single byte to a list of (n+1) bits: unpackByte 7 3 = [0,0,0,0,0,0,1,1] unpackByte :: Integer -> Integer -> [Integer]-unpackByte n b +unpackByte n b | n < 0 = [] | otherwise = (b `div` (2 ^ n)):unpackByte (n-1) (b `mod` 2 ^ n) @@ -416,48 +431,48 @@ intToBits :: Integer -> [Integer] intToBits = unpackByte 7 --- | Converts a byte to a list of 11 bits. Needed for blinding polynomial seed +-- | Converts a byte to a list of 11 bits. Needed for blinding polynomial seed bigIntToBits :: Integer -> [Integer] bigIntToBits = unpackByte 10 --- | Turns a list of integers into bits +-- | Turns a list of integers into bits intsToBits :: [Integer] -> [Integer] intsToBits = concatMap intToBits --- | Converts a list of bits to a single byte: bitsToInt [0,0,0,0,0,0,1,1] = 3 +-- | Converts a list of bits to a single byte: bitsToInt [0,0,0,0,0,0,1,1] = 3 bitsToInt :: [Integer] -> Integer-bitsToInt b = packByte 1 (reverse b) +bitsToInt b = packByte 1 (reverse b) where packByte n b | null b = 0 | otherwise = n * head b + packByte (n * 2) (tail b) -- | Generates a random polynomial of degree < n with pos 1's and neg -1's. Assumes pos + neg <= n-genRandPoly :: Int -> Int -> Int -> IO (Poly Integer)-genRandPoly n pos neg = do +genRandPoly :: Int -> Int -> Int -> IO (VPoly Integer)+genRandPoly n pos neg = do poly <- setRandValues [] n pos neg- return $ toPoly poly + return $ toPoly poly where- setRandValues lst n pos neg = - if n == 0 then return lst + setRandValues lst n pos neg =+ if n == 0 then return lst else do randVal <- randomIO :: IO Int- let randInRange = randVal `mod` n - if randInRange < pos + let randInRange = randVal `mod` n+ if randInRange < pos then setRandValues ((1):lst) (n - 1) (pos - 1) neg else if randInRange < (pos + neg) then setRandValues ((-1):lst) (n - 1) pos (neg - 1) else setRandValues (0:lst) (n - 1) pos neg -- | Creates an improper polynomial of length n from poly improperPolynomial :: Int -> [Integer] -> [Integer] improperPolynomial n poly = poly ++ replicate (fromIntegral n - length poly) 0 --- | Pads the given list with the requisite zeros to have a multiple of 8 length +-- | Pads the given list with the requisite zeros to have a multiple of 8 length padInt8 :: [Integer] -> [Integer]-padInt8 lst = lst ++ replicate ((8 - (length lst `mod` 8)) `mod` 8) 0 +padInt8 lst = lst ++ replicate ((8 - (length lst `mod` 8)) `mod` 8) 0 -- | Converts to octets toOctets :: [Integer] -> [Integer]-toOctets lst = - let int2s = concatMap (reverse . take 2 . reverse . unpackByte 7) lst +toOctets lst =+ let int2s = concatMap (reverse . take 2 . reverse . unpackByte 7) lst in map (bitsToInt . padInt8) $ chunksOf 8 int2s @@ -466,25 +481,25 @@ -- | Generates the proper parameter set based on the given bit level genParams :: String -- ^ Desired parameter set: This should be either one of the 12 listed in the IEEE Standard (1363.1-2008) Annex A -> ParamSet -- ^ Parameter set to be used by 'keyGen', 'encrypt', or 'decrypt'-genParams bit_level - | bit_level == "EES401EP1" = ParamSet {getN = 401, getP = 3, getQ = 2048, getDf = 113, getDg = 133, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 60, getBufferLenBits = 600, getBufferLenTrits = 400, getDm0 = 113, getShaLvl = 1, getDr = 113, getC = 11, getMinCallsR = 32, getMinCallsMask = 9, getOID = [0,2,4], getPkLen = 114, getBitLvl = 112} - | bit_level == "EES449EP1" = ParamSet {getN = 449, getP = 3, getQ = 2048, getDf = 134, getDg = 149, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 67, getBufferLenBits = 672, getBufferLenTrits = 448, getDm0 = 134, getShaLvl = 1, getDr = 134, getC = 9, getMinCallsR = 31, getMinCallsMask = 9, getOID = [0,3,3], getPkLen = 128, getBitLvl = 128} - | bit_level == "EES677EP1" = ParamSet {getN = 677, getP = 3, getQ = 2048, getDf = 157, getDg = 225, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 101, getBufferLenBits = 1008, getBufferLenTrits = 676, getDm0 = 157, getShaLvl = 256, getDr = 157, getC = 11, getMinCallsR = 27, getMinCallsMask = 9, getOID = [0,5,3], getPkLen = 192, getBitLvl = 192} - | bit_level == "EES1087EP2" = ParamSet {getN = 1087, getP = 3, getQ = 2048, getDf = 120, getDg = 362, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 170, getBufferLenBits = 1624, getBufferLenTrits = 1086, getDm0 = 120, getShaLvl = 256, getDr = 120, getC = 13, getMinCallsR = 25, getMinCallsMask = 14, getOID = [0,6,3], getPkLen = 256, getBitLvl = 256} - | bit_level == "EES541EP1" = ParamSet {getN = 541, getP = 3, getQ = 2048, getDf = 49, getDg = 180, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 86, getBufferLenBits = 808, getBufferLenTrits = 540, getDm0 = 49, getShaLvl = 1, getDr = 49, getC = 12, getMinCallsR = 15, getMinCallsMask = 11, getOID = [0,2,5], getPkLen = 112, getBitLvl = 112} - | bit_level == "EES613EP1" = ParamSet {getN = 613, getP = 3, getQ = 2048, getDf = 55, getDg = 204, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 97, getBufferLenBits = 912, getBufferLenTrits = 612, getDm0 = 55, getShaLvl = 1, getDr = 55, getC = 11, getMinCallsR = 16, getMinCallsMask = 13, getOID = [0,3,4], getPkLen = 128, getBitLvl = 128} - | bit_level == "EES887EP1" = ParamSet {getN = 887, getP = 3, getQ = 2048, getDf = 81, getDg = 295, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 141, getBufferLenBits = 1328, getBufferLenTrits = 886, getDm0 = 81, getShaLvl = 256, getDr = 81, getC = 10, getMinCallsR = 13, getMinCallsMask = 12, getOID = [0,5,4], getPkLen = 192, getBitLvl = 192} - | bit_level == "EES1171EP1" = ParamSet {getN = 1171, getP = 3, getQ = 2048, getDf = 106, getDg = 390, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 186, getBufferLenBits = 1752, getBufferLenTrits = 1170, getDm0 = 106, getShaLvl = 256, getDr = 106, getC = 10, getMinCallsR = 20, getMinCallsMask = 15, getOID = [0,6,4], getPkLen = 256, getBitLvl = 256} - | bit_level == "EES659EP1" = ParamSet {getN = 659, getP = 3, getQ = 2048, getDf = 38, getDg = 219, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 108, getBufferLenBits = 984, getBufferLenTrits = 658, getDm0 = 38, getShaLvl = 1, getDr = 38, getC = 11, getMinCallsR = 11, getMinCallsMask = 14, getOID = [0,2,6], getPkLen = 112, getBitLvl = 112} - | bit_level == "EES761EP2" = ParamSet {getN = 761, getP = 3, getQ = 2048, getDf = 42, getDg = 253, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 125, getBufferLenBits = 1136, getBufferLenTrits = 760, getDm0 = 42, getShaLvl = 1, getDr = 42, getC = 12, getMinCallsR = 13, getMinCallsMask = 16, getOID = [0,3,5], getPkLen = 128, getBitLvl = 128} - | bit_level == "EES1087EP1" = ParamSet {getN = 1087, getP = 3, getQ = 2048, getDf = 63, getDg = 362, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 178, getBufferLenBits = 1624, getBufferLenTrits = 1086, getDm0 = 63, getShaLvl = 256, getDr = 63, getC = 13, getMinCallsR = 13, getMinCallsMask = 14, getOID = [0,5,5], getPkLen = 192, getBitLvl = 192} - | bit_level == "EES1499EP1" = ParamSet {getN = 1499, getP = 3, getQ = 2048, getDf = 79, getDg = 499, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 247, getBufferLenBits = 2240, getBufferLenTrits = 1498, getDm0 = 79, getShaLvl = 256, getDr = 79, getC = 13, getMinCallsR = 17, getMinCallsMask = 19, getOID = [0,6,5], getPkLen = 256, getBitLvl = 256} +genParams bit_level+ | bit_level == "EES401EP1" = ParamSet {getN = 401, getP = 3, getQ = 2048, getDf = 113, getDg = 133, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 60, getBufferLenBits = 600, getBufferLenTrits = 400, getDm0 = 113, getShaLvl = 1, getDr = 113, getC = 11, getMinCallsR = 32, getMinCallsMask = 9, getOID = [0,2,4], getPkLen = 114, getBitLvl = 112}+ | bit_level == "EES449EP1" = ParamSet {getN = 449, getP = 3, getQ = 2048, getDf = 134, getDg = 149, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 67, getBufferLenBits = 672, getBufferLenTrits = 448, getDm0 = 134, getShaLvl = 1, getDr = 134, getC = 9, getMinCallsR = 31, getMinCallsMask = 9, getOID = [0,3,3], getPkLen = 128, getBitLvl = 128}+ | bit_level == "EES677EP1" = ParamSet {getN = 677, getP = 3, getQ = 2048, getDf = 157, getDg = 225, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 101, getBufferLenBits = 1008, getBufferLenTrits = 676, getDm0 = 157, getShaLvl = 256, getDr = 157, getC = 11, getMinCallsR = 27, getMinCallsMask = 9, getOID = [0,5,3], getPkLen = 192, getBitLvl = 192}+ | bit_level == "EES1087EP2" = ParamSet {getN = 1087, getP = 3, getQ = 2048, getDf = 120, getDg = 362, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 170, getBufferLenBits = 1624, getBufferLenTrits = 1086, getDm0 = 120, getShaLvl = 256, getDr = 120, getC = 13, getMinCallsR = 25, getMinCallsMask = 14, getOID = [0,6,3], getPkLen = 256, getBitLvl = 256}+ | bit_level == "EES541EP1" = ParamSet {getN = 541, getP = 3, getQ = 2048, getDf = 49, getDg = 180, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 86, getBufferLenBits = 808, getBufferLenTrits = 540, getDm0 = 49, getShaLvl = 1, getDr = 49, getC = 12, getMinCallsR = 15, getMinCallsMask = 11, getOID = [0,2,5], getPkLen = 112, getBitLvl = 112}+ | bit_level == "EES613EP1" = ParamSet {getN = 613, getP = 3, getQ = 2048, getDf = 55, getDg = 204, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 97, getBufferLenBits = 912, getBufferLenTrits = 612, getDm0 = 55, getShaLvl = 1, getDr = 55, getC = 11, getMinCallsR = 16, getMinCallsMask = 13, getOID = [0,3,4], getPkLen = 128, getBitLvl = 128}+ | bit_level == "EES887EP1" = ParamSet {getN = 887, getP = 3, getQ = 2048, getDf = 81, getDg = 295, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 141, getBufferLenBits = 1328, getBufferLenTrits = 886, getDm0 = 81, getShaLvl = 256, getDr = 81, getC = 10, getMinCallsR = 13, getMinCallsMask = 12, getOID = [0,5,4], getPkLen = 192, getBitLvl = 192}+ | bit_level == "EES1171EP1" = ParamSet {getN = 1171, getP = 3, getQ = 2048, getDf = 106, getDg = 390, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 186, getBufferLenBits = 1752, getBufferLenTrits = 1170, getDm0 = 106, getShaLvl = 256, getDr = 106, getC = 10, getMinCallsR = 20, getMinCallsMask = 15, getOID = [0,6,4], getPkLen = 256, getBitLvl = 256}+ | bit_level == "EES659EP1" = ParamSet {getN = 659, getP = 3, getQ = 2048, getDf = 38, getDg = 219, getLLen = 1, getDb = 112, getMaxMsgLenBytes = 108, getBufferLenBits = 984, getBufferLenTrits = 658, getDm0 = 38, getShaLvl = 1, getDr = 38, getC = 11, getMinCallsR = 11, getMinCallsMask = 14, getOID = [0,2,6], getPkLen = 112, getBitLvl = 112}+ | bit_level == "EES761EP2" = ParamSet {getN = 761, getP = 3, getQ = 2048, getDf = 42, getDg = 253, getLLen = 1, getDb = 128, getMaxMsgLenBytes = 125, getBufferLenBits = 1136, getBufferLenTrits = 760, getDm0 = 42, getShaLvl = 1, getDr = 42, getC = 12, getMinCallsR = 13, getMinCallsMask = 16, getOID = [0,3,5], getPkLen = 128, getBitLvl = 128}+ | bit_level == "EES1087EP1" = ParamSet {getN = 1087, getP = 3, getQ = 2048, getDf = 63, getDg = 362, getLLen = 1, getDb = 192, getMaxMsgLenBytes = 178, getBufferLenBits = 1624, getBufferLenTrits = 1086, getDm0 = 63, getShaLvl = 256, getDr = 63, getC = 13, getMinCallsR = 13, getMinCallsMask = 14, getOID = [0,5,5], getPkLen = 192, getBitLvl = 192}+ | bit_level == "EES1499EP1" = ParamSet {getN = 1499, getP = 3, getQ = 2048, getDf = 79, getDg = 499, getLLen = 1, getDb = 256, getMaxMsgLenBytes = 247, getBufferLenBits = 2240, getBufferLenTrits = 1498, getDm0 = 79, getShaLvl = 256, getDr = 79, getC = 13, getMinCallsR = 17, getMinCallsMask = 19, getOID = [0,6,5], getPkLen = 256, getBitLvl = 256} | otherwise = error "Unsupported Parameter Set" -- | The Parameter Set Record data ParamSet = ParamSet { getN :: Int, -- ^ The size of the polynomials- getP :: Integer, -- ^ The small modulus p + getP :: Integer, -- ^ The small modulus p getQ :: Integer, -- ^ The large modulus q getDf :: Int, -- ^ The number of 1's in f getDg :: Int, -- ^ The number of 1's in g@@ -493,7 +508,7 @@ getMaxMsgLenBytes :: Int, -- ^ The max number of bytes in the message getBufferLenBits :: Int, -- ^ The size of the resulting message before conversion to trits getBufferLenTrits :: Int, -- ^ The size of the resulting message after conversion to trits- getDm0 :: Int, -- ^ Minimum number of 1's, -1's and 0's in the message for decryption to succeed + getDm0 :: Int, -- ^ Minimum number of 1's, -1's and 0's in the message for decryption to succeed getShaLvl :: Int, -- ^ SHA algorithm to use. Should be either 1 or 256 getDr :: Int, -- ^ The number of 1's in the blinding polynomial getC :: Int, -- ^ Used by index generator function@@ -505,7 +520,7 @@ } deriving (Show) getSHA :: ParamSet -> ([Integer] -> [Integer])-getSHA params = case (getShaLvl params) of +getSHA params = case (getShaLvl params) of 256 -> sha256Octets 1 -> sha1Octets _ -> error "Unsupported SHA function"
src/Math/NTRU/EES1087EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES1087EP1 parameter set, for use at the 192-bit security level. + NTRU cryptographic system using the EES1087EP1 parameter set, for use at the 192-bit security level. -} -module Math.NTRU.EES1087EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES1087EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES1087EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES1087EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES1087EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES1087EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES1087EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES1087EP1")
src/Math/NTRU/EES1087EP2.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES1087EP2 parameter set, for use at the 256-bit security level. + NTRU cryptographic system using the EES1087EP2 parameter set, for use at the 256-bit security level. -} -module Math.NTRU.EES1087EP2 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES1087EP2 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES1087EP2") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES1087EP2") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES1087EP2")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES1087EP2") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES1087EP2")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES1087EP2")
src/Math/NTRU/EES1171EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES1171EP1 parameter set, for use at the 256-bit security level. + NTRU cryptographic system using the EES1171EP1 parameter set, for use at the 256-bit security level. -} -module Math.NTRU.EES1171EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES1171EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES1171EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES1171EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES1171EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES1171EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES1171EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES1171EP1")
src/Math/NTRU/EES1499EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES1499EP1 parameter set, for use at the 256-bit security level. + NTRU cryptographic system using the EES1499EP1 parameter set, for use at the 256-bit security level. -} -module Math.NTRU.EES1499EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES1499EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES1499EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES1499EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES1499EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES1499EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES1499EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES1499EP1")
src/Math/NTRU/EES401EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES401EP1 parameter set, for use at the 112-bit security level. + NTRU cryptographic system using the EES401EP1 parameter set, for use at the 112-bit security level. -} -module Math.NTRU.EES401EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES401EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES401EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES401EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES401EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES401EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES401EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES401EP1")
src/Math/NTRU/EES449EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES449EP1 parameter set, for use at the 128-bit security level. + NTRU cryptographic system using the EES449EP1 parameter set, for use at the 128-bit security level. -} -module Math.NTRU.EES449EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES449EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES449EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES449EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES449EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES449EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES449EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES449EP1")
src/Math/NTRU/EES541EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES541EP1 parameter set, for use at the 112-bit security level. + NTRU cryptographic system using the EES541EP1 parameter set, for use at the 112-bit security level. -} -module Math.NTRU.EES541EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES541EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES541EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES541EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES541EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES541EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES541EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES541EP1")
src/Math/NTRU/EES613EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES613EP1 parameter set, for use at the 128-bit security level. + NTRU cryptographic system using the EES613EP1 parameter set, for use at the 128-bit security level. -} -module Math.NTRU.EES613EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES613EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES613EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES613EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES613EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES613EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES613EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES613EP1")
src/Math/NTRU/EES659EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES659EP1 parameter set, for use at the 112-bit security level. + NTRU cryptographic system using the EES659EP1 parameter set, for use at the 112-bit security level. -} -module Math.NTRU.EES659EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES659EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES659EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES659EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES659EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES659EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES659EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES659EP1")
src/Math/NTRU/EES677EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES677EP1 parameter set, for use at the 192-bit security level. + NTRU cryptographic system using the EES677EP1 parameter set, for use at the 192-bit security level. -} -module Math.NTRU.EES677EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES677EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES677EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES677EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES677EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES677EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES677EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES677EP1")
src/Math/NTRU/EES761EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES761EP1 parameter set, for use at the 128-bit security level. + NTRU cryptographic system using the EES761EP1 parameter set, for use at the 128-bit security level. -} -module Math.NTRU.EES761EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES761EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES761EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES761EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES761EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES761EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES761EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES761EP1")
src/Math/NTRU/EES887EP1.hs view
@@ -1,25 +1,25 @@ {- |- NTRU cryptographic system using the EES887EP1 parameter set, for use at the 192-bit security level. + NTRU cryptographic system using the EES887EP1 parameter set, for use at the 192-bit security level. -} -module Math.NTRU.EES887EP1 (keyGen, encrypt, decrypt) where +module Math.NTRU.EES887EP1 (keyGen, encrypt, decrypt) where - import qualified Math.NTRU as NTRU +import qualified Math.NTRU as NTRU - -- | Generates a random PublicKey-PrivateKey pair - keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.- keyGen = NTRU.keyGen (NTRU.genParams "EES887EP1") +-- | Generates a random PublicKey-PrivateKey pair+keyGen :: IO ([Integer], [Integer]) -- ^ A tuple representing (PublicKey, PrivateKey) where PrivateKey = 1 + pf, per <https://www.securityinnovation.com/uploads/Crypto/NTRU%20Enhancements%201.pdf enahncement#2>.+keyGen = NTRU.keyGen (NTRU.genParams "EES887EP1") - -- | Encrypts a message with the given public key- encrypt :: [Integer] -- ^ A list of ASCII values representing the message- -> [Integer] -- ^ A list of numbers representing the public key- -> IO [Integer] -- ^ A list of numbers representing the ciphertext- encrypt = NTRU.encrypt (NTRU.genParams "EES887EP1")+-- | Encrypts a message with the given public key+encrypt :: [Integer] -- ^ A list of ASCII values representing the message+ -> [Integer] -- ^ A list of numbers representing the public key+ -> IO [Integer] -- ^ A list of numbers representing the ciphertext+encrypt = NTRU.encrypt (NTRU.genParams "EES887EP1") - -- | Decrypts and verifies a cyphertext with the given keys- decrypt :: [Integer] -- ^ A list of numbers representing the private key- -> [Integer] -- ^ A list of numbers representing the public key- -> [Integer] -- ^ A list of numbers representing the ciphertext- -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure- decrypt = NTRU.decrypt (NTRU.genParams "EES887EP1")+-- | Decrypts and verifies a cyphertext with the given keys+decrypt :: [Integer] -- ^ A list of numbers representing the private key+ -> [Integer] -- ^ A list of numbers representing the public key+ -> [Integer] -- ^ A list of numbers representing the ciphertext+ -> Maybe [Integer] -- ^ A list of numbers representing the original message, or nothing on failure+decrypt = NTRU.decrypt (NTRU.genParams "EES887EP1")