santuario-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Random failure when signing document with EC private key
Date Fri, 14 Jun 2013 17:07:05 GMT
I am signing a DOM document with an EC private key.
Now the verify gives randomly an error:
OpenSSL:EC - Signature length was odd.

Signing does not throw exceptions so from the procedure point
of view it succeeds. Signing is done as follows:

int sign_document(xercesc_3_1::DOMDocument* doc, EVP_PKEY* ECpkey) {
  XSECProvider prov;
  DSIGSignature* sig;
  OpenSSLCryptoKeyEc* ECkey = NULL;

  try {
    ECkey = new OpenSSLCryptoKeyEC(ECpkey);
    sig = prov.newSignatureFromDOM(doc);
  catch (XSECException &e) {
    std::cerr << XMLString::transcode(e.getMsg()) << std::endl;
    return 0;
  return 1;

I made a test setup where the same document is
signed and verified in a loop. Verification fails
with the above error message randomly between 1 
and 500+ rounds, but eventually the signature
verification will fail.

I noticed that when the verification fails then in 
the function OpenSSLCryptoKeyEC::signBase64SignatureDSA
rawLenS is different than in successful cases. 

In order to exclude possible DOM document issue I modified 
signBase64SignatureDSA function 
so that the same hash is signed in a loop. That produces
in the end different rawLenS as well, number of loops varies but
eventually different length is returned which most probably is
the reason for signature (that is verify) to fail. The actual signing
is done by OpenSSL ecdsa_do_sign function but debugging of it would
require better understanding of EC algorithms.

OpenSSL-1.0.1e and xml-security-c-1.7.0 versions are

Any idea what could be the reason for the random failure?


Please note: This e-mail may contain confidential information
intended solely for the addressee. If you have received this
e-mail in error, please do not disclose it to anyone, notify
the sender promptly, and delete the message from your system.
Thank you.

View raw message