You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.8 KiB

  1. // Copyright 2015 Joyent, Inc.
  2. var Buffer = require('safer-buffer').Buffer;
  3. var algInfo = {
  4. 'dsa': {
  5. parts: ['p', 'q', 'g', 'y'],
  6. sizePart: 'p'
  7. },
  8. 'rsa': {
  9. parts: ['e', 'n'],
  10. sizePart: 'n'
  11. },
  12. 'ecdsa': {
  13. parts: ['curve', 'Q'],
  14. sizePart: 'Q'
  15. },
  16. 'ed25519': {
  17. parts: ['A'],
  18. sizePart: 'A'
  19. }
  20. };
  21. algInfo['curve25519'] = algInfo['ed25519'];
  22. var algPrivInfo = {
  23. 'dsa': {
  24. parts: ['p', 'q', 'g', 'y', 'x']
  25. },
  26. 'rsa': {
  27. parts: ['n', 'e', 'd', 'iqmp', 'p', 'q']
  28. },
  29. 'ecdsa': {
  30. parts: ['curve', 'Q', 'd']
  31. },
  32. 'ed25519': {
  33. parts: ['A', 'k']
  34. }
  35. };
  36. algPrivInfo['curve25519'] = algPrivInfo['ed25519'];
  37. var hashAlgs = {
  38. 'md5': true,
  39. 'sha1': true,
  40. 'sha256': true,
  41. 'sha384': true,
  42. 'sha512': true
  43. };
  44. /*
  45. * Taken from
  46. * http://csrc.nist.gov/groups/ST/toolkit/documents/dss/NISTReCur.pdf
  47. */
  48. var curves = {
  49. 'nistp256': {
  50. size: 256,
  51. pkcs8oid: '1.2.840.10045.3.1.7',
  52. p: Buffer.from(('00' +
  53. 'ffffffff 00000001 00000000 00000000' +
  54. '00000000 ffffffff ffffffff ffffffff').
  55. replace(/ /g, ''), 'hex'),
  56. a: Buffer.from(('00' +
  57. 'FFFFFFFF 00000001 00000000 00000000' +
  58. '00000000 FFFFFFFF FFFFFFFF FFFFFFFC').
  59. replace(/ /g, ''), 'hex'),
  60. b: Buffer.from((
  61. '5ac635d8 aa3a93e7 b3ebbd55 769886bc' +
  62. '651d06b0 cc53b0f6 3bce3c3e 27d2604b').
  63. replace(/ /g, ''), 'hex'),
  64. s: Buffer.from(('00' +
  65. 'c49d3608 86e70493 6a6678e1 139d26b7' +
  66. '819f7e90').
  67. replace(/ /g, ''), 'hex'),
  68. n: Buffer.from(('00' +
  69. 'ffffffff 00000000 ffffffff ffffffff' +
  70. 'bce6faad a7179e84 f3b9cac2 fc632551').
  71. replace(/ /g, ''), 'hex'),
  72. G: Buffer.from(('04' +
  73. '6b17d1f2 e12c4247 f8bce6e5 63a440f2' +
  74. '77037d81 2deb33a0 f4a13945 d898c296' +
  75. '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16' +
  76. '2bce3357 6b315ece cbb64068 37bf51f5').
  77. replace(/ /g, ''), 'hex')
  78. },
  79. 'nistp384': {
  80. size: 384,
  81. pkcs8oid: '1.3.132.0.34',
  82. p: Buffer.from(('00' +
  83. 'ffffffff ffffffff ffffffff ffffffff' +
  84. 'ffffffff ffffffff ffffffff fffffffe' +
  85. 'ffffffff 00000000 00000000 ffffffff').
  86. replace(/ /g, ''), 'hex'),
  87. a: Buffer.from(('00' +
  88. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
  89. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE' +
  90. 'FFFFFFFF 00000000 00000000 FFFFFFFC').
  91. replace(/ /g, ''), 'hex'),
  92. b: Buffer.from((
  93. 'b3312fa7 e23ee7e4 988e056b e3f82d19' +
  94. '181d9c6e fe814112 0314088f 5013875a' +
  95. 'c656398d 8a2ed19d 2a85c8ed d3ec2aef').
  96. replace(/ /g, ''), 'hex'),
  97. s: Buffer.from(('00' +
  98. 'a335926a a319a27a 1d00896a 6773a482' +
  99. '7acdac73').
  100. replace(/ /g, ''), 'hex'),
  101. n: Buffer.from(('00' +
  102. 'ffffffff ffffffff ffffffff ffffffff' +
  103. 'ffffffff ffffffff c7634d81 f4372ddf' +
  104. '581a0db2 48b0a77a ecec196a ccc52973').
  105. replace(/ /g, ''), 'hex'),
  106. G: Buffer.from(('04' +
  107. 'aa87ca22 be8b0537 8eb1c71e f320ad74' +
  108. '6e1d3b62 8ba79b98 59f741e0 82542a38' +
  109. '5502f25d bf55296c 3a545e38 72760ab7' +
  110. '3617de4a 96262c6f 5d9e98bf 9292dc29' +
  111. 'f8f41dbd 289a147c e9da3113 b5f0b8c0' +
  112. '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f').
  113. replace(/ /g, ''), 'hex')
  114. },
  115. 'nistp521': {
  116. size: 521,
  117. pkcs8oid: '1.3.132.0.35',
  118. p: Buffer.from((
  119. '01ffffff ffffffff ffffffff ffffffff' +
  120. 'ffffffff ffffffff ffffffff ffffffff' +
  121. 'ffffffff ffffffff ffffffff ffffffff' +
  122. 'ffffffff ffffffff ffffffff ffffffff' +
  123. 'ffff').replace(/ /g, ''), 'hex'),
  124. a: Buffer.from(('01FF' +
  125. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
  126. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
  127. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
  128. 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFC').
  129. replace(/ /g, ''), 'hex'),
  130. b: Buffer.from(('51' +
  131. '953eb961 8e1c9a1f 929a21a0 b68540ee' +
  132. 'a2da725b 99b315f3 b8b48991 8ef109e1' +
  133. '56193951 ec7e937b 1652c0bd 3bb1bf07' +
  134. '3573df88 3d2c34f1 ef451fd4 6b503f00').
  135. replace(/ /g, ''), 'hex'),
  136. s: Buffer.from(('00' +
  137. 'd09e8800 291cb853 96cc6717 393284aa' +
  138. 'a0da64ba').replace(/ /g, ''), 'hex'),
  139. n: Buffer.from(('01ff' +
  140. 'ffffffff ffffffff ffffffff ffffffff' +
  141. 'ffffffff ffffffff ffffffff fffffffa' +
  142. '51868783 bf2f966b 7fcc0148 f709a5d0' +
  143. '3bb5c9b8 899c47ae bb6fb71e 91386409').
  144. replace(/ /g, ''), 'hex'),
  145. G: Buffer.from(('04' +
  146. '00c6 858e06b7 0404e9cd 9e3ecb66 2395b442' +
  147. '9c648139 053fb521 f828af60 6b4d3dba' +
  148. 'a14b5e77 efe75928 fe1dc127 a2ffa8de' +
  149. '3348b3c1 856a429b f97e7e31 c2e5bd66' +
  150. '0118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9' +
  151. '98f54449 579b4468 17afbd17 273e662c' +
  152. '97ee7299 5ef42640 c550b901 3fad0761' +
  153. '353c7086 a272c240 88be9476 9fd16650').
  154. replace(/ /g, ''), 'hex')
  155. }
  156. };
  157. module.exports = {
  158. info: algInfo,
  159. privInfo: algPrivInfo,
  160. hashAlgs: hashAlgs,
  161. curves: curves
  162. };