/* */ #include "LibgcryptARC4Context.h" #include "DlAbortEx.h" #include "fmt.h" namespace aria2 { namespace { void handleError(gcry_error_t err) { throw DL_ABORT_EX (fmt("Exception in libgcrypt routine(ARC4Context class): %s", gcry_strerror(err))); } } // namespace LibgcryptARC4Context::LibgcryptARC4Context():cipherCtx_(0) {} LibgcryptARC4Context::~LibgcryptARC4Context() { gcry_cipher_close(cipherCtx_); } void LibgcryptARC4Context::init(const unsigned char* key, size_t keyLength) { gcry_cipher_close(cipherCtx_); int algo = GCRY_CIPHER_ARCFOUR; int mode = GCRY_CIPHER_MODE_STREAM; unsigned int flags = 0; { gcry_error_t r = gcry_cipher_open(&cipherCtx_, algo, mode, flags); if(r) { handleError(r); } } { gcry_error_t r = gcry_cipher_setkey(cipherCtx_, key, keyLength); if(r) { handleError(r); } } { gcry_error_t r = gcry_cipher_setiv(cipherCtx_, 0, 0); if(r) { handleError(r); } } } } // namespace aria2