On 15 May 2012 15:22, Fábio Resner <fabiu...@gmail.com> wrote: > Hi, > > I'm trying to write an app to generate public/private/shared key for ECDH. > Here is what I was able to build based on examples: > > #include <openssl/ssl.h> > > #define ECDH_SIZE 67 > > int main() { > EC_KEY *ecdh = EC_KEY_new(); > const EC_POINT *point = NULL; > > EC_POINT *point2; > const EC_GROUP *group; > > // const void *pubkey = NULL; > unsigned char *pubkey = NULL; > void *shared = NULL; > > //Generate Public > ecdh = EC_KEY_new_by_curve_name(NID_secp521r1); > EC_KEY_generate_key(ecdh); > > point = EC_KEY_get0_public_key(ecdh); > EC_POINT_point2oct(EC_KEY_get0_group(ecdh), point, > POINT_CONVERSION_COMPRESSED, pubkey, ECDH_SIZE, NULL); > I am not familiar with the ECDH functions....but I am familiar with the EC functions and this line does not look right.
If you pass a null pointer for a buffer to point2oct then the function will return the size of the buffer that you require. You need to check the return value, malloc a buffer of the required size and then re-call point2oct. > //ComputeKey > group = EC_KEY_get0_group((ecdh)); > point2 = EC_POINT_new(group); > > EC_POINT_oct2point(group, point2, pubkey, ECDH_SIZE, NULL); > > ECDH_compute_key(shared, ECDH_SIZE, point2, ecdh, NULL); As I said I'm not familiar with the ECDH functions...but this looks like you are trying to generate a shared key using only one public/private key pair?? > EC_POINT_free(point2); > EC_KEY_free(ecdh); > ecdh = NULL; > > printf("To the end"); > > return 0; > } > > But it just broke on EC_POINT_oct2point(group, point2, pubkey, ECDH_SIZE, > NULL); > And pubkey is exiting EC_POINT_point2oct(EC_KEY_get0_group(ecdh), point, > POINT_CONVERSION_COMPRESSED, pubkey, ECDH_SIZE, NULL); with a NULL value. > The program exists and gives no segFAULT or any erros messages. > > Any suggestions? > > Thanks, > > -- > Fabio Resner. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org