I'm converting an EC Point from HEX to an EC_POINT with the function EC_POINT_point2hex
. Further, in order to verify if the point is properly converted, I adopt the inverse function EC_POINT_hex2point
, but I have in output the value 00
(null). As follows a MRE. Do you know if EC_POINT_hex2point()
should be used differently to overcome this issue?
#include <openssl/obj_mac.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include <stdio.h>
#include <string.h>
int main(){
BN_CTX *ctx = BN_CTX_new();
EC_GROUP *curve = EC_GROUP_new_by_curve_name(NID_secp160r1);
EC_POINT *P = EC_POINT_new(curve);
EC_POINT_hex2point(curve, "04C7851681AF643E195CCAAF1825BDF0C8FC702A0184E6C66BFFACFB124255A54A77534BB6FDCC51A", P, ctx);
//Verification
printf("Point: %s\n", EC_POINT_point2hex(curve, P, POINT_CONVERSION_UNCOMPRESSED, ctx));
}
Update 2:
The problem was mine. Basically, if you see the hex values for a uncompressed representation and for a secp160r1 should be 41 bytes (i.e. 82 HEX CHAR) and not 40.5 bytes (i.e. 81 HEX CHAR) as shown in the code.
Update:
I tried also this example with the same result: https://stackoverflow.com/a/1172533/6920619
I would avoid to convert every time the point with my custom functions. Can you provide me a suggestion (even some tries).