[Python-modules-commits] [python-cryptography] 01/04: Import python-cryptography_1.4.orig.tar.gz

Tristan Seligmann mithrandi at moszumanska.debian.org
Thu Jun 23 17:29:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

mithrandi pushed a commit to branch master
in repository python-cryptography.

commit b11e8dd6d10f65b140ef8105a250ea36e971419a
Author: Tristan Seligmann <mithrandi at debian.org>
Date:   Thu Jun 23 00:00:44 2016 +0200

    Import python-cryptography_1.4.orig.tar.gz
---
 AUTHORS.rst                                        |   2 +
 CHANGELOG.rst                                      |  20 +-
 PKG-INFO                                           |   2 +-
 docs/development/c-bindings.rst                    |   2 +-
 docs/development/custom-vectors/rsa-oaep-sha2.rst  |  56 +++
 .../rsa-oaep-sha2/VerifyRSAOAEPSHA2.java           | 416 +++++++++++++++++++++
 .../rsa-oaep-sha2/generate_rsa_oaep_sha2.py        | 127 +++++++
 docs/development/getting-started.rst               |  34 +-
 docs/development/submitting-patches.rst            |   2 +-
 docs/development/test-vectors.rst                  |   5 +-
 docs/faq.rst                                       |  17 +-
 docs/hazmat/backends/openssl.rst                   |   2 +-
 docs/hazmat/bindings/commoncrypto.rst              |   2 +-
 docs/hazmat/bindings/openssl.rst                   |   2 +-
 docs/hazmat/primitives/asymmetric/ec.rst           |   3 +-
 docs/hazmat/primitives/asymmetric/rsa.rst          |  76 +++-
 .../hazmat/primitives/asymmetric/serialization.rst |  13 +
 docs/hazmat/primitives/cryptographic-hashes.rst    |   4 +-
 .../hazmat/primitives/key-derivation-functions.rst | 150 ++++++++
 docs/installation.rst                              |  11 +-
 docs/x509/reference.rst                            |  58 +--
 setup.py                                           |   4 +-
 src/_cffi_src/openssl/bio.py                       |  53 +--
 src/_cffi_src/openssl/crypto.py                    |  10 +-
 src/_cffi_src/openssl/dh.py                        |  15 +-
 src/_cffi_src/openssl/dsa.py                       |  73 ++++
 src/_cffi_src/openssl/engine.py                    |   2 +-
 src/_cffi_src/openssl/err.py                       |  82 ++--
 src/_cffi_src/openssl/evp.py                       |   4 +-
 src/_cffi_src/openssl/objects.py                   |   3 +-
 src/_cffi_src/openssl/pem.py                       |   2 +
 src/_cffi_src/openssl/rand.py                      |   4 +-
 src/_cffi_src/openssl/rsa.py                       | 128 +++++++
 src/_cffi_src/openssl/ssl.py                       |  38 ++
 src/cryptography.egg-info/PKG-INFO                 |   2 +-
 src/cryptography.egg-info/SOURCES.txt              |   6 +
 src/cryptography/__about__.py                      |   2 +-
 .../hazmat/backends/openssl/backend.py             | 170 +++++++--
 src/cryptography/hazmat/backends/openssl/dsa.py    | 135 +++++--
 src/cryptography/hazmat/backends/openssl/ec.py     |   1 +
 src/cryptography/hazmat/backends/openssl/rsa.py    | 119 ++++--
 src/cryptography/hazmat/backends/openssl/x509.py   |  10 +
 .../hazmat/bindings/openssl/_conditional.py        |  15 +-
 .../hazmat/bindings/openssl/binding.py             |  40 +-
 .../hazmat/primitives/asymmetric/dsa.py            |  13 +
 .../hazmat/primitives/asymmetric/ec.py             |   6 +
 .../hazmat/primitives/asymmetric/rsa.py            |  12 +
 .../hazmat/primitives/asymmetric/utils.py          |   6 +-
 src/cryptography/hazmat/primitives/kdf/kbkdf.py    | 148 ++++++++
 .../hazmat/primitives/serialization.py             |  43 ++-
 src/cryptography/utils.py                          |   7 +-
 src/cryptography/x509/__init__.py                  |   9 -
 src/cryptography/x509/base.py                      |   2 +-
 src/cryptography/x509/extensions.py                |  45 ++-
 src/cryptography/x509/oid.py                       |   8 -
 tests/conftest.py                                  |   5 +
 tests/hazmat/backends/test_openssl.py              |  89 ++++-
 tests/hazmat/bindings/test_openssl.py              |   8 +-
 tests/hazmat/primitives/test_dsa.py                |  38 ++
 tests/hazmat/primitives/test_ec.py                 |  52 +++
 tests/hazmat/primitives/test_kbkdf.py              | 151 ++++++++
 tests/hazmat/primitives/test_kbkdf_vectors.py      |  23 ++
 tests/hazmat/primitives/test_rsa.py                | 175 ++++++++-
 tests/hazmat/primitives/test_serialization.py      |  11 +
 tests/hazmat/primitives/utils.py                   |  54 +++
 tests/test_utils.py                                |  99 ++++-
 tests/test_x509.py                                 |  35 +-
 tests/utils.py                                     |  37 ++
 68 files changed, 2649 insertions(+), 349 deletions(-)

diff --git a/AUTHORS.rst b/AUTHORS.rst
index eaadd52..8e95ca3 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -27,3 +27,5 @@ PGP key fingerprints are enclosed in parentheses.
 * Jiangge Zhang <tonyseek at gmail.com> (BBEC 782B 015F 71B1 5FF7  EACA 1A8C AA98 255F 5000)
 * Major Hayden <major at mhtx.net> (1BF9 9264 9596 0033 698C  252B 7370 51E0 C101 1FB1)
 * Phoebe Queen <foibey at gmail.com> (10D4 7741 AB65 50F4 B264 3888 DA40 201A 072B C1FA)
+* Google Inc.
+* Amaury Forgeot d'Arc <amauryfa at google.com>
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c30a137..1aa2131 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,12 +1,30 @@
 Changelog
 =========
 
+1.4 - 2016-06-04
+~~~~~~~~~~~~~~~~
+
+* Support for OpenSSL 0.9.8 has been removed. Users on older versions of
+  OpenSSL will need to upgrade.
+* Added :class:`~cryptography.hazmat.primitives.kdf.kbkdf.KBKDFHMAC`.
+* Added support for ``OpenSSH`` public key serialization.
+* Added support for SHA-2 in RSA
+  :class:`~cryptography.hazmat.primitives.asymmetric.padding.OAEP` when using
+  OpenSSL 1.0.2 or greater.
+* Added "one shot"
+  :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.sign`
+  and
+  :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey.verify`
+  methods to RSA keys.
+
+
 1.3.4 - 2016-06-03
 ~~~~~~~~~~~~~~~~~~
 
 * Added another OpenSSL function to the bindings to support an upcoming
   ``pyOpenSSL`` release.
 
+
 1.3.3 - 2016-06-02
 ~~~~~~~~~~~~~~~~~~
 
@@ -658,4 +676,4 @@ Changelog
 * Initial release.
 
 .. _`master`: https://github.com/pyca/cryptography/
-.. _`cffi`: https://cffi.readthedocs.org/en/latest/
+.. _`cffi`: https://cffi.readthedocs.io/
diff --git a/PKG-INFO b/PKG-INFO
index 64378e5..ee73ee7 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cryptography
-Version: 1.3.4
+Version: 1.4
 Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
 Home-page: https://github.com/pyca/cryptography
 Author: The cryptography developers
diff --git a/docs/development/c-bindings.rst b/docs/development/c-bindings.rst
index 993a4ab..cbd8fab 100644
--- a/docs/development/c-bindings.rst
+++ b/docs/development/c-bindings.rst
@@ -3,7 +3,7 @@ C bindings
 
 C bindings are bindings to C libraries, using cffi_ whenever possible.
 
-.. _cffi: https://cffi.readthedocs.org
+.. _cffi: https://cffi.readthedocs.io
 
 Bindings live in :py:mod:`cryptography.hazmat.bindings`.
 
diff --git a/docs/development/custom-vectors/rsa-oaep-sha2.rst b/docs/development/custom-vectors/rsa-oaep-sha2.rst
new file mode 100644
index 0000000..36f256d
--- /dev/null
+++ b/docs/development/custom-vectors/rsa-oaep-sha2.rst
@@ -0,0 +1,56 @@
+RSA OAEP SHA2 vector creation
+=============================
+
+This page documents the code that was used to generate the RSA OAEP SHA2
+test vectors as well as code used to verify them against another
+implementation.
+
+
+Creation
+--------
+
+``cryptography`` was modified to allow the use of SHA2 in OAEP encryption. Then
+the following python script was run to generate the vector files.
+
+.. literalinclude:: /development/custom-vectors/rsa-oaep-sha2/generate_rsa_oaep_sha2.py
+
+Download link: :download:`generate_rsa_oaep_sha2.py
+</development/custom-vectors/rsa-oaep-sha2/generate_rsa_oaep_sha2.py>`
+
+
+Verification
+------------
+
+A Java 8 program was written using `Bouncy Castle`_ to load and verify the test
+vectors.
+
+
+.. literalinclude:: /development/custom-vectors/rsa-oaep-sha2/VerifyRSAOAEPSHA2.java
+
+Download link: :download:`VerifyRSAOAEPSHA2.java
+</development/custom-vectors/rsa-oaep-sha2/VerifyRSAOAEPSHA2.java>`
+
+Using the Verifier
+------------------
+
+Download and install the `Java 8 SDK`_. Initial verification was performed
+using ``jdk-8u77-macosx-x64.dmg``.
+
+Download the latest `Bouncy Castle`_ JAR.  Initial verification was performed
+using ``bcprov-jdk15on-154.jar``.
+
+Set the ``-classpath`` to include the Bouncy Castle jar and the path to
+``VerifyRSAOAEPSHA2.java`` and compile the program.
+
+.. code-block:: console
+
+    $ javac -classpath ~/Downloads/bcprov-jdk15on-154.jar:./ VerifyRSAOAEPSHA2.java
+
+Finally, run the program with the path to the SHA-2 vectors:
+
+.. code-block:: console
+
+    $ java -classpath ~/Downloads/bcprov-jdk15on-154.jar:./ VerifyRSAOAEPSHA2
+
+.. _`Bouncy Castle`: https://www.bouncycastle.org/
+.. _`Java 8 SDK`: https://www.oracle.com/technetwork/java/javase/downloads/index.html
diff --git a/docs/development/custom-vectors/rsa-oaep-sha2/VerifyRSAOAEPSHA2.java b/docs/development/custom-vectors/rsa-oaep-sha2/VerifyRSAOAEPSHA2.java
new file mode 100644
index 0000000..e1bfd3d
--- /dev/null
+++ b/docs/development/custom-vectors/rsa-oaep-sha2/VerifyRSAOAEPSHA2.java
@@ -0,0 +1,416 @@
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.AlgorithmParameters;
+import java.security.GeneralSecurityException;
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.MGF1ParameterSpec;
+import java.security.spec.RSAPrivateKeySpec;
+import java.util.Arrays;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.OAEPParameterSpec;
+import javax.crypto.spec.PSource;
+import javax.xml.bind.DatatypeConverter;
+
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
+class TestVectorData {
+    public BigInteger pub_key_modulus;
+    public BigInteger pub_key_exponent;
+    public BigInteger priv_key_public_exponent;
+    public BigInteger priv_key_modulus;
+    public BigInteger priv_key_exponent;
+    public BigInteger priv_key_prime_1;
+    public BigInteger priv_key_prime_2;
+    public BigInteger priv_key_prime_exponent_1;
+    public BigInteger priv_key_prime_exponent_2;
+    public BigInteger priv_key_coefficient;
+    public byte[] plaintext;
+    public byte[] ciphertext;
+}
+
+class TestVectorLoader {
+    private static final String FILE_HEADER = "# RSA OAEP SHA2 vectors built";
+    private static final String EXAMPLE_HEADER = "# =====";
+    private static final String EXAMPLE = "# Example";
+    private static final String PUBLIC_KEY = "# Public key";
+    private static final String PUB_MODULUS = "# Modulus:";
+    private static final String PUB_EXPONENT = "# Exponent:";
+    private static final String PRIVATE_KEY = "# Private key";
+    private static final String PRIV_MODULUS = "# Modulus:";
+    private static final String PRIV_PUBLIC_EXPONENT = "# Public exponent:";
+    private static final String PRIV_EXPONENT = "# Exponent:";
+    private static final String PRIV_PRIME_1 = "# Prime 1:";
+    private static final String PRIV_PRIME_2 = "# Prime 2:";
+    private static final String PRIV_PRIME_EXPONENT_1 = "# Prime exponent 1:";
+    private static final String PRIV_PRIME_EXPONENT_2 = "# Prime exponent 2:";
+    private static final String PRIV_COEFFICIENT = "# Coefficient:";
+    private static final String OAEP_EXAMPLE_HEADER = "# OAEP Example";
+    private static final String MESSAGE = "# Message:";
+    private static final String ENCRYPTION = "# Encryption:";
+
+    private BufferedReader m_reader = null;
+    private FileReader m_file_reader = null;
+    private TestVectorData m_data = null;
+
+    TestVectorLoader() {
+
+    }
+
+    protected void finalize() {
+        close();
+    }
+
+    public void open(String path) throws IOException {
+        close();
+        m_file_reader = new FileReader(path);
+        m_reader = new BufferedReader(m_file_reader);
+        m_data = new TestVectorData();
+    }
+
+    public void close() {
+        try {
+            if (m_reader != null) {
+                m_reader.close();
+                m_reader = null;
+            }
+            if (m_file_reader != null) {
+                m_file_reader.close();
+                m_file_reader = null;
+            }
+            m_data = null;
+        } catch (IOException e) {
+            System.out.println("Exception closing files");
+            e.printStackTrace();
+        }
+    }
+
+    public TestVectorData loadNextTest() throws IOException {
+        if (m_file_reader == null || m_reader == null || m_data == null) {
+            throw new IOException("A test vector file must be opened first");
+        }
+
+        String line = m_reader.readLine();
+
+        if (line == null) {
+            // end of file
+            return null;
+        }
+
+        if (line.startsWith(FILE_HEADER)) {
+            // start of file
+            skipFileHeader(m_reader);
+            line = m_reader.readLine();
+        }
+
+        if (line.startsWith(OAEP_EXAMPLE_HEADER)) {
+            // Next example, keep existing keys and load next message
+            loadMessage(m_reader, m_data);
+            return m_data;
+        }
+
+        // otherwise it's a new example
+        if (!line.startsWith(EXAMPLE_HEADER)) {
+            throw new IOException("Test Header Missing");
+        }
+        startNewTest(m_reader);
+        m_data = new TestVectorData();
+
+        line = m_reader.readLine();
+        if (!line.startsWith(PUBLIC_KEY))
+            throw new IOException("Public Key Missing");
+        loadPublicKey(m_reader, m_data);
+
+        line = m_reader.readLine();
+        if (!line.startsWith(PRIVATE_KEY))
+            throw new IOException("Private Key Missing");
+        loadPrivateKey(m_reader, m_data);
+
+        line = m_reader.readLine();
+        if (!line.startsWith(OAEP_EXAMPLE_HEADER))
+            throw new IOException("Message Missing");
+        loadMessage(m_reader, m_data);
+
+        return m_data;
+    }
+
+    private byte[] unhexlify(String line) {
+        byte[] bytes = DatatypeConverter.parseHexBinary(line);
+        return bytes;
+    }
+
+    private BigInteger readBigInteger(BufferedReader br) throws IOException {
+        return new BigInteger(br.readLine(), 16);
+    }
+
+    private void skipFileHeader(BufferedReader br) throws IOException {
+        br.readLine(); // # # Derived from the NIST OAEP SHA1 vectors
+        br.readLine(); // # # Verified against the Bouncy Castle OAEP SHA2 implementation
+        br.readLine(); // #
+    }
+
+    private void startNewTest(BufferedReader br) throws IOException {
+        String line = br.readLine();
+        if (!line.startsWith(EXAMPLE))
+            throw new IOException("Example Header Missing");
+    }
+
+    private void loadPublicKey(BufferedReader br, TestVectorData data) throws IOException {
+        String line = br.readLine();
+        if (!line.startsWith(PUB_MODULUS))
+            throw new IOException("Public Key Modulus Missing");
+        data.pub_key_modulus = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PUB_EXPONENT))
+            throw new IOException("Public Key Exponent Missing");
+        data.pub_key_exponent = readBigInteger(br);
+    }
+
+    private void loadPrivateKey(BufferedReader br, TestVectorData data) throws IOException {
+        String line = br.readLine();
+        if (!line.startsWith(PRIV_MODULUS))
+            throw new IOException("Private Key Modulus Missing");
+        data.priv_key_modulus = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_PUBLIC_EXPONENT))
+            throw new IOException("Private Key Public Exponent Missing");
+        data.priv_key_public_exponent = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_EXPONENT))
+            throw new IOException("Private Key Exponent Missing");
+        data.priv_key_exponent = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_PRIME_1))
+            throw new IOException("Private Key Prime 1 Missing");
+        data.priv_key_prime_1 = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_PRIME_2))
+            throw new IOException("Private Key Prime 2 Missing");
+        data.priv_key_prime_2 = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_PRIME_EXPONENT_1))
+            throw new IOException("Private Key Prime Exponent 1 Missing");
+        data.priv_key_prime_exponent_1 = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_PRIME_EXPONENT_2))
+            throw new IOException("Private Key Prime Exponent 2 Missing");
+        data.priv_key_prime_exponent_2 = readBigInteger(br);
+
+        line = br.readLine();
+        if (!line.startsWith(PRIV_COEFFICIENT))
+            throw new IOException("Private Key Coefficient Missing");
+        data.priv_key_coefficient = readBigInteger(br);
+    }
+
+    private void loadMessage(BufferedReader br, TestVectorData data) throws IOException {
+        String line = br.readLine();
+        if (!line.startsWith(MESSAGE))
+            throw new IOException("Plaintext Missing");
+        data.plaintext = unhexlify(br.readLine());
+
+        line = br.readLine();
+        if (!line.startsWith(ENCRYPTION))
+            throw new IOException("Ciphertext Missing");
+        data.ciphertext = unhexlify(br.readLine());
+    }
+
+}
+
+public class VerifyRSAOAEPSHA2 {
+
+    public enum SHAHash {
+        SHA1, SHA224, SHA256, SHA384, SHA512
+    }
+
+    private SHAHash m_mgf1_hash;
+    private SHAHash m_alg_hash;
+    private Cipher m_cipher;
+    private PrivateKey m_private_key;
+    private AlgorithmParameters m_algo_param;
+
+    VerifyRSAOAEPSHA2(SHAHash mgf1_hash, SHAHash alg_hash, TestVectorData test_data) throws Exception {
+
+        m_mgf1_hash = mgf1_hash;
+        m_alg_hash = alg_hash;
+
+        MGF1ParameterSpec mgf1_spec = getMGF1ParameterSpec(m_mgf1_hash);
+        AlgorithmParameterSpec algo_param_spec = getAlgorithmParameterSpec(m_alg_hash, mgf1_spec);
+
+        m_algo_param = AlgorithmParameters.getInstance("OAEP");
+        m_algo_param.init(algo_param_spec);
+
+        m_private_key = loadPrivateKey(test_data);
+
+        m_cipher = getCipher(m_alg_hash);
+    }
+
+    private Cipher getCipher(SHAHash alg_hash) throws GeneralSecurityException {
+        Cipher cipher = null;
+
+        switch (alg_hash) {
+
+        case SHA1:
+            cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA1andMGF1Padding", "BC");
+            break;
+
+        case SHA224:
+            cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-224andMGF1Padding", "BC");
+            break;
+
+        case SHA256:
+            cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-256andMGF1Padding", "BC");
+            break;
+
+        case SHA384:
+            cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-384andMGF1Padding", "BC");
+            break;
+
+        case SHA512:
+            cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-512andMGF1Padding", "BC");
+            break;
+        }
+
+        return cipher;
+    }
+
+    private MGF1ParameterSpec getMGF1ParameterSpec(SHAHash mgf1_hash) {
+        MGF1ParameterSpec mgf1 = null;
+
+        switch (mgf1_hash) {
+
+        case SHA1:
+            mgf1 = MGF1ParameterSpec.SHA1;
+            break;
+        case SHA224:
+            mgf1 = MGF1ParameterSpec.SHA224;
+            break;
+
+        case SHA256:
+            mgf1 = MGF1ParameterSpec.SHA256;
+            break;
+
+        case SHA384:
+            mgf1 = MGF1ParameterSpec.SHA384;
+            break;
+
+        case SHA512:
+            mgf1 = MGF1ParameterSpec.SHA512;
+            break;
+        }
+
+        return mgf1;
+    }
+
+    private AlgorithmParameterSpec getAlgorithmParameterSpec(SHAHash alg_hash, MGF1ParameterSpec mgf1_spec) {
+
+        OAEPParameterSpec oaep_spec = null;
+
+        switch (alg_hash) {
+
+        case SHA1:
+            oaep_spec = new OAEPParameterSpec("SHA1", "MGF1", mgf1_spec, PSource.PSpecified.DEFAULT);
+            break;
+
+        case SHA224:
+            oaep_spec = new OAEPParameterSpec("SHA-224", "MGF1", mgf1_spec, PSource.PSpecified.DEFAULT);
+            break;
+
+        case SHA256:
+            oaep_spec = new OAEPParameterSpec("SHA-256", "MGF1", mgf1_spec, PSource.PSpecified.DEFAULT);
+            break;
+
+        case SHA384:
+            oaep_spec = new OAEPParameterSpec("SHA-384", "MGF1", mgf1_spec, PSource.PSpecified.DEFAULT);
+            break;
+
+        case SHA512:
+            oaep_spec = new OAEPParameterSpec("SHA-512", "MGF1", mgf1_spec, PSource.PSpecified.DEFAULT);
+            break;
+        }
+
+        return oaep_spec;
+    }
+
+    private PrivateKey loadPrivateKey(TestVectorData test_data) throws Exception {
+        KeyFactory kf = KeyFactory.getInstance("RSA");
+
+        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(test_data.priv_key_modulus, test_data.priv_key_exponent);
+
+        return kf.generatePrivate(keySpec);
+    }
+
+    public void testDecrypt(byte[] plaintext, byte[] ciphertext) throws Exception {
+        System.out.println("Verifying OAEP with mgf1_hash: " + m_mgf1_hash + " alg_hash: " + m_alg_hash + " - "
+                + ciphertext.length + " bytes ciphertext - "
+                + plaintext.length + " bytes plaintext");
+
+        m_cipher.init(Cipher.DECRYPT_MODE, m_private_key, m_algo_param);
+        byte[] java_plaintext = m_cipher.doFinal(ciphertext);
+
+        if (Arrays.equals(java_plaintext, plaintext) == false) {
+            throw new Exception("Verification failure - plaintext does not match after decryption.");
+        }
+    }
+
+    public static void main(String[] args) {
+        Security.addProvider(new BouncyCastleProvider());
+
+        // assume current directory if no path given on command line
+        String vector_path = "./vectors/cryptography_vectors/asymmetric/RSA/oaep-custom";
+
+        if (args.length > 0) {
+            vector_path = args[0];
+        }
+
+        System.out.println("Vector file path: " + vector_path);
+
+        try {
+            // loop over each combination of hash loading the vector file
+            // to verify for each
+            for (SHAHash mgf1_hash : SHAHash.values()) {
+                for (SHAHash alg_hash : SHAHash.values()) {
+                    if (mgf1_hash.name().toLowerCase().equals("sha1") &&
+                        alg_hash.name().toLowerCase().equals("sha1")) {
+                        continue;
+                    }
+                    String filename = "oaep-" + mgf1_hash.name().toLowerCase() +
+                                          "-" + alg_hash.name().toLowerCase() + ".txt";
+
+                    System.out.println("Loading " + filename + "...");
+
+                    TestVectorLoader loader = new TestVectorLoader();
+                    loader.open(vector_path + filename);
+
+                    TestVectorData test_data;
+
+                    // load each test in the file and verify
+                    while ((test_data = loader.loadNextTest()) != null) {
+                        VerifyRSAOAEPSHA2 verify = new VerifyRSAOAEPSHA2(mgf1_hash, alg_hash, test_data);
+                        verify.testDecrypt(test_data.plaintext, test_data.ciphertext);
+                    }
+
+                    System.out.println("Verifying " + filename + " completed successfully.");
+                }
+            }
+
+            System.out.println("All verification completed successfully");
+
+        } catch (Exception e) {
+            // if any exception is thrown the verification has failed
+            e.printStackTrace();
+            System.out.println("Verification Failed!");
+        }
+    }
+}
diff --git a/docs/development/custom-vectors/rsa-oaep-sha2/generate_rsa_oaep_sha2.py b/docs/development/custom-vectors/rsa-oaep-sha2/generate_rsa_oaep_sha2.py
new file mode 100644
index 0000000..5a48e0c
--- /dev/null
+++ b/docs/development/custom-vectors/rsa-oaep-sha2/generate_rsa_oaep_sha2.py
@@ -0,0 +1,127 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import binascii
+import itertools
+import os
+
+from cryptography.hazmat.backends.openssl.backend import backend
+from cryptography.hazmat.primitives import hashes
+from cryptography.hazmat.primitives.asymmetric import padding, rsa
+
+from tests.utils import load_pkcs1_vectors, load_vectors_from_file
+
+
+def build_vectors(mgf1alg, hashalg, filename):
+    vectors = load_vectors_from_file(filename, load_pkcs1_vectors)
+
+    output = []
+    for vector in vectors:
+        # RSA keys for this must be long enough to accommodate the length of
+        # the underlying hash function. This means we can't use the keys from
+        # the sha1 test vectors for sha512 tests because 1024-bit keys are too
+        # small. Instead we parse the vectors for the test cases, then
+        # generate our own 2048-bit keys for each.
+        private, _ = vector
+        skey = rsa.generate_private_key(65537, 2048, backend)
+        pn = skey.private_numbers()
+        examples = private["examples"]
+        output.append(b"# =============================================")
+        output.append(b"# Example")
+        output.append(b"# Public key")
+        output.append(b"# Modulus:")
+        output.append(format(pn.public_numbers.n, "x"))
+        output.append(b"# Exponent:")
+        output.append(format(pn.public_numbers.e, "x"))
+        output.append(b"# Private key")
+        output.append(b"# Modulus:")
+        output.append(format(pn.public_numbers.n, "x"))
+        output.append(b"# Public exponent:")
+        output.append(format(pn.public_numbers.e, "x"))
+        output.append(b"# Exponent:")
+        output.append(format(pn.d, "x"))
+        output.append(b"# Prime 1:")
+        output.append(format(pn.p, "x"))
+        output.append(b"# Prime 2:")
+        output.append(format(pn.q, "x"))
+        output.append(b"# Prime exponent 1:")
+        output.append(format(pn.dmp1, "x"))
+        output.append(b"# Prime exponent 2:")
+        output.append(format(pn.dmq1, "x"))
+        output.append(b"# Coefficient:")
+        output.append(format(pn.iqmp, "x"))
+        pkey = skey.public_key()
+        vectorkey = rsa.RSAPrivateNumbers(
+            p=private["p"],
+            q=private["q"],
+            d=private["private_exponent"],
+            dmp1=private["dmp1"],
+            dmq1=private["dmq1"],
+            iqmp=private["iqmp"],
+            public_numbers=rsa.RSAPublicNumbers(
+                e=private["public_exponent"],
+                n=private["modulus"]
+            )
+        ).private_key(backend)
+        count = 1
+
+        for example in examples:
+            message = vectorkey.decrypt(
+                binascii.unhexlify(example["encryption"]),
+                padding.OAEP(
+                    mgf=padding.MGF1(algorithm=hashes.SHA1()),
+                    algorithm=hashes.SHA1(),
+                    label=None
+                )
+            )
+            assert message == binascii.unhexlify(example["message"])
+            ct = pkey.encrypt(
+                message,
+                padding.OAEP(
+                    mgf=padding.MGF1(algorithm=mgf1alg),
+                    algorithm=hashalg,
+                    label=None
+                )
+            )
+            output.append(
+                b"# OAEP Example {0} alg={1} mgf1={2}".format(
+                    count, hashalg.name, mgf1alg.name
+                )
+            )
+            count += 1
+            output.append(b"# Message:")
+            output.append(example["message"])
+            output.append(b"# Encryption:")
+            output.append(binascii.hexlify(ct))
+
+    return b"\n".join(output)
+
+
+def write_file(data, filename):
+    with open(filename, "w") as f:
+        f.write(data)
+
+oaep_path = os.path.join(
+    "asymmetric", "RSA", "pkcs-1v2-1d2-vec", "oaep-vect.txt"
+)
+hashalgs = [
+    hashes.SHA1(),
+    hashes.SHA224(),
+    hashes.SHA256(),
+    hashes.SHA384(),
+    hashes.SHA512(),
+]
+for hashtuple in itertools.product(hashalgs, hashalgs):
+    if (
+        isinstance(hashtuple[0], hashes.SHA1) and
+        isinstance(hashtuple[1], hashes.SHA1)
+    ):
+        continue
+
+    write_file(
+        build_vectors(hashtuple[0], hashtuple[1], oaep_path),
+        "oaep-{0}-{1}.txt".format(hashtuple[0].name, hashtuple[1].name)
+    )
diff --git a/docs/development/getting-started.rst b/docs/development/getting-started.rst
index b347400..3ad9fe8 100644
--- a/docs/development/getting-started.rst
+++ b/docs/development/getting-started.rst
@@ -1,6 +1,8 @@
 Getting started
 ===============
 
+Development dependencies
+------------------------
 Working on ``cryptography`` requires the installation of a small number of
 development dependencies in addition to the dependencies for
 :doc:`/installation`. These are listed in ``dev-requirements.txt`` and they can
@@ -18,8 +20,31 @@ to check spelling in the documentation.
 
 You are now ready to run the tests and build the documentation.
 
+OpenSSL on OS X
+~~~~~~~~~~~~~~~
+
+You must have installed `OpenSSL`_ via `Homebrew`_ or `MacPorts`_ and must set
+``CFLAGS`` and ``LDFLAGS`` environment variables before installing the
+``dev-requirements.txt`` otherwise pip will fail with include errors.
+
+For example, with `Homebrew`_:
+
+.. code-block:: console
+
+    $ env LDFLAGS="-L$(brew --prefix openssl)/lib" \
+        CFLAGS="-I$(brew --prefix openssl)/include" \
+        pip install --requirement ./dev-requirements.txt
+
+Alternatively for a static build you can specify
+``CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1`` and ensure ``LDFLAGS`` points to the
+absolute path for the `OpenSSL`_ libraries before calling pip.
+
+.. tip::
+    You will also need to set these values when `Building documentation`_.
+
+
 Running tests
-~~~~~~~~~~~~~
+-------------
 
 ``cryptography`` unit tests are found in the ``tests/`` directory and are
 designed to be run using `pytest`_. `pytest`_ will discover the tests
@@ -53,7 +78,7 @@ will see one or more ``InterpreterNotFound`` errors.
 
 
 Explicit backend selection
-~~~~~~~~~~~~~~~~~~~~~~~~~~
+--------------------------
 
 While testing you may want to run tests against a subset of the backends that
 cryptography supports. Explicit backend selection can be done via the
@@ -67,7 +92,7 @@ delimited list of backend names.
     $ py.test --backend=openssl,commoncrypto
 
 Building documentation
-~~~~~~~~~~~~~~~~~~~~~~
+----------------------
 
 ``cryptography`` documentation is stored in the ``docs/`` directory. It is
 written in `reStructured Text`_ and rendered using `Sphinx`_.
@@ -84,6 +109,9 @@ Use `tox`_ to build the documentation. For example:
 The HTML documentation index can now be found at
 ``docs/_build/html/index.html``.
 
+.. _`Homebrew`: http://brew.sh
+.. _`MacPorts`: https://www.macports.org
+.. _`OpenSSL`: https://openssl.org
 .. _`pytest`: https://pypi.python.org/pypi/pytest
 .. _`tox`: https://pypi.python.org/pypi/tox
 .. _`virtualenv`: https://pypi.python.org/pypi/virtualenv
diff --git a/docs/development/submitting-patches.rst b/docs/development/submitting-patches.rst
index 563bc81..475e703 100644
--- a/docs/development/submitting-patches.rst
+++ b/docs/development/submitting-patches.rst
@@ -48,7 +48,7 @@ API considerations
 Most projects' APIs are designed with a philosophy of "make easy things easy,
 and make hard things possible". One of the perils of writing cryptographic code
 is that secure code looks just like insecure code, and its results are almost
-always indistinguishable. As a result ``cryptography`` has, as a design
+always indistinguishable. As a result, ``cryptography`` has, as a design
 philosophy: "make it hard to do insecure things". Here are a few strategies for
 API design that should be both followed, and should inspire other API choices:
 
diff --git a/docs/development/test-vectors.rst b/docs/development/test-vectors.rst
index cc44492..4f0ece5 100644
--- a/docs/development/test-vectors.rst
+++ b/docs/development/test-vectors.rst
@@ -44,6 +44,7 @@ Custom asymmetric vectors
     :maxdepth: 1
 
     custom-vectors/secp256k1
+    custom-vectors/rsa-oaep-sha2
 
 * ``asymmetric/PEM_Serialization/ec_private_key.pem`` and
   ``asymmetric/DER_Serialization/ec_private_key.der`` - Contains an Elliptic
@@ -331,6 +332,7 @@ Hashes
 * SHA1 from `NIST CAVP`_.
 * SHA2 (224, 256, 384, 512) from `NIST CAVP`_.
 * Whirlpool from the `Whirlpool website`_.
+* Blake2s and Blake2b from OpenSSL `test/evptests.txt`_.
 
 HMAC
 ~~~~
@@ -455,4 +457,5 @@ header format (substituting the correct information):
 .. _`root data`: https://hg.mozilla.org/projects/nss/file/25b2922cc564/security/nss/lib/ckfw/builtins/certdata.txt#l2053
 .. _`asymmetric/public/PKCS1/dsa.pub.pem`: https://github.com/ruby/ruby/blob/4ccb387f3bc436a08fc6d72c4931994f5de95110/test/openssl/test_pkey_dsa.rb#L53
 .. _`Mozilla bug`: https://bugzilla.mozilla.org/show_bug.cgi?id=233586
-.. _`Russian CA`: http://e-trust.gosuslugi.ru/MainCA
+.. _`Russian CA`: https://e-trust.gosuslugi.ru/MainCA
+.. _`test/evptests.txt`: https://github.com/openssl/openssl/blob/2d0b44126763f989a4cbffbffe9d0c7518158bb7/test/evptests.txt
diff --git a/docs/faq.rst b/docs/faq.rst
index 3456ba9..76dc4f3 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -40,7 +40,20 @@ If you have no other libraries using OpenSSL in your process, or they do not
 appear to be at fault, it's possible that this is a bug in ``cryptography``.
 Please file an `issue`_ with instructions on how to reproduce it.
 
+Importing cryptography causes a ``RuntimeError`` about OpenSSL 0.9.8
+--------------------------------------------------------------------
+
+The OpenSSL project has dropped support for the 0.9.8 release series. Since it
+is no longer receiving security patches from upstream, ``cryptography`` is also
+dropping support for it. To fix this issue you should upgrade to a newer
+version of OpenSSL (1.0.1 or later). This may require you to upgrade to a newer
+operating system.
+
+For the 1.4 release, you can set the ``CRYPTOGRAPHY_ALLOW_OPENSSL_098``
+environment variable. Please note that this is *temporary* and will be removed
+in ``cryptography`` 1.5.
+
 .. _`NaCl`: https://nacl.cr.yp.to/
-.. _`PyNaCl`: https://pynacl.readthedocs.org
-.. _`WSGIApplicationGroup`: https://modwsgi.readthedocs.org/en/develop/configuration-directives/WSGIApplicationGroup.html
+.. _`PyNaCl`: https://pynacl.readthedocs.io
+.. _`WSGIApplicationGroup`: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIApplicationGroup.html
 .. _`issue`: https://github.com/pyca/cryptography/issues
diff --git a/docs/hazmat/backends/openssl.rst b/docs/hazmat/backends/openssl.rst
index 03ac557..f488a8b 100644
--- a/docs/hazmat/backends/openssl.rst
+++ b/docs/hazmat/backends/openssl.rst
@@ -43,7 +43,7 @@ Red Hat Enterprise Linux 5) and greater. Earlier versions may work but are
 OS random engine
 ----------------
 
-OpenSSL uses a user-space CSPRNG that is seeded from system random (
+By default OpenSSL uses a user-space CSPRNG that is seeded from system random (
 ``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded
 automatically when a process calls ``fork()``. This can result in situations
 where two different processes can return similar or identical keys and
diff --git a/docs/hazmat/bindings/commoncrypto.rst b/docs/hazmat/bindings/commoncrypto.rst
index 4f58a6d..fd3d39a 100644
--- a/docs/hazmat/bindings/commoncrypto.rst
+++ b/docs/hazmat/bindings/commoncrypto.rst
@@ -26,5 +26,5 @@ available on Mac OS X versions 10.8 and above.
         functions, and access constants.
 
 
-.. _`CFFI`: https://cffi.readthedocs.org/
+.. _`CFFI`: https://cffi.readthedocs.io
 .. _`CommonCrypto`: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/Common%20Crypto.3cc.html
diff --git a/docs/hazmat/bindings/openssl.rst b/docs/hazmat/bindings/openssl.rst
index 99cd7a4..8935093 100644
--- a/docs/hazmat/bindings/openssl.rst
+++ b/docs/hazmat/bindings/openssl.rst
@@ -44,6 +44,6 @@ lower performance in some situations. In particular parallelism is reduced
 because it has to acquire the GIL whenever any lock operations occur within
 OpenSSL.
 
-.. _`CFFI`: https://cffi.readthedocs.org/
+.. _`CFFI`: https://cffi.readthedocs.io
 .. _`OpenSSL`: https://www.openssl.org/
 .. _`thread safety facilities`: https://www.openssl.org/docs/manmaster/crypto/threads.html
diff --git a/docs/hazmat/primitives/asymmetric/ec.rst b/docs/hazmat/primitives/asymmetric/ec.rst
index b32d331..2c59374 100644
--- a/docs/hazmat/primitives/asymmetric/ec.rst
+++ b/docs/hazmat/primitives/asymmetric/ec.rst
@@ -341,7 +341,8 @@ Key Interfaces
 
         :type: int
 
-        The bit length of the curve's base point.
+        Size (in bits) of a secret scalar for the curve (as generated by
+        :func:`generate_private_key`).
 
 
 .. class:: EllipticCurveSignatureAlgorithm
diff --git a/docs/hazmat/primitives/asymmetric/rsa.rst b/docs/hazmat/primitives/asymmetric/rsa.rst
index c2a6d43..70e1678 100644
--- a/docs/hazmat/primitives/asymmetric/rsa.rst
+++ b/docs/hazmat/primitives/asymmetric/rsa.rst
@@ -153,6 +153,20 @@ secure hash function and padding:
     >>> signer.update(message)
     >>> signature = signer.finalize()
 
+There is a shortcut to sign sufficiently short messages directly:
+
+.. doctest::
+
+    >>> message = b"A message I want to sign"
+    >>> signature = private_key.sign(
+    ...     message,
+    ...     padding.PSS(
+    ...         mgf=padding.MGF1(hashes.SHA256()),
+    ...         salt_length=padding.PSS.MAX_LENGTH
+    ...     ),
+    ...     hashes.SHA256()
+    ... )
+
 Valid paddings for signatures are
 :class:`~cryptography.hazmat.primitives.asymmetric.padding.PSS` and
 :class:`~cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15`. ``PSS``
@@ -190,6 +204,20 @@ a public key to use in verification using
 If the signature does not match, ``verify()`` will raise an
 :class:`~cryptography.exceptions.InvalidSignature` exception.
 
+There is a shortcut to verify sufficiently short messages directly:
+
+.. doctest::
+
+    >>> public_key.verify(
+    ...     signature,
+    ...     message,
+    ...     padding.PSS(
+    ...         mgf=padding.MGF1(hashes.SHA256()),
+    ...         salt_length=padding.PSS.MAX_LENGTH
+    ...     ),
... 3812 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-cryptography.git



More information about the Python-modules-commits mailing list