algs.js 4.7 KB

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