Changeset View
Changeset View
Standalone View
Standalone View
plugins/qca-botan/qca-botan.cpp
Show All 28 Lines | |||||
29 | #include <botan/botan.h> | 29 | #include <botan/botan.h> | ||
30 | #include <botan/algo_factory.h> | 30 | #include <botan/algo_factory.h> | ||
31 | #else | 31 | #else | ||
32 | #include <botan/auto_rng.h> | 32 | #include <botan/auto_rng.h> | ||
33 | #include <botan/block_cipher.h> | 33 | #include <botan/block_cipher.h> | ||
34 | #include <botan/filters.h> | 34 | #include <botan/filters.h> | ||
35 | #include <botan/hash.h> | 35 | #include <botan/hash.h> | ||
36 | #include <botan/pbkdf.h> | 36 | #include <botan/pbkdf.h> | ||
37 | #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0) | ||||
37 | #include <botan/hkdf.h> | 38 | #include <botan/hkdf.h> | ||
39 | #endif | ||||
38 | #include <botan/stream_cipher.h> | 40 | #include <botan/stream_cipher.h> | ||
39 | #endif | 41 | #endif | ||
40 | 42 | | |||
41 | #include <stdlib.h> | 43 | #include <stdlib.h> | ||
42 | #include <iostream> | 44 | #include <iostream> | ||
43 | 45 | | |||
44 | //----------------------------------------------------------- | 46 | //----------------------------------------------------------- | ||
45 | class botanRandomContext : public QCA::RandomContext | 47 | class botanRandomContext : public QCA::RandomContext | ||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | 209 | { | |||
223 | return makeKey(secret, salt, keyLength, *iterationCount); | 225 | return makeKey(secret, salt, keyLength, *iterationCount); | ||
224 | } | 226 | } | ||
225 | 227 | | |||
226 | protected: | 228 | protected: | ||
227 | Botan::S2K* m_s2k; | 229 | Botan::S2K* m_s2k; | ||
228 | }; | 230 | }; | ||
229 | 231 | | |||
230 | //----------------------------------------------------------- | 232 | //----------------------------------------------------------- | ||
233 | #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0) | ||||
231 | class BotanHKDFContext: public QCA::HKDFContext | 234 | class BotanHKDFContext: public QCA::HKDFContext | ||
232 | { | 235 | { | ||
233 | public: | 236 | public: | ||
234 | BotanHKDFContext(const QString &hashName, QCA::Provider *p, const QString &type) : QCA::HKDFContext(p, type) | 237 | BotanHKDFContext(const QString &hashName, QCA::Provider *p, const QString &type) : QCA::HKDFContext(p, type) | ||
235 | { | 238 | { | ||
236 | Botan::HMAC *hashObj; | 239 | Botan::HMAC *hashObj; | ||
237 | #if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0) | | |||
238 | hashObj = new Botan::HMAC(Botan::global_state().algorithm_factory().make_hash_function(hashName.toStdString())); | | |||
239 | #else | | |||
240 | hashObj = new Botan::HMAC(Botan::HashFunction::create_or_throw(hashName.toStdString()).release()); | 240 | hashObj = new Botan::HMAC(Botan::HashFunction::create_or_throw(hashName.toStdString()).release()); | ||
241 | #endif | | |||
242 | m_hkdf = new Botan::HKDF(hashObj); | 241 | m_hkdf = new Botan::HKDF(hashObj); | ||
243 | } | 242 | } | ||
244 | 243 | | |||
245 | ~BotanHKDFContext() | 244 | ~BotanHKDFContext() | ||
246 | { | 245 | { | ||
247 | delete m_hkdf; | 246 | delete m_hkdf; | ||
248 | } | 247 | } | ||
249 | 248 | | |||
Show All 13 Lines | 259 | m_hkdf->kdf(key.data(), keyLength, | |||
263 | reinterpret_cast<const Botan::byte*>(info.data()), info.size()); | 262 | reinterpret_cast<const Botan::byte*>(info.data()), info.size()); | ||
264 | QCA::SecureArray retval(QByteArray::fromRawData(reinterpret_cast<const char*>(key.data()), key.size())); | 263 | QCA::SecureArray retval(QByteArray::fromRawData(reinterpret_cast<const char*>(key.data()), key.size())); | ||
265 | return QCA::SymmetricKey(retval); | 264 | return QCA::SymmetricKey(retval); | ||
266 | } | 265 | } | ||
267 | 266 | | |||
268 | protected: | 267 | protected: | ||
269 | Botan::HKDF* m_hkdf; | 268 | Botan::HKDF* m_hkdf; | ||
270 | }; | 269 | }; | ||
270 | #endif | ||||
271 | 271 | | |||
272 | 272 | | |||
273 | //----------------------------------------------------------- | 273 | //----------------------------------------------------------- | ||
274 | class BotanCipherContext : public QCA::CipherContext | 274 | class BotanCipherContext : public QCA::CipherContext | ||
275 | { | 275 | { | ||
276 | public: | 276 | public: | ||
277 | BotanCipherContext( const QString &algo, const QString &mode, const QString &padding, | 277 | BotanCipherContext( const QString &algo, const QString &mode, const QString &padding, | ||
278 | QCA::Provider *p, const QString &type) : QCA::CipherContext(p, type) | 278 | QCA::Provider *p, const QString &type) : QCA::CipherContext(p, type) | ||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | 453 | list += "hmac(sha1)"; | |||
454 | // HMAC with SHA2 doesn't appear to work correctly in Botan. | 454 | // HMAC with SHA2 doesn't appear to work correctly in Botan. | ||
455 | // list += "hmac(sha256)"; | 455 | // list += "hmac(sha256)"; | ||
456 | // list += "hmac(sha384)"; | 456 | // list += "hmac(sha384)"; | ||
457 | // list += "hmac(sha512)"; | 457 | // list += "hmac(sha512)"; | ||
458 | list += "hmac(ripemd160)"; | 458 | list += "hmac(ripemd160)"; | ||
459 | list += "pbkdf1(sha1)"; | 459 | list += "pbkdf1(sha1)"; | ||
460 | list += "pbkdf1(md2)"; | 460 | list += "pbkdf1(md2)"; | ||
461 | list += "pbkdf2(sha1)"; | 461 | list += "pbkdf2(sha1)"; | ||
462 | #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0) | ||||
462 | list += "hkdf(sha256)"; | 463 | list += "hkdf(sha256)"; | ||
464 | #endif | ||||
463 | list += "aes128-ecb"; | 465 | list += "aes128-ecb"; | ||
464 | list += "aes128-cbc"; | 466 | list += "aes128-cbc"; | ||
465 | list += "aes128-cfb"; | 467 | list += "aes128-cfb"; | ||
466 | list += "aes128-ofb"; | 468 | list += "aes128-ofb"; | ||
467 | list += "aes192-ecb"; | 469 | list += "aes192-ecb"; | ||
468 | list += "aes192-cbc"; | 470 | list += "aes192-cbc"; | ||
469 | list += "aes192-cfb"; | 471 | list += "aes192-cfb"; | ||
470 | list += "aes192-ofb"; | 472 | list += "aes192-ofb"; | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
520 | else if ( type == "hmac(ripemd160)" ) | 522 | else if ( type == "hmac(ripemd160)" ) | ||
521 | return new BotanHMACContext( QString("RIPEMD-160"), this, type ); | 523 | return new BotanHMACContext( QString("RIPEMD-160"), this, type ); | ||
522 | else if ( type == "pbkdf1(sha1)" ) | 524 | else if ( type == "pbkdf1(sha1)" ) | ||
523 | return new BotanPBKDFContext( QString("PBKDF1(SHA-1)"), this, type ); | 525 | return new BotanPBKDFContext( QString("PBKDF1(SHA-1)"), this, type ); | ||
524 | else if ( type == "pbkdf1(md2)" ) | 526 | else if ( type == "pbkdf1(md2)" ) | ||
525 | return new BotanPBKDFContext( QString("PBKDF1(MD2)"), this, type ); | 527 | return new BotanPBKDFContext( QString("PBKDF1(MD2)"), this, type ); | ||
526 | else if ( type == "pbkdf2(sha1)" ) | 528 | else if ( type == "pbkdf2(sha1)" ) | ||
527 | return new BotanPBKDFContext( QString("PBKDF2(SHA-1)"), this, type ); | 529 | return new BotanPBKDFContext( QString("PBKDF2(SHA-1)"), this, type ); | ||
530 | #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0) | ||||
528 | else if ( type == "hkdf(sha256)" ) | 531 | else if ( type == "hkdf(sha256)" ) | ||
529 | return new BotanHKDFContext( QString("SHA-256"), this, type ); | 532 | return new BotanHKDFContext( QString("SHA-256"), this, type ); | ||
533 | #endif | ||||
530 | else if ( type == "aes128-ecb" ) | 534 | else if ( type == "aes128-ecb" ) | ||
531 | return new BotanCipherContext( QString("AES-128"), QString("ECB"), QString("NoPadding"), this, type ); | 535 | return new BotanCipherContext( QString("AES-128"), QString("ECB"), QString("NoPadding"), this, type ); | ||
532 | else if ( type == "aes128-cbc" ) | 536 | else if ( type == "aes128-cbc" ) | ||
533 | return new BotanCipherContext( QString("AES-128"), QString("CBC"), QString("NoPadding"), this, type ); | 537 | return new BotanCipherContext( QString("AES-128"), QString("CBC"), QString("NoPadding"), this, type ); | ||
534 | else if ( type == "aes128-cfb" ) | 538 | else if ( type == "aes128-cfb" ) | ||
535 | return new BotanCipherContext( QString("AES-128"), QString("CFB"), QString("NoPadding"), this, type ); | 539 | return new BotanCipherContext( QString("AES-128"), QString("CFB"), QString("NoPadding"), this, type ); | ||
536 | else if ( type == "aes128-ofb" ) | 540 | else if ( type == "aes128-ofb" ) | ||
537 | return new BotanCipherContext( QString("AES-128"), QString("OFB"), QString("NoPadding"), this, type ); | 541 | return new BotanCipherContext( QString("AES-128"), QString("OFB"), QString("NoPadding"), this, type ); | ||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |