[openssl-dev] ECDH engine

Blumenthal, Uri - 0553 - MITLL uri at ll.mit.edu
Wed Jan 27 17:25:46 UTC 2016


> When I started to write the ECDSA code for engine_pkcs11  in 2011 the code to
> support the method hooks was not
> in the code. So I used internal OpenSSL header files to copy the ECDSA_METHOD
> and replace the function needed.
> Look for "BUILD_WITH_ECS_LOCL_H" in libp11.  Not until 1.0.2 did OpenSSL
> support the needed calls to hook ECDSA.
> They did not add the hooks for ECDH.

I am missing one thing here. Hopefully you can help me understanding it.

OpenSSL-1.0.2 currently supports ECDH, as I observe by running
openssl pkeyutl -derive -inkey /tmp/derive.29494.priv.pem -peerkey
/tmp/derive.29494.token.pub.pem -out /tmp/derive.29494.shared1


So clearly there is working code available inside OpenSSL that does what is
needed. The only issue then is to add code to libp11 to access that code.

Am I correct? If not, could you please point at where/what I’m mistaken in?

> If you can't wait then you have to do it your self.  *YOU* could do the same
> thing for ECDH. But your code would only
> be good for 1.0.2 because the whole way of doing EC methods changes in 1.1.

That’s perfectly OK, because if my tea leaves reading is correct,
OpenSSL-1.0.2 will be around for several years at least. And most of the
package providers such as Macports won’t move their packages to OpenSSL-1.1
for probably that long. So making 1.0.2 working with ECDH now will
definitely make sense for me.

In fact, I think making libp11 compliant with OpenSSL-1.1 now is an
overreach, because this effort (unlike work on 1.0.2) is highly unlikely to
bring benefits to users for a few years.

> I believe Alexander said he had changes to OpenSSL, which is another approach.
> He has said there were here:
> https://github.com/AtmelCSO/cryptoauth-openssl-engine/tree/master/patches

I see that the actual patch is very small. And the only meaningful (for me)
change is adding a new method EC_generate_key(). I would like to understand
why this method is needed – is it only to allow OpenSSL to generate key pair
on the token? Alexander, could you comment please?

> You could also hire someone who could do more then: "test it and offer minor
> enhancements".

First, I cannot. Second, I don’t think (and haven’t seen any evidence to the
contrary yet) that anything more is needed. Especially seeing the minuscule
amount of changes Alexander had to do to OpenSSL, and I’m not even sure I
need those if I don’t insist on being able to generate new key pair on the
token using only OpenSSL.

> (And not me. I am taking the 1.1 approach to getting ECDH. working in engine.)

:-)  OK, I withdraw my unexpressed and unformulated offer. Consider yourself
un-asked.  :-)


> On 1/20/2016 2:19 PM, Blumenthal, Uri - 0553 - MITLL wrote:
>> Very possible that I'm missing the point here.
>> 
>> Still, since openssl-1_0_2 does ECDH, and it exposes ‎ECDSA to external
>> engine(s), how difficult would it be to add ECDH exposure? I suspect - a good
>> deal easier than getting 1.1 replace 1.0.x as the de-facto deployment
>> standard.
>> 
>> Plus, by this time there already are (and reasonably common) tokens that
>> support ECDH, other packages that do ECDH, and people (like myself :-)
>> willing to test it and offer minor enhancements.
>> 
>> Another point I seem to be missing - if what's necessary to implement ECDH in
>> an external engine is missing from 1_0_2 - how could ‎Alexander write a
>> (presumably) working ECDH engine for 1_0_2? If he could do it,  why can't
>> engine_pkcs11 be extended to do the same?
>> 
>> Sent from my BlackBerry 10 smartphone on the Verizon Wireless 4G LTE network.
>> From: Douglas E Engert
>> Sent: Wednesday, January 20, 2016 14:59
>> To: openssl-dev at openssl.org>> Reply To: openssl-dev at openssl.org
>> Subject: Re: [openssl-dev] ECDH engine
>>>> You are missing the point. OpenSSL-1.0.2 only exposed ECDSA, not ECDH to
>> external engines.  It took years to even get ECDSA exposed.
>> OpenSSL approach to support this is OpenSSL-1.1  that does a lot of other
>> things. But that was there approach. Its their package.
>>> >From working package to distribution always takes several years...
>> 
>> 
>> 
>>>> On 1/20/2016 1:34 PM, Blumenthal, Uri - 0553 - MITLL wrote:
>>>> Probably it was one of the main reasons why we didn't use pkcs11 for
>>>> ATECC508A and wrote an engine instead
>>> 
>>> I still argue with the approach (IMHO nobody needs yet another limited
>>> engine), but constraining ECC additions to 1.1 does not make any sense to
>>> me. 1.0.2 is going to be around for a quite a while. A lot of applications
>>> won’t migrate to 1.1 quickly – a few years would be a good/reasonable/safe
>>> bet. 
>>> 
>>> To restrict this work to 1.1 means pushing this basic capability off by
>>> (realistically) several years. Most people can’t/won't deploy openssl-1.1 as
>>> long as it interferes with the majority of the applications they or their OS
>>> is using, is not good. I for one won’t be able to use 1.1 in practice until
>>> it becomes the embraced standard and software such as Macports port set is
>>> moved to support it. I’m 100% sure there are many more of us in this bus, on
>>> different OS (e.g., it looks like Ubuntu is even worse off than Macports).
>>> 
>>> 
>>>> On Wed, Jan 20, 2016 at 11:10 AM, Blumenthal, Uri - 0553 - MITLL
>>>> <uri at ll.mit.edu> wrote:
>>>>> Are you saying it won't work on OpenSSL_1_0_2-stable?!
>>>>> 
>>>>> Sent from my BlackBerry 10 smartphone on the Verizon Wireless 4G LTE
>>>>> network.
>>>>> From: Douglas E Engert
>>>>> Sent: Wednesday, January 20, 2016 14:07
>>>>> To:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>> Reply To:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>> Subject: Re: [openssl-dev] ECDH engine
>>>>> 
>>>>> Patches are underdevelopment for OpenSC's libp11 and engine_pkcs11 to
>>>>> support ECDH. There are waiting for OpenSSL-1.1 to be come stable
>>>>> and some minor bug  fixes. Testing is proceeding using OpenSSL-1.1-pre2
>>>>> today.  OpenSSL-1.1 is needed because it exposes the functions needed
>>>>> to use ECDH from an external engine i.e.  the OPenSC engine_pkcs11.
>>>>>>>>>>   https://github.com/OpenSC/libp11/issues/52
>>>>>   https://github.com/dengert/libp11/tree/prep-openssl-1.1
>>>>>   https://github.com/dengert/engine_pkcs11/tree/prep-openssl-1.1
>>>>> 
>>>>> In addition to a major rewrite of combining the ECDSA_METHOD and
>>>>> ECDH_METHOD into an C_KEY_METHOD, OpenSSL-1.1  introduces a lot of
>>>>> changes, 
>>>>> mainly because it hides many of the structures that have been exposed in
>>>>> the past. This causes a major rewrite of code to use functions to access
>>>>> these structures.
>>>>> 
>>>>> Although OpenSC could still use an older version of OpenSSL, there is also
>>>>> underway changes for OpenSC to use OpenSSL-1.1:
>>>>> https://github.com/OpenSC/OpenSC/pull/654
>>>>> https://github.com/dengert/OpenSC/tree/prep-openssl-1.1
>>>>> 
>>>>> 
>>>>> On 1/20/2016 12:02 PM, Blumenthal, Uri - 0553 - MITLL wrote:
>>>>>> I forgot to add that ‎OpenSSL-1_0-2-stable with the current (Github
>>>>>> master) engine-pkcs11, libp11, and OpenSC successfully does ECDSA with
>>>>>> keys on the token (tested for ECC256 and ECC384).
>>>>>> 
>>>>>> OpenSC tools successfully derive (i.e., implement ECDH1_DERIVE). I'm
>>>>>> waiting for libp11 and engine_pkcs11 to add this capability.
>>>>>>>>>>>> Ideally this is where your code would plug in, and complete the circle.
>>>>>> 
>>>>>> As it currently is, a separate Atmel-specific ECC-specific engine is of a
>>>>>> limited usefulness.
>>>>>> 
>>>>>> Sent from my BlackBerry 10 smartphone on the Verizon Wireless 4G LTE
>>>>>> network.
>>>>>> From: Blumenthal, Uri - 0553 - MITLL
>>>>>> Sent: Wednesday, January 20, 2016 12:46
>>>>>> To:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>>> Reply To:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>>> Subject: Re: [openssl-dev] ECDH engine
>>>>>> 
>>>>>>> The ATECC508A is a chip. There are few USB devices built by Atmel on its
>>>>>>> base. Or you can use the chip directly over I2C (that many people like
>>>>>>> to do). You can follow the links that we posted on the ATECCX08 Engine
>>>>>>> repository WiKi to learn about the chip.
>>>>>> 
>>>>>> I see, thanks.
>>>>>> 
>>>>>>> Well, our first indent was to use the pksc11 library. But it didn't go
>>>>>>> to well for many reasons. I should go back for several months to collect
>>>>>>> these reasons but I think the main reason was that ATECC508A hardware is
>>>>>>> based on ECC-256 algorithms while pkcs11 is originally written for RSA -
>>>>>>> the overhead was looking too high (many ATECC508 customers are using
>>>>>>> limited hardware and want direct I2C connection to the chip).
>>>>>> 
>>>>>> There are a few hardware tokens (USB-pluggable), e.g. Yubikey, that
>>>>>> support ECC256 and (in case of Yubikey 4) ECC384.
>>>>>> 
>>>>>>> But let's talk about pkcs11. Can you point me to the set of
>>>>>>> documentation for EC-DERIVE? It may be a good time now to add the
>>>>>>> ATECC508 support to there.
>>>>>> 
>>>>>> Honestly, I’m more interested in adding ECDH support – assuming that it
>>>>>> would also serve ATECC508, rather than working on ATECC508B and hoping
>>>>>> that perhaps it would be usable for other ECC-capable tokens.
>>>>>> 
>>>>>> Here’s the PKCS#11 spec
>>>>>> <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/pkcs11-curr-v2.40.pd
>>>>>> f> 
>>>>>> http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/pkcs11-curr-v2.40.pdf
>>>>>> , which covers ECDH including ECDH1_DERIVE and ECDH1_COFACTOR_DERIVE. I
>>>>>> think older versions (like v2.20) have more content, but this is the
>>>>>> current one.
>>>>>> 
>>>>>> Hope it helps.
>>>>>> 
>>>>>> P.S. At this time I’m standing by my original opinion – that a better way
>>>>>> is incorporating ECDH1_*DERIVE in libp11 and engine_pkcs11, rather than
>>>>>> creating an engine specifically for one chip that add uncertainly of
>>>>>> non-interoperability with other chips/tokens.
>>>>>> 
>>>>>> 
>>>>>>> On Jan 20, 2016, at 8:11 AM, Blumenthal, Uri - 0553 - MITLL <
>>>>>>> <mailto:uri at ll.mit.edu> uri at ll.mit.edu> wrote:
>>>>>>> 
>>>>>>> What is this Atmel x508x? Is it a chip? Is it a token/smartcard? Is it
>>>>>>> accessible via PKCS#11 at all? Is it accessible by/via OpenSC?
>>>>>>> 
>>>>>>> I am trying to figure why such a generic and useful set of ECC
>>>>>>> operations (Sign, Derive) is implementation-limited to one single
>>>>>>> <whatever>.
>>>>>>> 
>>>>>>> A much better solution to me would be adding EC-DERIVE to engine_pkcs11,
>>>>>>> and automatically get all the tokens covered.
>>>>>>> 
>>>>>>> Since I'm probably‎ missing something, could you please educate me?
>>>>>>> 
>>>>>>> Sent from my BlackBerry 10 smartphone on the Verizon Wireless 4G LTE
>>>>>>> network.
>>>>>>> From: Alexander Gostrer‎
>>>>>>> Sent: Wednesday, January 20, 2016 10:47
>>>>>>> To: Dr. Stephen Henson
>>>>>>> Reply To:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>>>> Cc:  <mailto:openssl-dev at openssl.org> openssl-dev at openssl.org
>>>>>>> Subject: Re: [openssl-dev] ECDH engine
>>>>>>>>>>>>>> Hi Steve,
>>>>>>>>>>>>>> And here is the ENGINE implementation for Atmel ATECC508A with few small
>>>>>>> patches to OpenSSL_1_0_2-stable:
>>>>>>>  <https://github.com/AtmelCSO/cryptoauth-openssl-engine>
>>>>>>> https://github.com/AtmelCSO/cryptoauth-openssl-engine
>>>>>>> 
>>>>>>> Your comments are welcome.
>>>>>>> 
>>>>>>> Regards,
>>>>>>> Alex.
>>>>>>> 
>>>>>>> On Sat, Dec 19, 2015 at 12:49 PM, Dr. Stephen Henson <
>>>>>>> <mailto:steve at openssl.org> steve at openssl.org> wrote:
>>>>>>> On Fri, Dec 18, 2015, Alexander Gostrer wrote:
>>>>>>> 
>>>>>>>> > Hi Steve,
>>>>>>>> >
>>>>>>>> > John and I completed writing an ECDH engine based on the
>>>>>>>> > OpenSSL_1_0_2-stable branch. We were planning to expand it to the
>>>>>>>> master
>>>>>>>> > but found some major changes made by you recently. What is the status
>>>>>>>> of
>>>>>>>> > this task? Is it stable enough to follow it? Are you planning another
>>>>>>>> > changes? Is there a design document that we can use in our work?
>>>>>>>> >
>>>>>>> 
>>>>>>> The version in master shouldn't change much any more. Documentation will
>>>>>>> be
>>>>>>> available in the near future. The changes were meant to remove some of
>>>>>>> the
>>>>>>> weird "quirks" of ECC compared to other algortihms and to permit future
>>>>>>> expansion to a wider range of curves.
>>>>>>> 
>>>>>>> In the meantime it shouldn't be too hard to follow how the new code
>>>>>>> works.
>>>>>>> Instead of separate ECDH/ECDSA methods with weird locking and ex_data
>>>>>>> and
>>>>>>> minimal ENGINE support everything is combined into a single
>>>>>>> EC_KEY_METHOD
>>>>>>> which can contain ECDSA, ECDH and key generation (something which was
>>>>>>> impossible with the old code) and be tied directly to an ENGINE.
>>>>>>> 
>>>>>>> Most of the primary APIs such as ECDH_compute_key can be redirected
>>>>>>> directly
>>>>>>> through an engine supplied function in EC_KEY_METHOD.
>>>>>>> 
>>>>>>> Having said that the code is very new and may have the odd bug that
>>>>>>> needs to
>>>>>>> be fixed. If you have any problems let me know and I'll look into them.
>>>>>>> 
>>>>>>> Steve.
>>>>>>> --
>>>>>>> Dr Stephen N. Henson. OpenSSL project core developer.
>>>>>>> Commercial tech support now available see:  <http://www.openssl.org>
>>>>>>> <http://www.openssl.org> http://www.openssl.org
>>>>>>> 
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> openssl-dev mailing list
>>>>>>> To unsubscribe:  <https://mta.openssl.org/mailman/listinfo/openssl-dev>
>>>>>>> <https://mta.openssl.org/mailman/listinfo/openssl-dev>
>>>>>>> https://mta.openssl.org/mailman/listinfo/openssl-dev
>>>>>> 
>>>>>> 
>>>>>>  
>>>>>> _______________________________________________
>>>>>> openssl-dev mailing list
>>>>>> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
>>>>>> 
>>>>>> -- 
>>>>>> 
>>>>>>  Douglas E. Engert  <DEEngert at gmail.com> <mailto:DEEngert at gmail.com>
>>>>>>  
>>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> openssl-dev mailing list
>>>>> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
>>>>> 
>>>>> 
>>>> 
>>>>  
>>>> _______________________________________________
>>>> openssl-dev mailing list
>>>> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
>>>> 
>>>> -- 
>>>> 
>>>>  Douglas E. Engert  <DEEngert at gmail.com> <mailto:DEEngert at gmail.com>
>>>>  
>>>> 
>>> 
>>> 
>>>  
>>> _______________________________________________
>>> openssl-dev mailing list
>>> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
>>> 
>>> -- 
>>> 
>>>  Douglas E. Engert  <DEEngert at gmail.com> <mailto:DEEngert at gmail.com>
>>>  
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-dev/attachments/20160127/99798ff1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4308 bytes
Desc: not available
URL: <http://mta.openssl.org/pipermail/openssl-dev/attachments/20160127/99798ff1/attachment-0001.bin>


More information about the openssl-dev mailing list