<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;"><div><div><div>I’m not sure whether this is a bug (as I suspect – hence sending to openssl-dev), or a poorly-documented “feature” (so copying to openssl-users).</div><div><br></div><div>I am trying to use “openssl pkeyutl” to digitally sign (and verify) a file.</div><div><br></div><div>When the file size matches the size of the specified digest (32 bytes for SHA256, 48 bytes for SHA384, etc), everything seems fine:</div><div><p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$ openssl pkeyutl -engine pkcs11 -keyform engine -sign -inkey "pkcs11:object=SIGN%20key;object-type=private" -pkeyopt digest:sha384 -out t384.ecdsa.sig -in t384.dat</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">engine "pkcs11" set.</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">PKCS#11 token PIN: </p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$ openssl pkeyutl -engine pkcs11 -keyform engine -verify -pubin -inkey "pkcs11:object=SIGN%20pubkey;object-type=public" -sigfile t384.ecdsa.sig -in t384.dat</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">engine "pkcs11" set.</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">Signature Verified Successfully</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$</p></div><div><br></div><div>However, if I try to feed it a larger file, it complains regardless of whether I specify a hash-function to digest the file:</div><div><p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$ openssl pkeyutl -engine pkcs11 -keyform engine -sign -inkey "pkcs11:object=SIGN%20key;object-type=private" -pkeyopt digest:sha1 -out t2570.ecdsa.sig -in t2570.dat</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">engine "pkcs11" set.</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">PKCS#11 token PIN: </p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">Public Key operation error</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">140735120921424:error:80029001:PKCS11 library:func(41):Cancel:p11_ops.c:61:</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$ openssl pkeyutl -engine pkcs11 -keyform engine -sign -inkey "pkcs11:object=SIGN%20key;object-type=private" -pkeyopt digest:sha384 -out t2570.ecdsa.sig -in t2570.dat</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">engine "pkcs11" set.</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">PKCS#11 token PIN: </p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">Public Key operation error</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">140735120921424:error:80029001:PKCS11 library:func(41):Cancel:p11_ops.c:61:</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$ openssl pkeyutl -engine pkcs11 -keyform engine -sign -inkey "pkcs11:object=SIGN%20key;object-type=private" -out t2570.ecdsa.sig -in t2570.dat</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">engine "pkcs11" set.</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">PKCS#11 token PIN: </p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">Public Key operation error</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">140735120921424:error:80029001:PKCS11 library:func(41):Cancel:p11_ops.c:61:</p>
<p style="margin: 0px; font-size: 16px; font-family: Monaco; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">$</p></div><div><br></div><div>If the input to "pkeyutl –sign” is supposed to be digest output only – then what’s the point of having command line arguments specifying the digest to use? And if the input can be an arbitrary file (like for “dgst”), then why it doesn’t seem to work?</div><div><br></div><div>I’d appreciate comments, guidance, etc.</div><div><br></div><div>Thanks!</div><div><div>-- </div><div><div style="font-size: medium;">Regards,</div><div style="font-size: medium;">Uri Blumenthal</div></div></div></div></div></body></html>