crypto.nut 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. --
  2. -- Copyright (C) 2014 by Ole Reinhardt <ole.reinhardt@embedded-it.de>
  3. -- All rights reserved.
  4. --
  5. -- Redistribution and use in source and binary forms, with or without
  6. -- modification, are permitted provided that the following conditions
  7. -- are met:
  8. --
  9. -- 1. Redistributions of source code must retain the above copyright
  10. -- notice, this list of conditions and the following disclaimer.
  11. -- 2. Redistributions in binary form must reproduce the above copyright
  12. -- notice, this list of conditions and the following disclaimer in the
  13. -- documentation and/or other materials provided with the distribution.
  14. -- 3. Neither the name of the copyright holders nor the names of
  15. -- contributors may be used to endorse or promote products derived
  16. -- from this software without specific prior written permission.
  17. --
  18. -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. -- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. -- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. -- AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. -- THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. -- SUCH DAMAGE.
  30. --
  31. -- For additional information see http://www.ethernut.de/
  32. --
  33. -- Cryptographic functions
  34. --
  35. --
  36. bigint_reduction = {
  37. "CRYPTO_BIGINT_CLASSICAL",
  38. "CRYPTO_BIGINT_MONTGOMERY",
  39. "CRYPTO_BIGINT_BARRETT"
  40. }
  41. nutcrypto =
  42. {
  43. {
  44. name = "nutcrypto_aes",
  45. brief = "AES 128/256",
  46. description = "AES 128 / 256 block cypher.",
  47. provides = { "CRYPTO_AES" },
  48. sources =
  49. {
  50. "aes.c"
  51. }
  52. },
  53. {
  54. name = "nutcrypto_bigint",
  55. brief = "Big integer mathematics",
  56. description = "Big integer mathematics.",
  57. provides = { "CRYPTO_BIGINT" },
  58. sources =
  59. {
  60. "bigint.c"
  61. },
  62. options =
  63. {
  64. {
  65. macro = "CRYPTO_BIGINT_CLASSICAL",
  66. brief = "Classical bigint reduction algorithm",
  67. description = "Classical uses standard division. It has no limitations and is "..
  68. "theoretically the slowest due to the divisions used. For this particular "..
  69. "implementation it is surprisingly quite fast.",
  70. flavor = "boolean",
  71. exclusivity = bigint_reduction,
  72. file = "include/cfg/crypto.h",
  73. },
  74. {
  75. macro = "CRYPTO_BIGINT_MONTGOMERY",
  76. brief = "Montgomery bigint reduction algorithm",
  77. description = "Montgomery uses simple addition and multiplication to achieve its "..
  78. "performance. It has the limitation that 0 <= x, y < m, and so is not "..
  79. "used when CRT is active.",
  80. flavor = "boolean",
  81. exclusivity = bigint_reduction,
  82. file = "include/cfg/crypto.h",
  83. },
  84. {
  85. macro = "CRYPTO_BIGINT_BARRETT",
  86. brief = "Barrett bigint reduction algorithm",
  87. description = "Barrett performs expensive precomputation before reduction and "..
  88. "partial multiplies for computational speed. \n"..
  89. "It is about 40% faster than Classical/Montgomery with the expense "..
  90. "of about 2kB, and so this option is normally selected.",
  91. flavor = "boolean",
  92. exclusivity = bigint_reduction,
  93. file = "include/cfg/crypto.h",
  94. },
  95. {
  96. macro = "CRYPTO_BIGINT_CRT",
  97. brief = "Chinese Remainder Theorem (CRT)",
  98. description = "Allow the Chinese Remainder Theorem (CRT) to be used.\n\n"..
  99. "Uses a number of extra coefficients from the private key to improve the "..
  100. "performance of a decryption. This feature is one of the most "..
  101. "significant performance improvements (it reduces a decryption time by "..
  102. "over 3 times).\n\n"..
  103. "This option should be selected.",
  104. flavor = "boolean",
  105. default = true,
  106. file = "include/cfg/crypto.h",
  107. },
  108. {
  109. macro = "CRYPTO_BIGINT_KARATSUBA",
  110. brief = "Karatsuba Multiplication",
  111. description = "Allow Karasuba multiplication to be used.\n\n"..
  112. "Uses 3 multiplications (plus a number of additions/subtractions) "..
  113. "instead of 4. Multiplications are O(N^2) but addition/subtraction "..
  114. "is O(N) hence for large numbers is beneficial. For this project, the "..
  115. "effect was only useful for 4096 bit keys (for 32 bit processors). For "..
  116. "8 bit processors this option might be a possibility.\n\n"..
  117. "It costs about 2kB to enable it.",
  118. provides = { "BIGINT_KARATSUBA" },
  119. flavor = "boolean",
  120. file = "include/cfg/crypto.h",
  121. },
  122. {
  123. macro = "MUL_KARATSUBA_THRESH",
  124. brief = "Karatsuba Multiplication Theshold",
  125. description = "The minimum number of components needed before Karasuba muliplication "..
  126. "is used.\n\n"..
  127. "This is very dependent on the speed/implementation of bi_add()/"..
  128. "bi_subtract(). There is a bit of trial and error here and will be "..
  129. "at a different point for different architectures.",
  130. requires = { "BIGINT_KARATSUBA" },
  131. default = 20,
  132. flavor = "integer",
  133. file = "include/cfg/crypto.h",
  134. },
  135. {
  136. macro = "SQU_KARATSUBA_THRESH",
  137. brief = "Karatsuba Square Threshold",
  138. description = "The minimum number of components needed before Karatsuba squaring "..
  139. "is used.\n\n"..
  140. "This is very dependent on the speed/implementation of bi_add()/"..
  141. "bi_subtract(). There is a bit of trial and error here and will be "..
  142. "at a different point for different architectures.",
  143. requires = { "BIGINT_KARATSUBA", "BIGINT_SQUARE" },
  144. default = 40,
  145. flavor = "integer",
  146. file = "include/cfg/crypto.h",
  147. },
  148. {
  149. macro = "CRYPTO_BIGINT_SLIDING_WINDOW",
  150. brief = "Sliding Window Exponentiation",
  151. description = "Allow Sliding-Window Exponentiation to be used.\n\n"..
  152. "Potentially processes more than 1 bit at a time when doing "..
  153. "exponentiation. The sliding-window technique reduces the number of "..
  154. "precomputations compared to other precomputed techniques.\n\n"..
  155. "It results in a considerable performance improvement with it enabled"..
  156. "(it halves the decryption time) and so should be selected.",
  157. default = true,
  158. flavor = "boolean",
  159. file = "include/cfg/crypto.h",
  160. },
  161. {
  162. macro = "CRYPTO_BIGINT_SQUARE",
  163. brief = "Square Algorithm",
  164. description = "Allow squaring to be used instead of a multiplication. It uses "..
  165. "1/2 of the standard multiplies to obtain its performance. "..
  166. "It gives a 20% speed improvement overall and so should be selected.",
  167. active = "true",
  168. provides = { "BIGINT_SQUARE" },
  169. flavor = "boolean",
  170. file = "include/cfg/crypto.h",
  171. },
  172. {
  173. macro = "CRYPTO_BIGINT_CHECK_ON",
  174. brief = "BigInt Integrity Checking",
  175. description = "This is used when developing bigint algorithms. It performs a sanity "..
  176. "check on all operations at the expense of speed. \n\n"..
  177. "This option is only selected when developing and should normally be turned off.",
  178. default = false,
  179. flavor = "boolean",
  180. file = "include/cfg/crypto.h",
  181. },
  182. },
  183. },
  184. {
  185. name = "nutcrypto_rsa",
  186. brief = "RSA public key encryption / decryption",
  187. description = "RSA public encryption algorithm. Uses the bigint library "..
  188. "to perform its calculations",
  189. requires = { "CRYPTO_BIGINT" },
  190. provides = { "CRYPTO_RSA" },
  191. sources =
  192. {
  193. "rsa.c"
  194. }
  195. },
  196. {
  197. name = "nutcrypto_sha1",
  198. brief = "SHA1 implementation",
  199. description = "SHA1 implementation - as defined in FIPS PUB 180-1 published April 17, 1995.",
  200. provides = { "CRYPTO_SHA1" },
  201. sources =
  202. {
  203. "sha1.c"
  204. }
  205. },
  206. {
  207. name = "nutcrypto_rc4",
  208. brief = "RC4 implementation",
  209. description = "Implementation of the RC4/ARC4 algorithm.",
  210. provides = { "CRYPTO_RC4" },
  211. sources =
  212. {
  213. "rc4.c"
  214. }
  215. },
  216. {
  217. name = "nutcrypto_md2",
  218. brief = "MD2 implementation",
  219. description = "RFC 1115/1319 compliant MD2 implementation",
  220. provides = { "CRYPTO_MD2" },
  221. sources =
  222. {
  223. "md2.c"
  224. }
  225. },
  226. {
  227. name = "nutcrypto_md5",
  228. brief = "MD5 implementation",
  229. description = "RFC1321 compliant MD5 implementation",
  230. provides = { "CRYPTO_MD5" },
  231. sources =
  232. {
  233. "md5.c"
  234. }
  235. },
  236. {
  237. name = "nutcrypto_hmac",
  238. brief = "HMAC implementation",
  239. description = "HMAC implementation - This code was originally taken from RFC2104",
  240. requires = { "CRYPTO_MD5", "CRYPTO_SHA1" },
  241. provides = { "CRYPTO_HMAC" },
  242. sources =
  243. {
  244. "hmac.c"
  245. }
  246. },
  247. }