diff options
Diffstat (limited to 'futility/cmd_create.c')
-rw-r--r-- | futility/cmd_create.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/futility/cmd_create.c b/futility/cmd_create.c index a1341799..748ce2f7 100644 --- a/futility/cmd_create.c +++ b/futility/cmd_create.c @@ -80,51 +80,50 @@ static void print_help(int argc, char *argv[]) static int vb1_make_keypair() { - VbPrivateKey *privkey = 0; + struct vb2_private_key *privkey = NULL; VbPublicKey *pubkey = 0; - RSA *rsa_key = 0; + struct rsa_st *rsa_key = NULL; uint8_t *keyb_data = 0; uint32_t keyb_size; - enum vb2_signature_algorithm sig_alg; - uint64_t vb1_algorithm; - FILE *fp; int ret = 1; - fp = fopen(infile, "rb"); + FILE *fp = fopen(infile, "rb"); if (!fp) { fprintf(stderr, "Unable to open %s\n", infile); goto done; } + /* TODO: this is very similar to vb2_read_private_key_pem() */ + rsa_key = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL); fclose(fp); - if (!rsa_key) { fprintf(stderr, "Unable to read RSA key from %s\n", infile); goto done; } - sig_alg = vb2_rsa_sig_alg(rsa_key); + enum vb2_signature_algorithm sig_alg = vb2_rsa_sig_alg(rsa_key); if (sig_alg == VB2_SIG_INVALID) { fprintf(stderr, "Unsupported sig algorithm in RSA key\n"); goto done; } - /* combine the sig_alg with the hash_alg to get the vb1 algorithm */ - vb1_algorithm = (sig_alg - VB2_SIG_RSA1024) * 3 - + opt_hash_alg - VB2_HASH_SHA1; + /* Combine the sig_alg with the hash_alg to get the vb1 algorithm */ + uint64_t vb1_algorithm = + vb2_get_crypto_algorithm(opt_hash_alg, sig_alg); /* Create the private key */ - privkey = (VbPrivateKey *)malloc(sizeof(VbPrivateKey)); + privkey = (struct vb2_private_key *)calloc(sizeof(*privkey), 1); if (!privkey) goto done; privkey->rsa_private_key = rsa_key; - privkey->algorithm = vb1_algorithm; + privkey->sig_alg = sig_alg; + privkey->hash_alg = opt_hash_alg; /* Write it out */ strcpy(outext, ".vbprivk"); - if (0 != PrivateKeyWrite(outfile, privkey)) { + if (0 != vb2_write_private_key(outfile, privkey)) { fprintf(stderr, "unable to write private key\n"); goto done; } |