src/fwup_genkeys.c
/**
 * @brief Generate a public/private signing key pair
 * @param output_prefix if non-NULL, this is the prefix to the output file
 * @return 0 on success
 */
@brief Generate a public/private signing key pair
@param output_prefix if non-NULL, this is the prefix to the output file
@return 0 on success
@brief Generate a public / private signing key pair @param output_prefix if non - NULL this is the prefix to the output file @return 0 on success
int fwup_genkeys(const char *output_prefix)
{
    char pubkey_path[PATH_MAX];
    char privkey_path[PATH_MAX];
    unsigned char pk[crypto_sign_PUBLICKEYBYTES];
    unsigned char sk[crypto_sign_SECRETKEYBYTES];
    if (crypto_sign_keypair(pk, sk) < 0)
        ERR_RETURN("Error creating key pair");
    if (!output_prefix)
        output_prefix = "fwup-key";
    sprintf(pubkey_path, "%s.pub", output_prefix);
    sprintf(privkey_path, "%s.priv", output_prefix);
    OK_OR_RETURN(save_key(pubkey_path, pk, sizeof(pk)));
    OK_OR_RETURN(save_key(privkey_path, sk, sizeof(sk)));
    char message[512];
    char *base_pubkey_path = basename(pubkey_path);
    char *base_privkey_path = basename(privkey_path);
    sprintf(message, "Firmware signing keys created and saved to '%.32s' and '%.32s'\n\n"
                     "Distribute '%.32s' with your system so that firmware updates can be\n"
                     "authenticated. Keep '%.32s' in a safe location.\n",
            base_pubkey_path, base_privkey_path, base_pubkey_path, base_privkey_path);
    fwup_output(FRAMING_TYPE_SUCCESS, 0, message);
    return 0;
}
int fwup_genkeys ( const char * output_prefix ) { char pubkey_path [ PATH_MAX ] ; char privkey_path [ PATH_MAX ] ; unsigned char pk [ crypto_sign_PUBLICKEYBYTES ] ; unsigned char sk [ crypto_sign_SECRETKEYBYTES ] ; if ( crypto_sign_keypair ( pk , sk ) < 0 ) ERR_RETURN ( " " ) ; if ( ! output_prefix ) output_prefix = " " ; sprintf ( pubkey_path , " " , output_prefix ) ; sprintf ( privkey_path , " " , output_prefix ) ; OK_OR_RETURN ( save_key ( pubkey_path , pk , sizeof ( pk ) ) ) ; OK_OR_RETURN ( save_key ( privkey_path , sk , sizeof ( sk ) ) ) ; char message [ 512 ] ; char * base_pubkey_path = basename ( pubkey_path ) ; char * base_privkey_path = basename ( privkey_path ) ; sprintf ( message , " \n \n " " \n " " \n " , base_pubkey_path , base_privkey_path , base_pubkey_path , base_privkey_path ) ; fwup_output ( FRAMING_TYPE_SUCCESS , 0 , message ) ; return 0 ; }
@brief Generate a public/private signing key pair
 @param output_prefix if non-NULL, this is the prefix to the output file
 @return 0 on success
@brief Generate a public / private signing key pair @param output_prefix if non - NULL this is the prefix to the output file @return 0 on success