#include "ntp_types.h"
#include "ntp_random.h"
#include "l_stdlib.h"
+#include "ntp_assert.h"
#include "ntp-keygen-opts.h"
fprintf(stderr, "Writing new IFF key %s\n", filename);
fprintf(stdout, "# %s\n# %s", filename, ctime(&epoch));
dsa = pkey_iff->pkey.dsa;
+ NTP_INSIST(dsa != NULL);
BN_copy(dsa->priv_key, BN_value_one());
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_DSA(pkey, dsa);
PEM_write_PrivateKey(stdout, pkey, passwd2 ?
EVP_des_cbc() : NULL, NULL, 0, NULL, passwd2);
fprintf(stderr, "Generating MD5 keys...\n");
str = fheader("MD5key", hostname);
keyid = BN_new(); key = BN_new();
+ NTP_INSIST(keyid != NULL);
+ NTP_INSIST(key != NULL);
BN_rand(keyid, 16, -1, 0);
BN_rand(key, 128, -1, 0);
BN_bn2bin(key, bin);
*/
str = fheader("RSAkey", hostname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_RSA(pkey, rsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
*/
str = fheader("DSAkey", hostname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_DSA(pkey, dsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
*/
fprintf(stderr, "Generating IFF keys (%d bits)...\n", modulus);
b = BN_new(); r = BN_new(); k = BN_new();
+ NTP_INSIST(b != NULL);
+ NTP_INSIST(r != NULL);
+ NTP_INSIST(k != NULL);
u = BN_new(); v = BN_new(); w = BN_new(); ctx = BN_CTX_new();
+ NTP_INSIST(u != NULL);
+ NTP_INSIST(v != NULL);
+ NTP_INSIST(w != NULL);
+ NTP_INSIST(ctx != NULL);
BN_rand(b, BN_num_bits(dsa->q), -1, 0); /* a */
BN_mod(b, b, dsa->q, ctx);
BN_sub(v, dsa->q, b);
*/
str = fheader("IFFpar", trustname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_DSA(pkey, dsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
* small number to minimize the file size.
*/
ctx = BN_CTX_new();
+ NTP_INSIST(ctx != NULL);
BN_rand(rsa->e, BN_num_bits(rsa->n), -1, 0); /* b */
BN_mod(rsa->e, rsa->e, rsa->n, ctx);
BN_copy(rsa->d, BN_value_one());
*/
str = fheader("GQpar", trustname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_RSA(pkey, rsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
*/
fprintf(stderr, "Updating GQ keys (%d bits)...\n", modulus);
ctx = BN_CTX_new(); u = BN_new(); v = BN_new();
+ NTP_INSIST(ctx != NULL);
+ NTP_INSIST(u != NULL);
+ NTP_INSIST(v != NULL);
g = BN_new(); k = BN_new(); r = BN_new(); y = BN_new();
+ NTP_INSIST(g != NULL);
+ NTP_INSIST(k != NULL);
+ NTP_INSIST(r != NULL);
+ NTP_INSIST(y != NULL);
/*
* When generating his certificate, Bob rolls random private key
* u.
*/
rsa = gqpar->pkey.rsa;
+ NTP_INSIST(rsa != NULL);
BN_rand(u, BN_num_bits(rsa->n), -1, 0); /* u */
BN_mod(u, u, rsa->n, ctx);
BN_mod_inverse(v, u, rsa->n, ctx); /* u^-1 mod n */
*/
str = fheader("GQpar", trustname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_RSA(pkey, rsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
"Generating MV parameters for %d keys (%d bits)...\n", n,
modulus / n);
ctx = BN_CTX_new(); u = BN_new(); v = BN_new(); w = BN_new();
+ NTP_INSIST(ctx != NULL);
+ NTP_INSIST(u != NULL);
+ NTP_INSIST(v != NULL);
+ NTP_INSIST(w != NULL);
b = BN_new(); b1 = BN_new();
+ NTP_INSIST(b != NULL);
+ NTP_INSIST(b1 != NULL);
dsa = DSA_new();
+ NTP_INSIST(dsa != NULL);
dsa->p = BN_new();
+ NTP_INSIST(dsa->p != NULL);
dsa->q = BN_new();
+ NTP_INSIST(dsa->q != NULL);
dsa->g = BN_new();
+ NTP_INSIST(dsa->g != NULL);
s = emalloc((n + 1) * sizeof(BIGNUM));
s1 = emalloc((n + 1) * sizeof(BIGNUM));
- for (j = 1; j <= n; j++)
+ for (j = 1; j <= n; j++) {
s1[j] = BN_new();
+ NTP_INSIST(s1[j] != NULL);
+ }
temp = 0;
for (j = 1; j <= n; j++) {
while (1) {
*/
for (j = 1; j <= n; j++) {
s[j] = BN_new();
+ NTP_INSIST(s[j] != NULL);
BN_add(s[j], dsa->q, s1[j]);
BN_div(s[j], u, s[j], s1[j], ctx);
}
x = emalloc((n + 1) * sizeof(BIGNUM));
for (j = 1; j <= n; j++) {
x[j] = BN_new();
+ NTP_INSIST(x[j] != NULL);
while (1) {
BN_rand(x[j], BN_num_bits(dsa->q), 0, 0);
BN_mod(x[j], x[j], dsa->q, ctx);
a = emalloc((n + 1) * sizeof(BIGNUM));
for (i = 0; i <= n; i++) {
a[i] = BN_new();
+ NTP_INSIST(a[i] != NULL);
BN_one(a[i]);
}
for (j = 1; j <= n; j++) {
g = emalloc((n + 1) * sizeof(BIGNUM));
for (i = 0; i <= n; i++) {
g[i] = BN_new();
+ NTP_INSIST(g[i] != NULL);
BN_mod_exp(g[i], dsa->g, a[i], dsa->p, ctx);
}
* since it is expensive to compute.
*/
biga = BN_new();
+ NTP_INSIST(biga != NULL);
BN_one(biga);
for (j = 1; j <= n; j++) {
for (i = 0; i < n; i++) {
xhat = emalloc((n + 1) * sizeof(BIGNUM));
for (j = 1; j <= n; j++) {
xbar[j] = BN_new(); xhat[j] = BN_new();
+ NTP_INSIST(xbar[j] != NULL);
+ NTP_INSIST(xhat[j] != NULL);
BN_zero(xbar[j]);
BN_set_word(v, n);
for (i = 1; i <= n; i++) {
* otherwise, the plaintext and cryptotext would be identical.
*/
ss = BN_new();
+ NTP_INSIST(ss != NULL);
BN_copy(ss, dsa->q);
BN_div(ss, u, dsa->q, s1[n], ctx);
* enabling key is changed.
*/
bige = BN_new(); gbar = BN_new(); ghat = BN_new();
+ NTP_INSIST(bige != NULL);
+ NTP_INSIST(gbar != NULL);
+ NTP_INSIST(ghat != NULL);
BN_mod_exp(bige, biga, ss, dsa->p, ctx);
BN_mod_exp(gbar, dsa->g, ss, dsa->p, ctx);
BN_mod_mul(v, ss, b, dsa->q, ctx);
*/
str = fheader("MVpar", trustname);
pkey = EVP_PKEY_new();
+ NTP_INSIST(pkey != NULL);
EVP_PKEY_assign_DSA(pkey, dsa);
PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL,
NULL, 0, NULL, passwd2);
* for its use.
*/
sdsa = DSA_new();
+ NTP_INSIST(sdsa != NULL);
sdsa->p = BN_dup(dsa->p);
sdsa->q = BN_dup(BN_value_one());
sdsa->g = BN_dup(BN_value_one());
sdsa->priv_key = BN_new();
+ NTP_INSIST(sdsa->priv_key != NULL);
sdsa->pub_key = BN_new();
+ NTP_INSIST(sdsa->pub_key != NULL);
for (j = 1; j <= n; j++) {
BN_copy(sdsa->priv_key, xbar[j]);
BN_copy(sdsa->pub_key, xhat[j]);
sprintf(ident, "MVkey%d", j);
str = fheader(ident, trustname);
pkey1 = EVP_PKEY_new();
+ NTP_INSIST(pkey1 != NULL);
EVP_PKEY_set1_DSA(pkey1, sdsa);
PEM_write_PrivateKey(str, pkey1, passwd2 ?
EVP_des_cbc() : NULL, NULL, 0, NULL, passwd2);
id = OBJ_nid2sn(md->pkey_type);
fprintf(stderr, "Generating certificate %s\n", id);
cert = X509_new();
+ NTP_INSIST(cert != NULL);
X509_set_version(cert, 2L);
serial = ASN1_INTEGER_new();
+ NTP_INSIST(serial != NULL);
ASN1_INTEGER_set(serial, epoch + JAN_1970);
X509_set_serialNumber(cert, serial);
ASN1_INTEGER_free(serial);