Skip to content

Importing P-521 EC private key fails with CKR_ATTRIBUTE_VALUE_INVALID when private key has leading zero byte #430

@ivaylo-yordanov

Description

@ivaylo-yordanov

Importing a P-521 EC private key fails with CKR_ATTRIBUTE_VALUE_INVALID (0x13)
when the private key value contains a leading 00 byte. This is valid for P-521 keys since
the private key is 521 bits stored in 66 bytes, meaning some keys will naturally have a leading zero.

Steps to Reproduce

  1. Generate or obtain a P-521 private key whose value starts with a leading 00 byte
  2. Import using pkcs11-tool:
pkcs11-tool --module libkryoptic_pkcs11.so \
  --token-label "My token 1" \
  --login --pin "test" \
  --write-object private_key_ec_secp521r1.der \
  --type privkey \
  --id 06 --label "ECDSA-P521"

Expected Behavior

Key is imported successfully, as leading zero bytes are valid for P-521 private keys.

Actual Behavior

error: PKCS11 function C_CreateObject failed: rv = CKR_ATTRIBUTE_VALUE_INVALID (0x13)

Environment

  • Kryoptic version: built from main branch
  • OS: Ubuntu 24.04
  • OpenSSL: 3.2.0
  • pkcs11-tool: from OpenSC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions