ECDSA prime256v1 cross-platform signature verification error

I need to verify a signature with Java / Android and an ATEC108A chip that is generated in a .NET environment. (Using SunEC and AndroidOpenSSL)

The signature is generated in .Net using BCrypt, keys are also generated using BCrypt and stored in the Microsoft key store. The signature and public key can be sent to the AT chip and it verifies, however it does not work on Android.

Key / Signature Process:

  • The public key is exported from BCrypt in x.509 key format, which includes ids for SHA256-ECDSA and prime256v1 curve, resulting in:

    3059301306072A8648CE3D020106082A
    8648CE3D03010703420004368711132B
    BDB4C6D03F7DF4F4688F5F4F21A3B30B
    EB1016648555A25B27C915CAB5C26B98
    0FF792A0090BF1E131C175D9C66C8D79
    3476489770869E09273816
  • The signature from BCrypt is in 64 byte format, but android requires sequence and length identifiers, which results in a signature like this:

    304502201
    BD91B39A7447724223A4B3E9070A6FD5
    33360F96B072998058AA73E572F48D80
    22100
    ED0BDC731080CFC82C8B8FB37D74CC18
    3820343C2756671F0E1D813E469DD3D7
  • The message that was used for signing and verification is "Hello World", which hashed:

    A591A6D40BF420404A011733CFB7B190
    D62C65BF0BCDA32B57B277D9AD9F146E

Android process:

  • Create an X509 key key and a public key from the specified byte array:

    X509EncodedKeySpec keySpec = new X509EncodedKeySpec (encoded);
    KeyFactory kf = KeyFactory.getInstance ("EC", "AndroidOpenSSL");
    pubKey = kf.generatePublic (keySpec);
  • Create a signature using the AndroidOpenSSL provider:

    Signature signature;
    signature = Signature.getInstance ("SHA256withECDSA", "AndroidOpenSSL");
    signature.initVerify (pubKey);
  • Load the following hash array:

    signature.update (hash);
  • Check the specified signature:

    signature.verify (sign);

The signature and key above are verified on the AT chip (also verified with the ECDSA example, which runs JavaScript-OpenSSL), but not verified with AndroidOpenSSL. Am I missing something simple or where might the problem be?

The public key structure validates the ASN.1 decoder and is successfully loaded in code (extracted and validated from the public key), the signature is in the expected format for Java, and the hash values ​​are the same on both sides.

+3


source to share





All Articles