forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 58
/
kexhy.h
134 lines (111 loc) · 4.48 KB
/
kexhy.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KEX_HYBRID_H
#define KEX_HYBRID_H
#include "includes.h"
#ifdef WITH_HYBRID_KEX
#include "packet.h"
#include "kexoqs.h"
/* Hybrid key exchange context */
typedef struct hybrid_kex_ctx {
const char *hybrid_kex_name; /* Named SSH hybrid key exchange method */
#ifdef OPENSSL_HAS_ECC
/* ECDH specifics */
int ec_nid; /* Elliptic curve reference */
EC_KEY *ecdh_local_key; /* Local ecdh key */
const EC_GROUP *ecdh_group; /* Elliptic curve group used */
const EC_POINT *ecdh_local_public; /* Public ecdh part from local */
const EC_POINT *ecdh_remote_public; /* Public ecdh part from remote */
#endif /* OPENSSL_HAS_ECC */
#ifdef WITH_OQS
/* libOQS specifics */
OQS_KEX_CTX *oqs_kex_ctx; /* Liboqs context */
#endif /* WITH_OQS */
} HYBRID_KEX_CTX;
/*
* Header: Special ECDH version needed for hybrid key exchange
*/
#ifdef OPENSSL_HAS_ECC
/* Public functions */
void hybrid_ecdh_init(HYBRID_KEX_CTX *hybrid_kex_ctx, int ec_nid);
void hybrid_ecdh_free(HYBRID_KEX_CTX *hybrid_kex_ctx);
int hybrid_ecdh_gen(HYBRID_KEX_CTX *hybrid_kex_ctx);
int hybrid_ecdh_deserialise(struct ssh *ssh, HYBRID_KEX_CTX *hybrid_kex_ctx);
int hybrid_ecdh_serialise(struct ssh *ssh, HYBRID_KEX_CTX *hybrid_kex_ctx);
int hybrid_ecdh_shared_secret(HYBRID_KEX_CTX *hybrid_kex_ctx,
u_char **ecdh_shared_secret, size_t *ecdh_shared_secret_len);
#endif /* OPENSSL_HAS_ECC */
/*
* Headers: Named hybrid key exchange methods
*/
#if defined(OPENSSL_HAS_ECC) && defined(WITH_OQS)
/* ECDH+liboqs */
/* Exchange hash */
int hybrid_ecdh_oqs_hash (
int hash_alg,
const char *client_version_string,
const char *server_version_string,
const struct sshbuf *ckexinit,
const struct sshbuf *skexinit,
const u_char *serverhostkeyblob, size_t serverhostkeyblob_len,
const EC_GROUP *ecdh_group,
const EC_POINT *ecdh_client_public,
const EC_POINT *ecdh_server_public,
const uint8_t *oqs_client_public, size_t oqs_client_public_len,
const uint8_t *oqs_server_public, size_t oqs_server_public_len,
const u_char *shared_secret, size_t shared_secret_len,
u_char *hash, size_t *hash_len);
/* Shared functions */
int hybrid_ecdh_oqs_init(HYBRID_KEX_CTX **hybrid_kex_ctx,
char *hybrid_kex_name, int ec_nid);
void hybrid_ecdh_oqs_free(HYBRID_KEX_CTX *hybrid_kex_ctx);
int hybrid_ecdh_oqs_combine_shared_secrets(u_char *ecdh_shared_secret,
size_t ecdh_shared_secret_len, u_char *oqs_shared_secret,
size_t oqs_shared_secret_len, u_char **combined_shared_secret,
size_t *combined_shared_secret_len);
/* Client specific function */
int hybrid_ecdh_oqs_client(struct ssh *ssh);
/* Server specific function */
int hybrid_ecdh_oqs_server(struct ssh *ssh);
#endif /* defined(OPENSSL_HAS_ECC) && defined(WITH_OQS) */
#endif /* WITH_HYBRID_KEX */
/* Helper functions to register hybrid key exchange call-backs */
typedef int (*hybrid_func_cb)(struct ssh *);
static inline hybrid_func_cb
get_hybrid_ecdh_oqs_client_cb() {
#if defined(OPENSSL_HAS_ECC) && defined(WITH_OQS) && defined(WITH_HYBRID_KEX)
return hybrid_ecdh_oqs_client;
#else
return NULL;
#endif
}
static inline hybrid_func_cb
get_hybrid_ecdh_oqs_server_cb() {
#if defined(OPENSSL_HAS_ECC) && defined(WITH_OQS) && defined(WITH_HYBRID_KEX)
return hybrid_ecdh_oqs_server;
#else
return NULL;
#endif
}
#endif /* KEX_HYBRID_H */