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