]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/dsa/dsa_check.c
611a4e66f6865ed80216f6823ba57c213bf562bd
2 * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/bn.h>
13 #include "dsa_local.h"
14 #include "crypto/dsa.h"
16 int dsa_check_params(const DSA
*dsa
, int *ret
)
19 * (2b) FFC domain params conform to FIPS-186-4 explicit domain param
22 return ffc_params_FIPS186_4_validate(&dsa
->params
, FFC_PARAM_TYPE_DSA
, NULL
,
23 FFC_PARAMS_VALIDATE_ALL
, ret
, NULL
);
27 * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Full public key validation.
29 int dsa_check_pub_key(const DSA
*dsa
, const BIGNUM
*pub_key
, int *ret
)
31 return ffc_validate_public_key(&dsa
->params
, pub_key
, ret
);
35 * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Partial public key validation.
36 * To only be used with ephemeral FFC public keys generated using the approved
39 int dsa_check_pub_key_partial(const DSA
*dsa
, const BIGNUM
*pub_key
, int *ret
)
41 return ffc_validate_public_key_partial(&dsa
->params
, pub_key
, ret
);
44 int dsa_check_priv_key(const DSA
*dsa
, const BIGNUM
*priv_key
, int *ret
)
48 return (dsa
->params
.q
!= NULL
49 && ffc_validate_private_key(dsa
->params
.q
, priv_key
, ret
));
53 * FFC pairwise check from SP800-56A R3.
54 * Section 5.6.2.1.4 Owner Assurance of Pair-wise Consistency
56 int dsa_check_pairwise(const DSA
*dsa
)
60 BIGNUM
*pub_key
= NULL
;
62 if (dsa
->params
.p
== NULL
63 || dsa
->params
.g
== NULL
64 || dsa
->priv_key
== NULL
65 || dsa
->pub_key
== NULL
)
68 ctx
= BN_CTX_new_ex(dsa
->libctx
);
75 /* recalculate the public key = (g ^ priv) mod p */
76 if (!dsa_generate_public_key(ctx
, dsa
, dsa
->priv_key
, pub_key
))
78 /* check it matches the existing pubic_key */
79 ret
= BN_cmp(pub_key
, dsa
->pub_key
) == 0;