How can I best check these Elliptic Curve parameters are valid?

James Andrew

(Just abit of context:) I'm a novice to Cryptography, but for a school project I wanted to create a proof of concept 64-bit ECC curve. (Yes I do know 64-bit keys are not very secure!) However afaik there is no SEC standard parameters for 64-bit, only 160-512bit.

So I had to go about generating my own parameters, which is the bit i'm (quite) unsure on. I followed a quick guide, and came out with these parameters for my curve:

p = 10997031918897188677

a = 3628449283386729367

b = 4889270915382004880

x = 3124469192170877657

y = 4370601445727723733

n = 10997031916045924769 (order)

h = 1 (co-factor)

Could someone give me some advice as to if this curve will generate valid private/public key pairs? How could I check this?

Any help (/confirmation) would be greatly appreicated, thanks!

Chiara Hsieh

You can use OpenSSL's EC_GROUP_check() function to make sure it's a valid group. In the following program I did two things:

  • Generate an EC_GROUP with the provided parameters, and check if it's valid
  • Generate an EC_KEY using the generated EC_group, and check if it's valid

Note that it is the EC group you want to check if it can be used to generate valid EC keys, not EC curve.

Please read the comments for details:)

// gcc 22270485.c -lcrypto -o 22270485
#include <openssl/ec.h>
#include <stdio.h>

int main(){
    BN_CTX *ctx = NULL;
    BIGNUM *p, *a, *b, *x, *y, *order;
    EC_GROUP *group;
    EC_POINT *G;
    int ok = 1;

    ctx = BN_CTX_new();
    p = BN_new();
    a = BN_new();
    b = BN_new();
    x = BN_new();
    y = BN_new();
    order = BN_new();

    /* Set EC_GROUP */
    group = EC_GROUP_new(EC_GFp_mont_method());
    BN_dec2bn(&p, "10997031918897188677");
    BN_dec2bn(&a, "3628449283386729367");
    BN_dec2bn(&b, "4889270915382004880");
    EC_GROUP_set_curve_GFp(group, p, a, b, ctx);

    /* Set generator G=(x,y) and its cofactor */
    G = EC_POINT_new(group);
    BN_dec2bn(&x, "3124469192170877657");
    BN_dec2bn(&y, "4370601445727723733");
    BN_dec2bn(&order, "10997031916045924769");
    EC_POINT_set_affine_coordinates_GFp(group,G,x,y,ctx);
    EC_GROUP_set_generator(group,G,order,BN_value_one());

    /* Checks whether the parameter in the EC_GROUP define a valid ec group */
    if(!EC_GROUP_check(group,ctx)) {
        fprintf(stdout, "EC_GROUP_check() failed\n");
        ok = 0;
    }

    if (ok) {
        fprintf(stdout, "It is a valid EC group\n");
    }


    /* Generate a private/public key pair with above EC_GROUP */
    if (ok) {
        BIGNUM *private_key, *pub_x, *pub_y;
        EC_POINT *public_key;
        EC_KEY *eckey;

        pub_x = BN_new(); pub_y = BN_new();
        eckey = EC_KEY_new();

        /* create key on group */
        EC_KEY_set_group(eckey,group);
        EC_KEY_generate_key(eckey);

        /* Verifies that a private and/or public key is valid */
        if (!EC_KEY_check_key(eckey)) {
            fprintf(stdout, "EC_KEY_check_key() failed\n");
            ok = 0;
        }

        if (ok) {
            fprintf(stdout, "It is a valid EC key, where\n");

            private_key = EC_KEY_get0_private_key(eckey);
            fprintf(stdout, "\tprivate key = %s",BN_bn2dec(private_key));

            public_key = EC_KEY_get0_public_key(eckey);
            EC_POINT_get_affine_coordinates_GFp(group,public_key,pub_x,pub_y,ctx);
            fprintf(stdout, "\n\tpublic key = ( %s , %s )\n",
                BN_bn2dec(pub_x),BN_bn2dec(pub_y));
        }

        BN_free(pub_x); BN_free(pub_y);
        EC_KEY_free(eckey);
    }


    if (ctx)
        BN_CTX_free(ctx);
    BN_free(p); BN_free(a); BN_free(b);
    EC_GROUP_free(group);
    EC_POINT_free(G);
    BN_free(x); BN_free(y); BN_free(order);

    return 0;
}

Compile and run with this command:

$ gcc 22270485.c -lcrypto -o 22270485
$ ./22270485

The stdout should print

It is a valid EC group
It is a valid EC key, where
private key = 1524190197747279622
public key = ( 3228020167903858345 , 9344375093791763077 )

The private/public key pair will change every time, since EC_KEY_generate_key(eckey) randomly chooses a private key and compute the corresponding public key for every run.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I check that a file is a valid HDF5 file?

From Dev

How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

From Dev

How can I check for invalid input and loop until the input is valid?

From Dev

How can I curve a layout?

From Dev

How can I best check if A xor B are null?

From Dev

How can I best check if two unordered pairs match?

From Dev

Plotting an elliptic curve in SageMath

From Dev

Elliptic curve brute forcing

From Dev

How to sign the Certificates with Elliptic curve private keys and ECDSA algorithm?

From Dev

How to decipher the encrypted message using elliptic curve using JavaScript library?

From Dev

How can I check that method parameters have the same type as the methods this?

From Dev

How can I color a curve envelope

From Dev

How can I make a JSlider in a curve shape?

From Dev

How can I color a curve envelope

From Dev

How can i create a stair step/curve?

From Dev

How can I find the area above the curve

From Dev

How do I create a best-fit polynomial curve in Javascript?

From Dev

Get key parameters from imported Elliptic Curve key in ASN.1 format

From Dev

How can I check if an indexPath is valid, thus avoiding an "attempt to scroll to invalid index path" error?

From Dev

How can i check if my host command in script got a valid ip

From Java

Elliptic curve digital signature formats

From Dev

Elliptic curve threshold cryptography in node

From Dev

Point division Elliptic Curve in Java

From Dev

How can I select the best set of parameters in the Canny edge detection algorithm implemented in OpenCV?

From Dev

How can I verify in Postgresql that JSON is valid?

From Dev

How can i render valid html with JQuery?

From Dev

How can I prove a type is valid in Agda?

From Dev

How can I prove a type is valid in Agda?

From Dev

How to get range of finite field and coefficients used in elliptic curve cryptography from a certificate with OpenSSL?

Related Related

  1. 1

    How can I check that a file is a valid HDF5 file?

  2. 2

    How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

  3. 3

    How can I check for invalid input and loop until the input is valid?

  4. 4

    How can I curve a layout?

  5. 5

    How can I best check if A xor B are null?

  6. 6

    How can I best check if two unordered pairs match?

  7. 7

    Plotting an elliptic curve in SageMath

  8. 8

    Elliptic curve brute forcing

  9. 9

    How to sign the Certificates with Elliptic curve private keys and ECDSA algorithm?

  10. 10

    How to decipher the encrypted message using elliptic curve using JavaScript library?

  11. 11

    How can I check that method parameters have the same type as the methods this?

  12. 12

    How can I color a curve envelope

  13. 13

    How can I make a JSlider in a curve shape?

  14. 14

    How can I color a curve envelope

  15. 15

    How can i create a stair step/curve?

  16. 16

    How can I find the area above the curve

  17. 17

    How do I create a best-fit polynomial curve in Javascript?

  18. 18

    Get key parameters from imported Elliptic Curve key in ASN.1 format

  19. 19

    How can I check if an indexPath is valid, thus avoiding an "attempt to scroll to invalid index path" error?

  20. 20

    How can i check if my host command in script got a valid ip

  21. 21

    Elliptic curve digital signature formats

  22. 22

    Elliptic curve threshold cryptography in node

  23. 23

    Point division Elliptic Curve in Java

  24. 24

    How can I select the best set of parameters in the Canny edge detection algorithm implemented in OpenCV?

  25. 25

    How can I verify in Postgresql that JSON is valid?

  26. 26

    How can i render valid html with JQuery?

  27. 27

    How can I prove a type is valid in Agda?

  28. 28

    How can I prove a type is valid in Agda?

  29. 29

    How to get range of finite field and coefficients used in elliptic curve cryptography from a certificate with OpenSSL?

HotTag

Archive