Skip to content

Instantly share code, notes, and snippets.

@46bit
Created October 24, 2014 00:07
Show Gist options
  • Save 46bit/a3d562b1880863e4a0bd to your computer and use it in GitHub Desktop.
Save 46bit/a3d562b1880863e4a0bd to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <openssl/ec.h>
//#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
int main()
{
BN_CTX *bn_ctx = BN_CTX_new();
EC_GROUP *ec = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
EC_POINT *p, *r;
p = EC_POINT_new(ec);
r = EC_POINT_new(ec);
BIGNUM *x, *y;
x = BN_new();
y = BN_new();
int on_curve = -1;
char *x_str = "c97445f45cdef9f0d3e05e1e585fc297235b82b5be8ff3efca67c59852018192";
char *y_str = "b28ef557ba31dfcbdd21ac46e2a91e3c304f44cb87058ada2cb815151e610046";
BN_hex2bn(&x, x_str);
BN_hex2bn(&y, y_str);
EC_POINT_set_affine_coordinates_GFp(ec, p, x, y, bn_ctx);
// To get [xy]_str into dec not hex for initial value.
EC_POINT_get_affine_coordinates_GFp(ec, p, x, y, bn_ctx);
x_str = BN_bn2dec(x);
y_str = BN_bn2dec(y);
on_curve = EC_POINT_is_on_curve(ec, p, bn_ctx);
printf("Before:\n- x = %s\n- y = %s\n- on curve: %d\n", x_str, y_str, on_curve);
EC_POINT_dbl(ec, r, p, bn_ctx);
EC_POINT_get_affine_coordinates_GFp(ec, r, x, y, bn_ctx);
x_str = BN_bn2dec(x);
y_str = BN_bn2dec(y);
on_curve = EC_POINT_is_on_curve(ec, r, bn_ctx);
printf("After:\n- x = %s\n- y = %s\n- on curve: %d\n", x_str, y_str, on_curve);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment