* SOFTWARE. */
#include "includes.h"
-#include "util.h"
+#include "dbutil.h"
#include "signkey.h"
#include "bignum.h"
#include "random.h"
#include "gendss.h"
#include "dss.h"
-#define PSIZE 128 /* 1024 bit*/
#define QSIZE 20 /* 160 bit */
+/* This is just a test */
+
#ifdef DROPBEAR_DSS
static void getq(dss_key *key);
buf[0] |= 0x80; /* top bit high */
buf[QSIZE-1] |= 0x01; /* bottom bit high */
- if (mp_read_unsigned_bin(key->q, buf, QSIZE) != MP_OKAY) {
- fprintf(stderr, "dss key generation failed\n");
- exit(1);
- }
+ bytes_to_mp(key->q, buf, QSIZE);
/* 18 rounds are required according to HAC */
- if (mp_prime_next_prime(key->q, 18) != MP_OKAY) {
+ if (mp_prime_next_prime(key->q, 18, 0) != MP_OKAY) {
fprintf(stderr, "dss key generation failed\n");
exit(1);
}
static void getp(dss_key *key, unsigned int size) {
- mp_int tempX, tempC, tempP, temp2q;
+ DEF_MP_INT(tempX);
+ DEF_MP_INT(tempC);
+ DEF_MP_INT(tempP);
+ DEF_MP_INT(temp2q);
int result;
unsigned char *buf;
buf[0] |= 0x80; /* set the top bit high */
/* X is a random mp_int */
- if (mp_read_unsigned_bin(&tempX, buf, size) != MP_OKAY) {
- fprintf(stderr, "dss key generation failed\n");
- exit(1);
- }
+ bytes_to_mp(&tempX, buf, size);
/* C = X mod 2q */
if (mp_mod(&tempX, &temp2q, &tempC) != MP_OKAY) {
} while (!result);
mp_clear_multi(&tempX, &tempC, &tempP, &temp2q, NULL);
+ m_burn(buf, size);
m_free(buf);
}
static void getg(dss_key * key) {
- char printbuf[1000];
- mp_int div, h, val;
+ DEF_MP_INT(div);
+ DEF_MP_INT(h);
+ DEF_MP_INT(val);
m_mp_init_multi(&div, &h, &val, NULL);
} while (mp_cmp_d(key->g, 1) != MP_GT);
- mp_toradix(key->g, printbuf, 10);
-
mp_clear_multi(&div, &h, &val, NULL);
}
static void getx(dss_key *key) {
- mp_int val;
- char buf[QSIZE];
-
- m_mp_init(&val);
-
- do {
- genrandom(buf, QSIZE);
-
- if (mp_read_unsigned_bin(&val, buf, QSIZE) != MP_OKAY) {
- fprintf(stderr, "dss key generation failed\n");
- }
- } while ((mp_cmp_d(&val, 1) == MP_GT) && (mp_cmp(&val, key->q) == MP_LT));
-
- mp_copy(&val, key->x);
- mp_clear(&val);
-
+ gen_random_mpint(key->q, key->x);
}
static void gety(dss_key *key) {