Line | Source | Count |
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 | #include "includes.h" | - |
29 | | - |
30 | #include <sys/types.h> | - |
31 | | - |
32 | #include <signal.h> | - |
33 | #include <string.h> | - |
34 | | - |
35 | #include <openssl/bn.h> | - |
36 | #include <openssl/evp.h> | - |
37 | | - |
38 | #include "sshbuf.h" | - |
39 | #include "ssh2.h" | - |
40 | #include "sshkey.h" | - |
41 | #include "cipher.h" | - |
42 | #include "kex.h" | - |
43 | #include "log.h" | - |
44 | #include "digest.h" | - |
45 | #include "ssherr.h" | - |
46 | | - |
47 | extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE], | - |
48 | const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE]) | - |
49 | __attribute__((__bounded__(__minbytes__, 1, CURVE25519_SIZE))) | - |
50 | __attribute__((__bounded__(__minbytes__, 2, CURVE25519_SIZE))) | - |
51 | __attribute__((__bounded__(__minbytes__, 3, CURVE25519_SIZE))); | - |
52 | | - |
53 | void | - |
54 | kexc25519_keygen(u_char key[CURVE25519_SIZE], u_char pub[CURVE25519_SIZE]) | - |
55 | { | - |
56 | static const u_char basepoint[CURVE25519_SIZE] = {9}; | - |
57 | | - |
58 | arc4random_buf(key, CURVE25519_SIZE); | - |
59 | crypto_scalarmult_curve25519(pub, key, basepoint); | - |
60 | }executed 40 times by 1 test: end of block | 40 |
61 | | - |
62 | int | - |
63 | kexc25519_shared_key(const u_char key[CURVE25519_SIZE], | - |
64 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out) | - |
65 | { | - |
66 | u_char shared_key[CURVE25519_SIZE]; | - |
67 | int r; | - |
68 | | - |
69 | | - |
70 | explicit_bzero(shared_key, CURVE25519_SIZE); | - |
71 | if (timingsafe_bcmp(pub, shared_key, CURVE25519_SIZE) == 0)TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
72 | return SSH_ERR_KEY_INVALID_EC_VALUE; never executed: return -20; | 0 |
73 | | - |
74 | crypto_scalarmult_curve25519(shared_key, key, pub); | - |
75 | #ifdef DEBUG_KEXECDH | - |
76 | dump_digest("shared secret", shared_key, CURVE25519_SIZE); | - |
77 | #endif | - |
78 | sshbuf_reset(out); | - |
79 | r = sshbuf_put_bignum2_bytes(out, shared_key, CURVE25519_SIZE); | - |
80 | explicit_bzero(shared_key, CURVE25519_SIZE); | - |
81 | return r;executed 40 times by 1 test: return r; | 40 |
82 | } | - |
83 | | - |
84 | int | - |
85 | kex_c25519_hash( | - |
86 | int hash_alg, | - |
87 | const char *client_version_string, | - |
88 | const char *server_version_string, | - |
89 | const u_char *ckexinit, size_t ckexinitlen, | - |
90 | const u_char *skexinit, size_t skexinitlen, | - |
91 | const u_char *serverhostkeyblob, size_t sbloblen, | - |
92 | const u_char client_dh_pub[CURVE25519_SIZE], | - |
93 | const u_char server_dh_pub[CURVE25519_SIZE], | - |
94 | const u_char *shared_secret, size_t secretlen, | - |
95 | u_char *hash, size_t *hashlen) | - |
96 | { | - |
97 | struct sshbuf *b; | - |
98 | int r; | - |
99 | | - |
100 | if (*hashlen < ssh_digest_bytes(hash_alg))TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
101 | return SSH_ERR_INVALID_ARGUMENT; never executed: return -10; | 0 |
102 | if ((b = sshbuf_new()) == NULL)TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
103 | return SSH_ERR_ALLOC_FAIL; never executed: return -2; | 0 |
104 | if ((r = sshbuf_put_cstring(b, client_version_string)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
105 | (r = sshbuf_put_cstring(b, server_version_string)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
106 | | - |
107 | (r = sshbuf_put_u32(b, ckexinitlen+1)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
108 | (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
109 | (r = sshbuf_put(b, ckexinit, ckexinitlen)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
110 | (r = sshbuf_put_u32(b, skexinitlen+1)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
111 | (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
112 | (r = sshbuf_put(b, skexinit, skexinitlen)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
113 | (r = sshbuf_put_string(b, serverhostkeyblob, sbloblen)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
114 | (r = sshbuf_put_string(b, client_dh_pub, CURVE25519_SIZE)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
115 | (r = sshbuf_put_string(b, server_dh_pub, CURVE25519_SIZE)) < 0 ||TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
116 | (r = sshbuf_put(b, shared_secret, secretlen)) < 0) {TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
117 | sshbuf_free(b); | - |
118 | return r; never executed: return r; | 0 |
119 | } | - |
120 | #ifdef DEBUG_KEX | - |
121 | sshbuf_dump(b, stderr); | - |
122 | #endif | - |
123 | if (ssh_digest_buffer(hash_alg, b, hash, *hashlen) != 0) {TRUE | never evaluated | FALSE | evaluated 40 times by 1 test |
| 0-40 |
124 | sshbuf_free(b); | - |
125 | return SSH_ERR_LIBCRYPTO_ERROR; never executed: return -22; | 0 |
126 | } | - |
127 | sshbuf_free(b); | - |
128 | *hashlen = ssh_digest_bytes(hash_alg); | - |
129 | #ifdef DEBUG_KEX | - |
130 | dump_digest("hash", hash, *hashlen); | - |
131 | #endif | - |
132 | return 0;executed 40 times by 1 test: return 0; | 40 |
133 | } | - |
| | |