summaryrefslogtreecommitdiff
path: root/src/certtool-common.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-04-28 17:42:49 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-04-28 17:42:51 +0200
commit4cd6694c6d58843e0f6246ca85da3d32bd97ca14 (patch)
tree85c3d8d47dad19f551dafabfdfc4720cdf410387 /src/certtool-common.c
parent2c1c22d3bd1ee1677b18c7500a9610de47b7e0e3 (diff)
downloadgnutls-4cd6694c6d58843e0f6246ca85da3d32bd97ca14.tar.gz
certtool: combined all the seed decoding methods to a single one
That not only simplifies the code, but also allows decoding hex strings which contain not hex chars (and that allows decoding hex of the form XX:XX:XX)
Diffstat (limited to 'src/certtool-common.c')
-rw-r--r--src/certtool-common.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/certtool-common.c b/src/certtool-common.c
index 97ec3523c3..7e18a7f09d 100644
--- a/src/certtool-common.c
+++ b/src/certtool-common.c
@@ -1298,28 +1298,17 @@ int generate_prime(FILE * outfile, int how, common_info_st * info)
if (info->seed_size > 0) {
gnutls_keygen_data_st data;
- gnutls_datum_t hexseed, seed;
- hexseed.data = (void*)info->seed;
- hexseed.size = info->seed_size;
-
- ret = gnutls_hex_decode2(&hexseed, &seed);
- if (ret < 0) {
- fprintf(stderr, "Could not hex decode data: %s\n", gnutls_strerror(ret));
- exit(1);
- }
-
- if (seed.size < 32) {
- fprintf(stderr, "For DH parameter generation a 32-byte seed value or larger is expected (have: %d); use -d 2 for more information.\n", (int)seed.size);
+ if (info->seed_size < 32) {
+ fprintf(stderr, "For DH parameter generation a 32-byte seed value or larger is expected (have: %d); use -d 2 for more information.\n", (int)info->seed_size);
exit(1);
}
data.type = GNUTLS_KEYGEN_SEED;
- data.data = seed.data;
- data.size = seed.size;
+ data.data = (void*)info->seed;
+ data.size = info->seed_size;
ret = gnutls_x509_privkey_generate2(pkey, GNUTLS_PK_DSA, bits, GNUTLS_PRIVKEY_FLAG_PROVABLE, &data, 1);
- gnutls_free(seed.data);
} else {
ret = gnutls_x509_privkey_generate(pkey, GNUTLS_PK_DSA, bits, GNUTLS_PRIVKEY_FLAG_PROVABLE);
}
@@ -1435,3 +1424,27 @@ int generate_prime(FILE * outfile, int how, common_info_st * info)
return 0;
}
+
+void decode_seed(gnutls_datum_t *seed, const char *hex, unsigned hex_size)
+{
+ int ret;
+ size_t seed_size;
+
+ seed->size = hex_size;
+ seed->data = malloc(hex_size);
+
+ if (seed->data == NULL) {
+ fprintf(stderr, "memory error\n");
+ exit(1);
+ }
+
+ seed_size = hex_size;
+ ret = gnutls_hex2bin(hex, hex_size, seed->data, &seed_size);
+ if (ret < 0) {
+ fprintf(stderr, "Could not hex decode data: %s\n", gnutls_strerror(ret));
+ exit(1);
+ }
+ seed->size = seed_size;
+
+ return;
+}