<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="https://forum.yubico.com/feed.php?f=26&amp;t=1207" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2013-11-19T13:52:11+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=26&amp;t=1207</id>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-11-19T13:52:11+01:00</updated>
<published>2013-11-19T13:52:11+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4645#p4645</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4645#p4645"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4645#p4645"><![CDATA[
Hello again everyone,<br /><br />The guys at Yubico have been kind enough to provide me with a second Neo to test on and everything works fine on the new one (RSA signatures with small inputs take about 1.5 seconds, they no longer hang for 30-40 seconds then return a timeout error).<br /><br />The firmware version is the same (3.1.2) and I can't spot any differences in the ATR or the response to &quot;/identify&quot; in JCOP Tools. As far as I can tell the two Neos are identical, but one can sign just fine while the other one times out. This is with the exact same applet, same procedure to deploy, etc. It works on the new one and fails on the old one.<br /><br />I wonder if this could be a hardware issue - the old unit has seen a lot more use (a lot of flash writes), but the problem appears to have something to do with the random number generator. Maybe the RNG is faulty on the old unit and the card fails to get enough secure random bytes to do its padding for the RSA signature.<br /><br />Any ideas what I could try next?<br /><br />Thanks again to the Yubico team for providing me with a replacement unit.<br /><br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Tue Nov 19, 2013 1:52 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-11-08T20:04:53+01:00</updated>
<published>2013-11-08T20:04:53+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4593#p4593</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4593#p4593"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4593#p4593"><![CDATA[
Thank you Jakob!<br /><br />With your source code, running under JCOP Tools in Eclipse / Windows 7, here's my output:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">cm&gt;  /select 010203040506<br /> =&gt; 00 A4 04 00 06 01 02 03 04 05 06 00                ............<br /> (11589 usec)<br /> &lt;= 90 00                                              ..<br />Status: No Error<br />cm&gt;  /send 0001000000<br /> =&gt; 00 01 00 00 00                                     .....<br /> (15141 msec)<br /> &lt;= 90 00                                              ..<br />Status: No Error<br />cm&gt;  /send 0002000000<br /> =&gt; 00 02 00 00 00                                     .....<br /> (132184 usec)<br /> &lt;= 90 00                                              ..<br />Status: No Error<br />cm&gt;  /send 000300000104<br /> =&gt; 00 03 00 00 01 04                                  ......<br />jcshell: Error code: -6 (Card terminal error)<br />jcshell: Communication problems: No response after sending APDU; Unknown return code (0x8010002F) &#91;No response after sending APDU; Unknown return code (0x8010002F)&#93;</div><br /><br />So the key generation works (takes about 15 seconds), the signature initialization works (132ms) but the actual signing fails (the error code appears after about 30-40 seconds).<br /><br />What happens when you try it? <br /><br />Thank you,<br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Fri Nov 08, 2013 8:04 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Jakob]]></name></author>
<updated>2013-11-08T07:44:02+01:00</updated>
<published>2013-11-08T07:44:02+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4590#p4590</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4590#p4590"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4590#p4590"><![CDATA[
Ok - sorry for slow processing on this one. Just bringing up the stuff, filling in the blanks and get it done takes a bit of effort...<br /><br />Not sure I still fully understand what the problem is here. I've done a bit of cuttin' and pastin' to make up a test program and as far as I see it, it all works as expected. See below for a reference what that test program looks like and we may use that later on to narrow down the problem.<br /><br />Maybe I got something wrong here, but initializing a signature object without a valid private key does not seem to be a very good idea. Why would you do a <br /><br />What device firmware do you have ? NEOs shipped actually report two different firmware versions due to the &quot;two-layer design&quot;, with one piece of firmware and one Yubikey Javacard applet. The current device firmware version is 3.1.8 and this is what I've used for testing.<br /><br />Once I now have the setup going, let's see if we can resolve it from here.<br /><br />Best regards,<br /><br />JakobE<br />Hardware- and firmware guy @ Yubico<br /><br /><br /><br />package pkgBugTest;<br /><br />import javacard.framework.APDU;<br />import javacard.framework.ISO7816;<br />import javacard.framework.Applet;<br />import javacard.framework.ISOException;<br />import javacard.security.KeyPair;<br />import javacard.security.KeyBuilder;<br />import javacard.security.Signature;<br /><br />public class BugTest extends Applet <br />{<br />    private KeyPair tkp;<br />    Signature mySig;<br />    private final short OUT_OFFS = 100;<br />    <br />    public static void install(byte[] bArray, short bOffset, byte bLength) {<br />        new pkgBugTest.BugTest().register(bArray, (short) (bOffset + 1),<br />                bArray[bOffset]);<br />    }<br />    <br />    public void process(APDU apdu) {<br />        <br />        if (selectingApplet()) return;<br /><br />        byte[] buf = apdu.getBuffer();<br />        short len = apdu.setIncomingAndReceive();<br />        <br />        switch (buf[ISO7816.OFFSET_INS]) {<br />        <br />            case 0x01:<br />                tkp = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);<br />                tkp.genKeyPair();<br />                break;<br />    <br />            case 0x02:<br />                mySig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);<br />                mySig.init(tkp.getPrivate(), Signature.MODE_SIGN);<br />                break;                <br /><br />            case 0x03:<br />                len = mySig.sign(buf, (short) 0, (short) len, buf, OUT_OFFS);<br />                apdu.setOutgoingAndSend(OUT_OFFS, len);<br />                break;                <br />                                <br />            case 0x04:<br />                Signature sig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);<br />                sig.init(tkp.getPrivate(), Signature.MODE_SIGN);<br />                len = sig.sign(buf, (short) 0, (short) len, buf, OUT_OFFS);<br />                apdu.setOutgoingAndSend(OUT_OFFS, len);<br />                break;                <br />                                    <br />            default:<br />                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);<br />        }<br />    }<br />}<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=83">Jakob</a> — Fri Nov 08, 2013 7:44 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-25T19:12:12+01:00</updated>
<published>2013-10-25T19:12:12+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4549#p4549</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4549#p4549"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4549#p4549"><![CDATA[
Anyone? This is annoying as hell, especially since it works on two other platforms that I've tried (one of them running the exact same JCOP version as the Neo). <br /><br />I can try to get in touch with NXP (we are under NDA with them) to ask if this is a known issue, but can anyone else please confirm that  this happens on their Neos as well? I only have one Neo, but I doubt the problem is only with my device.<br /><br />Thank you,<br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Fri Oct 25, 2013 7:12 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-20T22:40:23+01:00</updated>
<published>2013-10-20T22:40:23+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4531#p4531</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4531#p4531"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4531#p4531"><![CDATA[
Ok, I've narrowed it down a bit and it does appear to have something to do with the entropy / random number generation.<br /><br />Basically, I can make it work by adding a dummy keypair generation right before initializing the Signature object. Something like this: <br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">tkp = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);<br />tkp.genKeyPair();</div><br /><br />right above<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);<br /></div><br /><br />That dummy is <strong>not </strong>used, it's just generated and then dumped. <br /><br />Now my guess: ALG_RSA_SHA_PKCS1 basically means (according to the JavaDoc):<br /><br /><div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />Signature algorithm ALG_RSA_SHA_PKCS1 generates a 20-byte SHA digest, pads the digest according to the PKCS#1 (v1.5) scheme, and encrypts it using RSA.<br /></div><br /><br />The problem is that the RSA key is 2048 bits (256 bytes) while the digest is only 20 bytes long. PKCS1 requires padding with random (if I understand correctly, it tries to pad it with 256-20-3 = 233 bytes). So it probably starts up a secure RNG and tries to generate 233 random bytes and for some reason that takes a long time or doesn't ever return. A smaller RSA key (1024 bits = 128 bytes) would only need about 105 bytes of random padding.<br /><br />I suspect that generating a new key somehow tells the RNG to collect some entropy (while the signature generation does not ???). <br /><br />This should be relatively easy to replicate, just don't create your keypair right before the Signature object, that will make it work. Try to create the KeyPair on install and sign in the process() method as response to a command APDU.<br /><br />Any clues?<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Sun Oct 20, 2013 10:40 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-19T02:05:54+01:00</updated>
<published>2013-10-19T02:05:54+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4528#p4528</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4528#p4528"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4528#p4528"><![CDATA[
<div class="codetitle"><b>Code:</b></div><div class="codecontent"> =&gt; 00 A4 04 00 08 A0 00 00 05 27 20 01 01 00<br /> &lt;= 03 01 02 03 87 07 01 00 00 00 90 00 </div><br /><br />So I guess firmware 3.1.2 ??<br /><br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Sat Oct 19, 2013 2:05 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[sliver]]></name></author>
<updated>2013-10-19T00:18:31+01:00</updated>
<published>2013-10-19T00:18:31+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4527#p4527</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4527#p4527"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4527#p4527"><![CDATA[
Try to select the Yubikey Applet. <br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">-&gt; 00 a4 04 00 08 a0 00 00 05 27 20 01 01 00<br />&lt;- 03 00 02 01 05 07 82 0f 00 00</div><br />0x030002 = Firmware 3.0.2 <br />0x01 = Programming sequence number<br />0x0507 = Level from touch detector<br />0x82 = Mode<br />0x0f = Challenge-response timeout in seconds<br />0x0000 = Auto eject time in seconds<br /><br />You might have to touch the button to be able to select this applet, or else it might return 0x6999. <br />See my posts here: <a href="http://forum.yubico.com/viewtopic.php?f=26&amp;t=1197" class="postlink">http://forum.yubico.com/viewtopic.php?f=26&amp;t=1197</a> <br /><br /><br />You could also use the &quot;ykinfo&quot; command in ykpersonalize<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2230">sliver</a> — Sat Oct 19, 2013 12:18 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-19T00:04:39+01:00</updated>
<published>2013-10-19T00:04:39+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4526#p4526</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4526#p4526"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4526#p4526"><![CDATA[
I'm not sure what firmware it's running, is there any way to tell via an APDU? I've disabled the HID part of it, it's in smartcard (APDU) only mode (can't remember what it was called officially). <br /><br />Here's what the JCOP Tools say :<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">cm&gt;  /atr<br />resetCard with timeout: 0 (ms)<br />--Waiting for card...<br />ATR=3B FC 13 00 00 81 31 FE 45 59 75 62 69 6B 65 79    ;.....1.EYubikey<br />    4E 45 4F 72 33 B1                                  NEOr3.<br /> IOCTL().<br />ATR: <br />      IFSC = 254                 <br />       BWI = 4                   <br />       CWI = 5                   <br />      Hist = YubikeyNEOr3        <br />         T = 1                   <br />        FI = 1                   <br />        DI = 3                   <br />   clk/etu = 93                  <br />         N = 0                   <br />&gt;  /identify<br /> =&gt; 00 A4 04 00 09 A0 00 00 01 67 41 30 00 FF          .........gA0..<br /> (24135 usec)<br /> &lt;= 03 C1 01 38 00 00 00 00 4E 58 31 33 30 41 01 03    ...8....NX130A..<br />    C3 10 EA 6A 82                                     ...j.<br />Status: File not found<br />FABKEY ID:   0x03<br />PATCH ID:    0xC1<br />TARGET ID:   0x01 (smartmx)<br />MASK ID:     0x38 (56)<br />CUSTOM MASK: 00000000<br />MASK NAME:   NX130A<br />FUSE STATE:  fused<br />ROM INFO:    C310EA<br />COMBO NAME:  smartmx-m38.03.C1-NX130A</div><br /><br />Is the firmware upgradeable on these? <br /><br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Sat Oct 19, 2013 12:04 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[sliver]]></name></author>
<updated>2013-10-18T23:44:04+01:00</updated>
<published>2013-10-18T23:44:04+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4525#p4525</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4525#p4525"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4525#p4525"><![CDATA[
What firmware version is your NEO? <br /><br />I have firmware 3.0.2, and when running your simple example i get <br /><br />RSA 1024 : 133 ms<br />RSA 2048: 592 ms<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2230">sliver</a> — Fri Oct 18, 2013 11:44 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-18T13:04:52+01:00</updated>
<published>2013-10-18T13:04:52+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4521#p4521</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4521#p4521"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4521#p4521"><![CDATA[
Hi Jakob,<br /><br />I've run a few more tests and here's what I found:<br /><br />1. RSA-1024 works fine, it signs within a few milliseconds.<br />2. RSA-2048 signing almost never returns, hangs almost indefinitely<br />3. The key is generated (on install) like this:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">MANUFACTURER_KEY = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);<br />MANUFACTURER_KEY.genKeyPair();</div><br /><br />then to sign data, I do this<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">Signature sig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);<br />sig.init(MANUFACTURER_KEY.getPrivate(), Signature.MODE_SIGN);<br />short sl = sig.sign(buf, offs, len, buf, offs);<br />apdu.setOutgoingAndSend(offs, sl);<br />break;</div><br /><br />I've tested this code on 3 cards - an engineering sample from NXP (running the same OS as the Yubikey, JCOP 2.4.2 R1), a microSD form factor card (running JCOP 2.4.1 R3) and the Yubikey Neo. The code works fine on the other two (signing times like 630737us), but not on the Yubikey.<br /><br />4. It appears to have nothing to do with the size of the data to sign, even a 3 byte array takes forever.<br /><br />Again, this is only for RSA 2048, RSA with 1024bit keys appears to work fine, it's very fast and usable.<br /><br />Any ideas?<br /><br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Fri Oct 18, 2013 1:04 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Jakob]]></name></author>
<updated>2013-10-18T08:33:57+01:00</updated>
<published>2013-10-18T08:33:57+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4518#p4518</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4518#p4518"/>
<title type="html"><![CDATA[Re: Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4518#p4518"><![CDATA[
Hi Razvan,<br /><br />Not sure what you mean by &quot;incredibly slow&quot; and exactly what algorithm you use. <br /><br />The &quot;official&quot; figure for something like RSA signature.sign() using algorithm Signature.ALG_RSA_SHA_PKCS1 with RSA CRT and SHA-1 is about 475 ms for a 128 bytes message. I very much believe this is in line with most JCOP devices in this class and is a somewhat average figure for this type of smartcard ICs.<br /><br />It may vary a bit, but it should definitely not be an order of magnitude so Please let me know if you're in this ballpark or if you're using something more &quot;exotic&quot; that this. <br /><br />Best regards,<br /><br />JakobE<br />Hardware- and firmware guy @ Yubico<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=83">Jakob</a> — Fri Oct 18, 2013 8:33 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[drazvan]]></name></author>
<updated>2013-10-18T01:05:54+01:00</updated>
<published>2013-10-18T01:05:54+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4515#p4515</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4515#p4515"/>
<title type="html"><![CDATA[Slow RSA-2048 encryption/signing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1207&amp;p=4515#p4515"><![CDATA[
Hello everyone,<br /><br />Has anyone else noticed that the RSA implementation on the Neo is incredibly slow, at least for 2048-bit keys? I have a bunch of JCOP cards here (some newer, some older than the Neo) and all of them are an order of magnitude faster at computing RSA signatures than the Neo. I could post code snippets if needed, but I have the feeling that RSA 2048 operations either do not go through the crypto accelerator or they force the use of persistent memory instead of RAM.<br /><br />Any ideas?<br /><br />Thank you,<br />Razvan<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2400">drazvan</a> — Fri Oct 18, 2013 1:05 am</p><hr />
]]></content>
</entry>
</feed>