summaryrefslogtreecommitdiffstats
path: root/providers/implementations/serializers/serializer_ffc_params.c
blob: da38763cfe38f1dac7e02d7819bedfc2715d3105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

/* Utility function for printing DSA/DH params. */

#include "prov/bio.h"
#include "serializer_local.h"

int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
{
    if (ffc->nid != NID_undef) {
        const char *name = ffc_named_group_from_nid(ffc->nid);

        if (name == NULL)
            goto err;
        if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
            goto err;
        return 1;
    }

    if (!ossl_prov_print_labeled_bignum(out, "P:   ", ffc->p))
        goto err;
    if (ffc->q != NULL) {
        if (!ossl_prov_print_labeled_bignum(out, "Q:   ", ffc->q))
            goto err;
    }
    if (!ossl_prov_print_labeled_bignum(out, "G:   ", ffc->g))
        goto err;
    if (ffc->j != NULL) {
        if (!ossl_prov_print_labeled_bignum(out, "J:   ", ffc->j))
            goto err;
    }
    if (ffc->seed != NULL) {
        if (!ossl_prov_print_labeled_buf(out, "SEED:", ffc->seed, ffc->seedlen))
            goto err;
    }
    if (ffc->gindex != -1) {
        if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
            goto err;
    }
    if (ffc->pcounter != -1) {
        if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
            goto err;
    }
    if (ffc->h != 0) {
        if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
            goto err;
    }
    return 1;
err:
    return 0;
}