| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | 3 | <!-- YAML | |
| 4 | 4 | changes: | |
| 5 | + - version: REPLACEME | ||
| 6 | + pr-url: https://github.com/nodejs/node/pull/59544 | ||
| 7 | + description: Argon2 algorithms are now supported. | ||
| 5 | 8 | - version: v24.7.0 | |
| 6 | 9 | pr-url: https://github.com/nodejs/node/pull/59539 | |
| 7 | 10 | description: AES-OCB algorithm is now supported. | |
@@ -107,15 +110,18 @@ WICG proposal: | |||
| 107 | 110 | Algorithms: | |
| 108 | 111 | ||
| 109 | 112 | * `'AES-OCB'`[^openssl30] | |
| 113 | + * `'Argon2d'`[^openssl32] | ||
| 114 | + * `'Argon2i'`[^openssl32] | ||
| 115 | + * `'Argon2id'`[^openssl32] | ||
| 110 | 116 | * `'ChaCha20-Poly1305'` | |
| 111 | 117 | * `'cSHAKE128'` | |
| 112 | 118 | * `'cSHAKE256'` | |
| 113 | 119 | * `'ML-DSA-44'`[^openssl35] | |
| 114 | 120 | * `'ML-DSA-65'`[^openssl35] | |
| 115 | 121 | * `'ML-DSA-87'`[^openssl35] | |
| 116 | - * `'ML-KEM-1024'`[^openssl35] | ||
| 117 | 122 | * `'ML-KEM-512'`[^openssl35] | |
| 118 | 123 | * `'ML-KEM-768'`[^openssl35] | |
| 124 | + * `'ML-KEM-1024'`[^openssl35] | ||
| 119 | 125 | * `'SHA3-256'` | |
| 120 | 126 | * `'SHA3-384'` | |
| 121 | 127 | * `'SHA3-512'` | |
@@ -505,6 +511,9 @@ implementation and the APIs supported for each: | |||
| 505 | 511 | | `'AES-GCM'` | ✔ | ✔ | ✔ | | | |
| 506 | 512 | | `'AES-KW'` | ✔ | ✔ | ✔ | | | |
| 507 | 513 | | `'AES-OCB'` | ✔ | ✔ | ✔ | | | |
| 514 | + | `'Argon2d'` | | | ✔ | | | ||
| 515 | + | `'Argon2i'` | | | ✔ | | | ||
| 516 | + | `'Argon2id'` | | | ✔ | | | ||
| 508 | 517 | | `'ChaCha20-Poly1305'`[^modern-algos] | ✔ | ✔ | ✔ | | | |
| 509 | 518 | | `'ECDH'` | ✔ | ✔ | ✔ | ✔ | | |
| 510 | 519 | | `'ECDSA'` | ✔ | ✔ | ✔ | ✔ | | |
@@ -544,6 +553,9 @@ implementation and the APIs supported for each: | |||
| 544 | 553 | | `'AES-GCM'` | ✔ | | | ✔ | | | | |
| 545 | 554 | | `'AES-KW'` | | | | ✔ | | | | |
| 546 | 555 | | `'AES-OCB'` | ✔ | | | ✔ | | | | |
| 556 | + | `'Argon2d'` | | | ✔ | | | | | ||
| 557 | + | `'Argon2i'` | | | ✔ | | | | | ||
| 558 | + | `'Argon2id'` | | | ✔ | | | | | ||
| 547 | 559 | | `'ChaCha20-Poly1305'`[^modern-algos] | ✔ | | | ✔ | | | | |
| 548 | 560 | | `'cSHAKE128'`[^modern-algos] | | | | | | ✔ | | |
| 549 | 561 | | `'cSHAKE256'`[^modern-algos] | | | | | | ✔ | | |
@@ -713,6 +725,9 @@ Valid key usages depend on the key algorithm (identified by | |||
| 713 | 725 | | `'AES-GCM'` | ✔ | | | ✔ | | | |
| 714 | 726 | | `'AES-KW'` | | | | ✔ | | | |
| 715 | 727 | | `'AES-OCB'` | ✔ | | | ✔ | | | |
| 728 | + | `'Argon2d'` | | | ✔ | | | | ||
| 729 | + | `'Argon2i'` | | | ✔ | | | | ||
| 730 | + | `'Argon2id'` | | | ✔ | | | | ||
| 716 | 731 | | `'ChaCha20-Poly1305'`[^modern-algos] | ✔ | | | ✔ | | | |
| 717 | 732 | | `'ECDH'` | | | ✔ | | | | |
| 718 | 733 | | `'ECDSA'` | | ✔ | | | | | |
@@ -863,6 +878,9 @@ The algorithms currently supported include: | |||
| 863 | 878 | <!-- YAML | |
| 864 | 879 | added: v15.0.0 | |
| 865 | 880 | changes: | |
| 881 | + - version: REPLACEME | ||
| 882 | + pr-url: https://github.com/nodejs/node/pull/59544 | ||
| 883 | + description: Argon2 algorithms are now supported. | ||
| 866 | 884 | - version: | |
| 867 | 885 | - v22.5.0 | |
| 868 | 886 | - v20.17.0 | |
@@ -879,7 +897,7 @@ changes: | |||
| 879 | 897 | ||
| 880 | 898 | <!--lint disable maximum-line-length remark-lint--> | |
| 881 | 899 | ||
| 882 | - * `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params} | ||
| 900 | + * `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params|Argon2Params} | ||
| 883 | 901 | * `baseKey` {CryptoKey} | |
| 884 | 902 | * `length` {number|null} **Default:** `null` | |
| 885 | 903 | * Returns: {Promise} Fulfills with an {ArrayBuffer} upon success. | |
@@ -899,6 +917,9 @@ containing the generated data. | |||
| 899 | 917 | ||
| 900 | 918 | The algorithms currently supported include: | |
| 901 | 919 | ||
| 920 | + * `'Argon2d'`[^modern-algos] | ||
| 921 | + * `'Argon2i'`[^modern-algos] | ||
| 922 | + * `'Argon2id'`[^modern-algos] | ||
| 902 | 923 | * `'ECDH'` | |
| 903 | 924 | * `'HKDF'` | |
| 904 | 925 | * `'PBKDF2'` | |
@@ -910,6 +931,9 @@ The algorithms currently supported include: | |||
| 910 | 931 | <!-- YAML | |
| 911 | 932 | added: v15.0.0 | |
| 912 | 933 | changes: | |
| 934 | + - version: REPLACEME | ||
| 935 | + pr-url: https://github.com/nodejs/node/pull/59544 | ||
| 936 | + description: Argon2 algorithms are now supported. | ||
| 913 | 937 | - version: | |
| 914 | 938 | - v18.4.0 | |
| 915 | 939 | - v16.17.0 | |
@@ -919,7 +943,7 @@ changes: | |||
| 919 | 943 | ||
| 920 | 944 | <!--lint disable maximum-line-length remark-lint--> | |
| 921 | 945 | ||
| 922 | - * `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params} | ||
| 946 | + * `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params|Argon2Params} | ||
| 923 | 947 | * `baseKey` {CryptoKey} | |
| 924 | 948 | * `derivedKeyAlgorithm` {string|Algorithm|HmacImportParams|AesDerivedKeyParams} | |
| 925 | 949 | * `extractable` {boolean} | |
@@ -939,6 +963,9 @@ generate raw keying material, then passing the result into the | |||
| 939 | 963 | ||
| 940 | 964 | The algorithms currently supported include: | |
| 941 | 965 | ||
| 966 | + * `'Argon2d'`[^modern-algos] | ||
| 967 | + * `'Argon2i'`[^modern-algos] | ||
| 968 | + * `'Argon2id'`[^modern-algos] | ||
| 942 | 969 | * `'ECDH'` | |
| 943 | 970 | * `'HKDF'` | |
| 944 | 971 | * `'PBKDF2'` | |
@@ -1234,7 +1261,7 @@ as the given `format` to create a {CryptoKey} instance using the provided | |||
| 1234 | 1261 | `algorithm`, `extractable`, and `keyUsages` arguments. If the import is | |
| 1235 | 1262 | successful, the returned promise will be resolved with the created {CryptoKey}. | |
| 1236 | 1263 | ||
| 1237 | - If importing a `'PBKDF2'` key, `extractable` must be `false`. | ||
| 1264 | + If importing KDF algorithm keys, `extractable` must be `false`. | ||
| 1238 | 1265 | ||
| 1239 | 1266 | The algorithms currently supported include: | |
| 1240 | 1267 | ||
@@ -1245,6 +1272,9 @@ The algorithms currently supported include: | |||
| 1245 | 1272 | | `'AES-GCM'` | | | ✔ | ✔ | ✔ | | | | |
| 1246 | 1273 | | `'AES-KW'` | | | ✔ | ✔ | ✔ | | | | |
| 1247 | 1274 | | `'AES-OCB'`[^modern-algos] | | | ✔ | | ✔ | | | | |
| 1275 | + | `'Argon2d'`[^modern-algos] | | | | | ✔ | | | | ||
| 1276 | + | `'Argon2i'`[^modern-algos] | | | | | ✔ | | | | ||
| 1277 | + | `'Argon2id'`[^modern-algos] | | | | | ✔ | | | | ||
| 1248 | 1278 | | `'ChaCha20-Poly1305'`[^modern-algos] | | | ✔ | | ✔ | | | | |
| 1249 | 1279 | | `'ECDH'` | ✔ | ✔ | ✔ | ✔ | | ✔ | | | |
| 1250 | 1280 | | `'ECDSA'` | ✔ | ✔ | ✔ | ✔ | | ✔ | | | |
@@ -1665,6 +1695,90 @@ added: v15.0.0 | |||
| 1665 | 1695 | * Type: {string} Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, or | |
| 1666 | 1696 | `'AES-KW'` | |
| 1667 | 1697 | ||
| 1698 | + ### Class: `Argon2Params` | ||
| 1699 | + | ||
| 1700 | + <!-- YAML | ||
| 1701 | + added: REPLACEME | ||
| 1702 | + --> | ||
| 1703 | + | ||
| 1704 | + #### `argon2Params.associatedData` | ||
| 1705 | + | ||
| 1706 | + <!-- YAML | ||
| 1707 | + added: REPLACEME | ||
| 1708 | + --> | ||
| 1709 | + | ||
| 1710 | + * Type: {ArrayBuffer|TypedArray|DataView|Buffer} | ||
| 1711 | + | ||
| 1712 | + Represents the optional associated data. | ||
| 1713 | + | ||
| 1714 | + #### `argon2Params.memory` | ||
| 1715 | + | ||
| 1716 | + <!-- YAML | ||
| 1717 | + added: REPLACEME | ||
| 1718 | + --> | ||
| 1719 | + | ||
| 1720 | + * Type: {number} | ||
| 1721 | + | ||
| 1722 | + Represents the memory size in kibibytes. It must be at least 8 times the degree of parallelism. | ||
| 1723 | + | ||
| 1724 | + #### `argon2Params.name` | ||
| 1725 | + | ||
| 1726 | + <!-- YAML | ||
| 1727 | + added: REPLACEME | ||
| 1728 | + --> | ||
| 1729 | + | ||
| 1730 | + * Type: {string} Must be one of `'Argon2d'`, `'Argon2i'`, or `'Argon2id'`. | ||
| 1731 | + | ||
| 1732 | + #### `argon2Params.nonce` | ||
| 1733 | + | ||
| 1734 | + <!-- YAML | ||
| 1735 | + added: REPLACEME | ||
| 1736 | + --> | ||
| 1737 | + | ||
| 1738 | + * Type: {ArrayBuffer|TypedArray|DataView|Buffer} | ||
| 1739 | + | ||
| 1740 | + Represents the nonce, which is a salt for password hashing applications. | ||
| 1741 | + | ||
| 1742 | + #### `argon2Params.parallelism` | ||
| 1743 | + | ||
| 1744 | + <!-- YAML | ||
| 1745 | + added: REPLACEME | ||
| 1746 | + --> | ||
| 1747 | + | ||
| 1748 | + * Type: {number} | ||
| 1749 | + | ||
| 1750 | + Represents the degree of parallelism. | ||
| 1751 | + | ||
| 1752 | + #### `argon2Params.passes` | ||
| 1753 | + | ||
| 1754 | + <!-- YAML | ||
| 1755 | + added: REPLACEME | ||
| 1756 | + --> | ||
| 1757 | + | ||
| 1758 | + * Type: {number} | ||
| 1759 | + | ||
| 1760 | + Represents the number of passes. | ||
| 1761 | + | ||
| 1762 | + #### `argon2Params.secretValue` | ||
| 1763 | + | ||
| 1764 | + <!-- YAML | ||
| 1765 | + added: REPLACEME | ||
| 1766 | + --> | ||
| 1767 | + | ||
| 1768 | + * Type: {ArrayBuffer|TypedArray|DataView|Buffer} | ||
| 1769 | + | ||
| 1770 | + Represents the optional secret value. | ||
| 1771 | + | ||
| 1772 | + #### `argon2Params.version` | ||
| 1773 | + | ||
| 1774 | + <!-- YAML | ||
| 1775 | + added: REPLACEME | ||
| 1776 | + --> | ||
| 1777 | + | ||
| 1778 | + * Type: {number} | ||
| 1779 | + | ||
| 1780 | + Represents the Argon2 version number. The default and currently only defined version is `19` (`0x13`). | ||
| 1781 | + | ||
| 1668 | 1782 | ### Class: `ContextParams` | |
| 1669 | 1783 | ||
| 1670 | 1784 | <!-- YAML | |
@@ -2419,6 +2533,8 @@ The length (in bytes) of the random salt to use. | |||
| 2419 | 2533 | ||
| 2420 | 2534 | [^openssl30]: Requires OpenSSL >= 3.0 | |
| 2421 | 2535 | ||
| 2536 | + [^openssl32]: Requires OpenSSL >= 3.2 | ||
| 2537 | + | ||
| 2422 | 2538 | [^openssl35]: Requires OpenSSL >= 3.5 | |
| 2423 | 2539 | ||
| 2424 | 2540 | [JSON Web Key]: https://tools.ietf.org/html/rfc7517 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | FunctionPrototypeCall, | |
| 5 | 5 | MathPow, | |
| 6 | + StringPrototypeToLowerCase, | ||
| 6 | 7 | Uint8Array, | |
| 7 | 8 | } = primordials; | |
| 8 | 9 | ||
@@ -17,7 +18,16 @@ const { | |||
| 17 | 18 | kTypeArgon2id, | |
| 18 | 19 | } = internalBinding('crypto'); | |
| 19 | 20 | ||
| 20 | - const { getArrayBufferOrView } = require('internal/crypto/util'); | ||
| 21 | + const { | ||
| 22 | + lazyDOMException, | ||
| 23 | + promisify, | ||
| 24 | + } = require('internal/util'); | ||
| 25 | + | ||
| 26 | + const { | ||
| 27 | + getArrayBufferOrView, | ||
| 28 | + kKeyObject, | ||
| 29 | + } = require('internal/crypto/util'); | ||
| 30 | + | ||
| 21 | 31 | const { | |
| 22 | 32 | validateString, | |
| 23 | 33 | validateFunction, | |
@@ -179,7 +189,54 @@ function check(algorithm, parameters) { | |||
| 179 | 189 | return { message, nonce, secret, associatedData, tagLength, passes, parallelism, memory, type }; | |
| 180 | 190 | } | |
| 181 | 191 | ||
| 192 | + const argon2Promise = promisify(argon2); | ||
| 193 | + function validateArgon2DeriveBitsLength(length) { | ||
| 194 | + if (length === null) | ||
| 195 | + throw lazyDOMException('length cannot be null', 'OperationError'); | ||
| 196 | + | ||
| 197 | + if (length % 8) { | ||
| 198 | + throw lazyDOMException( | ||
| 199 | + 'length must be a multiple of 8', | ||
| 200 | + 'OperationError'); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + if (length < 32) { | ||
| 204 | + throw lazyDOMException( | ||
| 205 | + 'length must be >= 32', | ||
| 206 | + 'OperationError'); | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + async function argon2DeriveBits(algorithm, baseKey, length) { | ||
| 211 | + validateArgon2DeriveBitsLength(length); | ||
| 212 | + | ||
| 213 | + let result; | ||
| 214 | + try { | ||
| 215 | + result = await argon2Promise( | ||
| 216 | + StringPrototypeToLowerCase(algorithm.name), | ||
| 217 | + { | ||
| 218 | + message: baseKey[kKeyObject].export(), | ||
| 219 | + nonce: algorithm.nonce, | ||
| 220 | + parallelism: algorithm.parallelism, | ||
| 221 | + tagLength: length / 8, | ||
| 222 | + memory: algorithm.memory, | ||
| 223 | + passes: algorithm.passes, | ||
| 224 | + secret: algorithm.secretValue, | ||
| 225 | + associatedData: algorithm.associatedData, | ||
| 226 | + }, | ||
| 227 | + ); | ||
| 228 | + } catch (err) { | ||
| 229 | + throw lazyDOMException( | ||
| 230 | + 'The operation failed for an operation-specific reason', | ||
| 231 | + { name: 'OperationError', cause: err }); | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + return result.buffer; | ||
| 235 | + } | ||
| 236 | + | ||
| 182 | 237 | module.exports = { | |
| 183 | 238 | argon2, | |
| 184 | 239 | argon2Sync, | |
| 240 | + argon2DeriveBits, | ||
| 241 | + validateArgon2DeriveBitsLength, | ||
| 185 | 242 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,6 +211,12 @@ const { | |||
| 211 | 211 | case 'HKDF': | |
| 212 | 212 | // Fall through | |
| 213 | 213 | case 'PBKDF2': | |
| 214 | + // Fall through | ||
| 215 | + case 'Argon2d': | ||
| 216 | + // Fall through | ||
| 217 | + case 'Argon2i': | ||
| 218 | + // Fall through | ||
| 219 | + case 'Argon2id': | ||
| 214 | 220 | result = importGenericSecretKey( | |
| 215 | 221 | algorithm, | |
| 216 | 222 | 'KeyObject', | |
@@ -998,6 +1004,7 @@ function importGenericSecretKey( | |||
| 998 | 1004 | keyObject = keyData; | |
| 999 | 1005 | break; | |
| 1000 | 1006 | } | |
| 1007 | + case 'raw-secret': | ||
| 1001 | 1008 | case 'raw': { | |
| 1002 | 1009 | keyObject = createSecretKey(keyData); | |
| 1003 | 1010 | break; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments