On Friday, April 26, 2019 at 5:47:27 AM UTC-4, Tom Smeding wrote: > > Hi all, > > The GetPublicElement() method of the > CryptoPP::ECDSA<CryptoPP::ECP>::PublicKey class returns a value of type > CryptoPP::ECP::Point, which represents the elliptic curve point that is > the public key. > This public key consists of two integers, x and y, that, if I am correct, > are always 32 bytes in size (though their MinEncodedSize could be less if > the leading byte is zero). > > However, in my application I would like to be able to get this size (32 > bytes) from the CryptoPP API somewhere, to reduce the number of magic > constants in my code. > Is this exported somewhere? I have not been able to find it, but that may > be my fault. >
So this is kind of a trick question... An x or y component of a coordinate only needs to be as large as a field element. When serialized leading 0's are usually preserved. For example, that means secp160 would use field element size of 20-bytes. However, SEC-1 says to use subgroup order and not field elements. So in the case of secp160, the component would use 21 bytes, not 20. SEC-2 was supposed to switch to field element but the change did not appear to occur. Also see https://github.com/weidai11/cryptopp/issues/785 . With that said, you can use this for a private key (just the exponent): GetAbstractGroupParameters().GetSubgroupOrder().ByteCount(); And you can use the following for a public point ((x,y) pair or just the (y) part of the coordinate). The boolean argument means "compressed". Compressed means just the y-coordinate. GetAbstractGroupParameters().GetEncodedElementSize(false); Jeff -- You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
