aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2018-10-01 18:00:01 -0400
committerAndreas Schneider <asn@cryptomilk.org>2019-03-07 12:03:32 +0100
commit104c9dca3f963440e4f1d1170c9244682e700e28 (patch)
treee76fa82a434e0d9ffef553c3efac68fe8c6860be /include
parentc180211c6b804628d308743a51a0270873cf7c6f (diff)
downloadlibssh-104c9dca3f963440e4f1d1170c9244682e700e28.tar.gz
libssh-104c9dca3f963440e4f1d1170c9244682e700e28.tar.xz
libssh-104c9dca3f963440e4f1d1170c9244682e700e28.zip
Use a common KDF function
Cleanup the KDF function to use only one function per crypto backend. Improve the KDF function to properly handle requested lenght and to avoid unnecessarily reallocating buffers. In OpenSSL use the new EVP_KDF API if available. Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include')
-rw-r--r--include/libssh/crypto.h8
-rw-r--r--include/libssh/wrapper.h20
2 files changed, 17 insertions, 11 deletions
diff --git a/include/libssh/crypto.h b/include/libssh/crypto.h
index 2d2d4f7f..4cd0cecd 100644
--- a/include/libssh/crypto.h
+++ b/include/libssh/crypto.h
@@ -122,7 +122,7 @@ struct ssh_crypto_struct {
ssh_curve25519_pubkey curve25519_server_pubkey;
#endif
ssh_string dh_server_signature; /* information used by dh_handshake. */
- size_t digest_len; /* len of all the fields below */
+ size_t digest_len; /* len of the two fields below */
unsigned char *session_id;
unsigned char *secret_hash; /* Secret hash is same as session id until re-kex */
unsigned char *encryptIV;
@@ -148,7 +148,7 @@ struct ssh_crypto_struct {
struct ssh_kex_struct client_kex;
char *kex_methods[SSH_KEX_METHODS];
enum ssh_key_exchange_e kex_type;
- enum ssh_mac_e mac_type; /* Mac operations to use for key gen */
+ enum ssh_kdf_digest digest_type; /* Digest type for session keys derivation */
enum ssh_crypto_direction_e used; /* Is this crypto still used for either of directions? */
};
@@ -204,5 +204,9 @@ struct ssh_cipher_struct {
};
const struct ssh_cipher_struct *ssh_get_chacha20poly1305_cipher(void);
+int sshkdf_derive_key(struct ssh_crypto_struct *crypto,
+ unsigned char *key, size_t key_len,
+ int key_type, unsigned char *output,
+ size_t requested_len);
#endif /* _CRYPTO_H_ */
diff --git a/include/libssh/wrapper.h b/include/libssh/wrapper.h
index e4a0bba1..df415bb5 100644
--- a/include/libssh/wrapper.h
+++ b/include/libssh/wrapper.h
@@ -36,11 +36,11 @@ enum ssh_digest_e {
SSH_DIGEST_SHA512
};
-enum ssh_mac_e {
- SSH_MAC_SHA1=1,
- SSH_MAC_SHA256,
- SSH_MAC_SHA384,
- SSH_MAC_SHA512
+enum ssh_kdf_digest {
+ SSH_KDF_SHA1=1,
+ SSH_KDF_SHA256,
+ SSH_KDF_SHA384,
+ SSH_KDF_SHA512
};
enum ssh_hmac_e {
@@ -70,6 +70,7 @@ enum ssh_crypto_direction_e {
};
struct ssh_cipher_struct;
+struct ssh_crypto_struct;
typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
MD5CTX md5_init(void);
@@ -101,15 +102,16 @@ EVPCTX evp_init(int nid);
void evp_update(EVPCTX ctx, const void *data, unsigned long len);
void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
-ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
-void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
-void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx);
-
HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
void hmac_update(HMACCTX c, const void *data, unsigned long len);
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
size_t hmac_digest_len(enum ssh_hmac_e type);
+int ssh_kdf(struct ssh_crypto_struct *crypto,
+ unsigned char *key, size_t key_len,
+ int key_type, unsigned char *output,
+ size_t requested_len);
+
int crypt_set_algorithms_client(ssh_session session);
int crypt_set_algorithms_server(ssh_session session);
struct ssh_crypto_struct *crypto_new(void);