- if (text)
- {
- DHparams_print(out,dh);
-#ifdef undef
- printf("p=");
- BN_print(stdout,dh->p);
- printf("\ng=");
- BN_print(stdout,dh->g);
- printf("\n");
- if (dh->length != 0)
- printf("recommended private length=%ld\n",dh->length);
-#endif
- }
-
- if (check)
- {
- if (!DH_check(dh,&i))
- {
- ERR_print_errors(bio_err);
- goto end;
- }
- if (i & DH_CHECK_P_NOT_PRIME)
- printf("p value is not prime\n");
- if (i & DH_CHECK_P_NOT_STRONG_PRIME)
- printf("p value is not a strong prime\n");
- if (i & DH_UNABLE_TO_CHECK_GENERATOR)
- printf("unable to check the generator value\n");
- if (i & DH_NOT_SUITABLE_GENERATOR)
- printf("the g value is not a generator\n");
- if (i == 0)
- printf("DH parameters appear to be ok.\n");
- }
- if (C)
- {
- unsigned char *data;
- int len,l,bits;
+ if (informat == FORMAT_ASN1)
+ dh = d2i_DHparams_bio(in, NULL);
+ else if (informat == FORMAT_PEM)
+ dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
+ else {
+ BIO_printf(bio_err, "bad input format specified\n");
+ goto end;
+ }
+ if (dh == NULL) {
+ BIO_printf(bio_err, "unable to load DH parameters\n");
+ ERR_print_errors(bio_err);
+ goto end;
+ }
+
+ if (text) {
+ DHparams_print(out, dh);
+# ifdef undef
+ printf("p=");
+ BN_print(stdout, dh->p);
+ printf("\ng=");
+ BN_print(stdout, dh->g);
+ printf("\n");
+ if (dh->length != 0)
+ printf("recommended private length=%ld\n", dh->length);
+# endif
+ }
+
+ if (check) {
+ if (!DH_check(dh, &i)) {
+ ERR_print_errors(bio_err);
+ goto end;
+ }
+ if (i & DH_CHECK_P_NOT_PRIME)
+ printf("p value is not prime\n");
+ if (i & DH_CHECK_P_NOT_SAFE_PRIME)
+ printf("p value is not a safe prime\n");
+ if (i & DH_UNABLE_TO_CHECK_GENERATOR)
+ printf("unable to check the generator value\n");
+ if (i & DH_NOT_SUITABLE_GENERATOR)
+ printf("the g value is not a generator\n");
+ if (i == 0)
+ printf("DH parameters appear to be ok.\n");
+ }
+ if (C) {
+ unsigned char *data;
+ int len, l, bits;
+
+ len = BN_num_bytes(dh->p);
+ bits = BN_num_bits(dh->p);
+ data = (unsigned char *)OPENSSL_malloc(len);
+ if (data == NULL) {
+ perror("OPENSSL_malloc");
+ goto end;
+ }
+ l = BN_bn2bin(dh->p, data);
+ printf("static unsigned char dh%d_p[]={", bits);
+ for (i = 0; i < l; i++) {
+ if ((i % 12) == 0)
+ printf("\n\t");
+ printf("0x%02X,", data[i]);
+ }
+ printf("\n\t};\n");