Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dh/dh_rfc7919.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||
2 | * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||
3 | * | - | ||||||||||||||||||
4 | * Licensed under the OpenSSL license (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 | #include <stdio.h> | - | ||||||||||||||||||
11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||
12 | #include "dh_locl.h" | - | ||||||||||||||||||
13 | #include <openssl/bn.h> | - | ||||||||||||||||||
14 | #include <openssl/objects.h> | - | ||||||||||||||||||
15 | #include "internal/bn_dh.h" | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | static DH *dh_param_init(const BIGNUM *p, int32_t nbits) | - | ||||||||||||||||||
18 | { | - | ||||||||||||||||||
19 | DH *dh = DH_new(); | - | ||||||||||||||||||
20 | if (dh == NULL)
| 0-1 | ||||||||||||||||||
21 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
22 | dh->p = (BIGNUM *)p; | - | ||||||||||||||||||
23 | dh->g = (BIGNUM *)&_bignum_const_2; | - | ||||||||||||||||||
24 | dh->length = nbits; | - | ||||||||||||||||||
25 | return dh; executed 1 time by 1 test: return dh; Executed by:
| 1 | ||||||||||||||||||
26 | } | - | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | DH *DH_new_by_nid(int nid) | - | ||||||||||||||||||
29 | { | - | ||||||||||||||||||
30 | switch (nid) { | - | ||||||||||||||||||
31 | case NID_ffdhe2048: executed 1 time by 1 test: case 1126: Executed by:
| 1 | ||||||||||||||||||
32 | return dh_param_init(&_bignum_ffdhe2048_p, 225); executed 1 time by 1 test: return dh_param_init(&_bignum_ffdhe2048_p, 225); Executed by:
| 1 | ||||||||||||||||||
33 | case NID_ffdhe3072: never executed: case 1127: | 0 | ||||||||||||||||||
34 | return dh_param_init(&_bignum_ffdhe3072_p, 275); never executed: return dh_param_init(&_bignum_ffdhe3072_p, 275); | 0 | ||||||||||||||||||
35 | case NID_ffdhe4096: never executed: case 1128: | 0 | ||||||||||||||||||
36 | return dh_param_init(&_bignum_ffdhe4096_p, 325); never executed: return dh_param_init(&_bignum_ffdhe4096_p, 325); | 0 | ||||||||||||||||||
37 | case NID_ffdhe6144: never executed: case 1129: | 0 | ||||||||||||||||||
38 | return dh_param_init(&_bignum_ffdhe6144_p, 375); never executed: return dh_param_init(&_bignum_ffdhe6144_p, 375); | 0 | ||||||||||||||||||
39 | case NID_ffdhe8192: never executed: case 1130: | 0 | ||||||||||||||||||
40 | return dh_param_init(&_bignum_ffdhe8192_p, 400); never executed: return dh_param_init(&_bignum_ffdhe8192_p, 400); | 0 | ||||||||||||||||||
41 | default: never executed: default: | 0 | ||||||||||||||||||
42 | DHerr(DH_F_DH_NEW_BY_NID, DH_R_INVALID_PARAMETER_NID); | - | ||||||||||||||||||
43 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
44 | } | - | ||||||||||||||||||
45 | } | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | int DH_get_nid(const DH *dh) | - | ||||||||||||||||||
48 | { | - | ||||||||||||||||||
49 | int nid; | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | if (BN_get_word(dh->g) != 2)
| 0 | ||||||||||||||||||
52 | return NID_undef; never executed: return 0; | 0 | ||||||||||||||||||
53 | if (!BN_cmp(dh->p, &_bignum_ffdhe2048_p))
| 0 | ||||||||||||||||||
54 | nid = NID_ffdhe2048; never executed: nid = 1126; | 0 | ||||||||||||||||||
55 | else if (!BN_cmp(dh->p, &_bignum_ffdhe3072_p))
| 0 | ||||||||||||||||||
56 | nid = NID_ffdhe3072; never executed: nid = 1127; | 0 | ||||||||||||||||||
57 | else if (!BN_cmp(dh->p, &_bignum_ffdhe4096_p))
| 0 | ||||||||||||||||||
58 | nid = NID_ffdhe4096; never executed: nid = 1128; | 0 | ||||||||||||||||||
59 | else if (!BN_cmp(dh->p, &_bignum_ffdhe6144_p))
| 0 | ||||||||||||||||||
60 | nid = NID_ffdhe6144; never executed: nid = 1129; | 0 | ||||||||||||||||||
61 | else if (!BN_cmp(dh->p, &_bignum_ffdhe8192_p))
| 0 | ||||||||||||||||||
62 | nid = NID_ffdhe8192; never executed: nid = 1130; | 0 | ||||||||||||||||||
63 | else | - | ||||||||||||||||||
64 | return NID_undef; never executed: return 0; | 0 | ||||||||||||||||||
65 | if (dh->q != NULL) {
| 0 | ||||||||||||||||||
66 | BIGNUM *q = BN_dup(dh->p); | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | /* Check q = p * 2 + 1 we already know q is odd, so just shift right */ | - | ||||||||||||||||||
69 | if (q == NULL || !BN_rshift1(q, q) || !BN_cmp(dh->q, q))
| 0 | ||||||||||||||||||
70 | nid = NID_undef; never executed: nid = 0; | 0 | ||||||||||||||||||
71 | BN_free(q); | - | ||||||||||||||||||
72 | } never executed: end of block | 0 | ||||||||||||||||||
73 | return nid; never executed: return nid; | 0 | ||||||||||||||||||
74 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |