options.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true */
  9. 'use strict';
  10. var objs = require('./objs');
  11. /**
  12. * @description The configuration options for the cryptographic policy. Provided
  13. * as a global property of this module.
  14. * @readonly
  15. *
  16. * @property {object} primitives.securerandom - Policy for generating message
  17. * digests.
  18. * @property {object} primitives.messageDigest.algorithm - Hash algorithm.
  19. * @property {string} primitives.messageDigest.algorithm.SHA256 - 'SHA256'
  20. * @property {string} primitives.messageDigest.algorithm.SHA512_224
  21. * -'SHA512/224'
  22. *
  23. * @property {object} primitives.keyDerivation - Policy for deriving keys.
  24. * @property {object} primitives.keyDerivation.pbkdf - Password-based key
  25. * derivation function (PBKDF)
  26. * @property {object} primitives.keyDerivation.pbkdf.keyLengthBytes - Key
  27. * length, in bytes.
  28. * @property {number} primitives.keyDerivation.pbkdf.keyLengthBytes.KL_16 - 16
  29. * @property {number} primitives.keyDerivation.pbkdf.keyLengthBytes.KL_32 - 32
  30. * @property {object} primitives.keyDerivation.pbkdf.minSaltLengthBytes -
  31. * Minimum salt length, in bytes.
  32. * @property {number} primitives.keyDerivation.pbkdf.minSaltLengthBytes.SL_20 -
  33. * 20.
  34. * @property {number} primitives.keyDerivation.pbkdf.minSaltLengthBytes.SL_32 -
  35. * 32
  36. * @property {object} primitives.keyDerivation.pbkdf.hashAlgorithm - Hash
  37. * algorithm.
  38. * @property {string} primitives.keyDerivation.pbkdf.hashAlgorithm.SHA256 -
  39. * 'SHA256'
  40. * @property {string} primitives.keyDerivation.pbkdf.hashAlgorithm.SHA512_224 -
  41. * 'SHA512/224'
  42. * @property {object} primitives.keyDerivation.pbkdf.numIterations - Number of
  43. * iterations.
  44. * @property {number} primitives.keyDerivation.pbkdf.I_1 - 1
  45. * @property {number} primitives.keyDerivation.pbkdf.I_8000 - 8000
  46. * @property {number} primitives.keyDerivation.pbkdf.I_16000 - 16000
  47. * @property {number} primitives.keyDerivation.pbkdf.I_32000 - 32000
  48. * @property {number} primitives.keyDerivation.pbkdf.I_64000 - 64000
  49. *
  50. * @property {object} symmetric.secretkey - Policy for generating secret keys.
  51. * @property {object} symmetric.secretkey.encryption - Secret key for
  52. * encryption.
  53. * @property {object} symmetric.secretKey.encryption.lengthBytes - Key length,
  54. * in bytes.
  55. * @property {number} symmetric.secretKey.encryption.lengthBytes.KL_16 - 16
  56. * @property {number} symmetric.secretKey.encryption.lengthBytes.KL_32 - 32
  57. * @property {object} symmetric.secretkey.mac - Secret key for MAC generation.
  58. * @property {object} symmetric.secretKey.mac.lengthBytes - Key length, in
  59. * bytes.
  60. * @property {number} symmetric.secretKey.mac.lengthBytes.KL_16 - 16
  61. * @property {number} symmetric.secretKey.mac.lengthBytes.KL_32 - 32
  62. *
  63. * @property {object} symmetric.cipher - Policy for symmetrically encrypting and
  64. * decrypting data.
  65. * @property {object} symmetric.cipher.algorithm - Cipher algorithm.
  66. * @property {object} symmetric.cipher.algorithm.AES_GCM - AES-GCM algorithm.
  67. * @property {string} symmetric.cipher.algorithm.AES_GCM.name - 'AES-GCM'
  68. * @property {object} symmetric.cipher.algorithm.AES_GCM.keyLengthBytes - Key
  69. * length, in bytes.
  70. * @property {number} symmetric.cipher.algorithm.AES_GCM.keyLengthBytes.KL_16 -
  71. * 16
  72. * @property {number} symmetric.cipher.algorithm.AES_GCM.keyLengthBytes.KL_32 -
  73. * 32
  74. * @property {object} symmetric.cipher.algorithm.AES_GCM.tagLengthBytes - Tag
  75. * length, in bytes.
  76. * @property {number} symmetric.cipher.algorithm.AES_GCM.tagLengthBytes.TL_16 -
  77. * 16
  78. * @property {number} symmetric.cipher.algorithm.AES_GCM.tagLengthBytes.TL_32 -
  79. * 32
  80. * @property {object} symmetric.cipher.ivLengthBytes - Initialization vector
  81. * length, in bytes.
  82. * @property {number} symmetric.cipher.ivLengthBytes.IVL_12 - 12
  83. * @property {number} symmetric.cipher.ivLengthBytes.IVL_16 - 16
  84. * @property {number} symmetric.cipher.ivLengthBytes.IVL_32 - 32
  85. * @property {number} symmetric.cipher.ivLengthBytes.IVL_64 - 64
  86. *
  87. * @property {object} symmetric.mac - Policy for generating MAC's.
  88. * @property {object} symmetric.mac.hashAlgorithm - Hash algorithm.
  89. * @property {string} symmetric.mac.hashAlgorithm.SHA256 = 'SHA256'
  90. * @property {string} symmetric.mac.hashAlgorithm.SHA512_224 = 'SHA512/224'
  91. *
  92. * @property {object} asymmetric.keyPair - Policy for generating key pairs.
  93. * @property {object} asymmetric.keyPair.encryption - Encryption key pair.
  94. * @property {object} asymmetric.keyPair.encryption.algorithm - Key pair
  95. * generation algorithm.
  96. * @property {string} asymmetric.keyPair.encryption.algorithm.RSA - 'RSA'.
  97. * @property {object} asymmetric.keyPair.encryption.keyLengthBits - Key length,
  98. * in bits.
  99. * @property {number} asymmetric.keyPair.encryption.keyLengthBits.KL_2048 - 2048
  100. * @property {number} asymmetric.keyPair.encryption.keyLengthBits.KL_3072 - 3072
  101. * @property {number} asymmetric.keyPair.encryption.keyLengthBits.KL_4096 - 4096
  102. * @property {object} asymmetric.keyPair.encryption.publicExponent - Public
  103. * exponent.
  104. * @property {number} asymmetric.keyPair.encryption.publicExponent.F4 - 65537
  105. *
  106. * @property {object} asymmetric.signer - Policy for signing data and verifying
  107. * signatures.
  108. * @property {object} asymmetric.signer.algorithm - Signer algorithm.
  109. * @property {string} asymmetric.signer.algorithm.RSA - 'RSA'
  110. * @property {object} asymmetric.signer.hashAlgorithm - Hash algorithm.
  111. * @property {string} asymmetric.signer.hashAlgorithm.SHA256 - SHA256'.
  112. * @property {string} asymmetric.signer.hashAlgorithm.SHA256_224 - 'SHA512/224'
  113. * @property {object} asymmetric.signer.padding - Padding.
  114. * @property {object} asymmetric.signer.padding.PSS - PSS padding.
  115. * @property {string} asymmetric.signer.padding.PSS.name - 'PSS'
  116. * @property {object} asymmetric.signer.padding.PSS.hashAlgorithm - Hash
  117. * algorithm.
  118. * @property {string} asymmetric.signer.padding.hashAlgorithm.SHA256 - 'SHA256'
  119. * @property {string} asymmetric.signer.padding.hashAlgorithm.SHA256_224 -
  120. * 'SHA512/224'
  121. * @property {object} asymmetric.signer.padding.PSS.saltLengthBytes - Salt
  122. * length, in bytes.
  123. * @property {number} asymmetric.signer.padding.PSS.saltLengthBytes.SL_32 - 32
  124. * @property {number} asymmetric.signer.padding.PSS.saltLengthBytes.SL_64 - 64
  125. * @property {object} asymmetric.signer.padding.PSS.maskGenerator - Mask
  126. * generation function.
  127. * @property {object} asymmetric.signer.padding.PSS.maskGenerator.MGF1 - MGF1
  128. * mask generation algorithm.
  129. * @property {string} asymmetric.signer.padding.PSS.maskGenerator.MGF1.name -
  130. * 'MGF1'
  131. * @property {object}
  132. * asymmetric.signer.padding.PSS.maskGenerator.MGF1.hashAlgorithm -
  133. * Hash algorithm.
  134. * @property {string}
  135. * asymmetric.signer.padding.PSS.maskGenerator.MGF1.hashAlgorithm.SHA256
  136. * -'SHA256'
  137. * @property {string}
  138. * asymmetric.signer.padding.PSS.maskGenerator.MGF1.hashAlgorithm.SHA256_224
  139. * - 'SHA512/224'
  140. * @property {object} asymmetric.signer.publicExponent - Public exponent.
  141. * @property {number} asymmetric.signer.publicExponent.F4 - 65537
  142. *
  143. * @property {object} asymmetric.cipher - Policy for asymmetrically encrypting
  144. * and decrypting data.
  145. * @property {object} asymmetric.cipher.algorithm - Cipher algorithm.
  146. * @property {object} asymmetric.cipher.algorithm.RSA_OAEP - RSA-OAEP algorithm.
  147. * @property {string} asymmetric.cipher.algorithm.RSA_OAEP.name. - 'RSA-OAEP'.
  148. * @property {object} asymmetric.cipher.algorithm.RSA_OAEP.hashAlgorithm - Hash
  149. * algorithm.
  150. * @property {string} asymmetric.cipher.algorithm.RSA_OAEP.hashAlgorithm.SHA256 -
  151. * 'SHA-256'
  152. * @property {string}
  153. * asymmetric.cipher.algorithm.RSA_OAEP.hashAlgorithm.SHA512_224 -
  154. * 'SHA512/224'
  155. * @property {object} asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator - Mask
  156. * generation function.
  157. * @property {object} asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator.MGF1 -
  158. * MGF1 mask generation function.
  159. * @property {string}
  160. * asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator.MGF1.name -
  161. * 'MGF1'
  162. * @property {object}
  163. * asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator.MGF1.hashAlgorithm
  164. * - Hash algorithm.
  165. * @property {string}
  166. * asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator.MGF1.hashAlgorithm.SHA256
  167. * - 'SHA256'
  168. * @property {string}
  169. * asymmetric.cipher.algorithm.RSA_OAEP.maskGenerator.MGF1.hashAlgorithm.SHA512_224
  170. * - 'SHA512/224'
  171. * @property {object} asymmetric.cipher.algorithm.RSA_KEM - RSA-KEM algorithm.
  172. * @property {string} asymmetric.cipher.algorithm.RSA_KEM.name - 'RSA-KEM'
  173. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.hashAlgorithm - Hash
  174. * algorithm.
  175. * @property {string} asymmetric.cipher.algorithm.RSA_KEM.hashAlgorithm.SHA256 -
  176. * 'SHA256'
  177. * @property {string}
  178. * asymmetric.cipher.algorithm.RSA_KEM.hashAlgorithm.SHA512_224 -
  179. * 'SHA512/224'
  180. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.secretKeyLengthBytes -
  181. * Secret key length, in bytes.
  182. * @property {number}
  183. * asymmetric.cipher.algorithm.RSA_KEM.secretKeyLengthBytes.KL_16 - 16
  184. * @property {number}
  185. * asymmetric.cipher.algorithm.RSA_KEM.secretKeyLengthBytes.KL_24 - 24
  186. * @property {number}
  187. * asymmetric.cipher.algorithm.RSA_KEM.secretKeyLengthBytes.KL_32 - 32
  188. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.ivLengthBytes -
  189. * Initialization vector length, in bytes.
  190. * @property {number} asymmetric.cipher.algorithm.RSA_KEM.ivLengthBytes.IVL_12 -
  191. * 12
  192. * @property {number} asymmetric.cipher.algorithm.RSA_KEM.ivLengthBytes.IVL_16 -
  193. * 16
  194. * @property {number} asymmetric.cipher.algorithm.RSA_KEM.ivLengthBytes.IVL_32 -
  195. * 32
  196. * @property {number} asymmetric.cipher.algorithm.RSA_KEM.ivLengthBytes.IVL_64 -
  197. * 64
  198. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.tagLengthBytes -Tag
  199. * length, in bytes.
  200. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.tagLengthBytes.TL_12 -
  201. * 12
  202. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.tagLengthBytes.TL_16 -
  203. * 16
  204. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.tagLengthBytes.TL_32 -
  205. * 32
  206. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.tagLengthBytes.TL_64 -
  207. * 64
  208. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.keyDeriver - Key
  209. * deriver
  210. * @property {object} asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.name - Key
  211. * deriver name.
  212. * @property {string} asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.name.KDF1 -
  213. * 'KDF1'
  214. * @property {string} asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.name.KDF2 -
  215. * 'KDF2'
  216. * @property {string} asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.name.MGF1 -
  217. * 'MGF1'
  218. * @property {object}
  219. * asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.hashAlgorithm - Hash
  220. * function.
  221. * @property {string}
  222. * asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.hashAlgorithm.SHA256
  223. * - 'SHA256'
  224. * @property {string}
  225. * asymmetric.cipher.algorithm.RSA_KEM.keyDeriver.hashAlgorithm.SHA512_224
  226. * - 'SHA512/224'
  227. *
  228. * @property {object} proofs - Policy for generating zero-knowledge proofs.
  229. * @property {object} proofs.messageDigest - Policy for generating message
  230. * digests.
  231. *
  232. * @property {object} digitalEnvelope - Policy for generating digital envelopes.
  233. * @property {object} digitalEnvelope.symmetric - Policy for symmetric
  234. * cryptography operations.
  235. * @property {object} digitalEnvelope.asymmetric.cipher - Policy for asymmetric
  236. * cipher operations.
  237. */
  238. module.exports = objs.freeze(objs.leanCopy({
  239. primitives: {
  240. messageDigest: {
  241. algorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'},
  242. },
  243. keyDerivation: {
  244. pbkdf: {
  245. keyLengthBytes: {KL_16: 16, KL_32: 32},
  246. minSaltLengthBytes: {SL_20: 20, SL_32: 32},
  247. hashAlgorithm: {SHA256: 'SHA256'},
  248. numIterations: {
  249. I_1: 1,
  250. I_8000: 8000,
  251. I_16000: 16000,
  252. I_32000: 32000,
  253. I_64000: 64000
  254. }
  255. }
  256. }
  257. },
  258. symmetric: {
  259. secretKey: {
  260. encryption: {lengthBytes: {KL_16: 16, KL_32: 32}},
  261. mac: {lengthBytes: {KL_32: 32, KL_64: 64}},
  262. },
  263. cipher: {
  264. algorithm: {
  265. AES_GCM: {
  266. name: 'AES-GCM',
  267. keyLengthBytes: {KL_16: 16, KL_32: 32},
  268. tagLengthBytes: {TL_16: 16, TL_32: 32}
  269. }
  270. },
  271. ivLengthBytes: {IVL_12: 12, IVL_16: 16, IVL_32: 32, IVL_64: 64},
  272. },
  273. mac: {hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}}
  274. },
  275. asymmetric: {
  276. keyPair: {
  277. encryption: {
  278. algorithm: {RSA: 'RSA'},
  279. keyLengthBits: {KL_2048: 2048, KL_3072: 3072, KL_4096: 4096},
  280. publicExponent: {F4: 65537}
  281. },
  282. },
  283. signer: {
  284. algorithm: {RSA: 'RSA'},
  285. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'},
  286. padding: {
  287. PSS: {
  288. name: 'PSS',
  289. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'},
  290. saltLengthBytes: {SL_32: 32, SL_64: 64},
  291. maskGenerator: {
  292. MGF1: {
  293. name: 'MGF1',
  294. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}
  295. }
  296. }
  297. }
  298. },
  299. publicExponent: {F4: 65537},
  300. },
  301. cipher: {
  302. algorithm: {
  303. RSA_OAEP: {
  304. name: 'RSA-OAEP',
  305. hashAlgorithm: {SHA256: 'SHA256'},
  306. maskGenerator: {MGF1: {name: 'MGF1', hashAlgorithm: {SHA1: 'SHA1'}}}
  307. },
  308. RSA_KEM: {
  309. name: 'RSA-KEM',
  310. secretKeyLengthBytes: {KL_16: 16, KL_24: 24, KL_32: 32},
  311. ivLengthBytes: {IVL_12: 12, IVL_16: 16, IVL_32: 32, IVL_64: 64},
  312. tagLengthBytes: {TL_12: 12, TL_16: 16, TL_32: 32, TL_64: 64},
  313. keyDeriver: {
  314. name: {KDF1: 'KDF1', KDF2: 'KDF2', MGF1: 'MGF1'},
  315. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}
  316. },
  317. symmetricCipher: {AES_GCM: 'AES-GCM'}
  318. }
  319. },
  320. }
  321. },
  322. proofs: {
  323. messageDigest: {
  324. algorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'},
  325. }
  326. },
  327. digitalEnvelope: {
  328. symmetric: {
  329. secretKey: {
  330. encryption: {lengthBytes: {KL_16: 16, KL_32: 32}},
  331. mac: {lengthBytes: {KL_32: 32, KL_64: 64}},
  332. },
  333. cipher: {
  334. algorithm: {
  335. AES_GCM: {
  336. name: 'AES-GCM',
  337. keyLengthBytes: {KL_16: 16, KL_32: 32},
  338. tagLengthBytes: {TL_16: 16, TL_32: 32}
  339. }
  340. },
  341. ivLengthBytes: {IVL_12: 12, IVL_16: 16, IVL_32: 32, IVL_64: 64},
  342. },
  343. mac: {hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}}
  344. },
  345. asymmetric: {
  346. cipher: {
  347. algorithm: {
  348. RSA_OAEP: {
  349. name: 'RSA-OAEP',
  350. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'},
  351. maskGenerator: {
  352. MGF1: {
  353. name: 'MGF1',
  354. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}
  355. }
  356. }
  357. },
  358. RSA_KEM: {
  359. name: 'RSA-KEM',
  360. secretKeyLengthBytes: {KL_16: 16, KL_24: 24, KL_32: 32},
  361. ivLengthBytes: {IVL_12: 12, IVL_16: 16, IVL_32: 32, IVL_64: 64},
  362. tagLengthBytes: {TL_12: 12, TL_16: 16, TL_32: 32, TL_64: 64},
  363. keyDeriver: {
  364. name: {KDF1: 'KDF1', KDF2: 'KDF2', MGF1: 'MGF1'},
  365. hashAlgorithm: {SHA256: 'SHA256', SHA512_224: 'SHA512/224'}
  366. },
  367. symmetricCipher: {AES_GCM: 'AES-GCM'}
  368. }
  369. },
  370. }
  371. }
  372. }
  373. }));