/src/boringssl/crypto/fipsmodule/dh/internal.h
Line | Count | Source |
1 | | // Copyright 2022 The BoringSSL Authors |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H |
16 | | #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H |
17 | | |
18 | | #include <openssl/base.h> |
19 | | |
20 | | #include "../../internal.h" |
21 | | #include "../../mem_internal.h" |
22 | | |
23 | | |
24 | | DECLARE_OPAQUE_STRUCT(dh_st, DHImpl) |
25 | | |
26 | | BSSL_NAMESPACE_BEGIN |
27 | | |
28 | | class DHImpl : public dh_st, public RefCounted<DHImpl> { |
29 | | public: |
30 | 0 | DHImpl() : RefCounted(CheckSubClass()) {} |
31 | | |
32 | | UniquePtr<BIGNUM> p; |
33 | | UniquePtr<BIGNUM> g; |
34 | | UniquePtr<BIGNUM> q; |
35 | | UniquePtr<BIGNUM> pub_key; // g^x mod p |
36 | | UniquePtr<BIGNUM> priv_key; // x |
37 | | |
38 | | // priv_length contains the length, in bits, of the private value. If zero, |
39 | | // the private value will be the same length as `p`. |
40 | | unsigned priv_length = 0; |
41 | | |
42 | | mutable Mutex method_mont_p_lock; |
43 | | mutable UniquePtr<BN_MONT_CTX> method_mont_p; |
44 | | |
45 | | private: |
46 | | friend RefCounted; |
47 | 0 | ~DHImpl() = default; |
48 | | }; |
49 | | |
50 | | // dh_check_params_fast checks basic invariants on `dh`'s domain parameters. It |
51 | | // does not check that `dh` forms a valid group, only that the sizes are within |
52 | | // DoS bounds. |
53 | | int dh_check_params_fast(const DH *dh); |
54 | | |
55 | | // dh_compute_key_padded_no_self_test does the same as `DH_compute_key_padded`, |
56 | | // but doesn't try to run the self-test first. This is for use in the self tests |
57 | | // themselves, to prevent an infinite loop. |
58 | | int dh_compute_key_padded_no_self_test(unsigned char *out, |
59 | | const BIGNUM *peers_key, DH *dh); |
60 | | |
61 | | BSSL_NAMESPACE_END |
62 | | |
63 | | #endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H |