---
src/crypt.c | 8 +++++---
src/crypto.h | 2 +-
src/libgcrypt.c | 8 +-------
src/libssh2_priv.h | 2 +-
src/openssl.c | 7 +------
src/transport.c | 3 ++-
6 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/src/crypt.c b/src/crypt.c
index 93d99c4..931ae8b 100644
--- a/src/crypt.c
+++ b/src/crypt.c
@@ -96,11 +96,12 @@ crypt_init(LIBSSH2_SESSION * session,
static int
crypt_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
- void **abstract)
+ size_t blocksize, void **abstract)
{
struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract;
(void) session;
- return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block);
+ return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
+ blocksize);
}
static int
@@ -248,7 +249,8 @@ crypt_init_arcfour128(LIBSSH2_SESSION * session,
unsigned char block[8];
size_t discard = 1536;
for (; discard; discard -= 8)
- _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block);
+ _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
+ method->blocksize);
}
return rc;
diff --git a/src/crypto.h b/src/crypto.h
index 8cf34f5..5dc5931 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -103,7 +103,7 @@ int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
- int encrypt, unsigned char *block);
+ int encrypt, unsigned char *block, size_t blocksize);
int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
unsigned char **method,
diff --git a/src/libgcrypt.c b/src/libgcrypt.c
index 5c2787b..29770c7 100644
--- a/src/libgcrypt.c
+++ b/src/libgcrypt.c
@@ -553,17 +553,11 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h,
int
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
- int encrypt, unsigned char *block)
+ int encrypt, unsigned char *block, size_t blklen)
{
int cipher = _libssh2_gcry_cipher (algo);
- size_t blklen = gcry_cipher_get_algo_blklen(cipher);
int ret;
- if (blklen == 1) {
-/* Hack for arcfour. */
- blklen = 8;
- }
-
if (encrypt) {
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
} else {
diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h
index 196864d..4ec9f73 100644
--- a/src/libssh2_priv.h
+++ b/src/libssh2_priv.h
@@ -883,7 +883,7 @@ struct _LIBSSH2_CRYPT_METHOD
int *free_iv, unsigned char *secret, int *free_secret,
int encrypt, void **abstract);
int (*crypt) (LIBSSH2_SESSION * session, unsigned char *block,
- void **abstract);
+ size_t blocksize, void **abstract);
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
_libssh2_cipher_type(algo);
diff --git a/src/openssl.c b/src/openssl.c
index c61cb0e..8643591 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -181,18 +181,13 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h,
int
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
- int encrypt, unsigned char *block)
+ int encrypt, unsigned char *block, size_t blocksize)
{
- int blocksize = ctx->cipher->block_size;
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
int ret;
(void) algo;
(void) encrypt;
- if (blocksize == 1) {
-/* Hack for arcfour. */
- blocksize = 8;
- }
ret = EVP_Cipher(ctx, buf, block, blocksize);
if (ret == 1) {
memcpy(block, buf, blocksize);
diff --git a/src/transport.c b/src/transport.c
index 15425b9..b4ec037 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -139,7 +139,7 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source,
assert((len % blocksize) == 0);
while (len >= blocksize) {
- if (session->remote.crypt->crypt(session, source,
+ if (session->remote.crypt->crypt(session, source, blocksize,
&session->remote.crypt_abstract)) {
LIBSSH2_FREE(session, p->payload);
return LIBSSH2_ERROR_DECRYPT;
@@ -846,6 +846,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
for(i = 0; i < packet_length; i += session->local.crypt->blocksize) {
unsigned char *ptr = &p->outbuf[i];
if (session->local.crypt->crypt(session, ptr,
+ session->local.crypt->blocksize,
&session->local.crypt_abstract))
return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */
}
--
1.7.1
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-09-11