5257f0
From 5617aafa2d44d0a4bc811830e225463abd01b2b2 Mon Sep 17 00:00:00 2001
5257f0
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
5257f0
Date: Tue, 21 May 2013 10:01:33 +0200
5257f0
Subject: [PATCH] Fix build against OpenSSL with enabled ECC curves.
5257f0
5257f0
---
5257f0
 ext/openssl/ossl_pkey_ec.c   |  4 ++++
5257f0
 test/openssl/test_pkey_ec.rb | 26 +++++++++++++-------------
5257f0
 2 files changed, 17 insertions(+), 13 deletions(-)
5257f0
5257f0
diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c
5257f0
index 8e6d88f..29e28ca 100644
5257f0
--- a/ext/openssl/ossl_pkey_ec.c
5257f0
+++ b/ext/openssl/ossl_pkey_ec.c
5257f0
@@ -762,8 +762,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
5257f0
                 method = EC_GFp_mont_method();
5257f0
             } else if (id == s_GFp_nist) {
5257f0
                 method = EC_GFp_nist_method();
5257f0
+#if !defined(OPENSSL_NO_EC2M)
5257f0
             } else if (id == s_GF2m_simple) {
5257f0
                 method = EC_GF2m_simple_method();
5257f0
+#endif
5257f0
             }
5257f0
 
5257f0
             if (method) {
5257f0
@@ -817,8 +819,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
5257f0
 
5257f0
             if (id == s_GFp) {
5257f0
                 new_curve = EC_GROUP_new_curve_GFp;
5257f0
+#if !defined(OPENSSL_NO_EC2M)
5257f0
             } else if (id == s_GF2m) {
5257f0
                 new_curve = EC_GROUP_new_curve_GF2m;
5257f0
+#endif
5257f0
             } else {
5257f0
                 ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
5257f0
             }
5257f0
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
5257f0
index f151335..56f3ff7 100644
5257f0
--- a/test/openssl/test_pkey_ec.rb
5257f0
+++ b/test/openssl/test_pkey_ec.rb
5257f0
@@ -7,28 +7,28 @@ class OpenSSL::TestEC < Test::Unit::TestCase
5257f0
     @data1 = 'foo'
5257f0
     @data2 = 'bar' * 1000 # data too long for DSA sig
5257f0
 
5257f0
-    @group1 = OpenSSL::PKey::EC::Group.new('secp112r1')
5257f0
-    @group2 = OpenSSL::PKey::EC::Group.new('sect163k1')
5257f0
-    @group3 = OpenSSL::PKey::EC::Group.new('prime256v1')
5257f0
+    @groups = []
5257f0
+    @keys = []
5257f0
 
5257f0
-    @key1 = OpenSSL::PKey::EC.new
5257f0
-    @key1.group = @group1
5257f0
-    @key1.generate_key
5257f0
+    OpenSSL::PKey::EC.builtin_curves.each do |curve, comment|
5257f0
+      group = OpenSSL::PKey::EC::Group.new(curve)
5257f0
 
5257f0
-    @key2 = OpenSSL::PKey::EC.new(@group2.curve_name)
5257f0
-    @key2.generate_key
5257f0
+      key = OpenSSL::PKey::EC.new(group)
5257f0
+      key.generate_key
5257f0
 
5257f0
-    @key3 = OpenSSL::PKey::EC.new(@group3)
5257f0
-    @key3.generate_key
5257f0
-
5257f0
-    @groups = [@group1, @group2, @group3]
5257f0
-    @keys = [@key1, @key2, @key3]
5257f0
+      @groups << group
5257f0
+      @keys << key
5257f0
+    end
5257f0
   end
5257f0
 
5257f0
   def compare_keys(k1, k2)
5257f0
     assert_equal(k1.to_pem, k2.to_pem)
5257f0
   end
5257f0
 
5257f0
+  def test_builtin_curves
5257f0
+    assert(!OpenSSL::PKey::EC.builtin_curves.empty?)
5257f0
+  end
5257f0
+
5257f0
   def test_curve_names
5257f0
     @groups.each_with_index do |group, idx|
5257f0
       key = @keys[idx]
5257f0
-- 
5257f0
1.8.2.1
5257f0