@protontech/openpgp 5.9.1-1 → 5.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/openpgp.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v5.9.1-1 - 2023-09-06 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v5.11.0 - 2023-11-27 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
2
2
  var openpgp = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -244,18 +244,17 @@ var openpgp = (function (exports) {
244
244
  this.push(null);
245
245
  break;
246
246
  }
247
- if (!this.push(value) || this._cancelling) {
248
- this._reading = false;
247
+ if (!this.push(value)) {
249
248
  break;
250
249
  }
251
250
  }
252
- } catch(e) {
253
- this.emit('error', e);
251
+ } catch (e) {
252
+ this.destroy(e);
254
253
  }
255
254
  }
256
255
 
257
- _destroy(reason) {
258
- this._reader.cancel(reason);
256
+ async _destroy(error, callback) {
257
+ this._reader.cancel(error).then(callback, callback);
259
258
  }
260
259
  }
261
260
 
@@ -290,7 +289,7 @@ var openpgp = (function (exports) {
290
289
  const reader = input.getReader();
291
290
  this._read = reader.read.bind(reader);
292
291
  this._releaseLock = () => {};
293
- this._cancel = () => {};
292
+ this._cancel = async () => {};
294
293
  return;
295
294
  }
296
295
  let streamType = isStream(input);
@@ -1510,6 +1509,533 @@ var openpgp = (function (exports) {
1510
1509
  }
1511
1510
  }
1512
1511
 
1512
+ /**
1513
+ * @module enums
1514
+ */
1515
+
1516
+ const byValue = Symbol('byValue');
1517
+
1518
+ var enums = {
1519
+
1520
+ /** Maps curve names under various standards to one
1521
+ * @see {@link https://wiki.gnupg.org/ECC|ECC - GnuPG wiki}
1522
+ * @enum {String}
1523
+ * @readonly
1524
+ */
1525
+ curve: {
1526
+ /** NIST P-256 Curve */
1527
+ 'p256': 'p256',
1528
+ 'P-256': 'p256',
1529
+ 'secp256r1': 'p256',
1530
+ 'prime256v1': 'p256',
1531
+ '1.2.840.10045.3.1.7': 'p256',
1532
+ '2a8648ce3d030107': 'p256',
1533
+ '2A8648CE3D030107': 'p256',
1534
+
1535
+ /** NIST P-384 Curve */
1536
+ 'p384': 'p384',
1537
+ 'P-384': 'p384',
1538
+ 'secp384r1': 'p384',
1539
+ '1.3.132.0.34': 'p384',
1540
+ '2b81040022': 'p384',
1541
+ '2B81040022': 'p384',
1542
+
1543
+ /** NIST P-521 Curve */
1544
+ 'p521': 'p521',
1545
+ 'P-521': 'p521',
1546
+ 'secp521r1': 'p521',
1547
+ '1.3.132.0.35': 'p521',
1548
+ '2b81040023': 'p521',
1549
+ '2B81040023': 'p521',
1550
+
1551
+ /** SECG SECP256k1 Curve */
1552
+ 'secp256k1': 'secp256k1',
1553
+ '1.3.132.0.10': 'secp256k1',
1554
+ '2b8104000a': 'secp256k1',
1555
+ '2B8104000A': 'secp256k1',
1556
+
1557
+ /** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
1558
+ 'ed25519Legacy': 'ed25519',
1559
+ 'ED25519': 'ed25519',
1560
+ /** @deprecated use `ed25519Legacy` instead */
1561
+ 'ed25519': 'ed25519',
1562
+ 'Ed25519': 'ed25519',
1563
+ '1.3.6.1.4.1.11591.15.1': 'ed25519',
1564
+ '2b06010401da470f01': 'ed25519',
1565
+ '2B06010401DA470F01': 'ed25519',
1566
+
1567
+ /** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
1568
+ 'curve25519Legacy': 'curve25519',
1569
+ 'X25519': 'curve25519',
1570
+ 'cv25519': 'curve25519',
1571
+ /** @deprecated use `curve25519Legacy` instead */
1572
+ 'curve25519': 'curve25519',
1573
+ 'Curve25519': 'curve25519',
1574
+ '1.3.6.1.4.1.3029.1.5.1': 'curve25519',
1575
+ '2b060104019755010501': 'curve25519',
1576
+ '2B060104019755010501': 'curve25519',
1577
+
1578
+ /** BrainpoolP256r1 Curve */
1579
+ 'brainpoolP256r1': 'brainpoolP256r1',
1580
+ '1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1',
1581
+ '2b2403030208010107': 'brainpoolP256r1',
1582
+ '2B2403030208010107': 'brainpoolP256r1',
1583
+
1584
+ /** BrainpoolP384r1 Curve */
1585
+ 'brainpoolP384r1': 'brainpoolP384r1',
1586
+ '1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1',
1587
+ '2b240303020801010b': 'brainpoolP384r1',
1588
+ '2B240303020801010B': 'brainpoolP384r1',
1589
+
1590
+ /** BrainpoolP512r1 Curve */
1591
+ 'brainpoolP512r1': 'brainpoolP512r1',
1592
+ '1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1',
1593
+ '2b240303020801010d': 'brainpoolP512r1',
1594
+ '2B240303020801010D': 'brainpoolP512r1'
1595
+ },
1596
+
1597
+ /** KDF parameters flags
1598
+ * Non-standard extensions (for now) to allow email forwarding
1599
+ * @enum {Integer}
1600
+ * @readonly
1601
+ */
1602
+ kdfFlags: {
1603
+ /** Specify fingerprint to use instead of the recipient's */
1604
+ replace_fingerprint: 0x01,
1605
+ /** Specify custom parameters to use in the KDF digest computation */
1606
+ replace_kdf_params: 0x02
1607
+ },
1608
+
1609
+ /** A string to key specifier type
1610
+ * @enum {Integer}
1611
+ * @readonly
1612
+ */
1613
+ s2k: {
1614
+ simple: 0,
1615
+ salted: 1,
1616
+ iterated: 3,
1617
+ argon2: 4,
1618
+ gnu: 101
1619
+ },
1620
+
1621
+ /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-crypto-refresh-08.html#section-9.1|crypto-refresh RFC, section 9.1}
1622
+ * @enum {Integer}
1623
+ * @readonly
1624
+ */
1625
+ publicKey: {
1626
+ /** RSA (Encrypt or Sign) [HAC] */
1627
+ rsaEncryptSign: 1,
1628
+ /** RSA (Encrypt only) [HAC] */
1629
+ rsaEncrypt: 2,
1630
+ /** RSA (Sign only) [HAC] */
1631
+ rsaSign: 3,
1632
+ /** Elgamal (Encrypt only) [ELGAMAL] [HAC] */
1633
+ elgamal: 16,
1634
+ /** DSA (Sign only) [FIPS186] [HAC] */
1635
+ dsa: 17,
1636
+ /** ECDH (Encrypt only) [RFC6637] */
1637
+ ecdh: 18,
1638
+ /** ECDSA (Sign only) [RFC6637] */
1639
+ ecdsa: 19,
1640
+ /** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
1641
+ * [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
1642
+ eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
1643
+ /** @deprecated use `eddsaLegacy` instead */
1644
+ ed25519Legacy: 22,
1645
+ /** @deprecated use `eddsaLegacy` instead */
1646
+ eddsa: 22,
1647
+ /** Reserved for AEDH */
1648
+ aedh: 23,
1649
+ /** Reserved for AEDSA */
1650
+ aedsa: 24,
1651
+ /** X25519 (Encrypt only) */
1652
+ x25519: 25,
1653
+ /** X448 (Encrypt only) */
1654
+ x448: 26,
1655
+ /** Ed25519 (Sign only) */
1656
+ ed25519: 27,
1657
+ /** Ed448 (Sign only) */
1658
+ ed448: 28,
1659
+ /** Symmetric authenticated encryption algorithms */
1660
+ aead: 100,
1661
+ /** Authentication using CMAC */
1662
+ hmac: 101
1663
+ },
1664
+
1665
+ /** {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
1666
+ * @enum {Integer}
1667
+ * @readonly
1668
+ */
1669
+ symmetric: {
1670
+ plaintext: 0,
1671
+ /** Not implemented! */
1672
+ idea: 1,
1673
+ tripledes: 2,
1674
+ cast5: 3,
1675
+ blowfish: 4,
1676
+ aes128: 7,
1677
+ aes192: 8,
1678
+ aes256: 9,
1679
+ twofish: 10
1680
+ },
1681
+
1682
+ /** {@link https://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
1683
+ * @enum {Integer}
1684
+ * @readonly
1685
+ */
1686
+ compression: {
1687
+ uncompressed: 0,
1688
+ /** RFC1951 */
1689
+ zip: 1,
1690
+ /** RFC1950 */
1691
+ zlib: 2,
1692
+ bzip2: 3
1693
+ },
1694
+
1695
+ /** {@link https://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
1696
+ * @enum {Integer}
1697
+ * @readonly
1698
+ */
1699
+ hash: {
1700
+ md5: 1,
1701
+ sha1: 2,
1702
+ ripemd: 3,
1703
+ sha256: 8,
1704
+ sha384: 9,
1705
+ sha512: 10,
1706
+ sha224: 11
1707
+ },
1708
+
1709
+ /** A list of hash names as accepted by webCrypto functions.
1710
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest|Parameters, algo}
1711
+ * @enum {String}
1712
+ */
1713
+ webHash: {
1714
+ 'SHA-1': 2,
1715
+ 'SHA-256': 8,
1716
+ 'SHA-384': 9,
1717
+ 'SHA-512': 10
1718
+ },
1719
+
1720
+ /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.6|RFC4880bis-04, section 9.6}
1721
+ * @enum {Integer}
1722
+ * @readonly
1723
+ */
1724
+ aead: {
1725
+ eax: 1,
1726
+ ocb: 2,
1727
+ experimentalGCM: 100 // Private algorithm
1728
+ },
1729
+
1730
+ /** A list of packet types and numeric tags associated with them.
1731
+ * @enum {Integer}
1732
+ * @readonly
1733
+ */
1734
+ packet: {
1735
+ publicKeyEncryptedSessionKey: 1,
1736
+ signature: 2,
1737
+ symEncryptedSessionKey: 3,
1738
+ onePassSignature: 4,
1739
+ secretKey: 5,
1740
+ publicKey: 6,
1741
+ secretSubkey: 7,
1742
+ compressedData: 8,
1743
+ symmetricallyEncryptedData: 9,
1744
+ marker: 10,
1745
+ literalData: 11,
1746
+ trust: 12,
1747
+ userID: 13,
1748
+ publicSubkey: 14,
1749
+ userAttribute: 17,
1750
+ symEncryptedIntegrityProtectedData: 18,
1751
+ modificationDetectionCode: 19,
1752
+ aeadEncryptedData: 20 // see IETF draft: https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1
1753
+ },
1754
+
1755
+ /** Data types in the literal packet
1756
+ * @enum {Integer}
1757
+ * @readonly
1758
+ */
1759
+ literal: {
1760
+ /** Binary data 'b' */
1761
+ binary: 'b'.charCodeAt(),
1762
+ /** Text data 't' */
1763
+ text: 't'.charCodeAt(),
1764
+ /** Utf8 data 'u' */
1765
+ utf8: 'u'.charCodeAt(),
1766
+ /** MIME message body part 'm' */
1767
+ mime: 'm'.charCodeAt()
1768
+ },
1769
+
1770
+
1771
+ /** One pass signature packet type
1772
+ * @enum {Integer}
1773
+ * @readonly
1774
+ */
1775
+ signature: {
1776
+ /** 0x00: Signature of a binary document. */
1777
+ binary: 0,
1778
+ /** 0x01: Signature of a canonical text document.
1779
+ *
1780
+ * Canonicalyzing the document by converting line endings. */
1781
+ text: 1,
1782
+ /** 0x02: Standalone signature.
1783
+ *
1784
+ * This signature is a signature of only its own subpacket contents.
1785
+ * It is calculated identically to a signature over a zero-lengh
1786
+ * binary document. Note that it doesn't make sense to have a V3
1787
+ * standalone signature. */
1788
+ standalone: 2,
1789
+ /** 0x10: Generic certification of a User ID and Public-Key packet.
1790
+ *
1791
+ * The issuer of this certification does not make any particular
1792
+ * assertion as to how well the certifier has checked that the owner
1793
+ * of the key is in fact the person described by the User ID. */
1794
+ certGeneric: 16,
1795
+ /** 0x11: Persona certification of a User ID and Public-Key packet.
1796
+ *
1797
+ * The issuer of this certification has not done any verification of
1798
+ * the claim that the owner of this key is the User ID specified. */
1799
+ certPersona: 17,
1800
+ /** 0x12: Casual certification of a User ID and Public-Key packet.
1801
+ *
1802
+ * The issuer of this certification has done some casual
1803
+ * verification of the claim of identity. */
1804
+ certCasual: 18,
1805
+ /** 0x13: Positive certification of a User ID and Public-Key packet.
1806
+ *
1807
+ * The issuer of this certification has done substantial
1808
+ * verification of the claim of identity.
1809
+ *
1810
+ * Most OpenPGP implementations make their "key signatures" as 0x10
1811
+ * certifications. Some implementations can issue 0x11-0x13
1812
+ * certifications, but few differentiate between the types. */
1813
+ certPositive: 19,
1814
+ /** 0x30: Certification revocation signature
1815
+ *
1816
+ * This signature revokes an earlier User ID certification signature
1817
+ * (signature class 0x10 through 0x13) or direct-key signature
1818
+ * (0x1F). It should be issued by the same key that issued the
1819
+ * revoked signature or an authorized revocation key. The signature
1820
+ * is computed over the same data as the certificate that it
1821
+ * revokes, and should have a later creation date than that
1822
+ * certificate. */
1823
+ certRevocation: 48,
1824
+ /** 0x18: Subkey Binding Signature
1825
+ *
1826
+ * This signature is a statement by the top-level signing key that
1827
+ * indicates that it owns the subkey. This signature is calculated
1828
+ * directly on the primary key and subkey, and not on any User ID or
1829
+ * other packets. A signature that binds a signing subkey MUST have
1830
+ * an Embedded Signature subpacket in this binding signature that
1831
+ * contains a 0x19 signature made by the signing subkey on the
1832
+ * primary key and subkey. */
1833
+ subkeyBinding: 24,
1834
+ /** 0x19: Primary Key Binding Signature
1835
+ *
1836
+ * This signature is a statement by a signing subkey, indicating
1837
+ * that it is owned by the primary key and subkey. This signature
1838
+ * is calculated the same way as a 0x18 signature: directly on the
1839
+ * primary key and subkey, and not on any User ID or other packets.
1840
+ *
1841
+ * When a signature is made over a key, the hash data starts with the
1842
+ * octet 0x99, followed by a two-octet length of the key, and then body
1843
+ * of the key packet. (Note that this is an old-style packet header for
1844
+ * a key packet with two-octet length.) A subkey binding signature
1845
+ * (type 0x18) or primary key binding signature (type 0x19) then hashes
1846
+ * the subkey using the same format as the main key (also using 0x99 as
1847
+ * the first octet). */
1848
+ keyBinding: 25,
1849
+ /** 0x1F: Signature directly on a key
1850
+ *
1851
+ * This signature is calculated directly on a key. It binds the
1852
+ * information in the Signature subpackets to the key, and is
1853
+ * appropriate to be used for subpackets that provide information
1854
+ * about the key, such as the Revocation Key subpacket. It is also
1855
+ * appropriate for statements that non-self certifiers want to make
1856
+ * about the key itself, rather than the binding between a key and a
1857
+ * name. */
1858
+ key: 31,
1859
+ /** 0x20: Key revocation signature
1860
+ *
1861
+ * The signature is calculated directly on the key being revoked. A
1862
+ * revoked key is not to be used. Only revocation signatures by the
1863
+ * key being revoked, or by an authorized revocation key, should be
1864
+ * considered valid revocation signatures.a */
1865
+ keyRevocation: 32,
1866
+ /** 0x28: Subkey revocation signature
1867
+ *
1868
+ * The signature is calculated directly on the subkey being revoked.
1869
+ * A revoked subkey is not to be used. Only revocation signatures
1870
+ * by the top-level signature key that is bound to this subkey, or
1871
+ * by an authorized revocation key, should be considered valid
1872
+ * revocation signatures.
1873
+ *
1874
+ * Key revocation signatures (types 0x20 and 0x28)
1875
+ * hash only the key being revoked. */
1876
+ subkeyRevocation: 40,
1877
+ /** 0x40: Timestamp signature.
1878
+ * This signature is only meaningful for the timestamp contained in
1879
+ * it. */
1880
+ timestamp: 64,
1881
+ /** 0x50: Third-Party Confirmation signature.
1882
+ *
1883
+ * This signature is a signature over some other OpenPGP Signature
1884
+ * packet(s). It is analogous to a notary seal on the signed data.
1885
+ * A third-party signature SHOULD include Signature Target
1886
+ * subpacket(s) to give easy identification. Note that we really do
1887
+ * mean SHOULD. There are plausible uses for this (such as a blind
1888
+ * party that only sees the signature, not the key or source
1889
+ * document) that cannot include a target subpacket. */
1890
+ thirdParty: 80
1891
+ },
1892
+
1893
+ /** Signature subpacket type
1894
+ * @enum {Integer}
1895
+ * @readonly
1896
+ */
1897
+ signatureSubpacket: {
1898
+ signatureCreationTime: 2,
1899
+ signatureExpirationTime: 3,
1900
+ exportableCertification: 4,
1901
+ trustSignature: 5,
1902
+ regularExpression: 6,
1903
+ revocable: 7,
1904
+ keyExpirationTime: 9,
1905
+ placeholderBackwardsCompatibility: 10,
1906
+ preferredSymmetricAlgorithms: 11,
1907
+ revocationKey: 12,
1908
+ issuer: 16,
1909
+ notationData: 20,
1910
+ preferredHashAlgorithms: 21,
1911
+ preferredCompressionAlgorithms: 22,
1912
+ keyServerPreferences: 23,
1913
+ preferredKeyServer: 24,
1914
+ primaryUserID: 25,
1915
+ policyURI: 26,
1916
+ keyFlags: 27,
1917
+ signersUserID: 28,
1918
+ reasonForRevocation: 29,
1919
+ features: 30,
1920
+ signatureTarget: 31,
1921
+ embeddedSignature: 32,
1922
+ issuerFingerprint: 33,
1923
+ preferredAEADAlgorithms: 34
1924
+ },
1925
+
1926
+ /** Key flags
1927
+ * @enum {Integer}
1928
+ * @readonly
1929
+ */
1930
+ keyFlags: {
1931
+ /** 0x01 - This key may be used to certify other keys. */
1932
+ certifyKeys: 1,
1933
+ /** 0x02 - This key may be used to sign data. */
1934
+ signData: 2,
1935
+ /** 0x04 - This key may be used to encrypt communications. */
1936
+ encryptCommunication: 4,
1937
+ /** 0x08 - This key may be used to encrypt storage. */
1938
+ encryptStorage: 8,
1939
+ /** 0x10 - The private component of this key may have been split
1940
+ * by a secret-sharing mechanism. */
1941
+ splitPrivateKey: 16,
1942
+ /** 0x20 - This key may be used for authentication. */
1943
+ authentication: 32,
1944
+ /** This key may be used for forwarded communications */
1945
+ forwardedCommunication: 64,
1946
+ /** 0x80 - The private component of this key may be in the
1947
+ * possession of more than one person. */
1948
+ sharedPrivateKey: 128
1949
+ },
1950
+
1951
+ /** Armor type
1952
+ * @enum {Integer}
1953
+ * @readonly
1954
+ */
1955
+ armor: {
1956
+ multipartSection: 0,
1957
+ multipartLast: 1,
1958
+ signed: 2,
1959
+ message: 3,
1960
+ publicKey: 4,
1961
+ privateKey: 5,
1962
+ signature: 6
1963
+ },
1964
+
1965
+ /** {@link https://tools.ietf.org/html/rfc4880#section-5.2.3.23|RFC4880, section 5.2.3.23}
1966
+ * @enum {Integer}
1967
+ * @readonly
1968
+ */
1969
+ reasonForRevocation: {
1970
+ /** No reason specified (key revocations or cert revocations) */
1971
+ noReason: 0,
1972
+ /** Key is superseded (key revocations) */
1973
+ keySuperseded: 1,
1974
+ /** Key material has been compromised (key revocations) */
1975
+ keyCompromised: 2,
1976
+ /** Key is retired and no longer used (key revocations) */
1977
+ keyRetired: 3,
1978
+ /** User ID information is no longer valid (cert revocations) */
1979
+ userIDInvalid: 32
1980
+ },
1981
+
1982
+ /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-5.2.3.25|RFC4880bis-04, section 5.2.3.25}
1983
+ * @enum {Integer}
1984
+ * @readonly
1985
+ */
1986
+ features: {
1987
+ /** 0x01 - Modification Detection (packets 18 and 19) */
1988
+ modificationDetection: 1,
1989
+ /** 0x02 - AEAD Encrypted Data Packet (packet 20) and version 5
1990
+ * Symmetric-Key Encrypted Session Key Packets (packet 3) */
1991
+ aead: 2,
1992
+ /** 0x04 - Version 5 Public-Key Packet format and corresponding new
1993
+ * fingerprint format */
1994
+ v5Keys: 4
1995
+ },
1996
+
1997
+ /**
1998
+ * Asserts validity of given value and converts from string/integer to integer.
1999
+ * @param {Object} type target enum type
2000
+ * @param {String|Integer} e value to check and/or convert
2001
+ * @returns {Integer} enum value if it exists
2002
+ * @throws {Error} if the value is invalid
2003
+ */
2004
+ write: function(type, e) {
2005
+ if (typeof e === 'number') {
2006
+ e = this.read(type, e);
2007
+ }
2008
+
2009
+ if (type[e] !== undefined) {
2010
+ return type[e];
2011
+ }
2012
+
2013
+ throw new Error('Invalid enum value.');
2014
+ },
2015
+
2016
+ /**
2017
+ * Converts enum integer value to the corresponding string, if it exists.
2018
+ * @param {Object} type target enum type
2019
+ * @param {Integer} e value to convert
2020
+ * @returns {String} name of enum value if it exists
2021
+ * @throws {Error} if the value is invalid
2022
+ */
2023
+ read: function(type, e) {
2024
+ if (!type[byValue]) {
2025
+ type[byValue] = [];
2026
+ Object.entries(type).forEach(([key, value]) => {
2027
+ type[byValue][value] = key;
2028
+ });
2029
+ }
2030
+
2031
+ if (type[byValue][e] !== undefined) {
2032
+ return type[byValue][e];
2033
+ }
2034
+
2035
+ throw new Error('Invalid enum value.');
2036
+ }
2037
+ };
2038
+
1513
2039
  // GPG4Browsers - An OpenPGP implementation in javascript
1514
2040
 
1515
2041
  const debugMode = (() => {
@@ -2091,6 +2617,12 @@ var openpgp = (function (exports) {
2091
2617
  */
2092
2618
  selectUint8: function(cond, a, b) {
2093
2619
  return (a & (256 - cond)) | (b & (255 + cond));
2620
+ },
2621
+ /**
2622
+ * @param {module:enums.symmetric} cipherAlgo
2623
+ */
2624
+ isAES: function(cipherAlgo) {
2625
+ return cipherAlgo === enums.symmetric.aes128 || cipherAlgo === enums.symmetric.aes192 || cipherAlgo === enums.symmetric.aes256;
2094
2626
  }
2095
2627
  };
2096
2628
 
@@ -2205,517 +2737,6 @@ var openpgp = (function (exports) {
2205
2737
  return encoded;
2206
2738
  }
2207
2739
 
2208
- /**
2209
- * @module enums
2210
- */
2211
-
2212
- const byValue = Symbol('byValue');
2213
-
2214
- var enums = {
2215
-
2216
- /** Maps curve names under various standards to one
2217
- * @see {@link https://wiki.gnupg.org/ECC|ECC - GnuPG wiki}
2218
- * @enum {String}
2219
- * @readonly
2220
- */
2221
- curve: {
2222
- /** NIST P-256 Curve */
2223
- 'p256': 'p256',
2224
- 'P-256': 'p256',
2225
- 'secp256r1': 'p256',
2226
- 'prime256v1': 'p256',
2227
- '1.2.840.10045.3.1.7': 'p256',
2228
- '2a8648ce3d030107': 'p256',
2229
- '2A8648CE3D030107': 'p256',
2230
-
2231
- /** NIST P-384 Curve */
2232
- 'p384': 'p384',
2233
- 'P-384': 'p384',
2234
- 'secp384r1': 'p384',
2235
- '1.3.132.0.34': 'p384',
2236
- '2b81040022': 'p384',
2237
- '2B81040022': 'p384',
2238
-
2239
- /** NIST P-521 Curve */
2240
- 'p521': 'p521',
2241
- 'P-521': 'p521',
2242
- 'secp521r1': 'p521',
2243
- '1.3.132.0.35': 'p521',
2244
- '2b81040023': 'p521',
2245
- '2B81040023': 'p521',
2246
-
2247
- /** SECG SECP256k1 Curve */
2248
- 'secp256k1': 'secp256k1',
2249
- '1.3.132.0.10': 'secp256k1',
2250
- '2b8104000a': 'secp256k1',
2251
- '2B8104000A': 'secp256k1',
2252
-
2253
- /** Ed25519 */
2254
- 'ED25519': 'ed25519',
2255
- 'ed25519': 'ed25519',
2256
- 'Ed25519': 'ed25519',
2257
- '1.3.6.1.4.1.11591.15.1': 'ed25519',
2258
- '2b06010401da470f01': 'ed25519',
2259
- '2B06010401DA470F01': 'ed25519',
2260
-
2261
- /** Curve25519 */
2262
- 'X25519': 'curve25519',
2263
- 'cv25519': 'curve25519',
2264
- 'curve25519': 'curve25519',
2265
- 'Curve25519': 'curve25519',
2266
- '1.3.6.1.4.1.3029.1.5.1': 'curve25519',
2267
- '2b060104019755010501': 'curve25519',
2268
- '2B060104019755010501': 'curve25519',
2269
-
2270
- /** BrainpoolP256r1 Curve */
2271
- 'brainpoolP256r1': 'brainpoolP256r1',
2272
- '1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1',
2273
- '2b2403030208010107': 'brainpoolP256r1',
2274
- '2B2403030208010107': 'brainpoolP256r1',
2275
-
2276
- /** BrainpoolP384r1 Curve */
2277
- 'brainpoolP384r1': 'brainpoolP384r1',
2278
- '1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1',
2279
- '2b240303020801010b': 'brainpoolP384r1',
2280
- '2B240303020801010B': 'brainpoolP384r1',
2281
-
2282
- /** BrainpoolP512r1 Curve */
2283
- 'brainpoolP512r1': 'brainpoolP512r1',
2284
- '1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1',
2285
- '2b240303020801010d': 'brainpoolP512r1',
2286
- '2B240303020801010D': 'brainpoolP512r1'
2287
- },
2288
-
2289
- /** KDF parameters flags
2290
- * Non-standard extensions (for now) to allow email forwarding
2291
- * @enum {Integer}
2292
- * @readonly
2293
- */
2294
- kdfFlags: {
2295
- /** Specify fingerprint to use instead of the recipient's */
2296
- replace_fingerprint: 0x01,
2297
- /** Specify custom parameters to use in the KDF digest computation */
2298
- replace_kdf_params: 0x02
2299
- },
2300
-
2301
- /** A string to key specifier type
2302
- * @enum {Integer}
2303
- * @readonly
2304
- */
2305
- s2k: {
2306
- simple: 0,
2307
- salted: 1,
2308
- iterated: 3,
2309
- argon2: 4,
2310
- gnu: 101
2311
- },
2312
-
2313
- /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.1|RFC4880bis-04, section 9.1}
2314
- * @enum {Integer}
2315
- * @readonly
2316
- */
2317
- publicKey: {
2318
- /** RSA (Encrypt or Sign) [HAC] */
2319
- rsaEncryptSign: 1,
2320
- /** RSA (Encrypt only) [HAC] */
2321
- rsaEncrypt: 2,
2322
- /** RSA (Sign only) [HAC] */
2323
- rsaSign: 3,
2324
- /** Elgamal (Encrypt only) [ELGAMAL] [HAC] */
2325
- elgamal: 16,
2326
- /** DSA (Sign only) [FIPS186] [HAC] */
2327
- dsa: 17,
2328
- /** ECDH (Encrypt only) [RFC6637] */
2329
- ecdh: 18,
2330
- /** ECDSA (Sign only) [RFC6637] */
2331
- ecdsa: 19,
2332
- /** EdDSA (Sign only)
2333
- * [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
2334
- eddsa: 22,
2335
- /** Reserved for AEDH */
2336
- aedh: 23,
2337
- /** Reserved for AEDSA */
2338
- aedsa: 24,
2339
- /** Symmetric authenticated encryption algorithms */
2340
- aead: 100,
2341
- /** Authentication using CMAC */
2342
- hmac: 101
2343
- },
2344
-
2345
- /** {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
2346
- * @enum {Integer}
2347
- * @readonly
2348
- */
2349
- symmetric: {
2350
- plaintext: 0,
2351
- /** Not implemented! */
2352
- idea: 1,
2353
- tripledes: 2,
2354
- cast5: 3,
2355
- blowfish: 4,
2356
- aes128: 7,
2357
- aes192: 8,
2358
- aes256: 9,
2359
- twofish: 10
2360
- },
2361
-
2362
- /** {@link https://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
2363
- * @enum {Integer}
2364
- * @readonly
2365
- */
2366
- compression: {
2367
- uncompressed: 0,
2368
- /** RFC1951 */
2369
- zip: 1,
2370
- /** RFC1950 */
2371
- zlib: 2,
2372
- bzip2: 3
2373
- },
2374
-
2375
- /** {@link https://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
2376
- * @enum {Integer}
2377
- * @readonly
2378
- */
2379
- hash: {
2380
- md5: 1,
2381
- sha1: 2,
2382
- ripemd: 3,
2383
- sha256: 8,
2384
- sha384: 9,
2385
- sha512: 10,
2386
- sha224: 11
2387
- },
2388
-
2389
- /** A list of hash names as accepted by webCrypto functions.
2390
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest|Parameters, algo}
2391
- * @enum {String}
2392
- */
2393
- webHash: {
2394
- 'SHA-1': 2,
2395
- 'SHA-256': 8,
2396
- 'SHA-384': 9,
2397
- 'SHA-512': 10
2398
- },
2399
-
2400
- /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.6|RFC4880bis-04, section 9.6}
2401
- * @enum {Integer}
2402
- * @readonly
2403
- */
2404
- aead: {
2405
- eax: 1,
2406
- ocb: 2,
2407
- experimentalGCM: 100 // Private algorithm
2408
- },
2409
-
2410
- /** A list of packet types and numeric tags associated with them.
2411
- * @enum {Integer}
2412
- * @readonly
2413
- */
2414
- packet: {
2415
- publicKeyEncryptedSessionKey: 1,
2416
- signature: 2,
2417
- symEncryptedSessionKey: 3,
2418
- onePassSignature: 4,
2419
- secretKey: 5,
2420
- publicKey: 6,
2421
- secretSubkey: 7,
2422
- compressedData: 8,
2423
- symmetricallyEncryptedData: 9,
2424
- marker: 10,
2425
- literalData: 11,
2426
- trust: 12,
2427
- userID: 13,
2428
- publicSubkey: 14,
2429
- userAttribute: 17,
2430
- symEncryptedIntegrityProtectedData: 18,
2431
- modificationDetectionCode: 19,
2432
- aeadEncryptedData: 20 // see IETF draft: https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1
2433
- },
2434
-
2435
- /** Data types in the literal packet
2436
- * @enum {Integer}
2437
- * @readonly
2438
- */
2439
- literal: {
2440
- /** Binary data 'b' */
2441
- binary: 'b'.charCodeAt(),
2442
- /** Text data 't' */
2443
- text: 't'.charCodeAt(),
2444
- /** Utf8 data 'u' */
2445
- utf8: 'u'.charCodeAt(),
2446
- /** MIME message body part 'm' */
2447
- mime: 'm'.charCodeAt()
2448
- },
2449
-
2450
-
2451
- /** One pass signature packet type
2452
- * @enum {Integer}
2453
- * @readonly
2454
- */
2455
- signature: {
2456
- /** 0x00: Signature of a binary document. */
2457
- binary: 0,
2458
- /** 0x01: Signature of a canonical text document.
2459
- *
2460
- * Canonicalyzing the document by converting line endings. */
2461
- text: 1,
2462
- /** 0x02: Standalone signature.
2463
- *
2464
- * This signature is a signature of only its own subpacket contents.
2465
- * It is calculated identically to a signature over a zero-lengh
2466
- * binary document. Note that it doesn't make sense to have a V3
2467
- * standalone signature. */
2468
- standalone: 2,
2469
- /** 0x10: Generic certification of a User ID and Public-Key packet.
2470
- *
2471
- * The issuer of this certification does not make any particular
2472
- * assertion as to how well the certifier has checked that the owner
2473
- * of the key is in fact the person described by the User ID. */
2474
- certGeneric: 16,
2475
- /** 0x11: Persona certification of a User ID and Public-Key packet.
2476
- *
2477
- * The issuer of this certification has not done any verification of
2478
- * the claim that the owner of this key is the User ID specified. */
2479
- certPersona: 17,
2480
- /** 0x12: Casual certification of a User ID and Public-Key packet.
2481
- *
2482
- * The issuer of this certification has done some casual
2483
- * verification of the claim of identity. */
2484
- certCasual: 18,
2485
- /** 0x13: Positive certification of a User ID and Public-Key packet.
2486
- *
2487
- * The issuer of this certification has done substantial
2488
- * verification of the claim of identity.
2489
- *
2490
- * Most OpenPGP implementations make their "key signatures" as 0x10
2491
- * certifications. Some implementations can issue 0x11-0x13
2492
- * certifications, but few differentiate between the types. */
2493
- certPositive: 19,
2494
- /** 0x30: Certification revocation signature
2495
- *
2496
- * This signature revokes an earlier User ID certification signature
2497
- * (signature class 0x10 through 0x13) or direct-key signature
2498
- * (0x1F). It should be issued by the same key that issued the
2499
- * revoked signature or an authorized revocation key. The signature
2500
- * is computed over the same data as the certificate that it
2501
- * revokes, and should have a later creation date than that
2502
- * certificate. */
2503
- certRevocation: 48,
2504
- /** 0x18: Subkey Binding Signature
2505
- *
2506
- * This signature is a statement by the top-level signing key that
2507
- * indicates that it owns the subkey. This signature is calculated
2508
- * directly on the primary key and subkey, and not on any User ID or
2509
- * other packets. A signature that binds a signing subkey MUST have
2510
- * an Embedded Signature subpacket in this binding signature that
2511
- * contains a 0x19 signature made by the signing subkey on the
2512
- * primary key and subkey. */
2513
- subkeyBinding: 24,
2514
- /** 0x19: Primary Key Binding Signature
2515
- *
2516
- * This signature is a statement by a signing subkey, indicating
2517
- * that it is owned by the primary key and subkey. This signature
2518
- * is calculated the same way as a 0x18 signature: directly on the
2519
- * primary key and subkey, and not on any User ID or other packets.
2520
- *
2521
- * When a signature is made over a key, the hash data starts with the
2522
- * octet 0x99, followed by a two-octet length of the key, and then body
2523
- * of the key packet. (Note that this is an old-style packet header for
2524
- * a key packet with two-octet length.) A subkey binding signature
2525
- * (type 0x18) or primary key binding signature (type 0x19) then hashes
2526
- * the subkey using the same format as the main key (also using 0x99 as
2527
- * the first octet). */
2528
- keyBinding: 25,
2529
- /** 0x1F: Signature directly on a key
2530
- *
2531
- * This signature is calculated directly on a key. It binds the
2532
- * information in the Signature subpackets to the key, and is
2533
- * appropriate to be used for subpackets that provide information
2534
- * about the key, such as the Revocation Key subpacket. It is also
2535
- * appropriate for statements that non-self certifiers want to make
2536
- * about the key itself, rather than the binding between a key and a
2537
- * name. */
2538
- key: 31,
2539
- /** 0x20: Key revocation signature
2540
- *
2541
- * The signature is calculated directly on the key being revoked. A
2542
- * revoked key is not to be used. Only revocation signatures by the
2543
- * key being revoked, or by an authorized revocation key, should be
2544
- * considered valid revocation signatures.a */
2545
- keyRevocation: 32,
2546
- /** 0x28: Subkey revocation signature
2547
- *
2548
- * The signature is calculated directly on the subkey being revoked.
2549
- * A revoked subkey is not to be used. Only revocation signatures
2550
- * by the top-level signature key that is bound to this subkey, or
2551
- * by an authorized revocation key, should be considered valid
2552
- * revocation signatures.
2553
- *
2554
- * Key revocation signatures (types 0x20 and 0x28)
2555
- * hash only the key being revoked. */
2556
- subkeyRevocation: 40,
2557
- /** 0x40: Timestamp signature.
2558
- * This signature is only meaningful for the timestamp contained in
2559
- * it. */
2560
- timestamp: 64,
2561
- /** 0x50: Third-Party Confirmation signature.
2562
- *
2563
- * This signature is a signature over some other OpenPGP Signature
2564
- * packet(s). It is analogous to a notary seal on the signed data.
2565
- * A third-party signature SHOULD include Signature Target
2566
- * subpacket(s) to give easy identification. Note that we really do
2567
- * mean SHOULD. There are plausible uses for this (such as a blind
2568
- * party that only sees the signature, not the key or source
2569
- * document) that cannot include a target subpacket. */
2570
- thirdParty: 80
2571
- },
2572
-
2573
- /** Signature subpacket type
2574
- * @enum {Integer}
2575
- * @readonly
2576
- */
2577
- signatureSubpacket: {
2578
- signatureCreationTime: 2,
2579
- signatureExpirationTime: 3,
2580
- exportableCertification: 4,
2581
- trustSignature: 5,
2582
- regularExpression: 6,
2583
- revocable: 7,
2584
- keyExpirationTime: 9,
2585
- placeholderBackwardsCompatibility: 10,
2586
- preferredSymmetricAlgorithms: 11,
2587
- revocationKey: 12,
2588
- issuer: 16,
2589
- notationData: 20,
2590
- preferredHashAlgorithms: 21,
2591
- preferredCompressionAlgorithms: 22,
2592
- keyServerPreferences: 23,
2593
- preferredKeyServer: 24,
2594
- primaryUserID: 25,
2595
- policyURI: 26,
2596
- keyFlags: 27,
2597
- signersUserID: 28,
2598
- reasonForRevocation: 29,
2599
- features: 30,
2600
- signatureTarget: 31,
2601
- embeddedSignature: 32,
2602
- issuerFingerprint: 33,
2603
- preferredAEADAlgorithms: 34
2604
- },
2605
-
2606
- /** Key flags
2607
- * @enum {Integer}
2608
- * @readonly
2609
- */
2610
- keyFlags: {
2611
- /** 0x01 - This key may be used to certify other keys. */
2612
- certifyKeys: 1,
2613
- /** 0x02 - This key may be used to sign data. */
2614
- signData: 2,
2615
- /** 0x04 - This key may be used to encrypt communications. */
2616
- encryptCommunication: 4,
2617
- /** 0x08 - This key may be used to encrypt storage. */
2618
- encryptStorage: 8,
2619
- /** 0x10 - The private component of this key may have been split
2620
- * by a secret-sharing mechanism. */
2621
- splitPrivateKey: 16,
2622
- /** 0x20 - This key may be used for authentication. */
2623
- authentication: 32,
2624
- /** This key may be used for forwarded communications */
2625
- forwardedCommunication: 64,
2626
- /** 0x80 - The private component of this key may be in the
2627
- * possession of more than one person. */
2628
- sharedPrivateKey: 128
2629
- },
2630
-
2631
- /** Armor type
2632
- * @enum {Integer}
2633
- * @readonly
2634
- */
2635
- armor: {
2636
- multipartSection: 0,
2637
- multipartLast: 1,
2638
- signed: 2,
2639
- message: 3,
2640
- publicKey: 4,
2641
- privateKey: 5,
2642
- signature: 6
2643
- },
2644
-
2645
- /** {@link https://tools.ietf.org/html/rfc4880#section-5.2.3.23|RFC4880, section 5.2.3.23}
2646
- * @enum {Integer}
2647
- * @readonly
2648
- */
2649
- reasonForRevocation: {
2650
- /** No reason specified (key revocations or cert revocations) */
2651
- noReason: 0,
2652
- /** Key is superseded (key revocations) */
2653
- keySuperseded: 1,
2654
- /** Key material has been compromised (key revocations) */
2655
- keyCompromised: 2,
2656
- /** Key is retired and no longer used (key revocations) */
2657
- keyRetired: 3,
2658
- /** User ID information is no longer valid (cert revocations) */
2659
- userIDInvalid: 32
2660
- },
2661
-
2662
- /** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-5.2.3.25|RFC4880bis-04, section 5.2.3.25}
2663
- * @enum {Integer}
2664
- * @readonly
2665
- */
2666
- features: {
2667
- /** 0x01 - Modification Detection (packets 18 and 19) */
2668
- modificationDetection: 1,
2669
- /** 0x02 - AEAD Encrypted Data Packet (packet 20) and version 5
2670
- * Symmetric-Key Encrypted Session Key Packets (packet 3) */
2671
- aead: 2,
2672
- /** 0x04 - Version 5 Public-Key Packet format and corresponding new
2673
- * fingerprint format */
2674
- v5Keys: 4
2675
- },
2676
-
2677
- /**
2678
- * Asserts validity of given value and converts from string/integer to integer.
2679
- * @param {Object} type target enum type
2680
- * @param {String|Integer} e value to check and/or convert
2681
- * @returns {Integer} enum value if it exists
2682
- * @throws {Error} if the value is invalid
2683
- */
2684
- write: function(type, e) {
2685
- if (typeof e === 'number') {
2686
- e = this.read(type, e);
2687
- }
2688
-
2689
- if (type[e] !== undefined) {
2690
- return type[e];
2691
- }
2692
-
2693
- throw new Error('Invalid enum value.');
2694
- },
2695
-
2696
- /**
2697
- * Converts enum integer value to the corresponding string, if it exists.
2698
- * @param {Object} type target enum type
2699
- * @param {Integer} e value to convert
2700
- * @returns {String} name of enum value if it exists
2701
- * @throws {Error} if the value is invalid
2702
- */
2703
- read: function(type, e) {
2704
- if (!type[byValue]) {
2705
- type[byValue] = [];
2706
- Object.entries(type).forEach(([key, value]) => {
2707
- type[byValue][value] = key;
2708
- });
2709
- }
2710
-
2711
- if (type[byValue][e] !== undefined) {
2712
- return type[byValue][e];
2713
- }
2714
-
2715
- throw new Error('Invalid enum value.');
2716
- }
2717
- };
2718
-
2719
2740
  // GPG4Browsers - An OpenPGP implementation in javascript
2720
2741
 
2721
2742
  var config = {
@@ -2932,7 +2953,7 @@ var openpgp = (function (exports) {
2932
2953
  * @memberof module:config
2933
2954
  * @property {String} versionString A version string to be included in armored messages
2934
2955
  */
2935
- versionString: 'OpenPGP.js 5.9.1-1',
2956
+ versionString: 'OpenPGP.js 5.11.0',
2936
2957
  /**
2937
2958
  * @memberof module:config
2938
2959
  * @property {String} commentString A comment string to be included in armored messages
@@ -2983,7 +3004,14 @@ var openpgp = (function (exports) {
2983
3004
  * @memberof module:config
2984
3005
  * @property {Set<String>} rejectCurves {@link module:enums.curve}
2985
3006
  */
2986
- rejectCurves: new Set([enums.curve.secp256k1])
3007
+ rejectCurves: new Set([enums.curve.secp256k1]),
3008
+ /**
3009
+ * Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
3010
+ * This check will make signing 2-3 times slower.
3011
+ * Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
3012
+ * computation, and could be used to recover the signer's secret key given a second signature over the same data.
3013
+ */
3014
+ checkEdDSAFaultySignatures: true
2987
3015
  };
2988
3016
 
2989
3017
  /**
@@ -3424,6 +3452,7 @@ var openpgp = (function (exports) {
3424
3452
  */
3425
3453
  read(bytes) {
3426
3454
  this.bytes = util.uint8ArrayToString(bytes.subarray(0, 8));
3455
+ return this.bytes.length;
3427
3456
  }
3428
3457
 
3429
3458
  /**
@@ -9970,7 +9999,7 @@ var openpgp = (function (exports) {
9970
9999
  if (util.getNodeCrypto() && nodeAlgos[algoName]) { // Node crypto library.
9971
10000
  return nodeEncrypt(algo, key, plaintext, iv);
9972
10001
  }
9973
- if (algoName.substr(0, 3) === 'aes') {
10002
+ if (util.isAES(algo)) {
9974
10003
  return aesEncrypt(algo, key, plaintext, iv, config);
9975
10004
  }
9976
10005
 
@@ -10013,7 +10042,7 @@ var openpgp = (function (exports) {
10013
10042
  if (util.getNodeCrypto() && nodeAlgos[algoName]) { // Node crypto library.
10014
10043
  return nodeDecrypt(algo, key, ciphertext, iv);
10015
10044
  }
10016
- if (algoName.substr(0, 3) === 'aes') {
10045
+ if (util.isAES(algo)) {
10017
10046
  return aesDecrypt(algo, key, ciphertext, iv);
10018
10047
  }
10019
10048
 
@@ -10032,7 +10061,7 @@ var openpgp = (function (exports) {
10032
10061
  let j = 0;
10033
10062
  while (chunk ? ct.length >= block_size : ct.length) {
10034
10063
  const decblock = cipherfn.encrypt(blockp);
10035
- blockp = ct;
10064
+ blockp = ct.subarray(0, block_size);
10036
10065
  for (i = 0; i < block_size; i++) {
10037
10066
  plaintext[j++] = blockp[i] ^ decblock[i];
10038
10067
  }
@@ -10958,42 +10987,42 @@ var openpgp = (function (exports) {
10958
10987
  throw new Error('GCM mode supports only AES cipher');
10959
10988
  }
10960
10989
 
10961
- if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
10962
- const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
10963
-
10990
+ if (util.getNodeCrypto()) { // Node crypto library
10964
10991
  return {
10965
10992
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10966
- if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
10967
- return AES_GCM.encrypt(pt, key, iv, adata);
10968
- }
10969
- const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
10993
+ const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10994
+ en.setAAD(adata);
10995
+ const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
10970
10996
  return new Uint8Array(ct);
10971
10997
  },
10972
10998
 
10973
10999
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
10974
- if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
10975
- return AES_GCM.decrypt(ct, key, iv, adata);
10976
- }
10977
- const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
11000
+ const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
11001
+ de.setAAD(adata);
11002
+ de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
11003
+ const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
10978
11004
  return new Uint8Array(pt);
10979
11005
  }
10980
11006
  };
10981
11007
  }
10982
11008
 
10983
- if (util.getNodeCrypto()) { // Node crypto library
11009
+ if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
11010
+ const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
11011
+
10984
11012
  return {
10985
11013
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
10986
- const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10987
- en.setAAD(adata);
10988
- const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
11014
+ if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
11015
+ return AES_GCM.encrypt(pt, key, iv, adata);
11016
+ }
11017
+ const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
10989
11018
  return new Uint8Array(ct);
10990
11019
  },
10991
11020
 
10992
11021
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
10993
- const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
10994
- de.setAAD(adata);
10995
- de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
10996
- const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
11022
+ if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
11023
+ return AES_GCM.decrypt(ct, key, iv, adata);
11024
+ }
11025
+ const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
10997
11026
  return new Uint8Array(pt);
10998
11027
  }
10999
11028
  };
@@ -11996,11 +12025,11 @@ var openpgp = (function (exports) {
11996
12025
  */
11997
12026
  function getRandomBytes(length) {
11998
12027
  const buf = new Uint8Array(length);
11999
- if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12000
- crypto.getRandomValues(buf);
12001
- } else if (nodeCrypto$5) {
12028
+ if (nodeCrypto$5) {
12002
12029
  const bytes = nodeCrypto$5.randomBytes(buf.length);
12003
12030
  buf.set(bytes);
12031
+ } else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
12032
+ crypto.getRandomValues(buf);
12004
12033
  } else {
12005
12034
  throw new Error('No secure random number generator available.');
12006
12035
  }
@@ -13562,7 +13591,7 @@ var openpgp = (function (exports) {
13562
13591
  },
13563
13592
  ed25519: {
13564
13593
  oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
13565
- keyType: enums.publicKey.eddsa,
13594
+ keyType: enums.publicKey.eddsaLegacy,
13566
13595
  hash: enums.hash.sha512,
13567
13596
  node: false, // nodeCurves.ed25519 TODO
13568
13597
  payloadSize: 32
@@ -13601,7 +13630,7 @@ var openpgp = (function (exports) {
13601
13630
  }
13602
13631
  };
13603
13632
 
13604
- class Curve {
13633
+ class CurveWithOID {
13605
13634
  constructor(oidOrName, params) {
13606
13635
  try {
13607
13636
  if (util.isArray(oidOrName) ||
@@ -13678,7 +13707,7 @@ var openpgp = (function (exports) {
13678
13707
  async function generate$1(curve) {
13679
13708
  const BigInteger = await util.getBigInteger();
13680
13709
 
13681
- curve = new Curve(curve);
13710
+ curve = new CurveWithOID(curve);
13682
13711
  const keyPair = await curve.genKeyPair();
13683
13712
  const Q = new BigInteger(keyPair.publicKey).toUint8Array();
13684
13713
  const secret = new BigInteger(keyPair.privateKey).toUint8Array('be', curve.payloadSize);
@@ -13869,7 +13898,7 @@ var openpgp = (function (exports) {
13869
13898
  * @async
13870
13899
  */
13871
13900
  async function sign$1(oid, hashAlgo, message, publicKey, privateKey, hashed) {
13872
- const curve = new Curve(oid);
13901
+ const curve = new CurveWithOID(oid);
13873
13902
  if (message && !util.isStream(message)) {
13874
13903
  const keyPair = { publicKey, privateKey };
13875
13904
  switch (curve.type) {
@@ -13914,7 +13943,7 @@ var openpgp = (function (exports) {
13914
13943
  * @async
13915
13944
  */
13916
13945
  async function verify$1(oid, hashAlgo, signature, message, publicKey, hashed) {
13917
- const curve = new Curve(oid);
13946
+ const curve = new CurveWithOID(oid);
13918
13947
  if (message && !util.isStream(message)) {
13919
13948
  switch (curve.type) {
13920
13949
  case 'web':
@@ -13948,7 +13977,7 @@ var openpgp = (function (exports) {
13948
13977
  * @async
13949
13978
  */
13950
13979
  async function validateParams$2(oid, Q, d) {
13951
- const curve = new Curve(oid);
13980
+ const curve = new CurveWithOID(oid);
13952
13981
  // Reject curves x25519 and ed25519
13953
13982
  if (curve.keyType !== enums.publicKey.ecdsa) {
13954
13983
  return false;
@@ -14151,7 +14180,7 @@ var openpgp = (function (exports) {
14151
14180
  naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
14152
14181
 
14153
14182
  /**
14154
- * Sign a message using the provided key
14183
+ * Sign a message using the provided legacy EdDSA key
14155
14184
  * @param {module:type/oid} oid - Elliptic curve object identifier
14156
14185
  * @param {module:enums.hash} hashAlgo - Hash algorithm used to sign (must be sha256 or stronger)
14157
14186
  * @param {Uint8Array} message - Message to sign
@@ -14167,10 +14196,24 @@ var openpgp = (function (exports) {
14167
14196
  async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
14168
14197
  if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14169
14198
  // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
14170
- throw new Error('Hash algorithm too weak: sha256 or stronger is required for EdDSA.');
14199
+ throw new Error('Hash algorithm too weak for EdDSA.');
14171
14200
  }
14172
14201
  const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
14173
14202
  const signature = naclFastLight.sign.detached(hashed, secretKey);
14203
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
14204
+ /**
14205
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14206
+ * if two signatures over the same message are obtained.
14207
+ * See https://github.com/jedisct1/libsodium/issues/170.
14208
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14209
+ * then the generated signature is always safe, and the verification step is skipped.
14210
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14211
+ * - in M between the computation of `r` and `h`.
14212
+ * - in the public key before computing `h`
14213
+ * The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
14214
+ */
14215
+ throw new Error('Transient signing failure');
14216
+ }
14174
14217
  // EdDSA signature params are returned in little-endian format
14175
14218
  return {
14176
14219
  r: signature.subarray(0, 32),
@@ -14179,7 +14222,7 @@ var openpgp = (function (exports) {
14179
14222
  }
14180
14223
 
14181
14224
  /**
14182
- * Verifies if a signature is valid for a message
14225
+ * Verifies if a legacy EdDSA signature is valid for a message
14183
14226
  * @param {module:type/oid} oid - Elliptic curve object identifier
14184
14227
  * @param {module:enums.hash} hashAlgo - Hash algorithm used in the signature
14185
14228
  * @param {{r: Uint8Array,
@@ -14191,11 +14234,14 @@ var openpgp = (function (exports) {
14191
14234
  * @async
14192
14235
  */
14193
14236
  async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
14237
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
14238
+ throw new Error('Hash algorithm too weak for EdDSA.');
14239
+ }
14194
14240
  const signature = util.concatUint8Array([r, s]);
14195
14241
  return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
14196
14242
  }
14197
14243
  /**
14198
- * Validate EdDSA parameters
14244
+ * Validate legacy EdDSA parameters
14199
14245
  * @param {module:type/oid} oid - Elliptic curve object identifier
14200
14246
  * @param {Uint8Array} Q - EdDSA public point
14201
14247
  * @param {Uint8Array} k - EdDSA secret seed
@@ -14215,9 +14261,10 @@ var openpgp = (function (exports) {
14215
14261
  const { publicKey } = naclFastLight.sign.keyPair.fromSeed(k);
14216
14262
  const dG = new Uint8Array([0x40, ...publicKey]); // Add public key prefix
14217
14263
  return util.equalsUint8Array(Q, dG);
14264
+
14218
14265
  }
14219
14266
 
14220
- var eddsa = /*#__PURE__*/Object.freeze({
14267
+ var eddsa_legacy = /*#__PURE__*/Object.freeze({
14221
14268
  __proto__: null,
14222
14269
  sign: sign$2,
14223
14270
  verify: verify$2,
@@ -14226,6 +14273,139 @@ var openpgp = (function (exports) {
14226
14273
 
14227
14274
  // OpenPGP.js - An OpenPGP implementation in javascript
14228
14275
 
14276
+ naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
14277
+
14278
+ /**
14279
+ * Generate (non-legacy) EdDSA key
14280
+ * @param {module:enums.publicKey} algo - Algorithm identifier
14281
+ * @returns {Promise<{ A: Uint8Array, seed: Uint8Array }>}
14282
+ */
14283
+ async function generate$2(algo) {
14284
+ switch (algo) {
14285
+ case enums.publicKey.ed25519: {
14286
+ const seed = getRandomBytes(32);
14287
+ const { publicKey: A } = naclFastLight.sign.keyPair.fromSeed(seed);
14288
+ return { A, seed };
14289
+ }
14290
+ default:
14291
+ throw new Error('Unsupported EdDSA algorithm');
14292
+ }
14293
+ }
14294
+
14295
+ /**
14296
+ * Sign a message using the provided key
14297
+ * @param {module:enums.publicKey} algo - Algorithm identifier
14298
+ * @param {module:enums.hash} hashAlgo - Hash algorithm used to sign (must be sha256 or stronger)
14299
+ * @param {Uint8Array} message - Message to sign
14300
+ * @param {Uint8Array} publicKey - Public key
14301
+ * @param {Uint8Array} privateKey - Private key used to sign the message
14302
+ * @param {Uint8Array} hashed - The hashed message
14303
+ * @returns {Promise<{
14304
+ * RS: Uint8Array
14305
+ * }>} Signature of the message
14306
+ * @async
14307
+ */
14308
+ async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
14309
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14310
+ throw new Error('Hash algorithm too weak for EdDSA.');
14311
+ }
14312
+ switch (algo) {
14313
+ case enums.publicKey.ed25519: {
14314
+ const secretKey = util.concatUint8Array([privateKey, publicKey]);
14315
+ const signature = naclFastLight.sign.detached(hashed, secretKey);
14316
+ if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
14317
+ /**
14318
+ * Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
14319
+ * if two signatures over the same message are obtained.
14320
+ * See https://github.com/jedisct1/libsodium/issues/170.
14321
+ * If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
14322
+ * then the generated signature is always safe, and the verification step is skipped.
14323
+ * Otherwise, we need to verify the generated to ensure that no bitflip occured:
14324
+ * - in M between the computation of `r` and `h`.
14325
+ * - in the public key before computing `h`
14326
+ * The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
14327
+ */
14328
+ throw new Error('Transient signing failure');
14329
+ }
14330
+ return { RS: signature };
14331
+ }
14332
+ case enums.publicKey.ed448:
14333
+ default:
14334
+ throw new Error('Unsupported EdDSA algorithm');
14335
+ }
14336
+
14337
+ }
14338
+
14339
+ /**
14340
+ * Verifies if a signature is valid for a message
14341
+ * @param {module:enums.publicKey} algo - Algorithm identifier
14342
+ * @param {module:enums.hash} hashAlgo - Hash algorithm used in the signature
14343
+ * @param {{ RS: Uint8Array }} signature Signature to verify the message
14344
+ * @param {Uint8Array} m - Message to verify
14345
+ * @param {Uint8Array} publicKey - Public key used to verify the message
14346
+ * @param {Uint8Array} hashed - The hashed message
14347
+ * @returns {Boolean}
14348
+ * @async
14349
+ */
14350
+ async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
14351
+ if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
14352
+ throw new Error('Hash algorithm too weak for EdDSA.');
14353
+ }
14354
+ switch (algo) {
14355
+ case enums.publicKey.ed25519: {
14356
+ return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
14357
+ }
14358
+ case enums.publicKey.ed448:
14359
+ default:
14360
+ throw new Error('Unsupported EdDSA algorithm');
14361
+ }
14362
+ }
14363
+ /**
14364
+ * Validate (non-legacy) EdDSA parameters
14365
+ * @param {module:enums.publicKey} algo - Algorithm identifier
14366
+ * @param {Uint8Array} A - EdDSA public point
14367
+ * @param {Uint8Array} seed - EdDSA secret seed
14368
+ * @param {Uint8Array} oid - (legacy only) EdDSA OID
14369
+ * @returns {Promise<Boolean>} Whether params are valid.
14370
+ * @async
14371
+ */
14372
+ async function validateParams$4(algo, A, seed) {
14373
+ switch (algo) {
14374
+ case enums.publicKey.ed25519: {
14375
+ /**
14376
+ * Derive public point A' from private key
14377
+ * and expect A == A'
14378
+ */
14379
+ const { publicKey } = naclFastLight.sign.keyPair.fromSeed(seed);
14380
+ return util.equalsUint8Array(A, publicKey);
14381
+ }
14382
+
14383
+ case enums.publicKey.ed448: // unsupported
14384
+ default:
14385
+ return false;
14386
+ }
14387
+ }
14388
+
14389
+ function getPreferredHashAlgo$1(algo) {
14390
+ switch (algo) {
14391
+ case enums.publicKey.ed25519:
14392
+ return enums.hash.sha256;
14393
+ default:
14394
+ throw new Error('Unknown EdDSA algo');
14395
+ }
14396
+ }
14397
+
14398
+ var eddsa = /*#__PURE__*/Object.freeze({
14399
+ __proto__: null,
14400
+ generate: generate$2,
14401
+ sign: sign$3,
14402
+ verify: verify$3,
14403
+ validateParams: validateParams$4,
14404
+ getPreferredHashAlgo: getPreferredHashAlgo$1
14405
+ });
14406
+
14407
+ // OpenPGP.js - An OpenPGP implementation in javascript
14408
+
14229
14409
  /**
14230
14410
  * AES key wrap
14231
14411
  * @function
@@ -14413,7 +14593,7 @@ var openpgp = (function (exports) {
14413
14593
  * @returns {Promise<Boolean>} Whether params are valid.
14414
14594
  * @async
14415
14595
  */
14416
- async function validateParams$4(oid, Q, d) {
14596
+ async function validateParams$5(oid, Q, d) {
14417
14597
  return validateStandardParams(enums.publicKey.ecdh, oid, Q, d);
14418
14598
  }
14419
14599
 
@@ -14455,7 +14635,7 @@ var openpgp = (function (exports) {
14455
14635
  /**
14456
14636
  * Generate ECDHE ephemeral key and secret from public key
14457
14637
  *
14458
- * @param {Curve} curve - Elliptic curve object
14638
+ * @param {CurveWithOID} curve - Elliptic curve object
14459
14639
  * @param {Uint8Array} Q - Recipient public key
14460
14640
  * @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
14461
14641
  * @async
@@ -14498,7 +14678,7 @@ var openpgp = (function (exports) {
14498
14678
  async function encrypt$3(oid, kdfParams, data, Q, fingerprint) {
14499
14679
  const m = encode$1(data);
14500
14680
 
14501
- const curve = new Curve(oid);
14681
+ const curve = new CurveWithOID(oid);
14502
14682
  const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
14503
14683
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
14504
14684
  const { keySize } = getCipher(kdfParams.cipher);
@@ -14510,7 +14690,7 @@ var openpgp = (function (exports) {
14510
14690
  /**
14511
14691
  * Generate ECDHE secret from private key and public part of ephemeral key
14512
14692
  *
14513
- * @param {Curve} curve - Elliptic curve object
14693
+ * @param {CurveWithOID} curve - Elliptic curve object
14514
14694
  * @param {Uint8Array} V - Public part of ephemeral key
14515
14695
  * @param {Uint8Array} Q - Recipient public key
14516
14696
  * @param {Uint8Array} d - Recipient private key
@@ -14558,7 +14738,7 @@ var openpgp = (function (exports) {
14558
14738
  * @async
14559
14739
  */
14560
14740
  async function decrypt$3(oid, kdfParams, V, C, Q, d, fingerprint) {
14561
- const curve = new Curve(oid);
14741
+ const curve = new CurveWithOID(oid);
14562
14742
  const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
14563
14743
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
14564
14744
  const { keySize } = getCipher(kdfParams.cipher);
@@ -14578,7 +14758,7 @@ var openpgp = (function (exports) {
14578
14758
  /**
14579
14759
  * Generate ECDHE secret from private key and public part of ephemeral key using webCrypto
14580
14760
  *
14581
- * @param {Curve} curve - Elliptic curve object
14761
+ * @param {CurveWithOID} curve - Elliptic curve object
14582
14762
  * @param {Uint8Array} V - Public part of ephemeral key
14583
14763
  * @param {Uint8Array} Q - Recipient public key
14584
14764
  * @param {Uint8Array} d - Recipient private key
@@ -14631,7 +14811,7 @@ var openpgp = (function (exports) {
14631
14811
  /**
14632
14812
  * Generate ECDHE ephemeral key and secret from public key using webCrypto
14633
14813
  *
14634
- * @param {Curve} curve - Elliptic curve object
14814
+ * @param {CurveWithOID} curve - Elliptic curve object
14635
14815
  * @param {Uint8Array} Q - Recipient public key
14636
14816
  * @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
14637
14817
  * @async
@@ -14679,7 +14859,7 @@ var openpgp = (function (exports) {
14679
14859
  /**
14680
14860
  * Generate ECDHE secret from private key and public part of ephemeral key using indutny/elliptic
14681
14861
  *
14682
- * @param {Curve} curve - Elliptic curve object
14862
+ * @param {CurveWithOID} curve - Elliptic curve object
14683
14863
  * @param {Uint8Array} V - Public part of ephemeral key
14684
14864
  * @param {Uint8Array} d - Recipient private key
14685
14865
  * @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
@@ -14699,7 +14879,7 @@ var openpgp = (function (exports) {
14699
14879
  /**
14700
14880
  * Generate ECDHE ephemeral key and secret from public key using indutny/elliptic
14701
14881
  *
14702
- * @param {Curve} curve - Elliptic curve object
14882
+ * @param {CurveWithOID} curve - Elliptic curve object
14703
14883
  * @param {Uint8Array} Q - Recipient public key
14704
14884
  * @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
14705
14885
  * @async
@@ -14719,7 +14899,7 @@ var openpgp = (function (exports) {
14719
14899
  /**
14720
14900
  * Generate ECDHE secret from private key and public part of ephemeral key using nodeCrypto
14721
14901
  *
14722
- * @param {Curve} curve - Elliptic curve object
14902
+ * @param {CurveWithOID} curve - Elliptic curve object
14723
14903
  * @param {Uint8Array} V - Public part of ephemeral key
14724
14904
  * @param {Uint8Array} d - Recipient private key
14725
14905
  * @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
@@ -14736,7 +14916,7 @@ var openpgp = (function (exports) {
14736
14916
  /**
14737
14917
  * Generate ECDHE ephemeral key and secret from public key using nodeCrypto
14738
14918
  *
14739
- * @param {Curve} curve - Elliptic curve object
14919
+ * @param {CurveWithOID} curve - Elliptic curve object
14740
14920
  * @param {Uint8Array} Q - Recipient public key
14741
14921
  * @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
14742
14922
  * @async
@@ -14751,18 +14931,202 @@ var openpgp = (function (exports) {
14751
14931
 
14752
14932
  var ecdh = /*#__PURE__*/Object.freeze({
14753
14933
  __proto__: null,
14754
- validateParams: validateParams$4,
14934
+ validateParams: validateParams$5,
14755
14935
  encrypt: encrypt$3,
14756
14936
  decrypt: decrypt$3
14757
14937
  });
14758
14938
 
14939
+ /**
14940
+ * @fileoverview This module implements HKDF using either the WebCrypto API or Node.js' crypto API.
14941
+ * @module crypto/hkdf
14942
+ * @private
14943
+ */
14944
+
14945
+ const webCrypto$9 = util.getWebCrypto();
14946
+ const nodeCrypto$a = util.getNodeCrypto();
14947
+ const nodeSubtleCrypto = nodeCrypto$a && nodeCrypto$a.webcrypto && nodeCrypto$a.webcrypto.subtle;
14948
+
14949
+ async function HKDF(hashAlgo, inputKey, salt, info, outLen) {
14950
+ const hash = enums.read(enums.webHash, hashAlgo);
14951
+ if (!hash) throw new Error('Hash algo not supported with HKDF');
14952
+
14953
+ if (webCrypto$9 || nodeSubtleCrypto) {
14954
+ const crypto = webCrypto$9 || nodeSubtleCrypto;
14955
+ const importedKey = await crypto.importKey('raw', inputKey, 'HKDF', false, ['deriveBits']);
14956
+ const bits = await crypto.deriveBits({ name: 'HKDF', hash, salt, info }, importedKey, outLen * 8);
14957
+ return new Uint8Array(bits);
14958
+ }
14959
+
14960
+ if (nodeCrypto$a) {
14961
+ const hashAlgoName = enums.read(enums.hash, hashAlgo);
14962
+ // Node-only HKDF implementation based on https://www.rfc-editor.org/rfc/rfc5869
14963
+
14964
+ const computeHMAC = (hmacKey, hmacMessage) => nodeCrypto$a.createHmac(hashAlgoName, hmacKey).update(hmacMessage).digest();
14965
+ // Step 1: Extract
14966
+ // PRK = HMAC-Hash(salt, IKM)
14967
+ const pseudoRandomKey = computeHMAC(salt, inputKey);
14968
+
14969
+ const hashLen = pseudoRandomKey.length;
14970
+
14971
+ // Step 2: Expand
14972
+ // HKDF-Expand(PRK, info, L) -> OKM
14973
+ const n = Math.ceil(outLen / hashLen);
14974
+ const outputKeyingMaterial = new Uint8Array(n * hashLen);
14975
+
14976
+ // HMAC input buffer updated at each iteration
14977
+ const roundInput = new Uint8Array(hashLen + info.length + 1);
14978
+ // T_i and last byte are updated at each iteration, but `info` remains constant
14979
+ roundInput.set(info, hashLen);
14980
+
14981
+ for (let i = 0; i < n; i++) {
14982
+ // T(0) = empty string (zero length)
14983
+ // T(i) = HMAC-Hash(PRK, T(i-1) | info | i)
14984
+ roundInput[roundInput.length - 1] = i + 1;
14985
+ // t = T(i+1)
14986
+ const t = computeHMAC(pseudoRandomKey, i > 0 ? roundInput : roundInput.subarray(hashLen));
14987
+ roundInput.set(t, 0);
14988
+
14989
+ outputKeyingMaterial.set(t, i * hashLen);
14990
+ }
14991
+
14992
+ return outputKeyingMaterial.subarray(0, outLen);
14993
+ }
14994
+
14995
+ throw new Error('No HKDF implementation available');
14996
+ }
14997
+
14998
+ /**
14999
+ * @fileoverview Key encryption and decryption for RFC 6637 ECDH
15000
+ * @module crypto/public_key/elliptic/ecdh
15001
+ * @private
15002
+ */
15003
+
15004
+ const HKDF_INFO = {
15005
+ x25519: util.encodeUTF8('OpenPGP X25519')
15006
+ };
15007
+
15008
+ /**
15009
+ * Generate ECDH key for Montgomery curves
15010
+ * @param {module:enums.publicKey} algo - Algorithm identifier
15011
+ * @returns {Promise<{ A: Uint8Array, k: Uint8Array }>}
15012
+ */
15013
+ async function generate$3(algo) {
15014
+ switch (algo) {
15015
+ case enums.publicKey.x25519: {
15016
+ // k stays in little-endian, unlike legacy ECDH over curve25519
15017
+ const k = getRandomBytes(32);
15018
+ const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
15019
+ return { A, k };
15020
+ }
15021
+ default:
15022
+ throw new Error('Unsupported ECDH algorithm');
15023
+ }
15024
+ }
15025
+
15026
+ /**
15027
+ * Validate ECDH parameters
15028
+ * @param {module:enums.publicKey} algo - Algorithm identifier
15029
+ * @param {Uint8Array} A - ECDH public point
15030
+ * @param {Uint8Array} k - ECDH secret scalar
15031
+ * @returns {Promise<Boolean>} Whether params are valid.
15032
+ * @async
15033
+ */
15034
+ async function validateParams$6(algo, A, k) {
15035
+ switch (algo) {
15036
+ case enums.publicKey.x25519: {
15037
+ /**
15038
+ * Derive public point A' from private key
15039
+ * and expect A == A'
15040
+ */
15041
+ const { publicKey } = naclFastLight.box.keyPair.fromSecretKey(k);
15042
+ return util.equalsUint8Array(A, publicKey);
15043
+ }
15044
+
15045
+ default:
15046
+ return false;
15047
+ }
15048
+ }
15049
+
15050
+ /**
15051
+ * Wrap and encrypt a session key
15052
+ *
15053
+ * @param {module:enums.publicKey} algo - Algorithm identifier
15054
+ * @param {Uint8Array} data - session key data to be encrypted
15055
+ * @param {Uint8Array} recipientA - Recipient public key (K_B)
15056
+ * @returns {Promise<{
15057
+ * ephemeralPublicKey: Uint8Array,
15058
+ * wrappedKey: Uint8Array
15059
+ * }>} ephemeral public key (K_A) and encrypted key
15060
+ * @async
15061
+ */
15062
+ async function encrypt$4(algo, data, recipientA) {
15063
+ switch (algo) {
15064
+ case enums.publicKey.x25519: {
15065
+ const ephemeralSecretKey = getRandomBytes(32);
15066
+ const sharedSecret = naclFastLight.scalarMult(ephemeralSecretKey, recipientA);
15067
+ const { publicKey: ephemeralPublicKey } = naclFastLight.box.keyPair.fromSecretKey(ephemeralSecretKey);
15068
+ const hkdfInput = util.concatUint8Array([
15069
+ ephemeralPublicKey,
15070
+ recipientA,
15071
+ sharedSecret
15072
+ ]);
15073
+ const { keySize } = getCipher(enums.symmetric.aes128);
15074
+ const encryptionKey = await HKDF(enums.hash.sha256, hkdfInput, new Uint8Array(), HKDF_INFO.x25519, keySize);
15075
+ const wrappedKey = wrap(encryptionKey, data);
15076
+ return { ephemeralPublicKey, wrappedKey };
15077
+ }
15078
+
15079
+ default:
15080
+ throw new Error('Unsupported ECDH algorithm');
15081
+ }
15082
+ }
15083
+
15084
+ /**
15085
+ * Decrypt and unwrap the session key
15086
+ *
15087
+ * @param {module:enums.publicKey} algo - Algorithm identifier
15088
+ * @param {Uint8Array} ephemeralPublicKey - (K_A)
15089
+ * @param {Uint8Array} wrappedKey,
15090
+ * @param {Uint8Array} A - Recipient public key (K_b), needed for KDF
15091
+ * @param {Uint8Array} k - Recipient secret key (b)
15092
+ * @returns {Promise<Uint8Array>} decrypted session key data
15093
+ * @async
15094
+ */
15095
+ async function decrypt$4(algo, ephemeralPublicKey, wrappedKey, A, k) {
15096
+ switch (algo) {
15097
+ case enums.publicKey.x25519: {
15098
+ const sharedSecret = naclFastLight.scalarMult(k, ephemeralPublicKey);
15099
+ const hkdfInput = util.concatUint8Array([
15100
+ ephemeralPublicKey,
15101
+ A,
15102
+ sharedSecret
15103
+ ]);
15104
+ const { keySize } = getCipher(enums.symmetric.aes128);
15105
+ const encryptionKey = await HKDF(enums.hash.sha256, hkdfInput, new Uint8Array(), HKDF_INFO.x25519, keySize);
15106
+ return unwrap(encryptionKey, wrappedKey);
15107
+ }
15108
+ default:
15109
+ throw new Error('Unsupported ECDH algorithm');
15110
+ }
15111
+ }
15112
+
15113
+ var ecdh_x = /*#__PURE__*/Object.freeze({
15114
+ __proto__: null,
15115
+ generate: generate$3,
15116
+ validateParams: validateParams$6,
15117
+ encrypt: encrypt$4,
15118
+ decrypt: decrypt$4
15119
+ });
15120
+
14759
15121
  // OpenPGP.js - An OpenPGP implementation in javascript
14760
15122
 
14761
15123
  var elliptic = /*#__PURE__*/Object.freeze({
14762
15124
  __proto__: null,
14763
- Curve: Curve,
15125
+ CurveWithOID: CurveWithOID,
14764
15126
  ecdh: ecdh,
15127
+ ecdhX: ecdh_x,
14765
15128
  ecdsa: ecdsa,
15129
+ eddsaLegacy: eddsa_legacy,
14766
15130
  eddsa: eddsa,
14767
15131
  generate: generate$1,
14768
15132
  getPreferredHashAlgo: getPreferredHashAlgo
@@ -14787,7 +15151,7 @@ var openpgp = (function (exports) {
14787
15151
  * @returns {Promise<{ r: Uint8Array, s: Uint8Array }>}
14788
15152
  * @async
14789
15153
  */
14790
- async function sign$3(hashAlgo, hashed, g, p, q, x) {
15154
+ async function sign$4(hashAlgo, hashed, g, p, q, x) {
14791
15155
  const BigInteger = await util.getBigInteger();
14792
15156
  const one = new BigInteger(1);
14793
15157
  p = new BigInteger(p);
@@ -14846,7 +15210,7 @@ var openpgp = (function (exports) {
14846
15210
  * @returns {boolean}
14847
15211
  * @async
14848
15212
  */
14849
- async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
15213
+ async function verify$4(hashAlgo, r, s, hashed, g, p, q, y) {
14850
15214
  const BigInteger = await util.getBigInteger();
14851
15215
  const zero = new BigInteger(0);
14852
15216
  r = new BigInteger(r);
@@ -14889,7 +15253,7 @@ var openpgp = (function (exports) {
14889
15253
  * @returns {Promise<Boolean>} Whether params are valid.
14890
15254
  * @async
14891
15255
  */
14892
- async function validateParams$5(p, q, g, y, x) {
15256
+ async function validateParams$7(p, q, g, y, x) {
14893
15257
  const BigInteger = await util.getBigInteger();
14894
15258
  p = new BigInteger(p);
14895
15259
  q = new BigInteger(q);
@@ -14944,9 +15308,9 @@ var openpgp = (function (exports) {
14944
15308
 
14945
15309
  var dsa = /*#__PURE__*/Object.freeze({
14946
15310
  __proto__: null,
14947
- sign: sign$3,
14948
- verify: verify$3,
14949
- validateParams: validateParams$5
15311
+ sign: sign$4,
15312
+ verify: verify$4,
15313
+ validateParams: validateParams$7
14950
15314
  });
14951
15315
 
14952
15316
  /**
@@ -15082,10 +15446,10 @@ var openpgp = (function (exports) {
15082
15446
  const s = util.readMPI(signature.subarray(read));
15083
15447
  return { r, s };
15084
15448
  }
15085
- // Algorithm-Specific Fields for EdDSA signatures:
15449
+ // Algorithm-Specific Fields for legacy EdDSA signatures:
15086
15450
  // - MPI of an EC point r.
15087
15451
  // - EdDSA value s, in MPI, in the little endian representation
15088
- case enums.publicKey.eddsa: {
15452
+ case enums.publicKey.eddsaLegacy: {
15089
15453
  // When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
15090
15454
  // https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
15091
15455
  let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
@@ -15094,7 +15458,12 @@ var openpgp = (function (exports) {
15094
15458
  s = util.leftPad(s, 32);
15095
15459
  return { r, s };
15096
15460
  }
15097
-
15461
+ // Algorithm-Specific Fields for Ed25519 signatures:
15462
+ // - 64 octets of the native signature
15463
+ case enums.publicKey.ed25519: {
15464
+ const RS = signature.subarray(read, read + 64); read += RS.length;
15465
+ return { RS };
15466
+ }
15098
15467
  case enums.publicKey.hmac: {
15099
15468
  const mac = new ShortByteString(); mac.read(signature.subarray(read));
15100
15469
  return { mac };
@@ -15119,7 +15488,7 @@ var openpgp = (function (exports) {
15119
15488
  * @returns {Promise<Boolean>} True if signature is valid.
15120
15489
  * @async
15121
15490
  */
15122
- async function verify$4(algo, hashAlgo, signature, publicParams, privateParams, data, hashed) {
15491
+ async function verify$5(algo, hashAlgo, signature, publicParams, privateParams, data, hashed) {
15123
15492
  switch (algo) {
15124
15493
  case enums.publicKey.rsaEncryptSign:
15125
15494
  case enums.publicKey.rsaEncrypt:
@@ -15135,16 +15504,20 @@ var openpgp = (function (exports) {
15135
15504
  }
15136
15505
  case enums.publicKey.ecdsa: {
15137
15506
  const { oid, Q } = publicParams;
15138
- const curveSize = new publicKey.elliptic.Curve(oid).payloadSize;
15507
+ const curveSize = new publicKey.elliptic.CurveWithOID(oid).payloadSize;
15139
15508
  // padding needed for webcrypto
15140
15509
  const r = util.leftPad(signature.r, curveSize);
15141
15510
  const s = util.leftPad(signature.s, curveSize);
15142
15511
  return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
15143
15512
  }
15144
- case enums.publicKey.eddsa: {
15513
+ case enums.publicKey.eddsaLegacy: {
15145
15514
  const { oid, Q } = publicParams;
15146
15515
  // signature already padded on parsing
15147
- return publicKey.elliptic.eddsa.verify(oid, hashAlgo, signature, data, Q, hashed);
15516
+ return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
15517
+ }
15518
+ case enums.publicKey.ed25519: {
15519
+ const { A } = publicParams;
15520
+ return publicKey.elliptic.eddsa.verify(algo, hashAlgo, signature, data, A, hashed);
15148
15521
  }
15149
15522
  case enums.publicKey.hmac: {
15150
15523
  if (!privateParams) {
@@ -15174,7 +15547,7 @@ var openpgp = (function (exports) {
15174
15547
  * @returns {Promise<Object>} Signature Object containing named signature parameters.
15175
15548
  * @async
15176
15549
  */
15177
- async function sign$4(algo, hashAlgo, publicKeyParams, privateKeyParams, data, hashed) {
15550
+ async function sign$5(algo, hashAlgo, publicKeyParams, privateKeyParams, data, hashed) {
15178
15551
  if (!publicKeyParams || !privateKeyParams) {
15179
15552
  throw new Error('Missing key parameters');
15180
15553
  }
@@ -15200,10 +15573,15 @@ var openpgp = (function (exports) {
15200
15573
  const { d } = privateKeyParams;
15201
15574
  return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
15202
15575
  }
15203
- case enums.publicKey.eddsa: {
15576
+ case enums.publicKey.eddsaLegacy: {
15204
15577
  const { oid, Q } = publicKeyParams;
15205
15578
  const { seed } = privateKeyParams;
15206
- return publicKey.elliptic.eddsa.sign(oid, hashAlgo, data, Q, seed, hashed);
15579
+ return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
15580
+ }
15581
+ case enums.publicKey.ed25519: {
15582
+ const { A } = publicKeyParams;
15583
+ const { seed } = privateKeyParams;
15584
+ return publicKey.elliptic.eddsa.sign(algo, hashAlgo, data, A, seed, hashed);
15207
15585
  }
15208
15586
  case enums.publicKey.hmac: {
15209
15587
  const { cipher: algo } = publicKeyParams;
@@ -15219,34 +15597,31 @@ var openpgp = (function (exports) {
15219
15597
  var signature = /*#__PURE__*/Object.freeze({
15220
15598
  __proto__: null,
15221
15599
  parseSignatureParams: parseSignatureParams,
15222
- verify: verify$4,
15223
- sign: sign$4
15600
+ verify: verify$5,
15601
+ sign: sign$5
15224
15602
  });
15225
15603
 
15226
15604
  // OpenPGP.js - An OpenPGP implementation in javascript
15227
15605
 
15228
15606
  class ECDHSymmetricKey {
15229
15607
  constructor(data) {
15230
- if (typeof data === 'undefined') {
15231
- data = new Uint8Array([]);
15232
- } else if (util.isString(data)) {
15233
- data = util.stringToUint8Array(data);
15234
- } else {
15235
- data = new Uint8Array(data);
15608
+ if (data) {
15609
+ this.data = data;
15236
15610
  }
15237
- this.data = data;
15238
15611
  }
15239
15612
 
15240
15613
  /**
15241
- * Read an ECDHSymmetricKey from an Uint8Array
15242
- * @param {Uint8Array} input - Where to read the encoded symmetric key from
15614
+ * Read an ECDHSymmetricKey from an Uint8Array:
15615
+ * - 1 octect for the length `l`
15616
+ * - `l` octects of encoded session key data
15617
+ * @param {Uint8Array} bytes
15243
15618
  * @returns {Number} Number of read bytes.
15244
15619
  */
15245
- read(input) {
15246
- if (input.length >= 1) {
15247
- const length = input[0];
15248
- if (input.length >= 1 + length) {
15249
- this.data = input.subarray(1, 1 + length);
15620
+ read(bytes) {
15621
+ if (bytes.length >= 1) {
15622
+ const length = bytes[0];
15623
+ if (bytes.length >= 1 + length) {
15624
+ this.data = bytes.subarray(1, 1 + length);
15250
15625
  return 1 + this.data.length;
15251
15626
  }
15252
15627
  }
@@ -15255,7 +15630,7 @@ var openpgp = (function (exports) {
15255
15630
 
15256
15631
  /**
15257
15632
  * Write an ECDHSymmetricKey as an Uint8Array
15258
- * @returns {Uint8Array} An array containing the value
15633
+ * @returns {Uint8Array} Serialised data
15259
15634
  */
15260
15635
  write() {
15261
15636
  return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
@@ -15295,6 +15670,9 @@ var openpgp = (function (exports) {
15295
15670
  * @returns {Number} Number of read bytes.
15296
15671
  */
15297
15672
  read(input) {
15673
+ if (input.length < 4 || (input[1] !== 1 && input[1] !== VERSION_FORWARDING)) {
15674
+ throw new UnsupportedError('Cannot read KDFParams');
15675
+ }
15298
15676
  const totalBytes = input[0];
15299
15677
  this.version = input[1];
15300
15678
  this.hash = input[2];
@@ -15382,12 +15760,57 @@ var openpgp = (function (exports) {
15382
15760
  const SymAlgoEnum = type_enum(enums.symmetric);
15383
15761
  const HashEnum = type_enum(enums.hash);
15384
15762
 
15763
+ /**
15764
+ * Encoded symmetric key for x25519 and x448
15765
+ * The payload format varies for v3 and v6 PKESK:
15766
+ * the former includes an algorithm byte preceeding the encrypted session key.
15767
+ *
15768
+ * @module type/x25519x448_symkey
15769
+ */
15770
+
15771
+ class ECDHXSymmetricKey {
15772
+ static fromObject({ wrappedKey, algorithm }) {
15773
+ const instance = new ECDHXSymmetricKey();
15774
+ instance.wrappedKey = wrappedKey;
15775
+ instance.algorithm = algorithm;
15776
+ return instance;
15777
+ }
15778
+
15779
+ /**
15780
+ * - 1 octect for the length `l`
15781
+ * - `l` octects of encoded session key data (with optional leading algorithm byte)
15782
+ * @param {Uint8Array} bytes
15783
+ * @returns {Number} Number of read bytes.
15784
+ */
15785
+ read(bytes) {
15786
+ let read = 0;
15787
+ let followLength = bytes[read++];
15788
+ this.algorithm = followLength % 2 ? bytes[read++] : null; // session key size is always even
15789
+ followLength -= followLength % 2;
15790
+ this.wrappedKey = bytes.subarray(read, read + followLength); read += followLength;
15791
+ }
15792
+
15793
+ /**
15794
+ * Write an MontgomerySymmetricKey as an Uint8Array
15795
+ * @returns {Uint8Array} Serialised data
15796
+ */
15797
+ write() {
15798
+ return util.concatUint8Array([
15799
+ this.algorithm ?
15800
+ new Uint8Array([this.wrappedKey.length + 1, this.algorithm]) :
15801
+ new Uint8Array([this.wrappedKey.length]),
15802
+ this.wrappedKey
15803
+ ]);
15804
+ }
15805
+ }
15806
+
15385
15807
  // GPG4Browsers - An OpenPGP implementation in javascript
15386
15808
 
15387
15809
  /**
15388
15810
  * Encrypts data using specified algorithm and public key parameters.
15389
15811
  * See {@link https://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1} for public key algorithms.
15390
- * @param {module:enums.publicKey} algo - Public key algorithm
15812
+ * @param {module:enums.publicKey} keyAlgo - Public key algorithm
15813
+ * @param {module:enums.symmetric} symmetricAlgo - Cipher algorithm
15391
15814
  * @param {Object} publicParams - Algorithm-specific public key parameters
15392
15815
  * @param {Object} privateParams - Algorithm-specific private key parameters
15393
15816
  * @param {Uint8Array} data - Data to be encrypted
@@ -15395,8 +15818,8 @@ var openpgp = (function (exports) {
15395
15818
  * @returns {Promise<Object>} Encrypted session key parameters.
15396
15819
  * @async
15397
15820
  */
15398
- async function publicKeyEncrypt(algo, publicParams, privateParams, data, fingerprint) {
15399
- switch (algo) {
15821
+ async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privateParams, data, fingerprint) {
15822
+ switch (keyAlgo) {
15400
15823
  case enums.publicKey.rsaEncrypt:
15401
15824
  case enums.publicKey.rsaEncryptSign: {
15402
15825
  const { n, e } = publicParams;
@@ -15413,6 +15836,17 @@ var openpgp = (function (exports) {
15413
15836
  oid, kdfParams, data, Q, fingerprint);
15414
15837
  return { V, C: new ECDHSymmetricKey(C) };
15415
15838
  }
15839
+ case enums.publicKey.x25519: {
15840
+ if (!util.isAES(symmetricAlgo)) {
15841
+ // see https://gitlab.com/openpgp-wg/rfc4880bis/-/merge_requests/276
15842
+ throw new Error('X25519 keys can only encrypt AES session keys');
15843
+ }
15844
+ const { A } = publicParams;
15845
+ const { ephemeralPublicKey, wrappedKey } = await publicKey.elliptic.ecdhX.encrypt(
15846
+ keyAlgo, data, A);
15847
+ const C = ECDHXSymmetricKey.fromObject({ algorithm: symmetricAlgo, wrappedKey });
15848
+ return { ephemeralPublicKey, C };
15849
+ }
15416
15850
  case enums.publicKey.aead: {
15417
15851
  if (!privateParams) {
15418
15852
  throw new Error('Cannot encrypt with symmetric key missing private parameters');
@@ -15469,6 +15903,16 @@ var openpgp = (function (exports) {
15469
15903
  return publicKey.elliptic.ecdh.decrypt(
15470
15904
  oid, kdfParams, V, C.data, Q, d, fingerprint);
15471
15905
  }
15906
+ case enums.publicKey.x25519: {
15907
+ const { A } = publicKeyParams;
15908
+ const { k } = privateKeyParams;
15909
+ const { ephemeralPublicKey, C } = sessionKeyParams;
15910
+ if (!util.isAES(C.algorithm)) {
15911
+ throw new Error('AES session key expected');
15912
+ }
15913
+ return publicKey.elliptic.ecdhX.decrypt(
15914
+ algo, ephemeralPublicKey, C.wrappedKey, A, k);
15915
+ }
15472
15916
  case enums.publicKey.aead: {
15473
15917
  const { cipher: algo } = publicKeyParams;
15474
15918
  const algoValue = algo.getValue();
@@ -15520,7 +15964,7 @@ var openpgp = (function (exports) {
15520
15964
  const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
15521
15965
  return { read: read, publicParams: { oid, Q } };
15522
15966
  }
15523
- case enums.publicKey.eddsa: {
15967
+ case enums.publicKey.eddsaLegacy: {
15524
15968
  const oid = new OID(); read += oid.read(bytes);
15525
15969
  checkSupportedCurve(oid);
15526
15970
  let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
@@ -15534,6 +15978,11 @@ var openpgp = (function (exports) {
15534
15978
  const kdfParams = new KDFParams(); read += kdfParams.read(bytes.subarray(read));
15535
15979
  return { read: read, publicParams: { oid, Q, kdfParams } };
15536
15980
  }
15981
+ case enums.publicKey.ed25519:
15982
+ case enums.publicKey.x25519: {
15983
+ const A = bytes.subarray(read, read + 32); read += A.length;
15984
+ return { read, publicParams: { A } };
15985
+ }
15537
15986
  case enums.publicKey.hmac:
15538
15987
  case enums.publicKey.aead: {
15539
15988
  const algo = new SymAlgoEnum(); read += algo.read(bytes);
@@ -15572,17 +16021,25 @@ var openpgp = (function (exports) {
15572
16021
  }
15573
16022
  case enums.publicKey.ecdsa:
15574
16023
  case enums.publicKey.ecdh: {
15575
- const curve = new Curve(publicParams.oid);
16024
+ const curve = new CurveWithOID(publicParams.oid);
15576
16025
  let d = util.readMPI(bytes.subarray(read)); read += d.length + 2;
15577
16026
  d = util.leftPad(d, curve.payloadSize);
15578
16027
  return { read, privateParams: { d } };
15579
16028
  }
15580
- case enums.publicKey.eddsa: {
15581
- const curve = new Curve(publicParams.oid);
16029
+ case enums.publicKey.eddsaLegacy: {
16030
+ const curve = new CurveWithOID(publicParams.oid);
15582
16031
  let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
15583
16032
  seed = util.leftPad(seed, curve.payloadSize);
15584
16033
  return { read, privateParams: { seed } };
15585
16034
  }
16035
+ case enums.publicKey.ed25519: {
16036
+ const seed = bytes.subarray(read, read + 32); read += seed.length;
16037
+ return { read, privateParams: { seed } };
16038
+ }
16039
+ case enums.publicKey.x25519: {
16040
+ const k = bytes.subarray(read, read + 32); read += k.length;
16041
+ return { read, privateParams: { k } };
16042
+ }
15586
16043
  case enums.publicKey.hmac: {
15587
16044
  const { cipher: algo } = publicParams;
15588
16045
  const keySize = hash.getHashByteLength(algo.getValue());
@@ -15634,6 +16091,16 @@ var openpgp = (function (exports) {
15634
16091
  const C = new ECDHSymmetricKey(); C.read(bytes.subarray(read));
15635
16092
  return { V, C };
15636
16093
  }
16094
+ // Algorithm-Specific Fields for X25519 encrypted session keys:
16095
+ // - 32 octets representing an ephemeral X25519 public key.
16096
+ // - A one-octet size of the following fields.
16097
+ // - The one-octet algorithm identifier, if it was passed (in the case of a v3 PKESK packet).
16098
+ // - The encrypted session key.
16099
+ case enums.publicKey.x25519: {
16100
+ const ephemeralPublicKey = bytes.subarray(read, read + 32); read += ephemeralPublicKey.length;
16101
+ const C = new ECDHXSymmetricKey(); C.read(bytes.subarray(read));
16102
+ return { ephemeralPublicKey, C };
16103
+ }
15637
16104
  // Algorithm-Specific Fields for symmetric AEAD encryption:
15638
16105
  // - AEAD algorithm
15639
16106
  // - Starting initialization vector
@@ -15660,22 +16127,13 @@ var openpgp = (function (exports) {
15660
16127
  * @returns {Uint8Array} The array containing the MPIs.
15661
16128
  */
15662
16129
  function serializeParams(algo, params) {
15663
- let orderedParams;
15664
- switch (algo) {
15665
- case enums.publicKey.hmac:
15666
- case enums.publicKey.aead: {
15667
- orderedParams = Object.keys(params).map(name => {
15668
- const param = params[name];
15669
- return util.isUint8Array(param) ? param : param.write();
15670
- });
15671
- break;
15672
- }
15673
- default:
15674
- orderedParams = Object.keys(params).map(name => {
15675
- const param = params[name];
15676
- return util.isUint8Array(param) ? util.uint8ArrayToMPI(param) : param.write();
15677
- });
15678
- }
16130
+ // Some algorithms do not rely on MPIs to store the binary params
16131
+ const algosWithNativeRepresentation = new Set([enums.publicKey.ed25519, enums.publicKey.x25519, enums.publicKey.aead, enums.publicKey.hmac]);
16132
+ const orderedParams = Object.keys(params).map(name => {
16133
+ const param = params[name];
16134
+ if (!util.isUint8Array(param)) return param.write();
16135
+ return algosWithNativeRepresentation.has(algo) ? param : util.uint8ArrayToMPI(param);
16136
+ });
15679
16137
  return util.concatUint8Array(orderedParams);
15680
16138
  }
15681
16139
 
@@ -15703,7 +16161,7 @@ var openpgp = (function (exports) {
15703
16161
  privateParams: { d: secret },
15704
16162
  publicParams: { oid: new OID(oid), Q }
15705
16163
  }));
15706
- case enums.publicKey.eddsa:
16164
+ case enums.publicKey.eddsaLegacy:
15707
16165
  return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
15708
16166
  privateParams: { seed: secret },
15709
16167
  publicParams: { oid: new OID(oid), Q }
@@ -15717,6 +16175,16 @@ var openpgp = (function (exports) {
15717
16175
  kdfParams: new KDFParams({ hash, cipher })
15718
16176
  }
15719
16177
  }));
16178
+ case enums.publicKey.ed25519:
16179
+ return publicKey.elliptic.eddsa.generate(algo).then(({ A, seed }) => ({
16180
+ privateParams: { seed },
16181
+ publicParams: { A }
16182
+ }));
16183
+ case enums.publicKey.x25519:
16184
+ return publicKey.elliptic.ecdhX.generate(algo).then(({ A, k }) => ({
16185
+ privateParams: { k },
16186
+ publicParams: { A }
16187
+ }));
15720
16188
  case enums.publicKey.hmac: {
15721
16189
  const symAlgo = enums.write(enums.hash, symmetric);
15722
16190
  const keyMaterial = getRandomBytes(hash.getHashByteLength(symAlgo));
@@ -15758,7 +16226,7 @@ var openpgp = (function (exports) {
15758
16226
  * @returns {Promise<Boolean>} Whether the parameters are valid.
15759
16227
  * @async
15760
16228
  */
15761
- async function validateParams$6(algo, publicParams, privateParams) {
16229
+ async function validateParams$8(algo, publicParams, privateParams) {
15762
16230
  if (!publicParams || !privateParams) {
15763
16231
  throw new Error('Missing key parameters');
15764
16232
  }
@@ -15787,10 +16255,20 @@ var openpgp = (function (exports) {
15787
16255
  const { d } = privateParams;
15788
16256
  return algoModule.validateParams(oid, Q, d);
15789
16257
  }
15790
- case enums.publicKey.eddsa: {
15791
- const { oid, Q } = publicParams;
16258
+ case enums.publicKey.eddsaLegacy: {
16259
+ const { Q, oid } = publicParams;
16260
+ const { seed } = privateParams;
16261
+ return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
16262
+ }
16263
+ case enums.publicKey.ed25519: {
16264
+ const { A } = publicParams;
15792
16265
  const { seed } = privateParams;
15793
- return publicKey.elliptic.eddsa.validateParams(oid, Q, seed);
16266
+ return publicKey.elliptic.eddsa.validateParams(algo, A, seed);
16267
+ }
16268
+ case enums.publicKey.x25519: {
16269
+ const { A } = publicParams;
16270
+ const { k } = privateParams;
16271
+ return publicKey.elliptic.ecdhX.validateParams(algo, A, k);
15794
16272
  }
15795
16273
  case enums.publicKey.hmac: {
15796
16274
  const { cipher: algo, digest } = publicParams;
@@ -15860,6 +16338,23 @@ var openpgp = (function (exports) {
15860
16338
  }
15861
16339
  }
15862
16340
 
16341
+ /**
16342
+ * Get preferred hash algo for a given elliptic algo
16343
+ * @param {module:enums.publicKey} algo - alrogithm identifier
16344
+ * @param {module:type/oid} [oid] - curve OID if needed by algo
16345
+ */
16346
+ function getPreferredCurveHashAlgo(algo, oid) {
16347
+ switch (algo) {
16348
+ case enums.publicKey.ecdsa:
16349
+ case enums.publicKey.eddsaLegacy:
16350
+ return publicKey.elliptic.getPreferredHashAlgo(oid);
16351
+ case enums.publicKey.ed25519:
16352
+ return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
16353
+ default:
16354
+ throw new Error('Unknown elliptic signing algo');
16355
+ }
16356
+ }
16357
+
15863
16358
  var crypto$1 = /*#__PURE__*/Object.freeze({
15864
16359
  __proto__: null,
15865
16360
  publicKeyEncrypt: publicKeyEncrypt,
@@ -15869,11 +16364,12 @@ var openpgp = (function (exports) {
15869
16364
  parseEncSessionKeyParams: parseEncSessionKeyParams,
15870
16365
  serializeParams: serializeParams,
15871
16366
  generateParams: generateParams,
15872
- validateParams: validateParams$6,
16367
+ validateParams: validateParams$8,
15873
16368
  getPrefixRandom: getPrefixRandom,
15874
16369
  generateSessionKey: generateSessionKey,
15875
16370
  getAEADMode: getAEADMode,
15876
- getCipher: getCipher
16371
+ getCipher: getCipher,
16372
+ getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
15877
16373
  });
15878
16374
 
15879
16375
  /**
@@ -16116,15 +16612,15 @@ var openpgp = (function (exports) {
16116
16612
  this.type = 'gnu-dummy';
16117
16613
  // GnuPG extension mode 1001 -- don't write secret key at all
16118
16614
  } else {
16119
- throw new Error('Unknown s2k gnu protection mode.');
16615
+ throw new UnsupportedError('Unknown s2k gnu protection mode.');
16120
16616
  }
16121
16617
  } else {
16122
- throw new Error('Unknown s2k type.');
16618
+ throw new UnsupportedError('Unknown s2k type.');
16123
16619
  }
16124
16620
  break;
16125
16621
 
16126
16622
  default:
16127
- throw new Error('Unknown s2k type.');
16623
+ throw new UnsupportedError('Unknown s2k type.'); // unreachable
16128
16624
  }
16129
16625
 
16130
16626
  return i;
@@ -16228,7 +16724,7 @@ var openpgp = (function (exports) {
16228
16724
  case enums.s2k.simple:
16229
16725
  return new GenericS2K(type, config$1);
16230
16726
  default:
16231
- throw new Error(`Unsupported S2K type ${type}`);
16727
+ throw new UnsupportedError(`Unsupported S2K type ${type}`);
16232
16728
  }
16233
16729
  }
16234
16730
 
@@ -24982,13 +25478,17 @@ var openpgp = (function (exports) {
24982
25478
  * @param {Uint8Array} bytes - Payload of a tag 1 packet
24983
25479
  */
24984
25480
  read(bytes) {
24985
- this.version = bytes[0];
25481
+ let i = 0;
25482
+ this.version = bytes[i++];
24986
25483
  if (this.version !== VERSION$3) {
24987
25484
  throw new UnsupportedError(`Version ${this.version} of the PKESK packet is unsupported.`);
24988
25485
  }
24989
- this.publicKeyID.read(bytes.subarray(1, bytes.length));
24990
- this.publicKeyAlgorithm = bytes[9];
24991
- this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(10));
25486
+ i += this.publicKeyID.read(bytes.subarray(i));
25487
+ this.publicKeyAlgorithm = bytes[i++];
25488
+ this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(i), this.version);
25489
+ if (this.publicKeyAlgorithm === enums.publicKey.x25519) {
25490
+ this.sessionKeyAlgorithm = enums.write(enums.symmetric, this.encrypted.C.algorithm);
25491
+ }
24992
25492
  }
24993
25493
 
24994
25494
  /**
@@ -25014,15 +25514,11 @@ var openpgp = (function (exports) {
25014
25514
  * @async
25015
25515
  */
25016
25516
  async encrypt(key) {
25017
- const data = util.concatUint8Array([
25018
- new Uint8Array([enums.write(enums.symmetric, this.sessionKeyAlgorithm)]),
25019
- this.sessionKey,
25020
- util.writeChecksum(this.sessionKey)
25021
- ]);
25022
25517
  const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
25518
+ const encoded = encodeSessionKey(this.version, algo, this.sessionKeyAlgorithm, this.sessionKey);
25023
25519
  const privateParams = algo === enums.publicKey.aead ? key.privateParams : null;
25024
25520
  this.encrypted = await mod.publicKeyEncrypt(
25025
- algo, key.publicParams, privateParams, data, key.getFingerprintBytes());
25521
+ algo, this.sessionKeyAlgorithm, key.publicParams, privateParams, encoded, key.getFingerprintBytes());
25026
25522
  }
25027
25523
 
25028
25524
  /**
@@ -25039,34 +25535,86 @@ var openpgp = (function (exports) {
25039
25535
  throw new Error('Decryption error');
25040
25536
  }
25041
25537
 
25042
- const randomPayload = randomSessionKey ? util.concatUint8Array([
25043
- new Uint8Array([randomSessionKey.sessionKeyAlgorithm]),
25044
- randomSessionKey.sessionKey,
25045
- util.writeChecksum(randomSessionKey.sessionKey)
25046
- ]) : null;
25047
- const decoded = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
25048
- const symmetricAlgoByte = decoded[0];
25049
- const sessionKey = decoded.subarray(1, decoded.length - 2);
25050
- const checksum = decoded.subarray(decoded.length - 2);
25051
- const computedChecksum = util.writeChecksum(sessionKey);
25052
- const isValidChecksum = computedChecksum[0] === checksum[0] & computedChecksum[1] === checksum[1];
25053
-
25054
- if (randomSessionKey) {
25055
- // We must not leak info about the validity of the decrypted checksum or cipher algo.
25056
- // The decrypted session key must be of the same algo and size as the random session key, otherwise we discard it and use the random data.
25057
- const isValidPayload = isValidChecksum & symmetricAlgoByte === randomSessionKey.sessionKeyAlgorithm & sessionKey.length === randomSessionKey.sessionKey.length;
25058
- this.sessionKeyAlgorithm = util.selectUint8(isValidPayload, symmetricAlgoByte, randomSessionKey.sessionKeyAlgorithm);
25059
- this.sessionKey = util.selectUint8Array(isValidPayload, sessionKey, randomSessionKey.sessionKey);
25538
+ const randomPayload = randomSessionKey ?
25539
+ encodeSessionKey(this.version, this.publicKeyAlgorithm, randomSessionKey.sessionKeyAlgorithm, randomSessionKey.sessionKey) :
25540
+ null;
25541
+ const decryptedData = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
25060
25542
 
25061
- } else {
25062
- const isValidPayload = isValidChecksum && enums.read(enums.symmetric, symmetricAlgoByte);
25063
- if (isValidPayload) {
25064
- this.sessionKey = sessionKey;
25065
- this.sessionKeyAlgorithm = symmetricAlgoByte;
25543
+ const { sessionKey, sessionKeyAlgorithm } = decodeSessionKey(this.version, this.publicKeyAlgorithm, decryptedData, randomSessionKey);
25544
+
25545
+ // v3 Montgomery curves have cleartext cipher algo
25546
+ if (this.publicKeyAlgorithm !== enums.publicKey.x25519) {
25547
+ this.sessionKeyAlgorithm = sessionKeyAlgorithm;
25548
+ }
25549
+ this.sessionKey = sessionKey;
25550
+ }
25551
+ }
25552
+
25553
+
25554
+ function encodeSessionKey(version, keyAlgo, cipherAlgo, sessionKeyData) {
25555
+ switch (keyAlgo) {
25556
+ case enums.publicKey.rsaEncrypt:
25557
+ case enums.publicKey.rsaEncryptSign:
25558
+ case enums.publicKey.elgamal:
25559
+ case enums.publicKey.ecdh:
25560
+ case enums.publicKey.aead: {
25561
+ // add checksum
25562
+ return util.concatUint8Array([
25563
+ new Uint8Array([cipherAlgo]),
25564
+ sessionKeyData,
25565
+ util.writeChecksum(sessionKeyData.subarray(sessionKeyData.length % 8))
25566
+ ]);
25567
+ }
25568
+ case enums.publicKey.x25519:
25569
+ return sessionKeyData;
25570
+ default:
25571
+ throw new Error('Unsupported public key algorithm');
25572
+ }
25573
+ }
25574
+
25575
+
25576
+ function decodeSessionKey(version, keyAlgo, decryptedData, randomSessionKey) {
25577
+ switch (keyAlgo) {
25578
+ case enums.publicKey.rsaEncrypt:
25579
+ case enums.publicKey.rsaEncryptSign:
25580
+ case enums.publicKey.elgamal:
25581
+ case enums.publicKey.ecdh:
25582
+ case enums.publicKey.aead: {
25583
+ // verify checksum in constant time
25584
+ const result = decryptedData.subarray(0, decryptedData.length - 2);
25585
+ const checksum = decryptedData.subarray(decryptedData.length - 2);
25586
+ const computedChecksum = util.writeChecksum(result.subarray(result.length % 8));
25587
+ const isValidChecksum = computedChecksum[0] === checksum[0] & computedChecksum[1] === checksum[1];
25588
+ const decryptedSessionKey = { sessionKeyAlgorithm: result[0], sessionKey: result.subarray(1) };
25589
+ if (randomSessionKey) {
25590
+ // We must not leak info about the validity of the decrypted checksum or cipher algo.
25591
+ // The decrypted session key must be of the same algo and size as the random session key, otherwise we discard it and use the random data.
25592
+ const isValidPayload = isValidChecksum &
25593
+ decryptedSessionKey.sessionKeyAlgorithm === randomSessionKey.sessionKeyAlgorithm &
25594
+ decryptedSessionKey.sessionKey.length === randomSessionKey.sessionKey.length;
25595
+ return {
25596
+ sessionKey: util.selectUint8Array(isValidPayload, decryptedSessionKey.sessionKey, randomSessionKey.sessionKey),
25597
+ sessionKeyAlgorithm: util.selectUint8(
25598
+ isValidPayload,
25599
+ decryptedSessionKey.sessionKeyAlgorithm,
25600
+ randomSessionKey.sessionKeyAlgorithm
25601
+ )
25602
+ };
25066
25603
  } else {
25067
- throw new Error('Decryption error');
25604
+ const isValidPayload = isValidChecksum && enums.read(enums.symmetric, decryptedSessionKey.sessionKeyAlgorithm);
25605
+ if (isValidPayload) {
25606
+ return decryptedSessionKey;
25607
+ } else {
25608
+ throw new Error('Decryption error');
25609
+ }
25068
25610
  }
25069
25611
  }
25612
+ case enums.publicKey.x25519:
25613
+ return {
25614
+ sessionKey: decryptedData
25615
+ };
25616
+ default:
25617
+ throw new Error('Unsupported public key algorithm');
25070
25618
  }
25071
25619
  }
25072
25620
 
@@ -25497,7 +26045,7 @@ var openpgp = (function (exports) {
25497
26045
  result.bits = util.uint8ArrayBitLength(modulo);
25498
26046
  } else if (this.publicParams.oid) {
25499
26047
  result.curve = this.publicParams.oid.getName();
25500
- } else {
26048
+ } else if (this.publicParams.cipher) {
25501
26049
  result.symmetric = this.publicParams.cipher.getName();
25502
26050
  }
25503
26051
  return result;
@@ -25829,6 +26377,7 @@ var openpgp = (function (exports) {
25829
26377
  async read(bytes) {
25830
26378
  // - A Public-Key or Public-Subkey packet, as described above.
25831
26379
  let i = await this.readPublicKey(bytes);
26380
+ const startOfSecretKeyData = i;
25832
26381
 
25833
26382
  // - One octet indicating string-to-key usage conventions. Zero
25834
26383
  // indicates that the secret-key data is not encrypted. 255 or 254
@@ -25842,41 +26391,48 @@ var openpgp = (function (exports) {
25842
26391
  i++;
25843
26392
  }
25844
26393
 
25845
- // - [Optional] If string-to-key usage octet was 255, 254, or 253, a
25846
- // one-octet symmetric encryption algorithm.
25847
- if (this.s2kUsage === 255 || this.s2kUsage === 254 || this.s2kUsage === 253) {
25848
- this.symmetric = bytes[i++];
26394
+ try {
26395
+ // - [Optional] If string-to-key usage octet was 255, 254, or 253, a
26396
+ // one-octet symmetric encryption algorithm.
26397
+ if (this.s2kUsage === 255 || this.s2kUsage === 254 || this.s2kUsage === 253) {
26398
+ this.symmetric = bytes[i++];
25849
26399
 
25850
- // - [Optional] If string-to-key usage octet was 253, a one-octet
25851
- // AEAD algorithm.
25852
- if (this.s2kUsage === 253) {
25853
- this.aead = bytes[i++];
25854
- }
26400
+ // - [Optional] If string-to-key usage octet was 253, a one-octet
26401
+ // AEAD algorithm.
26402
+ if (this.s2kUsage === 253) {
26403
+ this.aead = bytes[i++];
26404
+ }
25855
26405
 
25856
- // - [Optional] If string-to-key usage octet was 255, 254, or 253, a
25857
- // string-to-key specifier. The length of the string-to-key
25858
- // specifier is implied by its type, as described above.
25859
- const s2kType = bytes[i++];
25860
- this.s2k = newS2KFromType(s2kType);
25861
- i += this.s2k.read(bytes.subarray(i, bytes.length));
26406
+ // - [Optional] If string-to-key usage octet was 255, 254, or 253, a
26407
+ // string-to-key specifier. The length of the string-to-key
26408
+ // specifier is implied by its type, as described above.
26409
+ const s2kType = bytes[i++];
26410
+ this.s2k = newS2KFromType(s2kType);
26411
+ i += this.s2k.read(bytes.subarray(i, bytes.length));
25862
26412
 
25863
- if (this.s2k.type === 'gnu-dummy') {
25864
- return;
26413
+ if (this.s2k.type === 'gnu-dummy') {
26414
+ return;
26415
+ }
26416
+ } else if (this.s2kUsage) {
26417
+ this.symmetric = this.s2kUsage;
25865
26418
  }
25866
- } else if (this.s2kUsage) {
25867
- this.symmetric = this.s2kUsage;
25868
- }
25869
26419
 
25870
- // - [Optional] If secret data is encrypted (string-to-key usage octet
25871
- // not zero), an Initial Vector (IV) of the same length as the
25872
- // cipher's block size.
25873
- if (this.s2kUsage) {
25874
- this.iv = bytes.subarray(
25875
- i,
25876
- i + mod.getCipher(this.symmetric).blockSize
25877
- );
26420
+ // - [Optional] If secret data is encrypted (string-to-key usage octet
26421
+ // not zero), an Initial Vector (IV) of the same length as the
26422
+ // cipher's block size.
26423
+ if (this.s2kUsage) {
26424
+ this.iv = bytes.subarray(
26425
+ i,
26426
+ i + mod.getCipher(this.symmetric).blockSize
26427
+ );
25878
26428
 
25879
- i += this.iv.length;
26429
+ i += this.iv.length;
26430
+ }
26431
+ } catch (e) {
26432
+ // if the s2k is unsupported, we still want to support encrypting and verifying with the given key
26433
+ if (!this.s2kUsage) throw e; // always throw for decrypted keys
26434
+ this.unparseableKeyMaterial = bytes.subarray(startOfSecretKeyData);
26435
+ this.isEncrypted = true;
25880
26436
  }
25881
26437
 
25882
26438
  // - Only for a version 5 packet, a four-octet scalar octet count for
@@ -25912,8 +26468,15 @@ var openpgp = (function (exports) {
25912
26468
  * @returns {Uint8Array} A string of bytes containing the secret key OpenPGP packet.
25913
26469
  */
25914
26470
  write() {
25915
- const arr = [this.writePublicKey()];
26471
+ const serializedPublicKey = this.writePublicKey();
26472
+ if (this.unparseableKeyMaterial) {
26473
+ return util.concatUint8Array([
26474
+ serializedPublicKey,
26475
+ this.unparseableKeyMaterial
26476
+ ]);
26477
+ }
25916
26478
 
26479
+ const arr = [serializedPublicKey];
25917
26480
  arr.push(new Uint8Array([this.s2kUsage]));
25918
26481
 
25919
26482
  const optionalFieldsArr = [];
@@ -25973,6 +26536,18 @@ var openpgp = (function (exports) {
25973
26536
  return this.isEncrypted === false;
25974
26537
  }
25975
26538
 
26539
+ /**
26540
+ * Check whether the key includes secret key material.
26541
+ * Some secret keys do not include it, and can thus only be used
26542
+ * for public-key operations (encryption and verification).
26543
+ * Such keys are:
26544
+ * - GNU-dummy keys, where the secret material has been stripped away
26545
+ * - encrypted keys with unsupported S2K or cipher
26546
+ */
26547
+ isMissingSecretKeyMaterial() {
26548
+ return this.unparseableKeyMaterial !== undefined || this.isDummy();
26549
+ }
26550
+
25976
26551
  /**
25977
26552
  * Check whether this is a gnu-dummy key
25978
26553
  * @returns {Boolean}
@@ -25993,6 +26568,7 @@ var openpgp = (function (exports) {
25993
26568
  if (this.isDecrypted()) {
25994
26569
  this.clearPrivateParams();
25995
26570
  }
26571
+ delete this.unparseableKeyMaterial;
25996
26572
  this.isEncrypted = null;
25997
26573
  this.keyMaterial = null;
25998
26574
  this.s2k = newS2KFromType(enums.s2k.gnu, config$1);
@@ -26064,6 +26640,10 @@ var openpgp = (function (exports) {
26064
26640
  return false;
26065
26641
  }
26066
26642
 
26643
+ if (this.unparseableKeyMaterial) {
26644
+ throw new Error('Key packet cannot be decrypted: unsupported S2K or cipher algo');
26645
+ }
26646
+
26067
26647
  if (this.isDecrypted()) {
26068
26648
  throw new Error('Key packet is already decrypted.');
26069
26649
  }
@@ -26148,7 +26728,7 @@ var openpgp = (function (exports) {
26148
26728
  * Clear private key parameters
26149
26729
  */
26150
26730
  clearPrivateParams() {
26151
- if (this.isDummy()) {
26731
+ if (this.isMissingSecretKeyMaterial()) {
26152
26732
  return;
26153
26733
  }
26154
26734
 
@@ -27547,25 +28127,22 @@ var openpgp = (function (exports) {
27547
28127
  const dataToSign = {};
27548
28128
  dataToSign.key = primaryKey;
27549
28129
  dataToSign.bind = subkey;
27550
- const subkeySignaturePacket = new SignaturePacket();
27551
- subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
27552
- subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
27553
- subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
28130
+ const signatureProperties = { signatureType: enums.signature.subkeyBinding };
27554
28131
  if (options.sign) {
27555
- subkeySignaturePacket.keyFlags = [enums.keyFlags.signData];
27556
- subkeySignaturePacket.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
28132
+ signatureProperties.keyFlags = [enums.keyFlags.signData];
28133
+ signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
27557
28134
  signatureType: enums.signature.keyBinding
27558
28135
  }, options.date, undefined, undefined, undefined, config);
27559
28136
  } else {
27560
- subkeySignaturePacket.keyFlags = options.forwarding ?
28137
+ signatureProperties.keyFlags = options.forwarding ?
27561
28138
  [enums.keyFlags.forwardedCommunication] :
27562
28139
  [enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
27563
28140
  }
27564
28141
  if (options.keyExpirationTime > 0) {
27565
- subkeySignaturePacket.keyExpirationTime = options.keyExpirationTime;
27566
- subkeySignaturePacket.keyNeverExpires = false;
28142
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
28143
+ signatureProperties.keyNeverExpires = false;
27567
28144
  }
27568
- await subkeySignaturePacket.sign(primaryKey, dataToSign, options.date);
28145
+ const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
27569
28146
  return subkeySignaturePacket;
27570
28147
  }
27571
28148
 
@@ -27579,7 +28156,7 @@ var openpgp = (function (exports) {
27579
28156
  * @returns {Promise<enums.hash>}
27580
28157
  * @async
27581
28158
  */
27582
- async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID = {}, config) {
28159
+ async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
27583
28160
  let hashAlgo = config.preferredHashAlgorithm;
27584
28161
  let prefAlgo = hashAlgo;
27585
28162
  if (key) {
@@ -27590,17 +28167,11 @@ var openpgp = (function (exports) {
27590
28167
  prefAlgo : hashAlgo;
27591
28168
  }
27592
28169
  }
27593
- switch (Object.getPrototypeOf(keyPacket)) {
27594
- case SecretKeyPacket.prototype:
27595
- case PublicKeyPacket.prototype:
27596
- case SecretSubkeyPacket.prototype:
27597
- case PublicSubkeyPacket.prototype:
27598
- switch (keyPacket.algorithm) {
27599
- case enums.publicKey.ecdh:
27600
- case enums.publicKey.ecdsa:
27601
- case enums.publicKey.eddsa:
27602
- prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
27603
- }
28170
+ switch (keyPacket.algorithm) {
28171
+ case enums.publicKey.ecdsa:
28172
+ case enums.publicKey.eddsaLegacy:
28173
+ case enums.publicKey.ed25519:
28174
+ prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
27604
28175
  }
27605
28176
  return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
27606
28177
  prefAlgo : hashAlgo;
@@ -27668,7 +28239,7 @@ var openpgp = (function (exports) {
27668
28239
  const signaturePacket = new SignaturePacket();
27669
28240
  Object.assign(signaturePacket, signatureProperties);
27670
28241
  signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
27671
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(privateKey, signingKeyPacket, date, userID, config);
28242
+ signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
27672
28243
  signaturePacket.rawNotations = notations;
27673
28244
  await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
27674
28245
  return signaturePacket;
@@ -27809,11 +28380,11 @@ var openpgp = (function (exports) {
27809
28380
  } catch (e) {
27810
28381
  throw new Error('Unknown curve');
27811
28382
  }
27812
- if (options.curve === enums.curve.ed25519 || options.curve === enums.curve.curve25519) {
27813
- options.curve = options.sign ? enums.curve.ed25519 : enums.curve.curve25519;
28383
+ if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
28384
+ options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
27814
28385
  }
27815
28386
  if (options.sign) {
27816
- options.algorithm = options.curve === enums.curve.ed25519 ? enums.publicKey.eddsa : enums.publicKey.ecdsa;
28387
+ options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
27817
28388
  } else {
27818
28389
  options.algorithm = enums.publicKey.ecdh;
27819
28390
  }
@@ -27841,6 +28412,7 @@ var openpgp = (function (exports) {
27841
28412
  return keyAlgo !== enums.publicKey.rsaEncrypt &&
27842
28413
  keyAlgo !== enums.publicKey.elgamal &&
27843
28414
  keyAlgo !== enums.publicKey.ecdh &&
28415
+ keyAlgo !== enums.publicKey.x25519 &&
27844
28416
  (!signature.keyFlags ||
27845
28417
  (signature.keyFlags[0] & enums.keyFlags.signData) !== 0);
27846
28418
  }
@@ -27850,7 +28422,8 @@ var openpgp = (function (exports) {
27850
28422
  return keyAlgo !== enums.publicKey.dsa &&
27851
28423
  keyAlgo !== enums.publicKey.rsaSign &&
27852
28424
  keyAlgo !== enums.publicKey.ecdsa &&
27853
- keyAlgo !== enums.publicKey.eddsa &&
28425
+ keyAlgo !== enums.publicKey.eddsaLegacy &&
28426
+ keyAlgo !== enums.publicKey.ed25519 &&
27854
28427
  (!signature.keyFlags ||
27855
28428
  (signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
27856
28429
  (signature.keyFlags[0] & enums.keyFlags.encryptStorage) !== 0);
@@ -27895,7 +28468,7 @@ var openpgp = (function (exports) {
27895
28468
  }
27896
28469
  break;
27897
28470
  case enums.publicKey.ecdsa:
27898
- case enums.publicKey.eddsa:
28471
+ case enums.publicKey.eddsaLegacy:
27899
28472
  case enums.publicKey.ecdh:
27900
28473
  if (config.rejectCurves.has(algoInfo.curve)) {
27901
28474
  throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
@@ -29405,7 +29978,7 @@ var openpgp = (function (exports) {
29405
29978
  * @static
29406
29979
  * @private
29407
29980
  */
29408
- async function generate$2(options, config) {
29981
+ async function generate$4(options, config) {
29409
29982
  options.sign = true; // primary key is always a signing key
29410
29983
  options = sanitizeKeyOptions(options);
29411
29984
  options.subkeys = options.subkeys.map((subkey, index) => sanitizeKeyOptions(options.subkeys[index], options));
@@ -29522,50 +30095,50 @@ var openpgp = (function (exports) {
29522
30095
  const dataToSign = {};
29523
30096
  dataToSign.userID = userIDPacket;
29524
30097
  dataToSign.key = secretKeyPacket;
29525
- const signaturePacket = new SignaturePacket();
29526
- signaturePacket.signatureType = enums.signature.certGeneric;
29527
- signaturePacket.publicKeyAlgorithm = secretKeyPacket.algorithm;
29528
- signaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, secretKeyPacket, undefined, undefined, config);
29529
- signaturePacket.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
29530
- signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
30098
+
30099
+ const signatureProperties = {};
30100
+ signatureProperties.signatureType = enums.signature.certGeneric;
30101
+ signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
30102
+ signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
29531
30103
  // prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
29532
30104
  enums.symmetric.aes256,
29533
30105
  enums.symmetric.aes128,
29534
30106
  enums.symmetric.aes192
29535
30107
  ], config.preferredSymmetricAlgorithm);
29536
30108
  if (config.aeadProtect) {
29537
- signaturePacket.preferredAEADAlgorithms = createPreferredAlgos([
30109
+ signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
29538
30110
  enums.aead.eax,
29539
30111
  enums.aead.ocb
29540
30112
  ], config.preferredAEADAlgorithm);
29541
30113
  }
29542
- signaturePacket.preferredHashAlgorithms = createPreferredAlgos([
30114
+ signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
29543
30115
  // prefer fast asm.js implementations (SHA-256)
29544
30116
  enums.hash.sha256,
29545
30117
  enums.hash.sha512
29546
30118
  ], config.preferredHashAlgorithm);
29547
- signaturePacket.preferredCompressionAlgorithms = createPreferredAlgos([
30119
+ signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
29548
30120
  enums.compression.zlib,
29549
30121
  enums.compression.zip,
29550
30122
  enums.compression.uncompressed
29551
30123
  ], config.preferredCompressionAlgorithm);
29552
30124
  if (index === 0) {
29553
- signaturePacket.isPrimaryUserID = true;
30125
+ signatureProperties.isPrimaryUserID = true;
29554
30126
  }
29555
30127
  // integrity protection always enabled
29556
- signaturePacket.features = [0];
29557
- signaturePacket.features[0] |= enums.features.modificationDetection;
30128
+ signatureProperties.features = [0];
30129
+ signatureProperties.features[0] |= enums.features.modificationDetection;
29558
30130
  if (config.aeadProtect) {
29559
- signaturePacket.features[0] |= enums.features.aead;
30131
+ signatureProperties.features[0] |= enums.features.aead;
29560
30132
  }
29561
30133
  if (config.v5Keys) {
29562
- signaturePacket.features[0] |= enums.features.v5Keys;
30134
+ signatureProperties.features[0] |= enums.features.v5Keys;
29563
30135
  }
29564
30136
  if (options.keyExpirationTime > 0) {
29565
- signaturePacket.keyExpirationTime = options.keyExpirationTime;
29566
- signaturePacket.keyNeverExpires = false;
30137
+ signatureProperties.keyExpirationTime = options.keyExpirationTime;
30138
+ signatureProperties.keyNeverExpires = false;
29567
30139
  }
29568
- await signaturePacket.sign(secretKeyPacket, dataToSign, options.date);
30140
+
30141
+ const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
29569
30142
 
29570
30143
  return { userIDPacket, signaturePacket };
29571
30144
  })).then(list => {
@@ -30084,6 +30657,15 @@ var openpgp = (function (exports) {
30084
30657
  enums.read(enums.aead, await getPreferredAlgo('aead', encryptionKeys, date, userIDs, config$1)) :
30085
30658
  undefined;
30086
30659
 
30660
+ await Promise.all(encryptionKeys.map(key => key.getEncryptionKey()
30661
+ .catch(() => null) // ignore key strength requirements
30662
+ .then(maybeKey => {
30663
+ if (maybeKey && (maybeKey.keyPacket.algorithm === enums.publicKey.x25519) && !util.isAES(algo)) {
30664
+ throw new Error('Could not generate a session key compatible with the given `encryptionKeys`: X22519 keys can only be used to encrypt AES session keys; change `config.preferredSymmetricAlgorithm` accordingly.');
30665
+ }
30666
+ })
30667
+ ));
30668
+
30087
30669
  const sessionKeyData = mod.generateSessionKey(algo);
30088
30670
  return { data: sessionKeyData, algorithm: algorithmName, aeadAlgorithm: aeadAlgorithmName };
30089
30671
  }
@@ -30258,7 +30840,7 @@ var openpgp = (function (exports) {
30258
30840
  const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
30259
30841
  const onePassSig = new OnePassSignaturePacket();
30260
30842
  onePassSig.signatureType = signatureType;
30261
- onePassSig.hashAlgorithm = await getPreferredHashAlgo$1(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30843
+ onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
30262
30844
  onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
30263
30845
  onePassSig.issuerKeyID = signingKey.getKeyID();
30264
30846
  if (i === signingKeys.length - 1) {
@@ -30391,7 +30973,7 @@ var openpgp = (function (exports) {
30391
30973
  if (literalDataList.length !== 1) {
30392
30974
  throw new Error('Can only verify message with one literal data packet.');
30393
30975
  }
30394
- const signatureList = signature.packets;
30976
+ const signatureList = signature.packets.filterByTag(enums.packet.signature); // drop UnparsablePackets
30395
30977
  return createVerificationObjects(signatureList, literalDataList, verificationKeys, date, true, config$1);
30396
30978
  }
30397
30979
 
@@ -30738,7 +31320,7 @@ var openpgp = (function (exports) {
30738
31320
  * @async
30739
31321
  */
30740
31322
  verify(keys, date = new Date(), config$1 = config) {
30741
- const signatureList = this.signature.packets;
31323
+ const signatureList = this.signature.packets.filterByTag(enums.packet.signature); // drop UnparsablePackets
30742
31324
  const literalDataPacket = new LiteralDataPacket();
30743
31325
  // we assume that cleartext signature is generated based on UTF8 cleartext
30744
31326
  literalDataPacket.setText(this.text);
@@ -30823,7 +31405,7 @@ var openpgp = (function (exports) {
30823
31405
  let oneHeader = null;
30824
31406
  let hashAlgos = [];
30825
31407
  headers.forEach(function(header) {
30826
- oneHeader = header.match(/Hash: (.+)/); // get header value
31408
+ oneHeader = header.match(/^Hash: (.+)$/); // get header value
30827
31409
  if (oneHeader) {
30828
31410
  oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace
30829
31411
  oneHeader = oneHeader.split(',');
@@ -30915,7 +31497,7 @@ var openpgp = (function (exports) {
30915
31497
  const options = { userIDs, passphrase, type, rsaBits, curve, keyExpirationTime, date, subkeys, symmetricHash, symmetricCipher };
30916
31498
 
30917
31499
  try {
30918
- const { key, revocationCertificate } = await generate$2(options, config$1);
31500
+ const { key, revocationCertificate } = await generate$4(options, config$1);
30919
31501
  key.getKeys().forEach(({ keyPacket }) => checkKeyRequirements(keyPacket, config$1));
30920
31502
 
30921
31503
  return {
@@ -31109,7 +31691,7 @@ var openpgp = (function (exports) {
31109
31691
  * @async
31110
31692
  * @static
31111
31693
  */
31112
- async function encrypt$4({ message, encryptionKeys, signingKeys, passwords, sessionKey, format = 'armored', signature = null, wildcard = false, signingKeyIDs = [], encryptionKeyIDs = [], date = new Date(), signingUserIDs = [], encryptionUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
31694
+ async function encrypt$5({ message, encryptionKeys, signingKeys, passwords, sessionKey, format = 'armored', signature = null, wildcard = false, signingKeyIDs = [], encryptionKeyIDs = [], date = new Date(), signingUserIDs = [], encryptionUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
31113
31695
  config$1 = { ...config, ...config$1 }; checkConfig(config$1);
31114
31696
  checkMessage(message); checkOutputMessageFormat(format);
31115
31697
  encryptionKeys = toArray$1(encryptionKeys); signingKeys = toArray$1(signingKeys); passwords = toArray$1(passwords);
@@ -31178,7 +31760,7 @@ var openpgp = (function (exports) {
31178
31760
  * @async
31179
31761
  * @static
31180
31762
  */
31181
- async function decrypt$4({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
31763
+ async function decrypt$5({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
31182
31764
  config$1 = { ...config, ...config$1 }; checkConfig(config$1);
31183
31765
  checkMessage(message); verificationKeys = toArray$1(verificationKeys); decryptionKeys = toArray$1(decryptionKeys); passwords = toArray$1(passwords); sessionKeys = toArray$1(sessionKeys);
31184
31766
  if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead');
@@ -31241,7 +31823,7 @@ var openpgp = (function (exports) {
31241
31823
  * @async
31242
31824
  * @static
31243
31825
  */
31244
- async function sign$5({ message, signingKeys, format = 'armored', detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
31826
+ async function sign$6({ message, signingKeys, format = 'armored', detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
31245
31827
  config$1 = { ...config, ...config$1 }; checkConfig(config$1);
31246
31828
  checkCleartextOrMessage(message); checkOutputMessageFormat(format);
31247
31829
  signingKeys = toArray$1(signingKeys); signingKeyIDs = toArray$1(signingKeyIDs); signingUserIDs = toArray$1(signingUserIDs); signatureNotations = toArray$1(signatureNotations);
@@ -31310,7 +31892,7 @@ var openpgp = (function (exports) {
31310
31892
  * @async
31311
31893
  * @static
31312
31894
  */
31313
- async function verify$5({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
31895
+ async function verify$6({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
31314
31896
  config$1 = { ...config, ...config$1 }; checkConfig(config$1);
31315
31897
  checkCleartextOrMessage(message); verificationKeys = toArray$1(verificationKeys);
31316
31898
  if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead');
@@ -44479,7 +45061,7 @@ var openpgp = (function (exports) {
44479
45061
  return [];
44480
45062
  }
44481
45063
 
44482
- function validateParams$7({ type, version, tagLength, password, salt, ad, secret, parallelism, memorySize, passes }) {
45064
+ function validateParams$9({ type, version, tagLength, password, salt, ad, secret, parallelism, memorySize, passes }) {
44483
45065
  const assertLength = (name, value, min, max) => {
44484
45066
  if (value < min || value > max) { throw new Error(`${name} size should be between ${min} and ${max} bytes`); }
44485
45067
  };
@@ -44502,7 +45084,7 @@ var openpgp = (function (exports) {
44502
45084
  function argon2id(params, { memory, instance: wasmInstance }) {
44503
45085
  if (!isLittleEndian$1) throw new Error('BigEndian system not supported'); // optmisations assume LE system
44504
45086
 
44505
- const ctx = validateParams$7({ type: TYPE$2, version: VERSION$4, ...params });
45087
+ const ctx = validateParams$9({ type: TYPE$2, version: VERSION$4, ...params });
44506
45088
 
44507
45089
  const { G:wasmG, G2:wasmG2, xor:wasmXOR, getLZ:wasmLZ } = wasmInstance.exports;
44508
45090
  const wasmRefs = {};
@@ -44806,10 +45388,10 @@ var openpgp = (function (exports) {
44806
45388
  exports.config = config;
44807
45389
  exports.createCleartextMessage = createCleartextMessage;
44808
45390
  exports.createMessage = createMessage;
44809
- exports.decrypt = decrypt$4;
45391
+ exports.decrypt = decrypt$5;
44810
45392
  exports.decryptKey = decryptKey;
44811
45393
  exports.decryptSessionKeys = decryptSessionKeys;
44812
- exports.encrypt = encrypt$4;
45394
+ exports.encrypt = encrypt$5;
44813
45395
  exports.encryptKey = encryptKey;
44814
45396
  exports.encryptSessionKey = encryptSessionKey;
44815
45397
  exports.enums = enums;
@@ -44824,9 +45406,9 @@ var openpgp = (function (exports) {
44824
45406
  exports.readSignature = readSignature;
44825
45407
  exports.reformatKey = reformatKey;
44826
45408
  exports.revokeKey = revokeKey;
44827
- exports.sign = sign$5;
45409
+ exports.sign = sign$6;
44828
45410
  exports.unarmor = unarmor;
44829
- exports.verify = verify$5;
45411
+ exports.verify = verify$6;
44830
45412
 
44831
45413
  Object.defineProperty(exports, '__esModule', { value: true });
44832
45414