Skip to content

Commit 3a700eb

Browse files
author
Pan
committed
Added crypto, wrapper definition files.
1 parent c42d801 commit 3a700eb

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

ssh/c_crypto.pxd

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from c_ssh cimport ssh_string
18+
from c_wrapper cimport ssh_mac_e, ssh_hmac_e, ssh_des_e, ssh_hmac_struct
19+
20+
cdef extern from "libssh/include/crypto.h" nogil:
21+
enum:
22+
DIGEST_MAX_LEN
23+
enum ssh_key_exchange_e:
24+
SSH_KEX_DH_GROUP1_SHA1,
25+
SSH_KEX_DH_GROUP14_SHA1,
26+
SSH_KEX_ECDH_SHA2_NISTP256,
27+
SSH_KEX_ECDH_SHA2_NISTP384,
28+
SSH_KEX_ECDH_SHA2_NISTP521,
29+
SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG
30+
31+
enum ssh_cipher_e:
32+
SSH_NO_CIPHER,
33+
SSH_BLOWFISH_CBC,
34+
SSH_3DES_CBC,
35+
SSH_3DES_CBC_SSH1,
36+
SSH_DES_CBC_SSH1,
37+
SSH_AES128_CBC,
38+
SSH_AES192_CBC,
39+
SSH_AES256_CBC,
40+
SSH_AES128_CTR,
41+
SSH_AES192_CTR,
42+
SSH_AES256_CTR
43+
44+
struct ssh_crypto_struct:
45+
pass
46+
47+
ssh_string dh_server_signature
48+
size_t digest_len
49+
unsigned char *session_id
50+
unsigned char *secret_hash
51+
unsigned char *encryptIV
52+
unsigned char *decryptIV
53+
unsigned char *decryptkey
54+
unsigned char *encryptkey
55+
unsigned char *encryptMAC
56+
unsigned char *decryptMAC
57+
unsigned char hmacbuf[DIGEST_MAX_LEN]
58+
ssh_hmac_e in_hmac, out_hmac
59+
struct ssh_cipher_struct:
60+
const char *name
61+
unsigned int blocksize
62+
ssh_cipher_e ciphertype
63+
ssh_cipher_struct *in_cipher
64+
ssh_cipher_struct *out_cipher

ssh/c_wrapper.pxd

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from c_ssh cimport ssh_session
18+
from c_crypto cimport ssh_cipher_struct, ssh_crypto_struct
19+
20+
cdef extern from "libssh/include/wrapper.h" nogil:
21+
enum ssh_mac_e:
22+
SSH_MAC_SHA1,
23+
SSH_MAC_SHA256,
24+
SSH_MAC_SHA384,
25+
SSH_MAC_SHA512
26+
27+
enum ssh_hmac_e:
28+
SSH_HMAC_SHA1,
29+
SSH_HMAC_SHA256,
30+
SSH_HMAC_SHA384,
31+
SSH_HMAC_SHA512,
32+
SSH_HMAC_MD5
33+
34+
enum ssh_des_e:
35+
SSH_3DES,
36+
SSH_DES
37+
38+
struct ssh_hmac_struct:
39+
const char* name
40+
ssh_hmac_e hmac_type
41+
42+
# ctypedef ssh_mac_ctx_struct *ssh_mac_ctx
43+
# MD5CTX md5_init()
44+
# void md5_update(MD5CTX c, const void *data, unsigned long len)
45+
# void md5_final(unsigned char *md,MD5CTX c)
46+
# SHACTX sha1_init()
47+
# void sha1_update(SHACTX c, const void *data, unsigned long len)
48+
# void sha1_final(unsigned char *md,SHACTX c)
49+
void sha1(unsigned char *digest,int len,unsigned char *hash)
50+
51+
# SHA256CTX sha256_init()
52+
# void sha256_update(SHA256CTX c, const void *data, unsigned long len)
53+
# void sha256_final(unsigned char *md,SHA256CTX c)
54+
void sha256(unsigned char *digest, int len, unsigned char *hash)
55+
56+
# SHA384CTX sha384_init();
57+
# void sha384_update(SHA384CTX c, const void *data, unsigned long len)
58+
# void sha384_final(unsigned char *md,SHA384CTX c)
59+
void sha384(unsigned char *digest, int len, unsigned char *hash)
60+
61+
# SHA512CTX sha512_init();
62+
# void sha512_update(SHA512CTX c, const void *data, unsigned long len)
63+
# void sha512_final(unsigned char *md,SHA512CTX c)
64+
void sha512(unsigned char *digest, int len, unsigned char *hash)
65+
66+
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen)
67+
# EVPCTX evp_init(int nid)
68+
# void evp_update(EVPCTX ctx, const void *data, unsigned long len)
69+
# void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen)
70+
71+
# ssh_mac_ctx ssh_mac_ctx_init(ssh_mac_e type)
72+
# void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len)
73+
# void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx)
74+
75+
# HMACCTX hmac_init(const void *key,int len, ssh_hmac_e type)
76+
# void hmac_update(HMACCTX c, const void *data, unsigned long len)
77+
# void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len)
78+
size_t hmac_digest_len(ssh_hmac_e type)
79+
80+
int crypt_set_algorithms(ssh_session session, ssh_des_e des_type)
81+
int crypt_set_algorithms_server(ssh_session session)
82+
ssh_crypto_struct *crypto_new()
83+
void crypto_free(ssh_crypto_struct *crypto)
84+
85+
void ssh_reseed()
86+
87+
void ssh_cipher_clear(ssh_cipher_struct *cipher)
88+
ssh_hmac_struct *ssh_get_hmactab()
89+
const char *ssh_hmac_type_to_string(ssh_hmac_e hmac_type)

ssh/ssh.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ cimport c_agent
2020
cimport c_auth
2121
cimport c_channels
2222
cimport c_misc
23+
cimport c_crypto
24+
cimport c_wrapper

0 commit comments

Comments
 (0)