Skip to content

Instantly share code, notes, and snippets.

@klali
Last active February 26, 2018 18:02
Show Gist options
  • Save klali/129af62d360f6d5c59c184bf22dd9aeb to your computer and use it in GitHub Desktop.
Save klali/129af62d360f6d5c59c184bf22dd9aeb to your computer and use it in GitHub Desktop.
add a namned group of secp521r1 to an ec key
#include <stdio.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
int main(int argc, char **argv) {
if(argc != 2) {
printf("give key as arg\n");
exit(1);
}
FILE *key = fopen(argv[1], "r");
EVP_PKEY *pkey = PEM_read_PrivateKey(key, NULL, NULL, NULL);
EC_KEY *eckey = EVP_PKEY_get1_EC_KEY(pkey);
EC_GROUP *ngroup = EC_GROUP_new_by_curve_name(NID_secp521r1);
EC_GROUP_set_asn1_flag(ngroup, 1);
EC_KEY_set_group(eckey, ngroup);
PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL);
}
@klali
Copy link
Author

klali commented Feb 21, 2018

compile with something like:

$ gcc eccconv.c -lcrypto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment