How to generate the ECIES public key for a given secp256r1 private key

850 views Asked by At

How can I generate the ECIES public key for a given secp256r1 private key, like what is used for "Profile B" defined in 3GPP TS 33.501 version 15.5.0 Release 15, C.3.4.2?

If provided with the private key F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA (from C.4.4 of the above spec), how can I derive the public key:

Home Network Public Key:
if compressed: '0272DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD1',
otherwise uncompressed: '0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4'

I've played around with the Python CryptoMobile suite and can get the right results for Profile A. But I haven't been able to modify it for Profile B. I'm open to other libraries/languages as well.

Thanks

1

There are 1 answers

0
Rusty Lemur On BEST ANSWER

After some digging through the cryptography source code, I came up with this solution:

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import asymmetric

priv_key = 'F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA'
privkey_int = int(priv_key, base=16)
privkey_ec = asymmetric.ec.derive_private_key(privkey_int, asymmetric.ec.SECP256R1())
pubkey_ec = privkey_ec.public_key()
pubkey_bytes = pubkey_ec.public_bytes(
    encoding=serialization.Encoding.X962, 
    format=serialization.PublicFormat.CompressedPoint
)
print(binascii.hexlify(pubkey_bytes).decode('utf-8'))
'0272DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD1'