static crypto_t _cipher_new(crypto_t c, gchar *key, const gchar *algoname, const gint cipher_mode, const guint cipher_flags) { gcry_error_t e; c->algo = gcry_cipher_map_name(algoname); if (c->algo ==0) { return (_fail(c, g_strdup_printf("algorithm `%s' was not available", algoname))); } c->cipher.flags = cipher_flags; c->cipher.mode = cipher_mode; c->cipher.should_pad = (cipher_mode != GCRY_CIPHER_MODE_STREAM && cipher_mode != GCRY_CIPHER_MODE_CFB && cipher_mode != GCRY_CIPHER_MODE_OFB) ? TRUE : FALSE; c->cipher.blklen = gcry_cipher_get_algo_blklen(c->algo); if (c->cipher.blklen ==0) return (_fail(c, g_strdup("gcry_cipher_get_algo_blklen failed"))); e = gcry_cipher_open(&c->cipher.h, c->algo, cipher_mode, cipher_flags); if (e != 0) { return (_fail(c, g_strdup_printf("gcry_cipher_open failed: %s", gpg_strerror(e)))); } return (_setkey(c, key)); }
// ----------------------------------------------------------------------------- // function_name: setkey // // Sets the key to used within the encryption/decryption algorithms // // Returns: void // ----------------------------------------------------------------------------- // EXPORT_C void setkey(const char *key) { _setkey(key); }