Generate 33 bytes public key for curve25519 in python

781 views Asked by At

Using Java's spongycastle, i am able to generate curve25519 private keys(32 bytes) and public keys(33 bytes).

Similarly for Python, i am using Nacl library for curve25519 but here public key generated is of 32 bytes only. The one byte of y co-ordinate is missing in public key.

from nacl.public import PrivateKey
import binascii

privKey = PrivateKey.generate()
pubKey = privKey.public_key

print("privKey:", binascii.hexlify(bytes(privKey)))
print("pubKey: ", binascii.hexlify(bytes(pubKey)))

any suggestion why Nacl library is not compressing the public key ?

1

There are 1 answers

0
nil On

spongycastle(Java) and PyNacl(Python) are totally two different libraries.

PyNacl(Python) and LazySodiumJava(Java) derive from C library libsodium, they can only generate 32bit key.

I think maybe you could look for other Python packages, which is consistent with spongycastle(Java).