int generate_key(int length, PyObject **py_private_key_ccn, PyObject **py_public_key_ccn, PyObject **py_public_key_digest, int *public_key_digest_len) { RSA *private_key_rsa; int r; seed_prng(); private_key_rsa = RSA_generate_key(length, 65537, NULL, NULL); save_seed(); if (!private_key_rsa) { unsigned int err; err = ERR_get_error(); PyErr_Format(g_PyExc_CCNKeyError, "Unable to generate digest from the" " key: %s", ERR_reason_error_string(err)); return -1; } r = ccn_keypair_from_rsa(0, private_key_rsa, py_private_key_ccn, py_public_key_ccn); if (r < 0) return -1; r = create_public_key_digest(private_key_rsa, py_public_key_digest, public_key_digest_len); if (r < 0) return -1; return 0; }
int generate_key(int length, PyObject **py_private_key_ndn, PyObject **py_public_key_ndn, PyObject **py_public_key_digest, int *public_key_digest_len) { RSA *private_key_rsa; struct ndn_pkey *private_key = NULL; int r; seed_prng(); private_key_rsa = RSA_generate_key(length, 65537, NULL, NULL); private_key = (struct ndn_pkey *)EVP_PKEY_new(); EVP_PKEY_assign_RSA ((EVP_PKEY *)private_key, private_key_rsa); save_seed (); if (!private_key_rsa || !private_key) { unsigned int err; err = ERR_get_error(); PyErr_Format(g_PyExc_NDNKeyError, "Unable to generate the" " key: %s", ERR_reason_error_string(err)); return -1; } r = ndn_keypair(0, private_key, py_private_key_ndn, py_public_key_ndn); if (r < 0) return -1; r = create_public_key_digest(private_key, py_public_key_digest, public_key_digest_len); if (r < 0) return -1; EVP_PKEY_free ((EVP_PKEY*)private_key); return 0; }
void main (int argc, char **argv, char **env) { /* Set-up */ int I, M, T; /* states, observations, sequence length */ int *X; /* integer array */ double **alpha, **beta, **gamma, ***xi; DHMM posterior, prior; FILE *PRIOR, *DATA, *POSTERIOR; unsigned long seed; /* pseudorandom generator seed */ /* Initialize */ /* To do: 1. Put in argument-checking code here. */ set_seed(&seed, 0); /* read in the prior */ PRIOR = fopen(argv[1], "r"); read_DHMM(PRIOR, &prior); fclose(PRIOR); /* read in the data */ DATA = fopen(argv[2], "r"); read_sequence(DATA, &T, &X); fclose(DATA); /* allocate working space */ I = prior.I; M = prior.M; new_DHMM(&posterior, I, M); alpha = array_double_2d(1, I, 1, T); beta = array_double_2d(1, I, 1, T); gamma = array_double_2d(1, I, 1, T); xi = array_double_3d(1, I, 1, I, 1, T); /* Process */ /* we must initialize the posterior mode or the algorithm */ /* will not work correctly */ initialize_DHMM(&seed, &posterior); /* run the penalized maximum likelihood algorithm and write results */ Penalized_Baum_Welch(&posterior, &prior, T, X, alpha, beta, gamma, xi); /* write out the posterior */ POSTERIOR = fopen(argv[3], "w"); write_DHMM(POSTERIOR, &posterior); fclose(POSTERIOR); /* Clean-up */ save_seed(&seed); free_array_double_2d(alpha, 1, I, 1, T); free_array_double_2d( beta, 1, I, 1, T); free_array_double_2d(gamma, 1, I, 1, T); free_array_double_3d( xi, 1, I, 1, I, 1, T); free_array_int_1d( X, 1, T); free_DHMM(&posterior); free_DHMM(&prior); }