int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), int encrypt, unsigned char *block, size_t blklen) { int cipher = _libssh2_gcry_cipher (algo); int ret; if (encrypt) { ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen); } else { ret = gcry_cipher_decrypt(*ctx, block, blklen, block, blklen); } return ret; }
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), int encrypt, unsigned char *block) { 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 { ret = gcry_cipher_decrypt(*ctx, block, blklen, block, blklen); } return ret; }
int _libssh2_cipher_init(_libssh2_cipher_ctx * h, _libssh2_cipher_type(algo), unsigned char *iv, unsigned char *secret, int encrypt) { int ret; int cipher = _libssh2_gcry_cipher(algo); int mode = _libssh2_gcry_mode(algo); int keylen = gcry_cipher_get_algo_keylen(cipher); (void) encrypt; ret = gcry_cipher_open(h, cipher, mode, 0); if(ret) { return -1; } ret = gcry_cipher_setkey(*h, secret, keylen); if(ret) { gcry_cipher_close(*h); return -1; } if(mode != GCRY_CIPHER_MODE_STREAM) { int blklen = gcry_cipher_get_algo_blklen(cipher); if(mode == GCRY_CIPHER_MODE_CTR) ret = gcry_cipher_setctr(*h, iv, blklen); else ret = gcry_cipher_setiv(*h, iv, blklen); if(ret) { gcry_cipher_close(*h); return -1; } } return 0; }