mirror of
				https://github.com/libssh2/libssh2.git
				synced 2025-10-30 12:05:34 +03:00 
			
		
		
		
	less hard coding of cipher mode in libgcrypt backend
This commit is contained in:
		| @@ -524,16 +524,14 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, | ||||
|                      _libssh2_cipher_type(algo), | ||||
|                      unsigned char *iv, unsigned char *secret, int encrypt) | ||||
| { | ||||
|     int mode = 0, ret; | ||||
|     int keylen = gcry_cipher_get_algo_keylen(algo); | ||||
|     int ret; | ||||
|     int cipher = _libssh2_gcry_cipher (algo); | ||||
|     int mode = _libssh2_gcry_mode (algo); | ||||
|     int keylen = gcry_cipher_get_algo_keylen(cipher); | ||||
|  | ||||
|     (void) encrypt; | ||||
|  | ||||
|     if (algo != GCRY_CIPHER_ARCFOUR) { | ||||
|         mode = GCRY_CIPHER_MODE_CBC; | ||||
|     } | ||||
|  | ||||
|     ret = gcry_cipher_open(h, algo, mode, 0); | ||||
|     ret = gcry_cipher_open(h, cipher, mode, 0); | ||||
|     if (ret) { | ||||
|         return -1; | ||||
|     } | ||||
| @@ -544,8 +542,8 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
|     if (algo != GCRY_CIPHER_ARCFOUR) { | ||||
|         int blklen = gcry_cipher_get_algo_blklen(algo); | ||||
|     if (mode != GCRY_CIPHER_MODE_STREAM) { | ||||
|         int blklen = gcry_cipher_get_algo_blklen(cipher); | ||||
|         ret = gcry_cipher_setiv(*h, iv, blklen); | ||||
|         if (ret) { | ||||
|             gcry_cipher_close(*h); | ||||
| @@ -561,8 +559,10 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, | ||||
|                       _libssh2_cipher_type(algo), | ||||
|                       int encrypt, unsigned char *block) | ||||
| { | ||||
|     size_t blklen = gcry_cipher_get_algo_blklen(algo); | ||||
|     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; | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| /* Copyright (C) 2006, 2007, The Written Word, Inc. | ||||
|  * Copyright (C) 2008, Simon Josefsson | ||||
| /* | ||||
|  * Copyright (C) 2008, 2009 Simon Josefsson | ||||
|  * Copyright (C) 2006, 2007, The Written Word, Inc. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, | ||||
| @@ -155,13 +156,24 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, | ||||
| #define _libssh2_cipher_type(name) int name | ||||
| #define _libssh2_cipher_ctx gcry_cipher_hd_t | ||||
|  | ||||
| #define _libssh2_cipher_aes256 GCRY_CIPHER_AES256 | ||||
| #define _libssh2_cipher_aes192 GCRY_CIPHER_AES192 | ||||
| #define _libssh2_cipher_aes128 GCRY_CIPHER_AES128 | ||||
| #define _libssh2_cipher_blowfish GCRY_CIPHER_BLOWFISH | ||||
| #define _libssh2_cipher_arcfour GCRY_CIPHER_ARCFOUR | ||||
| #define _libssh2_cipher_cast5 GCRY_CIPHER_CAST5 | ||||
| #define _libssh2_cipher_3des GCRY_CIPHER_3DES | ||||
| #define _libssh2_gcry_ciphermode(c,m) ((c << 8) | m) | ||||
| #define _libssh2_gcry_cipher(c) (c >> 8) | ||||
| #define _libssh2_gcry_mode(m) (m & 0xFF) | ||||
|  | ||||
| #define _libssh2_cipher_aes256			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC) | ||||
| #define _libssh2_cipher_aes192			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC) | ||||
| #define _libssh2_cipher_aes128			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC) | ||||
| #define _libssh2_cipher_blowfish		\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_CBC) | ||||
| #define _libssh2_cipher_arcfour			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM) | ||||
| #define _libssh2_cipher_cast5			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC) | ||||
| #define _libssh2_cipher_3des			\ | ||||
|   _libssh2_gcry_ciphermode(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC) | ||||
|  | ||||
| int _libssh2_cipher_init(_libssh2_cipher_ctx * h, | ||||
|                          _libssh2_cipher_type(algo), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user