Add DH keygen to providers
[openssl.git] / providers / implementations / serializers / serializer_ffc_params.c
1 /*
2  * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /* Utility function for printing DSA/DH params. */
11
12 #include "prov/bio.h"
13 #include "serializer_local.h"
14
15 int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
16 {
17     if (ffc->nid != NID_undef) {
18         const char *name = ffc_named_group_from_uid(ffc->nid);
19
20         if (name == NULL)
21             goto err;
22         if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
23             goto err;
24         return 1;
25     }
26
27     if (!ossl_prov_print_labeled_bignum(out, "P:   ", ffc->p))
28         goto err;
29     if (ffc->q != NULL) {
30         if (!ossl_prov_print_labeled_bignum(out, "Q:   ", ffc->q))
31             goto err;
32     }
33     if (!ossl_prov_print_labeled_bignum(out, "G:   ", ffc->g))
34         goto err;
35     if (ffc->j != NULL) {
36         if (!ossl_prov_print_labeled_bignum(out, "J:   ", ffc->j))
37             goto err;
38     }
39     if (ffc->seed != NULL) {
40         if (!ossl_prov_print_labeled_buf(out, "SEED:", ffc->seed, ffc->seedlen))
41             goto err;
42     }
43     if (ffc->gindex != -1) {
44         if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
45             goto err;
46     }
47     if (ffc->pcounter != -1) {
48         if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
49             goto err;
50     }
51     if (ffc->h != 0) {
52         if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
53             goto err;
54     }
55     return 1;
56 err:
57     return 0;
58 }