/src/gnutls/lib/nettle/int/ecdsa-compute-k.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2019 Red Hat, Inc. |
3 | | * |
4 | | * Author: Daiki Ueno |
5 | | * |
6 | | * This file is part of GNUTLS. |
7 | | * |
8 | | * The GNUTLS library is free software; you can redistribute it and/or |
9 | | * modify it under the terms of the GNU Lesser General Public License |
10 | | * as published by the Free Software Foundation; either version 2.1 of |
11 | | * the License, or (at your option) any later version. |
12 | | * |
13 | | * This library is distributed in the hope that it will be useful, but |
14 | | * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | * Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/> |
20 | | * |
21 | | */ |
22 | | |
23 | | #if HAVE_CONFIG_H |
24 | | # include "config.h" |
25 | | #endif |
26 | | |
27 | | #include "ecdsa-compute-k.h" |
28 | | |
29 | | #include "dsa-compute-k.h" |
30 | | #include "gnutls_int.h" |
31 | | |
32 | | static inline int |
33 | | _gnutls_ecc_curve_to_dsa_q(mpz_t * q, gnutls_ecc_curve_t curve) |
34 | 0 | { |
35 | 0 | switch (curve) { |
36 | 0 | #ifdef ENABLE_NON_SUITEB_CURVES |
37 | 0 | case GNUTLS_ECC_CURVE_SECP192R1: |
38 | 0 | mpz_init_set_str(*q, |
39 | 0 | "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836" |
40 | 0 | "146BC9B1B4D22831", 16); |
41 | 0 | return 0; |
42 | 0 | case GNUTLS_ECC_CURVE_SECP224R1: |
43 | 0 | mpz_init_set_str(*q, |
44 | 0 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2" |
45 | 0 | "E0B8F03E13DD29455C5C2A3D", 16); |
46 | 0 | return 0; |
47 | 0 | #endif |
48 | 0 | case GNUTLS_ECC_CURVE_SECP256R1: |
49 | 0 | mpz_init_set_str(*q, |
50 | 0 | "FFFFFFFF00000000FFFFFFFFFFFFFFFF" |
51 | 0 | "BCE6FAADA7179E84F3B9CAC2FC632551", 16); |
52 | 0 | return 0; |
53 | 0 | case GNUTLS_ECC_CURVE_SECP384R1: |
54 | 0 | mpz_init_set_str(*q, |
55 | 0 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" |
56 | 0 | "FFFFFFFFFFFFFFFFC7634D81F4372DDF" |
57 | 0 | "581A0DB248B0A77AECEC196ACCC52973", 16); |
58 | 0 | return 0; |
59 | 0 | case GNUTLS_ECC_CURVE_SECP521R1: |
60 | 0 | mpz_init_set_str(*q, |
61 | 0 | "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" |
62 | 0 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" |
63 | 0 | "FFA51868783BF2F966B7FCC0148F709A" |
64 | 0 | "5D03BB5C9B8899C47AEBB6FB71E91386" "409", 16); |
65 | 0 | return 0; |
66 | 0 | default: |
67 | 0 | return |
68 | 0 | gnutls_assert_val(GNUTLS_E_UNSUPPORTED_SIGNATURE_ALGORITHM); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | int |
73 | | _gnutls_ecdsa_compute_k(mpz_t k, |
74 | | gnutls_ecc_curve_t curve, |
75 | | const mpz_t x, |
76 | | gnutls_mac_algorithm_t mac, |
77 | | const uint8_t * digest, size_t length) |
78 | 0 | { |
79 | 0 | mpz_t q; |
80 | 0 | int ret; |
81 | |
|
82 | 0 | ret = _gnutls_ecc_curve_to_dsa_q(&q, curve); |
83 | 0 | if (ret < 0) |
84 | 0 | return gnutls_assert_val(ret); |
85 | | |
86 | 0 | ret = _gnutls_dsa_compute_k(k, q, x, mac, digest, length); |
87 | 0 | mpz_clear(q); |
88 | 0 | return ret; |
89 | 0 | } |