diff options
author | Gary Kramlich <grim@reaperworld.com> | 2017-06-30 01:55:59 +0000 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2017-06-30 01:55:59 +0000 |
commit | 4459d8f7b51a96677b6251a98b29325fafe15eed (patch) | |
tree | 84967749ce947f27d06a6497c14fdd85e2a54fb6 | |
parent | c180324a2de1dd3494ebe8c11b5e995a916d4359 (diff) | |
parent | b2e58f6ae08f5894690d7ebe68b6b2a1e1b447a7 (diff) | |
download | pidgin-4459d8f7b51a96677b6251a98b29325fafe15eed.tar.gz |
Merged in CMaiku/pidgin (pull request #219)
Port PurpleCipher usage to Nettle & remove it
Approved-by: Gary Kramlich <grim@reaperworld.com>
39 files changed, 154 insertions, 5311 deletions
diff --git a/ChangeLog.API b/ChangeLog.API index 6c785fa9f8..91efbb7c5b 100644 --- a/ChangeLog.API +++ b/ChangeLog.API @@ -23,14 +23,6 @@ version 3.0.0 (??/??/????): * purple_account_presence_new * purple_buddy_presence_new * purple_account_register_completed - * PurpleAESCipher, PurpleDESCipher, PurpleDES3Cipher, PurpleHMACCipher, - PurplePBKDF2Cipher and PurpleRC4Cipher inherit PurpleCipher - * purple_aes_cipher_new - * purple_des3_cipher_new - * purple_des_cipher_new - * purple_hmac_cipher_new - * purple_pbkdf2_cipher_new - * purple_rc4_cipher_new * purple_blist_node_is_transient * purple_blist_node_set_transient * purple_certificate_get_der_data @@ -55,13 +47,6 @@ version 3.0.0 (??/??/????): * purple_counting_node_get_* * purple_counting_node_change_* * purple_counting_node_set_* - * PurpleHash and purple_hash_* API - * PurpleMD4Hash, PurpleMD5Hash, PurpleSHA1Hash and PurpleSHA265Hash - inherit PurpleHash - * purple_md4_hash_new - * purple_md5_hash_new - * purple_sha1_hash_new - * purple_sha256_hash_new * PurpleIMConversation and PurpleChatConversation inherit PurpleConversation * purple_notify_emails_pending @@ -197,8 +182,6 @@ version 3.0.0 (??/??/????): * conversation.h has been split into conversation.h (PurpleConversation), conversationtypes.h (PurpleIMConversation and PurpleChatConversation) and conversations.h (Conversations subsystem) - * Files in libpurple/ciphers have been renamed. To use a particular - cipher, include its header. * Renamed ft.h file to xfer.h * Renamed plugin.h file to plugins.h * prpl.h has been split into protocol.h (PurpleProtocol GObject and @@ -259,9 +242,6 @@ version 3.0.0 (??/??/????): * Replaced 'chat-buddy' with 'chat-user' in conversation signals * Replaced chatname, buddyname arguments of 'chat-user-flags' (formerly 'chat-buddy-flags') signal with PurpleChatUser * - * PurpleCipher split into PurpleCipher and PurpleHash, both are - GObjects. Please see the documentation for details. - * purple_cipher_context_* functions are now purple_cipher_* * PurpleCircBuffer changed to PurpleCircularBuffer, is now a GObject. Please see the documentation for details. * purple_circ_buffer_* functions are now purple_circular_buffer_* @@ -403,7 +383,6 @@ version 3.0.0 (??/??/????): * buddy-added and buddy-removed blist signals * privacy.h file * value.h file - * _PurpleCipherBatchMode * _PurpleCmdFlag * _PurpleCmdPriority * _PurpleCmdRet @@ -430,19 +409,8 @@ version 3.0.0 (??/??/????): purple_certificate_check_signature_chain, instead * purple_certificate_display_x509. Use purple_request_certificate, instead - * PurpleCipherContext - * purple_cipher_context_destroy - * purple_cipher_context_get_data - * purple_cipher_context_get_option - * purple_cipher_context_new - * purple_cipher_context_new_by_name - * purple_cipher_context_set_data - * purple_cipher_context_set_option - * purple_cipher_get_capabilities - * purple_cipher_get_name - * PurpleCipherOps - * purple_ciphers_* - * PurpleCipher's init and uninit operations + * Purple Cipher API (PurpleCipherContext and friends). + Use GLib's GHmac or GChecksum instead. * purple_connection_error_reason * purple_connection_new * purple_connection_new_unregister diff --git a/configure.ac b/configure.ac index 12882a01e3..01f94e074b 100644 --- a/configure.ac +++ b/configure.ac @@ -1866,105 +1866,6 @@ if test "x$SSL_CERTIFICATES_DIR" != "x" ; then fi AM_CONDITIONAL(INSTALL_SSL_CERTIFICATES, test "x$SSL_CERTIFICATES_DIR" = "x") -dnl These two are inverses of each other <-- stolen from evolution! - -AC_ARG_ENABLE(gnutls, - [ --enable-gnutls=[yes,no] attempt to use GnuTLS for SSL support [default=yes]], - [enable_gnutls="$enableval"], - [enable_gnutls="yes"]) - -AC_ARG_ENABLE(nss, - [ --enable-nss=[yes,no,static] attempt to use Mozilla libnss for SSL support [default=yes]], - [enable_nss="$enableval"], - [enable_nss="yes"]) - -msg_ssl="None. Novell Groupwise and Google Talk will not work without GnuTLS or NSS. OpenSSL is NOT usable!" -looked_for_gnutls="no" -dnl # -dnl # Check for GnuTLS if it isn't disabled -dnl # -if test "x$enable_gnutls" != "xno"; then - looked_for_gnutls="yes" - - if `$PKG_CONFIG --exists gnutls`; then - dnl # minimum required version should almost certainly be higher - PKG_CHECK_MODULES(GNUTLS, [gnutls >= 2.10], [ - have_gnutls="yes" - ], [ - AC_MSG_RESULT(no) - have_gnutls="no" - ]) - fi - - if test "x$have_gnutls" = "xyes"; then - AC_DEFINE(HAVE_GNUTLS, 1, [Define if you have GnuTLS]) - msg_gnutls="GnuTLS" - fi -fi - -AM_CONDITIONAL(USE_GNUTLS, test "x$have_gnutls" = "xyes") - - -dnl # -dnl # Check for NSS if it isn't disabled -dnl # -looked_for_nss="no" -if test "x$enable_nss" != "xno"; then - looked_for_nss="yes" - - if `$PKG_CONFIG --exists mozilla-nss`; then - dnl # TODO: set required minimum version - PKG_CHECK_MODULES(NSS, mozilla-nss, [ - have_nss="yes" - ], [ - AC_MSG_RESULT(no) - have_nss="no" - ]) - elif `$PKG_CONFIG --exists nss`; then - dnl # TODO: set required minimum version - PKG_CHECK_MODULES(NSS, nss, [ - have_nss="yes" - ], [ - AC_MSG_RESULT(no) - have_nss="no" - ]) - fi - - if test "x$have_nss" = "xyes"; then - AC_DEFINE(HAVE_NSS, 1, [Define if you have Mozilla NSS]) - msg_nss="Mozilla NSS" - fi -fi - -AM_CONDITIONAL(USE_NSS, test "x$have_nss" = "xyes") - - -if test "x$msg_nss" != "x" -a "x$msg_gnutls" != "x"; then - msg_ssl="$msg_nss and $msg_gnutls" -elif test "x$msg_nss" != "x"; then - msg_ssl=$msg_nss -elif test "x$msg_gnutls" != "x"; then - msg_ssl=$msg_gnutls -elif test "x$looked_for_gnutls" = "xyes" -a "x$looked_for_nss" = "xyes" -a "x$force_deps" = "xyes" ; then - AC_MSG_ERROR([ -Neither GnuTLS or NSS SSL development headers found. -Use --disable-nss --disable-gnutls if you do not need SSL support. -Novell Groupwise and Google Talk will not work without GnuTLS or NSS. OpenSSL is NOT usable! -]) -elif test "x$looked_for_gnutls" = "xyes" -a "x$force_deps" = "xyes" ; then - AC_MSG_ERROR([ -GnuTLS SSL development headers not found. -Use --disable-gnutls if you do not need SSL support. -Novell Groupwise and Google Talk will not work without SSL support. -]) -elif test "x$looked_for_nss" = "xyes" -a "x$force_deps" = "xyes" ; then - AC_MSG_ERROR([ -NSS SSL development headers not found. -Use --disable-nss if you do not need SSL support. -Novell Groupwise and Google Talk will not work without SSL support. -]) -fi - if test "$ac_cv_cygwin" = yes ; then LDADD="$LDADD -static" AC_DEFINE(DEBUG, 1, [Define if debugging is enabled.]) @@ -1986,6 +1887,33 @@ fi AC_SUBST(PLUGINS_DEFINE) dnl ####################################################################### +dnl # Check for Nettle (Crypto Library) +dnl ####################################################################### +AC_ARG_ENABLE(nettle, + [AC_HELP_STRING([--disable-nettle], [disable Nettle support])], + enable_nettle="$enableval", enable_nettle="yes") + +if test "x$enable_nettle" = "xyes" ; then + PKG_CHECK_MODULES(NETTLE, [nettle >= 3.0], [ + enable_nettle="yes" + AC_SUBST(NETTLE_CFLAGS) + AC_SUBST(NETTLE_LIBS) + AC_DEFINE(HAVE_NETTLE, 1, [Define if we have Nettle.]) + ], [ + enable_nettle="no" + ]) + + if test "x$enable_nettle" != "xyes" -a "x$force_deps" = "xyes" ; then + AC_MSG_ERROR([ +Nettle development headers not found +Use --disable-nettle if you do not need it. +]) + fi +fi + +AM_CONDITIONAL(ENABLE_NETTLE, test "x$enable_nettle" = "xyes") + +dnl ####################################################################### dnl # Check for Cyrus-SASL (for xmpp/irc) dnl ####################################################################### dnl AC_CHECK_SIZEOF(short) @@ -2231,10 +2159,10 @@ if test "x$enable_dbus" = "xyes" ; then eval eval echo D-Bus services directory...... : $DBUS_SERVICES_DIR fi echo Build with GNU Libidn......... : $enable_idn -echo SSL Library/Libraries......... : $msg_ssl if test "x$SSL_CERTIFICATES_DIR" != "x" ; then eval eval echo SSL CA certificates directory. : $SSL_CERTIFICATES_DIR fi +echo Build with Nettle support..... : $enable_nettle echo Build with Cyrus SASL support. : $enable_cyrus_sasl echo Use kerberos 4 with zephyr.... : $kerberos echo Use external libzephyr........ : $zephyr diff --git a/doc/reference/libpurple/Makefile.am b/doc/reference/libpurple/Makefile.am index c85113820d..359ed3400e 100644 --- a/doc/reference/libpurple/Makefile.am +++ b/doc/reference/libpurple/Makefile.am @@ -135,8 +135,6 @@ GTKDOC_CFLAGS = \ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(GNUTLS_CFLAGS) \ - $(NSS_CFLAGS) \ $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) @@ -155,8 +153,6 @@ GTKDOC_LIBS = \ $(GSTINTERFACES_LIBS) \ $(IDN_LIBS) \ $(JSON_LIBS) \ - $(GNUTLS_LIBS) \ - $(NSS_LIBS) \ $(ZLIB_LIBS) \ $(INTROSPECTION_LIBS) \ -lm diff --git a/doc/reference/libpurple/libpurple-docs.xml b/doc/reference/libpurple/libpurple-docs.xml index 83f070731c..a50ff2a941 100644 --- a/doc/reference/libpurple/libpurple-docs.xml +++ b/doc/reference/libpurple/libpurple-docs.xml @@ -104,17 +104,6 @@ <xi:include href="xml/cmds.xml" /> </chapter> - <chapter id="ciphers"> - <title>Ciphers and Hashes</title> - - <xi:include href="xml/aescipher.xml" /> - <xi:include href="xml/descipher.xml" /> - <xi:include href="xml/des3cipher.xml" /> - <xi:include href="xml/pbkdf2cipher.xml" /> - <xi:include href="xml/rc4cipher.xml" /> - <xi:include href="xml/md4hash.xml" /> - </chapter> - <chapter id="smiley"> <title>Smiley APIs</title> diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am index bd4d8c561c..3d57fabbd8 100644 --- a/libpurple/Makefile.am +++ b/libpurple/Makefile.am @@ -39,13 +39,6 @@ purple_coresources = \ buddylist.c \ buddyicon.c \ chat.c \ - ciphers/aescipher.c \ - ciphers/descipher.c \ - ciphers/des3cipher.c \ - ciphers/md4hash.c \ - ciphers/pbkdf2cipher.c \ - ciphers/rc4cipher.c \ - cipher.c \ circularbuffer.c \ cmds.c \ connection.c \ @@ -131,7 +124,6 @@ purple_coreheaders = \ buddylist.h \ buddyicon.h \ chat.h \ - cipher.h \ circularbuffer.h \ cmds.h \ connection.h \ @@ -231,20 +223,11 @@ purple_mediaheaders = \ codec.h \ enum-types.h -purple_cipherheaders = \ - aescipher.h \ - descipher.h \ - des3cipher.h \ - md4hash.h \ - pbkdf2cipher.h \ - rc4cipher.h - purple_builtheaders = purple.h version.h enums.h purple_enumheaders = \ $(srcdir)/account.h \ $(srcdir)/buddyicon.h \ - $(srcdir)/cipher.h \ $(srcdir)/connection.h \ $(srcdir)/conversation.h \ $(srcdir)/conversationtypes.h \ @@ -308,7 +291,6 @@ dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blistnode.h # to not being able to find the enums.h file if it's already # been generated in the $(srcdir). purple_build_coreheaders = $(addprefix $(srcdir)/, $(purple_coreheaders)) \ - $(addprefix $(srcdir)/ciphers/, $(purple_cipherheaders)) \ $(addprefix $(srcdir)/media/, $(purple_mediaheaders)) \ $(filter-out: enums.h, $(purple_builtheaders)) dbus_build_exported = $(addprefix $(srcdir)/, $(dbus_exported)) @@ -347,7 +329,7 @@ libpurple_client_la_LIBADD = $(DBUS_LIBS) purple-client-bindings.c: dbus-analyze-functions.py $(dbus_exported) $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client -o $@ $(dbus_build_exported) -purple-client-bindings.h: dbus-analyze-types.py dbus-analyze-functions.py $(purple_coreheaders) $(addprefix ciphers/, $(purple_cipherheaders)) $(addprefix media/, $(purple_mediaheaders)) $(purple_builtheaders) $(dbus_exported) +purple-client-bindings.h: dbus-analyze-types.py dbus-analyze-functions.py $(purple_coreheaders) $(addprefix media/, $(purple_mediaheaders)) $(purple_builtheaders) $(dbus_exported) $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-types.py --keyword=enum --verbatim -o $@ $(purple_build_coreheaders) $(AM_V_at) $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client --headers --append -o $@ $(dbus_build_exported) @@ -409,10 +391,6 @@ libpurpleinclude_HEADERS = \ $(purple_builtheaders) \ $(dbus_headers) -cipherincludedir=$(includedir)/libpurple/ciphers -cipherinclude_HEADERS = \ - $(addprefix $(srcdir)/ciphers/, $(purple_cipherheaders)) - mediaincludedir=$(includedir)/libpurple/media mediainclude_HEADERS = \ $(addprefix $(srcdir)/media/, $(purple_mediaheaders)) @@ -456,8 +434,6 @@ libpurple_la_LIBADD = \ $(GSTINTERFACES_LIBS) \ $(IDN_LIBS) \ $(JSON_LIBS) \ - $(GNUTLS_LIBS) \ - $(NSS_LIBS) \ $(ZLIB_LIBS) \ $(INTROSPECTION_LIBS) \ -lm @@ -476,8 +452,6 @@ AM_CPPFLAGS = \ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(GNUTLS_CFLAGS) \ - $(NSS_CFLAGS) \ $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) @@ -489,7 +463,6 @@ INTROSPECTION_COMPILER_ARGS = --includedir=$(prefix)/share/gir-1.0 if HAVE_INTROSPECTION introspection_sources = \ $(libpurpleinclude_HEADERS) \ - $(addprefix ciphers/, $(purple_cipherheaders)) \ $(addprefix media/, $(purple_mediaheaders)) Purple-$(PURPLE_MAJOR_VERSION).$(PURPLE_MINOR_VERSION).gir: $(builddir)/libpurple.la @@ -519,8 +492,6 @@ Purple_3_0_gir_CFLAGS = \ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(GNUTLS_CFLAGS) \ - $(NSS_CFLAGS) \ $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) diff --git a/libpurple/Makefile.mingw b/libpurple/Makefile.mingw index fdd416cb83..cbb3927d97 100644 --- a/libpurple/Makefile.mingw +++ b/libpurple/Makefile.mingw @@ -68,13 +68,6 @@ C_SRC = \ buddylist.c \ buddyicon.c \ certificate.c \ - ciphers/aescipher.c \ - ciphers/descipher.c \ - ciphers/des3cipher.c \ - ciphers/md4hash.c \ - ciphers/pbkdf2cipher.c \ - ciphers/rc4cipher.c \ - cipher.c \ circularbuffer.c \ cmds.c \ connection.c \ @@ -146,7 +139,6 @@ RC_SRC = win32/libpurplerc.rc ENUM_HEADERS = \ account.h \ - cipher.h \ connection.h \ conversation.h \ conversationtypes.h \ diff --git a/libpurple/cipher.c b/libpurple/cipher.c deleted file mode 100644 index c839d577d8..0000000000 --- a/libpurple/cipher.c +++ /dev/null @@ -1,555 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#include "internal.h" -#include "cipher.h" -#include "debug.h" - -/****************************************************************************** - * PurpleCipher API - *****************************************************************************/ -GType -purple_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleCipherClass), - NULL, - NULL, - NULL, - NULL, - NULL, - sizeof(PurpleCipher), - 0, - NULL, - NULL - }; - - type = g_type_register_static(G_TYPE_OBJECT, - "PurpleCipher", - &info, G_TYPE_FLAG_ABSTRACT); - } - - return type; -} - -static const gchar * -purple_cipher_get_name(PurpleCipher *cipher) -{ - PurpleCipherClass *klass; - const gchar *name; - - if (!PURPLE_IS_CIPHER(cipher)) - return "(error: not a cipher)"; - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - if (!klass) - return "(error: unknown cipher class)"; - - name = g_type_name(G_TYPE_FROM_CLASS(klass)); - if (!name) - return "(error: unknown cipher name)"; - - return name; -} - -static const gchar * -purple_hash_get_name(PurpleHash *hash) -{ - PurpleHashClass *klass; - const gchar *name; - - if (!PURPLE_IS_HASH(hash)) - return "(error: not a hash)"; - - klass = PURPLE_HASH_GET_CLASS(hash); - if (!klass) - return "(error: unknown hash class)"; - - name = g_type_name(G_TYPE_FROM_CLASS(klass)); - if (!name) - return "(error: unknown hash name)"; - - return name; -} - -void -purple_cipher_reset(PurpleCipher *cipher) { - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->reset) - klass->reset(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the reset method", - purple_cipher_get_name(cipher)); - } -} - -void -purple_cipher_reset_state(PurpleCipher *cipher) { - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->reset_state) - klass->reset_state(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the reset_state method", - purple_cipher_get_name(cipher)); - } -} - -void -purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) -{ - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - g_return_if_fail(iv); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->set_iv) - klass->set_iv(cipher, iv, len); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the set_iv method", - purple_cipher_get_name(cipher)); - } -} - -void -purple_cipher_append(PurpleCipher *cipher, const guchar *data, - size_t len) -{ - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->append) - klass->append(cipher, data, len); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the append method", - purple_cipher_get_name(cipher)); - } -} - -gboolean -purple_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->digest) - return klass->digest(cipher, digest, len); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the digest method", - purple_cipher_get_name(cipher)); - } - - return FALSE; -} - -gboolean -purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len) -{ - /* 8k is a bit excessive, will tweak later. */ - guchar digest[BUF_LEN * 4]; - size_t digest_size, n; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); - g_return_val_if_fail(digest_s, FALSE); - - digest_size = purple_cipher_get_digest_size(cipher); - - g_return_val_if_fail(digest_size <= BUF_LEN * 4, FALSE); - - if(!purple_cipher_digest(cipher, digest, sizeof(digest))) - return FALSE; - - /* Every digest byte occupies 2 chars + the NUL at the end. */ - g_return_val_if_fail(digest_size * 2 + 1 <= len, FALSE); - - for(n = 0; n < digest_size; n++) - sprintf(digest_s + (n * 2), "%02x", digest[n]); - - digest_s[n * 2] = '\0'; - - return TRUE; -} - -size_t -purple_cipher_get_digest_size(PurpleCipher *cipher) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->get_digest_size) - return klass->get_digest_size(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the get_digest_size method", - purple_cipher_get_name(cipher)); - } - - return FALSE; -} - -ssize_t -purple_cipher_encrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); - g_return_val_if_fail(input != NULL, -1); - g_return_val_if_fail(output != NULL, -1); - g_return_val_if_fail(out_size >= in_len, -1); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->encrypt) - return klass->encrypt(cipher, input, in_len, output, out_size); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the encrypt method", - purple_cipher_get_name(cipher)); - } - - return -1; -} - -ssize_t -purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); - g_return_val_if_fail(input != NULL, -1); - g_return_val_if_fail(output != NULL, -1); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->decrypt) - return klass->decrypt(cipher, input, in_len, output, out_size); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the decrypt method", - purple_cipher_get_name(cipher)); - } - - return -1; -} - -void -purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len) { - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->set_salt) - klass->set_salt(cipher, salt, len); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the set_salt method", - purple_cipher_get_name(cipher)); - } -} - -void -purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) { - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->set_key) - klass->set_key(cipher, key, len); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the set_key method", - purple_cipher_get_name(cipher)); - } -} - -size_t -purple_cipher_get_key_size(PurpleCipher *cipher) { - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->get_key_size) - return klass->get_key_size(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the get_key_size method", - purple_cipher_get_name(cipher)); - } - - return -1; -} - -void -purple_cipher_set_batch_mode(PurpleCipher *cipher, - PurpleCipherBatchMode mode) -{ - PurpleCipherClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_CIPHER(cipher)); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->set_batch_mode) - klass->set_batch_mode(cipher, mode); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the set_batch_mode method", - purple_cipher_get_name(cipher)); - } -} - -PurpleCipherBatchMode -purple_cipher_get_batch_mode(PurpleCipher *cipher) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->get_batch_mode) - return klass->get_batch_mode(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the get_batch_mode method", - purple_cipher_get_name(cipher)); - } - - return -1; -} - -size_t -purple_cipher_get_block_size(PurpleCipher *cipher) -{ - PurpleCipherClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); - - klass = PURPLE_CIPHER_GET_CLASS(cipher); - - if (klass && klass->get_block_size) - return klass->get_block_size(cipher); - else { - purple_debug_warning("cipher", "the %s cipher does not " - "implement the get_block_size method", - purple_cipher_get_name(cipher)); - } - - return -1; -} - -/****************************************************************************** - * PurpleHash API - *****************************************************************************/ -GType -purple_hash_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleHashClass), - NULL, - NULL, - NULL, - NULL, - NULL, - sizeof(PurpleHash), - 0, - NULL, - NULL - }; - - type = g_type_register_static(G_TYPE_OBJECT, - "PurpleHash", - &info, G_TYPE_FLAG_ABSTRACT); - } - - return type; -} - -void -purple_hash_reset(PurpleHash *hash) { - PurpleHashClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_HASH(hash)); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->reset) - klass->reset(hash); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the reset method", purple_hash_get_name(hash)); - } -} - -void -purple_hash_reset_state(PurpleHash *hash) { - PurpleHashClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_HASH(hash)); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->reset_state) - klass->reset_state(hash); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the reset_state method", purple_hash_get_name(hash)); - } -} - -void -purple_hash_append(PurpleHash *hash, const guchar *data, - size_t len) -{ - PurpleHashClass *klass = NULL; - - g_return_if_fail(PURPLE_IS_HASH(hash)); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->append) - klass->append(hash, data, len); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the append method", purple_hash_get_name(hash)); - } -} - -gboolean -purple_hash_digest(PurpleHash *hash, guchar digest[], size_t len) -{ - PurpleHashClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->digest) - return klass->digest(hash, digest, len); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the digest method", purple_hash_get_name(hash)); - } - - return FALSE; -} - -gboolean -purple_hash_digest_to_str(PurpleHash *hash, gchar digest_s[], size_t len) -{ - /* 8k is a bit excessive, will tweak later. */ - guchar digest[BUF_LEN * 4]; - size_t digest_size, n; - - g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE); - g_return_val_if_fail(digest_s, FALSE); - - digest_size = purple_hash_get_digest_size(hash); - - g_return_val_if_fail(digest_size <= BUF_LEN * 4, FALSE); - - if(!purple_hash_digest(hash, digest, sizeof(digest))) - return FALSE; - - /* Every digest byte occupies 2 chars + the NUL at the end. */ - g_return_val_if_fail(digest_size * 2 + 1 <= len, FALSE); - - for(n = 0; n < digest_size; n++) - sprintf(digest_s + (n * 2), "%02x", digest[n]); - - digest_s[n * 2] = '\0'; - - return TRUE; -} - -size_t -purple_hash_get_digest_size(PurpleHash *hash) -{ - PurpleHashClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->get_digest_size) - return klass->get_digest_size(hash); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the get_digest_size method", purple_hash_get_name(hash)); - } - - return FALSE; -} - -size_t -purple_hash_get_block_size(PurpleHash *hash) -{ - PurpleHashClass *klass = NULL; - - g_return_val_if_fail(PURPLE_IS_HASH(hash), -1); - - klass = PURPLE_HASH_GET_CLASS(hash); - - if (klass && klass->get_block_size) - return klass->get_block_size(hash); - else { - purple_debug_warning("hash", "the %s hash does not implement " - "the get_block_size method", purple_hash_get_name(hash)); - } - - return -1; -} diff --git a/libpurple/cipher.h b/libpurple/cipher.h deleted file mode 100644 index 57b90d38be..0000000000 --- a/libpurple/cipher.h +++ /dev/null @@ -1,421 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_CIPHER_H -#define PURPLE_CIPHER_H -/** - * SECTION:cipher - * @section_id: libpurple-cipher - * @short_description: <filename>cipher.h</filename> - * @title: Cipher and Hash API - */ - -#include <glib.h> -#include <glib-object.h> -#include <string.h> - -#define PURPLE_TYPE_CIPHER (purple_cipher_get_type()) -#define PURPLE_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_CIPHER, PurpleCipher)) -#define PURPLE_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_CIPHER, PurpleCipherClass)) -#define PURPLE_IS_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_CIPHER)) -#define PURPLE_IS_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_CIPHER)) -#define PURPLE_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_CIPHER, PurpleCipherClass)) - -typedef struct _PurpleCipher PurpleCipher; -typedef struct _PurpleCipherClass PurpleCipherClass; - -#define PURPLE_TYPE_HASH (purple_hash_get_type()) -#define PURPLE_HASH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_HASH, PurpleHash)) -#define PURPLE_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_HASH, PurpleHashClass)) -#define PURPLE_IS_HASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_HASH)) -#define PURPLE_IS_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_HASH)) -#define PURPLE_HASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_HASH, PurpleHashClass)) - -typedef struct _PurpleHash PurpleHash; -typedef struct _PurpleHashClass PurpleHashClass; - -/** - * PurpleCipherBatchMode: - * @PURPLE_CIPHER_BATCH_MODE_ECB: Electronic Codebook Mode - * @PURPLE_CIPHER_BATCH_MODE_CBC: Cipher Block Chaining Mode - * - * Modes for batch encrypters - */ -typedef enum { - PURPLE_CIPHER_BATCH_MODE_ECB, - PURPLE_CIPHER_BATCH_MODE_CBC -} PurpleCipherBatchMode; - -/** - * PurpleCipher: - * - * Purple Cipher is an opaque data structure and should not be used directly. - */ -struct _PurpleCipher { - GObject gparent; -}; - -struct _PurpleCipherClass { - GObjectClass parent_class; - - /** The reset function */ - void (*reset)(PurpleCipher *cipher); - - /** The reset state function */ - void (*reset_state)(PurpleCipher *cipher); - - /** The set initialization vector function */ - void (*set_iv)(PurpleCipher *cipher, guchar *iv, size_t len); - - /** The append data function */ - void (*append)(PurpleCipher *cipher, const guchar *data, size_t len); - - /** The digest function */ - gboolean (*digest)(PurpleCipher *cipher, guchar digest[], size_t len); - - /** The get digest size function */ - size_t (*get_digest_size)(PurpleCipher *cipher); - - /** The encrypt function */ - ssize_t (*encrypt)(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); - - /** The decrypt function */ - ssize_t (*decrypt)(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); - - /** The set salt function */ - void (*set_salt)(PurpleCipher *cipher, const guchar *salt, size_t len); - - /** The set key function */ - void (*set_key)(PurpleCipher *cipher, const guchar *key, size_t len); - - /** The get key size function */ - size_t (*get_key_size)(PurpleCipher *cipher); - - /** The set batch mode function */ - void (*set_batch_mode)(PurpleCipher *cipher, PurpleCipherBatchMode mode); - - /** The get batch mode function */ - PurpleCipherBatchMode (*get_batch_mode)(PurpleCipher *cipher); - - /** The get block size function */ - size_t (*get_block_size)(PurpleCipher *cipher); - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -/** - * PurpleHash: - * - * Purple Hash is an opaque data structure and should not be used directly. - */ -struct _PurpleHash { - GObject gparent; -}; - -struct _PurpleHashClass { - GObjectClass parent_class; - - /** The reset function */ - void (*reset)(PurpleHash *hash); - - /** The reset state function */ - void (*reset_state)(PurpleHash *hash); - - /** The append data function */ - void (*append)(PurpleHash *hash, const guchar *data, size_t len); - - /** The digest function */ - gboolean (*digest)(PurpleHash *hash, guchar digest[], size_t len); - - /** The get digest size function */ - size_t (*get_digest_size)(PurpleHash *hash); - - /** The get block size function */ - size_t (*get_block_size)(PurpleHash *hash); - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -/*****************************************************************************/ -/* PurpleCipher API */ -/*****************************************************************************/ - -/** - * purple_cipher_get_type: - * - * Returns: The #GType for the Cipher object. - */ -GType purple_cipher_get_type(void); - -/** - * purple_cipher_reset: - * @cipher: The cipher - * - * Resets a cipher to it's default value - * Note: If you have set an IV you will have to set it after resetting - */ -void purple_cipher_reset(PurpleCipher *cipher); - -/** - * purple_cipher_reset_state: - * @cipher: The cipher - * - * Resets a cipher state to it's default value, but doesn't touch stateless - * configuration. - * - * That means, IV and digest will be wiped out, but keys, ops or salt - * will remain untouched. - */ -void purple_cipher_reset_state(PurpleCipher *cipher); - -/** - * purple_cipher_set_iv: - * @cipher: The cipher - * @iv: The initialization vector to set - * @len: The len of the IV - * - * Sets the initialization vector for a cipher - * Note: This should only be called right after a cipher is created or reset - */ -void purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len); - -/** - * purple_cipher_append: - * @cipher: The cipher - * @data: The data to append - * @len: The length of the data - * - * Appends data to the cipher context - */ -void purple_cipher_append(PurpleCipher *cipher, const guchar *data, size_t len); - -/** - * purple_cipher_digest: - * @cipher: The cipher - * @digest: The return buffer for the digest - * @len: The length of the buffer - * - * Digests a cipher context - */ -gboolean purple_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len); - -/** - * purple_cipher_digest_to_str: - * @cipher: The cipher - * @digest_s: The return buffer for the string digest - * @len: The length of the buffer - * - * Converts a guchar digest into a hex string - */ -gboolean purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len); - -/** - * purple_cipher_get_digest_size: - * @cipher: The cipher whose digest size to get - * - * Gets the digest size of a cipher - * - * Returns: The digest size of the cipher - */ -size_t purple_cipher_get_digest_size(PurpleCipher *cipher); - -/** - * purple_cipher_encrypt: - * @cipher: The cipher - * @input: The data to encrypt - * @in_len: The length of the data - * @output: The output buffer - * @out_size: The size of the output buffer - * - * Encrypts data using the cipher - * - * Returns: A length of data that was outputed or -1, if failed - */ -ssize_t purple_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); - -/** - * purple_cipher_decrypt: - * @cipher: The cipher - * @input: The data to encrypt - * @in_len: The length of the returned value - * @output: The output buffer - * @out_size: The size of the output buffer - * - * Decrypts data using the cipher - * - * Returns: A length of data that was outputed or -1, if failed - */ -ssize_t purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); - -/** - * purple_cipher_set_salt: - * @cipher: The cipher whose salt to set - * @salt: The salt - * @len: The length of the salt - * - * Sets the salt on a cipher - */ -void purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len); - -/** - * purple_cipher_set_key: - * @cipher: The cipher whose key to set - * @key: The key - * @len: The size of the key - * - * Sets the key on a cipher - */ -void purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len); - -/** - * purple_cipher_get_key_size: - * @cipher: The cipher whose key size to get - * - * Gets the size of the key if the cipher supports it - * - * Returns: The size of the key - */ -size_t purple_cipher_get_key_size(PurpleCipher *cipher); - -/** - * purple_cipher_set_batch_mode: - * @cipher: The cipher whose batch mode to set - * @mode: The batch mode under which the cipher should operate - * - * Sets the batch mode of a cipher - */ -void purple_cipher_set_batch_mode(PurpleCipher *cipher, PurpleCipherBatchMode mode); - -/** - * purple_cipher_get_batch_mode: - * @cipher: The cipher whose batch mode to get - * - * Gets the batch mode of a cipher - * - * Returns: The batch mode under which the cipher is operating - */ -PurpleCipherBatchMode purple_cipher_get_batch_mode(PurpleCipher *cipher); - -/** - * purple_cipher_get_block_size: - * @cipher: The cipher whose block size to get - * - * Gets the block size of a cipher - * - * Returns: The block size of the cipher - */ -size_t purple_cipher_get_block_size(PurpleCipher *cipher); - -/*****************************************************************************/ -/* PurpleHash API */ -/*****************************************************************************/ - -/** - * purple_hash_get_type: - * - * Returns: The #GType for the Hash object. - */ -GType purple_hash_get_type(void); - -/** - * purple_hash_reset: - * @hash: The hash - * - * Resets a hash to it's default value - * Note: If you have set an IV you will have to set it after resetting - */ -void purple_hash_reset(PurpleHash *hash); - -/** - * purple_hash_reset_state: - * @hash: The hash - * - * Resets a hash state to it's default value, but doesn't touch stateless - * configuration. - * - * That means, IV and digest will be wiped out, but keys, ops or salt - * will remain untouched. - */ -void purple_hash_reset_state(PurpleHash *hash); - -/** - * purple_hash_append: - * @hash: The hash - * @data: The data to append - * @len: The length of the data - * - * Appends data to the hash context - */ -void purple_hash_append(PurpleHash *hash, const guchar *data, size_t len); - -/** - * purple_hash_digest: - * @hash: The hash - * @digest: The return buffer for the digest - * @len: The length of the buffer - * - * Digests a hash context - */ -gboolean purple_hash_digest(PurpleHash *hash, guchar digest[], size_t len); - -/** - * purple_hash_digest_to_str: - * @hash: The hash - * @digest_s: The return buffer for the string digest - * @len: The length of the buffer - * - * Converts a guchar digest into a hex string - */ -gboolean purple_hash_digest_to_str(PurpleHash *hash, gchar digest_s[], size_t len); - -/** - * purple_hash_get_digest_size: - * @hash: The hash whose digest size to get - * - * Gets the digest size of a hash - * - * Returns: The digest size of the hash - */ -size_t purple_hash_get_digest_size(PurpleHash *hash); - -/** - * purple_hash_get_block_size: - * @hash: The hash whose block size to get - * - * Gets the block size of a hash - * - * Returns: The block size of the hash - */ -size_t purple_hash_get_block_size(PurpleHash *hash); - -G_END_DECLS - -#endif /* PURPLE_CIPHER_H */ diff --git a/libpurple/ciphers/aescipher.c b/libpurple/ciphers/aescipher.c deleted file mode 100644 index acb4eb9741..0000000000 --- a/libpurple/ciphers/aescipher.c +++ /dev/null @@ -1,725 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - * Written by Tomek Wasilczyk <twasilczyk@pidgin.im> - */ - -#include "internal.h" -#include "glibcompat.h" - -#include "aescipher.h" -#include "debug.h" -#include "enums.h" - -#include <string.h> - -#if defined(HAVE_GNUTLS) -# define PURPLE_AES_USE_GNUTLS 1 -# include <gnutls/gnutls.h> -# include <gnutls/crypto.h> -#elif defined(HAVE_NSS) -# define PURPLE_AES_USE_NSS 1 -# include <nss.h> -# include <pk11pub.h> -# include <prerror.h> -#else -# warning "No GnuTLS or NSS support" -#endif - -/* 128bit */ -#define PURPLE_AES_BLOCK_SIZE 16 - -/****************************************************************************** - * Structs - *****************************************************************************/ -#define PURPLE_AES_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_AES_CIPHER, PurpleAESCipherPrivate)) - -typedef struct { - guchar iv[PURPLE_AES_BLOCK_SIZE]; - guchar key[32]; - guint key_size; - gboolean failure; - PurpleCipherBatchMode batch_mode; -} PurpleAESCipherPrivate; - -/****************************************************************************** - * Enums - *****************************************************************************/ -enum { - PROP_NONE, - PROP_BATCH_MODE, - PROP_IV, - PROP_KEY, - PROP_LAST, -}; - -/******************************************************************************* - * Globals - ******************************************************************************/ -static GParamSpec *properties[PROP_LAST]; - -/****************************************************************************** - * Cipher Stuff - *****************************************************************************/ - -typedef gboolean (*purple_aes_cipher_crypt_func)( - const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - PurpleCipherBatchMode batch_mode); - -static void -purple_aes_cipher_reset(PurpleCipher *cipher) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - g_return_if_fail(priv != NULL); - - memset(priv->iv, 0, sizeof(priv->iv)); - memset(priv->key, 0, sizeof(priv->key)); - priv->key_size = 32; /* 256bit */ - priv->failure = FALSE; -} - -static void -purple_aes_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - if ((len > 0 && iv == NULL) || - (len != 0 && len != sizeof(priv->iv))) { - purple_debug_error("cipher-aes", "invalid IV length\n"); - priv->failure = TRUE; - return; - } - - if (len == 0) - memset(priv->iv, 0, sizeof(priv->iv)); - else - memcpy(priv->iv, iv, len); - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_IV]); -} - -static void -purple_aes_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - if ((len > 0 && key == NULL) || - (len != 0 && len != 16 && len != 24 && len != 32)) { - purple_debug_error("cipher-aes", "invalid key length\n"); - priv->failure = TRUE; - return; - } - - priv->key_size = len; - memset(priv->key, 0, sizeof(priv->key)); - if (len > 0) - memcpy(priv->key, key, len); - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_KEY]); -} - -static guchar * -purple_aes_cipher_pad_pkcs7(const guchar input[], size_t in_len, size_t *out_len) -{ - int padding_len, total_len; - guchar *padded; - - g_return_val_if_fail(input != NULL, NULL); - g_return_val_if_fail(out_len != NULL, NULL); - - padding_len = PURPLE_AES_BLOCK_SIZE - (in_len % PURPLE_AES_BLOCK_SIZE); - total_len = in_len + padding_len; - g_assert((total_len % PURPLE_AES_BLOCK_SIZE) == 0); - - padded = g_new(guchar, total_len); - *out_len = total_len; - - memcpy(padded, input, in_len); - memset(padded + in_len, padding_len, padding_len); - - return padded; -} - -static ssize_t -purple_aes_cipher_unpad_pkcs7(guchar input[], size_t in_len) -{ - guchar padding_len, i; - size_t out_len; - - g_return_val_if_fail(input != NULL, -1); - g_return_val_if_fail(in_len > 0, -1); - - padding_len = input[in_len - 1]; - if (padding_len == 0 || padding_len > PURPLE_AES_BLOCK_SIZE || - padding_len > in_len) { - purple_debug_warning("cipher-aes", - "Invalid padding length: %d (total %" G_GSIZE_FORMAT ") - " - "most probably, the key was invalid\n", - padding_len, in_len); - return -1; - } - - out_len = in_len - padding_len; - for (i = 0; i < padding_len; i++) { - if (input[out_len + i] != padding_len) { - purple_debug_warning("cipher-aes", - "Padding doesn't match at pos %d (found %02x, " - "expected %02x) - " - "most probably, the key was invalid\n", - i, input[out_len + i], padding_len); - return -1; - } - } - - memset(input + out_len, 0, padding_len); - return out_len; -} - -#ifdef PURPLE_AES_USE_GNUTLS - -static gnutls_cipher_hd_t -purple_aes_cipher_gnutls_crypt_init(guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], - guint key_size) -{ - gnutls_cipher_hd_t handle; - gnutls_cipher_algorithm_t algorithm; - gnutls_datum_t key_info, iv_info; - int ret; - - if (key_size == 16) - algorithm = GNUTLS_CIPHER_AES_128_CBC; - else if (key_size == 24) - algorithm = GNUTLS_CIPHER_AES_192_CBC; - else if (key_size == 32) - algorithm = GNUTLS_CIPHER_AES_256_CBC; - else - g_return_val_if_reached(NULL); - - key_info.data = key; - key_info.size = key_size; - - iv_info.data = iv; - iv_info.size = PURPLE_AES_BLOCK_SIZE; - - ret = gnutls_cipher_init(&handle, algorithm, &key_info, &iv_info); - if (ret != 0) { - purple_debug_error("cipher-aes", - "gnutls_cipher_init failed: %d\n", ret); - return NULL; - } - - return handle; -} - -static gboolean -purple_aes_cipher_gnutls_encrypt(const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - PurpleCipherBatchMode batch_mode) -{ - gnutls_cipher_hd_t handle; - int ret; - - /* We have to simulate ECB mode, which is not supported by GnuTLS. */ - if (batch_mode == PURPLE_CIPHER_BATCH_MODE_ECB) { - size_t i; - for (i = 0; i < len / PURPLE_AES_BLOCK_SIZE; i++) { - int offset = i * PURPLE_AES_BLOCK_SIZE; - guchar iv_local[PURPLE_AES_BLOCK_SIZE]; - gboolean succ; - - memcpy(iv_local, iv, sizeof(iv_local)); - succ = purple_aes_cipher_gnutls_encrypt( - input + offset, output + offset, - PURPLE_AES_BLOCK_SIZE, - iv_local, key, key_size, - PURPLE_CIPHER_BATCH_MODE_CBC); - if (!succ) - return FALSE; - } - return TRUE; - } - - handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size); - if (handle == NULL) - return FALSE; - - ret = gnutls_cipher_encrypt2(handle, (guchar *)input, len, output, len); - gnutls_cipher_deinit(handle); - - if (ret != 0) { - purple_debug_error("cipher-aes", - "gnutls_cipher_encrypt2 failed: %d\n", ret); - return FALSE; - } - - return TRUE; -} - -static gboolean -purple_aes_cipher_gnutls_decrypt(const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - PurpleCipherBatchMode batch_mode) -{ - gnutls_cipher_hd_t handle; - int ret; - - /* We have to simulate ECB mode, which is not supported by GnuTLS. */ - if (batch_mode == PURPLE_CIPHER_BATCH_MODE_ECB) { - size_t i; - for (i = 0; i < len / PURPLE_AES_BLOCK_SIZE; i++) { - int offset = i * PURPLE_AES_BLOCK_SIZE; - guchar iv_local[PURPLE_AES_BLOCK_SIZE]; - gboolean succ; - - memcpy(iv_local, iv, sizeof(iv_local)); - succ = purple_aes_cipher_gnutls_decrypt( - input + offset, output + offset, - PURPLE_AES_BLOCK_SIZE, - iv_local, key, key_size, - PURPLE_CIPHER_BATCH_MODE_CBC); - if (!succ) - return FALSE; - } - return TRUE; - } - - handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size); - if (handle == NULL) - return FALSE; - - ret = gnutls_cipher_decrypt2(handle, input, len, output, len); - gnutls_cipher_deinit(handle); - - if (ret != 0) { - purple_debug_error("cipher-aes", - "gnutls_cipher_decrypt2 failed: %d\n", ret); - return FALSE; - } - - return TRUE; -} - -#elif defined(PURPLE_AES_USE_NSS) - -typedef struct { - PK11SlotInfo *slot; - PK11SymKey *sym_key; - SECItem *sec_param; - PK11Context *enc_context; -} PurpleAESCipherNSSContext; - -static void -purple_aes_cipher_nss_cleanup(PurpleAESCipherNSSContext *context) -{ - g_return_if_fail(context != NULL); - - if (context->enc_context != NULL) - PK11_DestroyContext(context->enc_context, TRUE); - if (context->sec_param != NULL) - SECITEM_FreeItem(context->sec_param, TRUE); - if (context->sym_key != NULL) - PK11_FreeSymKey(context->sym_key); - if (context->slot != NULL) - PK11_FreeSlot(context->slot); - - memset(context, 0, sizeof(PurpleAESCipherNSSContext)); -} - -static gboolean -purple_aes_cipher_nss_crypt(const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - CK_ATTRIBUTE_TYPE operation, CK_MECHANISM_TYPE cipher_mech) -{ - PurpleAESCipherNSSContext context; - SECItem key_item, iv_item; - SECStatus ret; - int outlen = 0; - unsigned int outlen_tmp = 0; - - memset(&context, 0, sizeof(PurpleAESCipherNSSContext)); - - if (NSS_NoDB_Init(NULL) != SECSuccess) { - purple_debug_error("cipher-aes", - "NSS_NoDB_Init failed: %d\n", PR_GetError()); - return FALSE; - } - - context.slot = PK11_GetBestSlot(cipher_mech, NULL); - if (context.slot == NULL) { - purple_debug_error("cipher-aes", - "PK11_GetBestSlot failed: %d\n", PR_GetError()); - return FALSE; - } - - key_item.type = siBuffer; - key_item.data = key; - key_item.len = key_size; - context.sym_key = PK11_ImportSymKey(context.slot, cipher_mech, - PK11_OriginUnwrap, CKA_ENCRYPT, &key_item, NULL); - if (context.sym_key == NULL) { - purple_debug_error("cipher-aes", - "PK11_ImportSymKey failed: %d\n", PR_GetError()); - purple_aes_cipher_nss_cleanup(&context); - return FALSE; - } - - iv_item.type = siBuffer; - iv_item.data = iv; - iv_item.len = PURPLE_AES_BLOCK_SIZE; - context.sec_param = PK11_ParamFromIV(cipher_mech, &iv_item); - if (context.sec_param == NULL) { - purple_debug_error("cipher-aes", - "PK11_ParamFromIV failed: %d\n", PR_GetError()); - purple_aes_cipher_nss_cleanup(&context); - return FALSE; - } - - context.enc_context = PK11_CreateContextBySymKey(cipher_mech, operation, - context.sym_key, context.sec_param); - if (context.enc_context == NULL) { - purple_debug_error("cipher-aes", - "PK11_CreateContextBySymKey failed: %d\n", - PR_GetError()); - purple_aes_cipher_nss_cleanup(&context); - return FALSE; - } - - ret = PK11_CipherOp(context.enc_context, output, &outlen, len, - (guchar *)input, len); - if (ret != SECSuccess) { - purple_debug_error("cipher-aes", - "PK11_CipherOp failed: %d\n", PR_GetError()); - purple_aes_cipher_nss_cleanup(&context); - return FALSE; - } - - ret = PK11_DigestFinal(context.enc_context, output + outlen, &outlen_tmp, - len - outlen); - if (ret != SECSuccess) { - purple_debug_error("cipher-aes", - "PK11_DigestFinal failed: %d\n", PR_GetError()); - purple_aes_cipher_nss_cleanup(&context); - return FALSE; - } - - purple_aes_cipher_nss_cleanup(&context); - - outlen += outlen_tmp; - if (outlen != (int)len) { - purple_debug_error("cipher-aes", - "resulting length doesn't match: %d (expected: %" - G_GSIZE_FORMAT ")\n", outlen, len); - return FALSE; - } - - return TRUE; -} - -static CK_MECHANISM_TYPE -purple_aes_cipher_nss_batch_mode(PurpleCipherBatchMode batch_mode) -{ - switch (batch_mode) { - case PURPLE_CIPHER_BATCH_MODE_CBC: - return CKM_AES_CBC; - case PURPLE_CIPHER_BATCH_MODE_ECB: - return CKM_AES_ECB; - } - - return CKM_AES_CBC; -} - -static gboolean -purple_aes_cipher_nss_encrypt(const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - PurpleCipherBatchMode batch_mode) -{ - return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size, - CKA_ENCRYPT, purple_aes_cipher_nss_batch_mode(batch_mode)); -} - -static gboolean -purple_aes_cipher_nss_decrypt(const guchar *input, guchar *output, size_t len, - guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, - PurpleCipherBatchMode batch_mode) -{ - return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size, - CKA_DECRYPT, purple_aes_cipher_nss_batch_mode(batch_mode)); -} - -#endif /* PURPLE_AES_USE_NSS */ - -static ssize_t -purple_aes_cipher_encrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - purple_aes_cipher_crypt_func encrypt_func; - guchar *input_padded; - size_t out_len = 0; - gboolean succ; - - if (priv->failure) - return -1; - - input_padded = purple_aes_cipher_pad_pkcs7(input, in_len, &out_len); - - if (out_len > out_size) { - purple_debug_error("cipher-aes", "Output buffer too small (%" - G_GSIZE_FORMAT " > %" G_GSIZE_FORMAT ")", - out_len, out_size); - memset(input_padded, 0, out_len); - g_free(input_padded); - return -1; - } - -#if defined(PURPLE_AES_USE_GNUTLS) - encrypt_func = purple_aes_cipher_gnutls_encrypt; -#elif defined(PURPLE_AES_USE_NSS) - encrypt_func = purple_aes_cipher_nss_encrypt; -#else - purple_debug_error("cipher-aes", "No matching encrypt_func\n"); - return -1; -#endif - - succ = encrypt_func(input_padded, output, out_len, priv->iv, - priv->key, priv->key_size, priv->batch_mode); - - memset(input_padded, 0, out_len); - g_free(input_padded); - - if (!succ) { - memset(output, 0, out_len); - return -1; - } - - return out_len; -} - -static ssize_t -purple_aes_cipher_decrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - purple_aes_cipher_crypt_func decrypt_func; - gboolean succ; - ssize_t out_len; - - if (priv->failure) - return -1; - - if (in_len > out_size) { - purple_debug_error("cipher-aes", "Output buffer too small\n"); - return -1; - } - - if ((in_len % PURPLE_AES_BLOCK_SIZE) != 0 || in_len == 0) { - purple_debug_error("cipher-aes", "Malformed data\n"); - return -1; - } - -#if defined(PURPLE_AES_USE_GNUTLS) - decrypt_func = purple_aes_cipher_gnutls_decrypt; -#elif defined(PURPLE_AES_USE_NSS) - decrypt_func = purple_aes_cipher_nss_decrypt; -#else - purple_debug_error("cipher-aes", "No matching decrypt_func\n"); - return -1; -#endif - - succ = decrypt_func(input, output, in_len, priv->iv, priv->key, - priv->key_size, priv->batch_mode); - - if (!succ) { - memset(output, 0, in_len); - return -1; - } - - out_len = purple_aes_cipher_unpad_pkcs7(output, in_len); - if (out_len < 0) { - memset(output, 0, in_len); - return -1; - } - - return out_len; -} - -static size_t -purple_aes_cipher_get_key_size(PurpleCipher *cipher) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - return priv->key_size; -} - -static void -purple_aes_cipher_set_batch_mode(PurpleCipher *cipher, - PurpleCipherBatchMode mode) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - if (mode != PURPLE_CIPHER_BATCH_MODE_CBC && - mode != PURPLE_CIPHER_BATCH_MODE_ECB) - { - purple_debug_error("cipher-aes", "unsupported batch mode\n"); - priv->failure = TRUE; - } - - priv->batch_mode = mode; - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_BATCH_MODE]); -} - -static PurpleCipherBatchMode -purple_aes_cipher_get_batch_mode(PurpleCipher *cipher) -{ - PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); - - return priv->batch_mode; -} - -static size_t -purple_aes_cipher_get_block_size(PurpleCipher *cipher) -{ - return PURPLE_AES_BLOCK_SIZE; -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_aes_cipher_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_BATCH_MODE: - g_value_set_enum(value, - purple_cipher_get_batch_mode(cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_aes_cipher_set_property(GObject *obj, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_BATCH_MODE: - purple_cipher_set_batch_mode(cipher, - g_value_get_enum(value)); - break; - case PROP_IV: - { - guchar *iv = (guchar *)g_value_get_string(value); - purple_cipher_set_iv(cipher, iv, strlen((gchar*)iv)); - } - break; - case PROP_KEY: - purple_cipher_set_key(cipher, (guchar *)g_value_get_string(value), - purple_aes_cipher_get_key_size(cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_aes_cipher_class_init(PurpleAESCipherClass *klass) { - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); - - obj_class->get_property = purple_aes_cipher_get_property; - obj_class->set_property = purple_aes_cipher_set_property; - - cipher_class->reset = purple_aes_cipher_reset; - cipher_class->set_iv = purple_aes_cipher_set_iv; - cipher_class->encrypt = purple_aes_cipher_encrypt; - cipher_class->decrypt = purple_aes_cipher_decrypt; - cipher_class->set_key = purple_aes_cipher_set_key; - cipher_class->get_key_size = purple_aes_cipher_get_key_size; - cipher_class->set_batch_mode = purple_aes_cipher_set_batch_mode; - cipher_class->get_batch_mode = purple_aes_cipher_get_batch_mode; - cipher_class->get_block_size = purple_aes_cipher_get_block_size; - - g_type_class_add_private(klass, sizeof(PurpleAESCipherPrivate)); - - properties[PROP_BATCH_MODE] = g_param_spec_enum("batch-mode", - "batch-mode", "batch-mode", PURPLE_TYPE_CIPHER_BATCH_MODE, - PURPLE_CIPHER_BATCH_MODE_CBC, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - - properties[PROP_IV] = g_param_spec_string("iv", "iv", "iv", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - properties[PROP_KEY] = g_param_spec_string("key", "key", "key", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(obj_class, PROP_LAST, properties); -} - -static void -purple_aes_cipher_init(PurpleCipher *cipher) { - purple_cipher_reset(cipher); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_aes_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleAESCipherClass), - NULL, - NULL, - (GClassInitFunc)purple_aes_cipher_class_init, - NULL, - NULL, - sizeof(PurpleAESCipher), - 0, - (GInstanceInitFunc)purple_aes_cipher_init, - NULL - }; - - type = g_type_register_static(PURPLE_TYPE_CIPHER, - "PurpleAESCipher", - &info, 0); - } - - return type; -} - -PurpleCipher * -purple_aes_cipher_new(void) { - return g_object_new(PURPLE_TYPE_AES_CIPHER, NULL); -} diff --git a/libpurple/ciphers/aescipher.h b/libpurple/ciphers/aescipher.h deleted file mode 100644 index 8982ffa702..0000000000 --- a/libpurple/ciphers/aescipher.h +++ /dev/null @@ -1,65 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_AES_CIPHER_H -#define PURPLE_AES_CIPHER_H -/** - * SECTION:aescipher - * @section_id: libpurple-aescipher - * @short_description: <filename>ciphers/aescipher.h</filename> - * @title: AES Cipher - */ - -#include "cipher.h" - -#define PURPLE_TYPE_AES_CIPHER (purple_aes_cipher_get_type()) -#define PURPLE_AES_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_AES_CIPHER, PurpleAESCipher)) -#define PURPLE_AES_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_AES_CIPHER, PurpleAESCipherClass)) -#define PURPLE_IS_AES_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_AES_CIPHER)) -#define PURPLE_IS_AES_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_AES_CIPHER)) -#define PURPLE_AES_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_AES_CIPHER, PurpleAESCipherClass)) - -typedef struct _PurpleAESCipher PurpleAESCipher; -typedef struct _PurpleAESCipherClass PurpleAESCipherClass; - -struct _PurpleAESCipher { - PurpleCipher gparent; -}; - -struct _PurpleAESCipherClass { - PurpleCipherClass gparent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_aes_cipher_get_type(void); - -PurpleCipher *purple_aes_cipher_new(void); - -G_END_DECLS - -#endif /* PURPLE_AES_CIPHER_H */ diff --git a/libpurple/ciphers/des3cipher.c b/libpurple/ciphers/des3cipher.c deleted file mode 100644 index deb0546e2c..0000000000 --- a/libpurple/ciphers/des3cipher.c +++ /dev/null @@ -1,524 +0,0 @@ -/* - * Original des taken from gpg - * - * des.c - Triple-DES encryption/decryption Algorithm - * Copyright (C) 1998 Free Software Foundation, Inc. - * - * Please see below for more legal information! - * - * According to the definition of DES in FIPS PUB 46-2 from December 1993. - * For a description of triple encryption, see: - * Bruce Schneier: Applied Cryptography. Second Edition. - * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#include "internal.h" -#include "glibcompat.h" - -#include "des3cipher.h" -#include "descipher.h" -#include "enums.h" - -#include <string.h> - -/****************************************************************************** - * Structs - *****************************************************************************/ - -#define PURPLE_DES3_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_DES3_CIPHER, PurpleDES3CipherPrivate)) - -typedef struct _PurpleDES3CipherPrivate PurpleDES3CipherPrivate; -struct _PurpleDES3CipherPrivate -{ - PurpleCipherBatchMode mode; - guchar iv[8]; - /* First key for encryption */ - PurpleCipher *key1; - /* Second key for decryption */ - PurpleCipher *key2; - /* Third key for encryption */ - PurpleCipher *key3; -}; - -/****************************************************************************** - * Enums - *****************************************************************************/ -enum { - PROP_NONE, - PROP_BATCH_MODE, - PROP_IV, - PROP_KEY, - PROP_LAST, -}; - -/****************************************************************************** - * Globals - *****************************************************************************/ -static GObjectClass *parent_class = NULL; -static GParamSpec *properties[PROP_LAST]; - -/****************************************************************************** - * Cipher Stuff - *****************************************************************************/ - -static size_t -purple_des3_cipher_get_key_size(PurpleCipher *cipher) -{ - return 24; -} - -/* - * Fill a DES3 context with subkeys calculated from 3 64bit key. - * Does not check parity bits, but simply ignore them. - * Does not check for weak keys. - **/ -static void -purple_des3_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_return_if_fail(len == 24); - - purple_cipher_set_key(PURPLE_CIPHER(priv->key1), key + 0, - purple_cipher_get_key_size(PURPLE_CIPHER(priv->key1))); - purple_cipher_set_key(PURPLE_CIPHER(priv->key2), key + 8, - purple_cipher_get_key_size(PURPLE_CIPHER(priv->key2))); - purple_cipher_set_key(PURPLE_CIPHER(priv->key3), key + 16, - purple_cipher_get_key_size(PURPLE_CIPHER(priv->key3))); - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_KEY]); -} - -static ssize_t -purple_des3_cipher_ecb_encrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8] = {0,0,0,0,0,0,0,0}; - gsize out_len; - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_return_val_if_fail(out_size >= in_len, -1); - - while (offset + 8 <= in_len) { - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - input + offset, output + offset, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 0); - - offset += 8; - } - - out_len = in_len; - if (offset < in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - memset(buf, 0, 8); - while (tmp < in_len) { - buf[i++] = input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 0); - } - - return out_len; -} - -static ssize_t -purple_des3_cipher_cbc_encrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8]; - gsize out_len; - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - memcpy(buf, priv->iv, 8); - - g_return_val_if_fail(out_size >= in_len, -1); - - while (offset + 8 <= in_len) { - for (i = 0; i < 8; i++) - buf[i] ^= input[offset + i]; - - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 0); - - memcpy(buf, output+offset, 8); - offset += 8; - } - - out_len = in_len; - if (offset < in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - i = 0; - while (tmp < in_len) { - buf[i++] ^= input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 0); - } - - return out_len; -} - -static ssize_t -purple_des3_cipher_encrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - if (priv->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { - return purple_des3_cipher_ecb_encrypt(des3_cipher, input, in_len, output, out_size); - } else if (priv->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { - return purple_des3_cipher_cbc_encrypt(des3_cipher, input, in_len, output, out_size); - } else { - g_return_val_if_reached(0); - } - - return 0; -} - -static ssize_t -purple_des3_cipher_ecb_decrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8] = {0,0,0,0,0,0,0,0}; - gsize out_len; - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_return_val_if_fail(out_size >= in_len, -1); - - while (offset + 8 <= in_len) { - /* NOTE: Apply key in reverse */ - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - input + offset, output + offset, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 1); - - offset += 8; - } - - out_len = in_len; - if (offset < in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - memset(buf, 0, 8); - while (tmp < in_len) { - buf[i++] = input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 1); - } - - return out_len; -} - -static ssize_t -purple_des3_cipher_cbc_decrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8] = {0,0,0,0,0,0,0,0}; - guint8 link[8]; - gsize out_len; - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_return_val_if_fail(out_size >= in_len, -1); - - memcpy(link, priv->iv, 8); - while (offset + 8 <= in_len) { - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - input + offset, output + offset, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 1); - - for (i = 0; i < 8; i++) - output[offset + i] ^= link[i]; - - memcpy(link, input + offset, 8); - - offset+=8; - } - - out_len = in_len; - if(offset<in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - memset(buf, 0, 8); - i = 0; - while(tmp<in_len) { - buf[i++] = input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), - buf, output + offset, 1); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), - output + offset, buf, 0); - purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), - buf, output + offset, 1); - - for (i = 0; i < 8; i++) - output[offset + i] ^= link[i]; - } - - return out_len; -} - -static ssize_t -purple_des3_cipher_decrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(cipher); - - if (priv->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { - return purple_des3_cipher_ecb_decrypt(des3_cipher, input, in_len, output, out_size); - } else if (priv->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { - return purple_des3_cipher_cbc_decrypt(des3_cipher, input, in_len, output, out_size); - } else { - g_return_val_if_reached(0); - } - - return 0; -} - -static void -purple_des3_cipher_set_batch_mode(PurpleCipher *cipher, PurpleCipherBatchMode mode) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - priv->mode = mode; - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_BATCH_MODE]); -} - -static PurpleCipherBatchMode -purple_des3_cipher_get_batch_mode(PurpleCipher *cipher) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - return priv->mode; -} - -static void -purple_des3_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_return_if_fail(len == 8); - - memcpy(priv->iv, iv, len); - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_IV]); -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_des3_cipher_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_BATCH_MODE: - g_value_set_enum(value, - purple_cipher_get_batch_mode(cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_des3_cipher_set_property(GObject *obj, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_BATCH_MODE: - purple_cipher_set_batch_mode(cipher, - g_value_get_enum(value)); - break; - case PROP_IV: - { - guchar *iv = (guchar *)g_value_get_string(value); - purple_cipher_set_iv(cipher, iv, strlen((gchar*)iv)); - } - break; - case PROP_KEY: - purple_cipher_set_key(cipher, (guchar *)g_value_get_string(value), - purple_des3_cipher_get_key_size(cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_des3_cipher_finalize(GObject *obj) -{ - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(obj); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - g_object_unref(G_OBJECT(priv->key1)); - g_object_unref(G_OBJECT(priv->key2)); - g_object_unref(G_OBJECT(priv->key3)); - - memset(priv->iv, 0, sizeof(priv->iv)); - - parent_class->finalize(obj); -} - -static void -purple_des3_cipher_class_init(PurpleDES3CipherClass *klass) { - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->finalize = purple_des3_cipher_finalize; - obj_class->get_property = purple_des3_cipher_get_property; - obj_class->set_property = purple_des3_cipher_set_property; - - cipher_class->set_iv = purple_des3_cipher_set_iv; - cipher_class->encrypt = purple_des3_cipher_encrypt; - cipher_class->decrypt = purple_des3_cipher_decrypt; - cipher_class->set_key = purple_des3_cipher_set_key; - cipher_class->set_batch_mode = purple_des3_cipher_set_batch_mode; - cipher_class->get_batch_mode = purple_des3_cipher_get_batch_mode; - cipher_class->get_key_size = purple_des3_cipher_get_key_size; - - g_type_class_add_private(klass, sizeof(PurpleDES3CipherPrivate)); - - properties[PROP_BATCH_MODE] = g_param_spec_enum("batch-mode", "batch-mode", - "batch-mode", PURPLE_TYPE_CIPHER_BATCH_MODE, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - properties[PROP_IV] = g_param_spec_string("iv", "iv", "iv", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - properties[PROP_KEY] = g_param_spec_string("key", "key", "key", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(obj_class, PROP_LAST, properties); -} - -static void -purple_des3_cipher_init(PurpleCipher *cipher) { - PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); - PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); - - priv->key1 = purple_des_cipher_new(); - priv->key2 = purple_des_cipher_new(); - priv->key3 = purple_des_cipher_new(); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_des3_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleDES3CipherClass), - NULL, - NULL, - (GClassInitFunc)purple_des3_cipher_class_init, - NULL, - NULL, - sizeof(PurpleDES3Cipher), - 0, - (GInstanceInitFunc)purple_des3_cipher_init, - NULL - }; - - type = g_type_register_static(PURPLE_TYPE_CIPHER, - "PurpleDES3Cipher", - &info, 0); - } - - return type; -} - -PurpleCipher * -purple_des3_cipher_new(void) { - return g_object_new(PURPLE_TYPE_DES3_CIPHER, NULL); -} diff --git a/libpurple/ciphers/des3cipher.h b/libpurple/ciphers/des3cipher.h deleted file mode 100644 index 788b684cd2..0000000000 --- a/libpurple/ciphers/des3cipher.h +++ /dev/null @@ -1,66 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_DES3_CIPHER_H -#define PURPLE_DES3_CIPHER_H -/** - * SECTION:des3cipher - * @section_id: libpurple-des3cipher - * @short_description: <filename>ciphers/des3cipher.h</filename> - * @title: Triple-DES Cipher - */ - -#include "cipher.h" - -#define PURPLE_TYPE_DES3_CIPHER (purple_des3_cipher_get_type()) -#define PURPLE_DES3_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_DES3_CIPHER, PurpleDES3Cipher)) -#define PURPLE_DES3_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_DES3_CIPHER, PurpleDES3CipherClass)) -#define PURPLE_IS_DES3_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_DES3_CIPHER)) -#define PURPLE_IS_DES3_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_DES3_CIPHER)) -#define PURPLE_DES3_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_DES3_CIPHER, PurpleDES3CipherClass)) - -typedef struct _PurpleDES3Cipher PurpleDES3Cipher; -typedef struct _PurpleDES3CipherClass PurpleDES3CipherClass; - -struct _PurpleDES3Cipher { - PurpleCipher gparent; -}; - -struct _PurpleDES3CipherClass { - PurpleCipherClass gparent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_des3_cipher_get_type(void); - -PurpleCipher *purple_des3_cipher_new(void); - -G_END_DECLS - -#endif /* PURPLE_DES3_CIPHER_H */ - diff --git a/libpurple/ciphers/descipher.c b/libpurple/ciphers/descipher.c deleted file mode 100644 index 82b10e0886..0000000000 --- a/libpurple/ciphers/descipher.c +++ /dev/null @@ -1,581 +0,0 @@ -/* - * Original des taken from gpg - * - * des.c - DES encryption/decryption Algorithm - * Copyright (C) 1998 Free Software Foundation, Inc. - * - * Please see below for more legal information! - * - * According to the definition of DES in FIPS PUB 46-2 from December 1993. - * For a description of triple encryption, see: - * Bruce Schneier: Applied Cryptography. Second Edition. - * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#include "internal.h" -#include "glibcompat.h" - -#include "descipher.h" -#include "enums.h" - -#include <string.h> - -/****************************************************************************** - * Structs - *****************************************************************************/ -#define PURPLE_DES_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_DES_CIPHER, PurpleDESCipherPrivate)) - -typedef struct { - guint32 encrypt_subkeys[32]; - guint32 decrypt_subkeys[32]; -} PurpleDESCipherPrivate; - -/****************************************************************************** - * Enums - *****************************************************************************/ -enum { - PROP_NONE, - PROP_KEY, - PROP_LAST, -}; - -/****************************************************************************** - * Globals - *****************************************************************************/ -static GObjectClass *parent_class = NULL; -static GParamSpec *properties[PROP_LAST]; - -/* - * The s-box values are permuted according to the 'primitive function P' - */ -static guint32 sbox1[64] = { - 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, - 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200, - 0x00800202, 0x00808002, 0x00800000, 0x00000002, 0x00000202, 0x00800200, - 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, - 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, - 0x00008202, 0x00800000, 0x00008000, 0x00808202, 0x00000002, 0x00808000, - 0x00808200, 0x00800000, 0x00800000, 0x00000200, 0x00808002, 0x00008000, - 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, - 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, - 0x00008202, 0x00808200, 0x00000202, 0x00800200, 0x00800200, 0x00000000, - 0x00008002, 0x00008200, 0x00000000, 0x00808002 -}; - -static guint32 sbox2[64] = { - 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, - 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, - 0x40004000, 0x00080000, 0x00000010, 0x40080010, 0x00084000, 0x00080010, - 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, - 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, - 0x40080000, 0x00004010, 0x00000000, 0x00084010, 0x40080010, 0x00080000, - 0x40004010, 0x40080000, 0x40084000, 0x00004000, 0x40080000, 0x40004000, - 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, - 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, - 0x40000010, 0x00080010, 0x00084000, 0x00000000, 0x40004000, 0x00004010, - 0x40000000, 0x40080010, 0x40084010, 0x00084000 -}; - -static guint32 sbox3[64] = { - 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, - 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000, - 0x04010104, 0x00010004, 0x04010000, 0x00000104, 0x04000000, 0x00000004, - 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, - 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, - 0x00000100, 0x04000000, 0x04010100, 0x04000000, 0x00010004, 0x00000104, - 0x00010000, 0x04010100, 0x04000100, 0x00000000, 0x00000100, 0x00010004, - 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, - 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, - 0x00010100, 0x04000004, 0x04010000, 0x04000104, 0x00000104, 0x04010000, - 0x00010104, 0x00000004, 0x04010004, 0x00010100 -}; - -static guint32 sbox4[64] = { - 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, - 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040, - 0x80000040, 0x00000000, 0x00400040, 0x80400000, 0x80000000, 0x00001000, - 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, - 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, - 0x80401040, 0x80000040, 0x00400040, 0x80400000, 0x00401000, 0x80401040, - 0x80000040, 0x00000000, 0x00000000, 0x00401000, 0x00001040, 0x00400040, - 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, - 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, - 0x00401040, 0x80400040, 0x80001000, 0x00001040, 0x00400000, 0x80401000, - 0x00000040, 0x00400000, 0x00001000, 0x00401040 -}; - -static guint32 sbox5[64] = { - 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, - 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080, - 0x21000080, 0x21040000, 0x00040080, 0x20000000, 0x01000000, 0x20040000, - 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, - 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, - 0x21000000, 0x00040080, 0x00040000, 0x21000080, 0x00000080, 0x01000000, - 0x20000000, 0x01040000, 0x21000080, 0x20040080, 0x01000080, 0x20000000, - 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, - 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, - 0x20040000, 0x21000000, 0x00040080, 0x01000080, 0x20000080, 0x00040000, - 0x00000000, 0x20040000, 0x01040080, 0x20000080 -}; - -static guint32 sbox6[64] = { - 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, - 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008, - 0x00200008, 0x10002000, 0x10000000, 0x00002008, 0x00000000, 0x00200008, - 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, - 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, - 0x10202000, 0x10000000, 0x10002000, 0x00000008, 0x10200008, 0x00202000, - 0x10202008, 0x00200000, 0x00002008, 0x10000008, 0x00200000, 0x10002000, - 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, - 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, - 0x10200000, 0x00202008, 0x00002000, 0x00200008, 0x10002008, 0x00000000, - 0x10202000, 0x10000000, 0x00200008, 0x10002008 -}; - -static guint32 sbox7[64] = { - 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, - 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001, - 0x00000001, 0x02000000, 0x02100001, 0x00000401, 0x02000400, 0x00100401, - 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, - 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, - 0x02000000, 0x00100400, 0x02000000, 0x00100400, 0x00100000, 0x02000401, - 0x02000401, 0x02100001, 0x02100001, 0x00000001, 0x00100001, 0x02000000, - 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, - 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, - 0x00000001, 0x02100401, 0x00000000, 0x00100401, 0x02100000, 0x00000400, - 0x02000001, 0x02000400, 0x00000400, 0x00100001 -}; - -static guint32 sbox8[64] = { - 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, - 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800, - 0x08020800, 0x00020820, 0x00000800, 0x00000020, 0x08020000, 0x08000020, - 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, - 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, - 0x00020820, 0x00020000, 0x00020820, 0x00020000, 0x08020800, 0x00000800, - 0x00000020, 0x08020020, 0x00000800, 0x00020820, 0x08000800, 0x00000020, - 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, - 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, - 0x08000820, 0x00000000, 0x08020820, 0x00020800, 0x00020800, 0x00000820, - 0x00000820, 0x00020020, 0x08000000, 0x08020800 -}; - -/* - * These two tables are part of the 'permuted choice 1' function. - * In this implementation several speed improvements are done. - */ -static guint32 leftkey_swap[16] = { - 0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, - 0x00010100, 0x00010101, 0x01000000, 0x01000001, 0x01000100, 0x01000101, - 0x01010000, 0x01010001, 0x01010100, 0x01010101 -}; - -static guint32 rightkey_swap[16] = { - 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, - 0x00010100, 0x01010100, 0x00000001, 0x01000001, 0x00010001, 0x01010001, - 0x00000101, 0x01000101, 0x00010101, 0x01010101, -}; - -/* - * Numbers of left shifts per round for encryption subkey schedule - * To calculate the decryption key scheduling we just reverse the - * ordering of the subkeys so we can omit the table for decryption - * subkey schedule. - */ -static guint8 encrypt_rotate_tab[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - - -/****************************************************************************** - * Helpers - *****************************************************************************/ -/* - * Macro to swap bits across two words - */ -#define DO_PERMUTATION(a, temp, b, offset, mask) \ - temp = ((a>>offset) ^ b) & mask; \ - b ^= temp; \ - a ^= temp<<offset; - -/* - * This performs the 'initial permutation' for the data to be encrypted or - * decrypted - */ -#define INITIAL_PERMUTATION(left, temp, right) \ - DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \ - DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ - DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ - DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ - DO_PERMUTATION(left, temp, right, 1, 0x55555555) - -/* - * The 'inverse initial permutation' - */ -#define FINAL_PERMUTATION(left, temp, right) \ - DO_PERMUTATION(left, temp, right, 1, 0x55555555) \ - DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ - DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ - DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ - DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) - -/* - * A full DES round including 'expansion function', 'sbox substitution' - * and 'primitive function P' but without swapping the left and right word. - */ -#define DES_ROUND(from, to, work, subkey) \ - work = ((from<<1) | (from>>31)) ^ *subkey++; \ - to ^= sbox8[ work & 0x3f ]; \ - to ^= sbox6[ (work>>8) & 0x3f ]; \ - to ^= sbox4[ (work>>16) & 0x3f ]; \ - to ^= sbox2[ (work>>24) & 0x3f ]; \ - work = ((from>>3) | (from<<29)) ^ *subkey++; \ - to ^= sbox7[ work & 0x3f ]; \ - to ^= sbox5[ (work>>8) & 0x3f ]; \ - to ^= sbox3[ (work>>16) & 0x3f ]; \ - to ^= sbox1[ (work>>24) & 0x3f ]; - - -/* - * Macros to convert 8 bytes from/to 32bit words - */ -#define READ_64BIT_DATA(data, left, right) \ - left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \ - right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]; - -#define WRITE_64BIT_DATA(data, left, right) \ - data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \ - data[2] = (left >> 8) &0xff; data[3] = left &0xff; \ - data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \ - data[6] = (right >> 8) &0xff; data[7] = right &0xff; - -/****************************************************************************** - * Cipher Stuff - *****************************************************************************/ -/* - * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for - * 16 encryption rounds. - * To calculate subkeys for decryption the caller - * have to reorder the generated subkeys. - * - * rawkey: 8 Bytes of key data - * subkey: Array of at least 32 guint32s. Will be filled - * with calculated subkeys. - * - */ -static void -purple_des_cipher_key_schedule(const guint8 * rawkey, guint32 * subkey) { - guint32 left, right, work; - int round; - - READ_64BIT_DATA (rawkey, left, right) - - DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f) - DO_PERMUTATION (right, work, left, 0, 0x10101010) - - left = (leftkey_swap[(left >> 0) & 0xf] << 3) - | (leftkey_swap[(left >> 8) & 0xf] << 2) - | (leftkey_swap[(left >> 16) & 0xf] << 1) - | (leftkey_swap[(left >> 24) & 0xf] ) - | (leftkey_swap[(left >> 5) & 0xf] << 7) - | (leftkey_swap[(left >> 13) & 0xf] << 6) - | (leftkey_swap[(left >> 21) & 0xf] << 5) - | (leftkey_swap[(left >> 29) & 0xf] << 4); - - left &= 0x0fffffff; - - right = (rightkey_swap[(right >> 1) & 0xf] << 3) - | (rightkey_swap[(right >> 9) & 0xf] << 2) - | (rightkey_swap[(right >> 17) & 0xf] << 1) - | (rightkey_swap[(right >> 25) & 0xf] ) - | (rightkey_swap[(right >> 4) & 0xf] << 7) - | (rightkey_swap[(right >> 12) & 0xf] << 6) - | (rightkey_swap[(right >> 20) & 0xf] << 5) - | (rightkey_swap[(right >> 28) & 0xf] << 4); - - right &= 0x0fffffff; - - for (round = 0; round < 16; ++round) { - left = ((left << encrypt_rotate_tab[round]) | - (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; - right = ((right << encrypt_rotate_tab[round]) | - (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; - - *subkey++ = ((left << 4) & 0x24000000) - | ((left << 28) & 0x10000000) - | ((left << 14) & 0x08000000) - | ((left << 18) & 0x02080000) - | ((left << 6) & 0x01000000) - | ((left << 9) & 0x00200000) - | ((left >> 1) & 0x00100000) - | ((left << 10) & 0x00040000) - | ((left << 2) & 0x00020000) - | ((left >> 10) & 0x00010000) - | ((right >> 13) & 0x00002000) - | ((right >> 4) & 0x00001000) - | ((right << 6) & 0x00000800) - | ((right >> 1) & 0x00000400) - | ((right >> 14) & 0x00000200) - | (right & 0x00000100) - | ((right >> 5) & 0x00000020) - | ((right >> 10) & 0x00000010) - | ((right >> 3) & 0x00000008) - | ((right >> 18) & 0x00000004) - | ((right >> 26) & 0x00000002) - | ((right >> 24) & 0x00000001); - - *subkey++ = ((left << 15) & 0x20000000) - | ((left << 17) & 0x10000000) - | ((left << 10) & 0x08000000) - | ((left << 22) & 0x04000000) - | ((left >> 2) & 0x02000000) - | ((left << 1) & 0x01000000) - | ((left << 16) & 0x00200000) - | ((left << 11) & 0x00100000) - | ((left << 3) & 0x00080000) - | ((left >> 6) & 0x00040000) - | ((left << 15) & 0x00020000) - | ((left >> 4) & 0x00010000) - | ((right >> 2) & 0x00002000) - | ((right << 8) & 0x00001000) - | ((right >> 14) & 0x00000808) - | ((right >> 9) & 0x00000400) - | ((right) & 0x00000200) - | ((right << 7) & 0x00000100) - | ((right >> 7) & 0x00000020) - | ((right >> 3) & 0x00000011) - | ((right << 2) & 0x00000004) - | ((right >> 21) & 0x00000002); - } -} - -/* - * Fill a DES context with subkeys calculated from a 64bit key. - * Does not check parity bits, but simply ignore them. - * Does not check for weak keys. - */ -static void -purple_des_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) { - PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); - PurpleDESCipherPrivate *priv = PURPLE_DES_CIPHER_GET_PRIVATE(des_cipher); - int i; - - g_return_if_fail(len == 8); - - purple_des_cipher_key_schedule(key, priv->encrypt_subkeys); - - for(i = 0; i < 32; i += 2) { - priv->decrypt_subkeys[i] = priv->encrypt_subkeys[30 - i]; - priv->decrypt_subkeys[i + 1] = priv->encrypt_subkeys[31 - i]; - } - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_KEY]); -} - -static size_t -purple_des_cipher_get_key_size(PurpleCipher *cipher) -{ - return 8; -} - -/* - * Electronic Codebook Mode DES encryption/decryption of data according to - * 'mode'. - */ -int -purple_des_cipher_ecb_crypt(PurpleDESCipher *des_cipher, const guint8 * from, guint8 * to, - int mode) -{ - guint32 left, right, work; - guint32 *keys; - PurpleDESCipherPrivate *priv = PURPLE_DES_CIPHER_GET_PRIVATE(des_cipher); - - keys = mode ? priv->decrypt_subkeys : - priv->encrypt_subkeys; - - READ_64BIT_DATA (from, left, right) - INITIAL_PERMUTATION (left, work, right) - - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) - - FINAL_PERMUTATION (right, work, left) - WRITE_64BIT_DATA (to, right, left) - - return 0; -} - -static ssize_t -purple_des_cipher_encrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); - - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8] = {0,0,0,0,0,0,0,0}; - gsize out_len; - - g_return_val_if_fail(out_size >= in_len, -1); - - while(offset + 8 <= in_len) { - purple_des_cipher_ecb_crypt(des_cipher, input + offset, output + offset, 0); - offset += 8; - } - - out_len = in_len; - - if(offset<in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - while(tmp<in_len) { - buf[i++] = input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(des_cipher, buf, output + offset, 0); - } - - return out_len; -} - -static ssize_t -purple_des_cipher_decrypt(PurpleCipher *cipher, const guchar input[], - size_t in_len, guchar output[], size_t out_size) -{ - PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); - - gsize offset = 0; - int i = 0; - gsize tmp; - guint8 buf[8] = {0,0,0,0,0,0,0,0}; - gsize out_len; - - g_return_val_if_fail(out_size >= in_len, -1); - - while(offset + 8 <= in_len) { - purple_des_cipher_ecb_crypt(des_cipher, input + offset, output + offset, 1); - offset += 8; - } - - out_len = in_len; - if(offset<in_len) { - g_return_val_if_fail(in_len >= offset, -1); - out_len += in_len - offset; - g_return_val_if_fail(out_size >= out_len, -1); - tmp = offset; - while(tmp<in_len) { - buf[i++] = input[tmp]; - tmp++; - } - - purple_des_cipher_ecb_crypt(des_cipher, buf, output + offset, 1); - } - - return out_len; -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_des_cipher_set_property(GObject *obj, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_KEY: - purple_cipher_set_key(cipher, (guchar *)g_value_get_string(value), - purple_des_cipher_get_key_size(cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_des_cipher_class_init(PurpleDESCipherClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->set_property = purple_des_cipher_set_property; - - cipher_class->encrypt = purple_des_cipher_encrypt; - cipher_class->decrypt = purple_des_cipher_decrypt; - cipher_class->set_key = purple_des_cipher_set_key; - cipher_class->get_key_size = purple_des_cipher_get_key_size; - - g_type_class_add_private(klass, sizeof(PurpleDESCipherPrivate)); - - properties[PROP_KEY] = g_param_spec_string("key", "key", "key", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(obj_class, PROP_LAST, properties); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_des_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - .class_size = sizeof(PurpleDESCipherClass), - .class_init = (GClassInitFunc)purple_des_cipher_class_init, - .instance_size = sizeof(PurpleDESCipher), - .instance_init = (GInstanceInitFunc)purple_cipher_reset, - }; - - type = g_type_register_static(PURPLE_TYPE_CIPHER, - "PurpleDESCipher", - &info, 0); - } - - return type; -} - -/** - * purple_des_cipher_new: - * - * Creates a new #PurpleCipher instance which implements the DES block cipher. - * - * Return Value: The new DES implementation of #PurpleCipher. - */ -PurpleCipher * -purple_des_cipher_new(void) { - return g_object_new(PURPLE_TYPE_DES_CIPHER, NULL); -} diff --git a/libpurple/ciphers/descipher.h b/libpurple/ciphers/descipher.h deleted file mode 100644 index d01ee60e72..0000000000 --- a/libpurple/ciphers/descipher.h +++ /dev/null @@ -1,67 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PURPLE_DES_CIPHER_H -#define PURPLE_DES_CIPHER_H -/** - * SECTION:descipher - * @section_id: libpurple-descipher - * @short_description: <filename>ciphers/descipher.h</filename> - * @title: DES Cipher - */ - -#include "cipher.h" - -#define PURPLE_TYPE_DES_CIPHER (purple_des_cipher_get_type()) -#define PURPLE_DES_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_DES_CIPHER, PurpleDESCipher)) -#define PURPLE_DES_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_DES_CIPHER, PurpleDESCipherClass)) -#define PURPLE_IS_DES_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_DES_CIPHER)) -#define PURPLE_IS_DES_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_DES_CIPHER)) -#define PURPLE_DES_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_DES_CIPHER, PurpleDESCipherClass)) - -typedef struct _PurpleDESCipher PurpleDESCipher; -typedef struct _PurpleDESCipherClass PurpleDESCipherClass; - -struct _PurpleDESCipher { - PurpleCipher gparent; -}; - -struct _PurpleDESCipherClass { - PurpleCipherClass gparent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_des_cipher_get_type(void); - -PurpleCipher *purple_des_cipher_new(void); - -int purple_des_cipher_ecb_crypt(PurpleDESCipher *des_cipher, const guint8 * from, guint8 * to, int mode); - -G_END_DECLS - -#endif /* PURPLE_DES_CIPHER_H */ diff --git a/libpurple/ciphers/md4hash.c b/libpurple/ciphers/md4hash.c deleted file mode 100644 index fca7b1b256..0000000000 --- a/libpurple/ciphers/md4hash.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Original md4 taken from linux kernel - * MD4 Message Digest Algorithm (RFC1320). - * - * Implementation derived from Andrew Tridgell and Steve French's - * CIFS MD4 implementation, and the cryptoapi implementation - * originally based on the public domain implementation written - * by Colin Plumb in 1993. - * - * Copyright (c) Andrew Tridgell 1997-1998. - * Modified by Steve French (sfrench@us.ibm.com) 2002 - * Copyright (c) Cryptoapi developers. - * Copyright (c) 2002 David S. Miller (davem@redhat.com) - * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> - */ -#include "internal.h" -#include "md4hash.h" - -#include <string.h> - -#define MD4_DIGEST_SIZE 16 -#define MD4_BLOCK_WORDS 16 -#define MD4_HASH_WORDS 4 - -#define PURPLE_MD4_HASH_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4HashPrivate)) - -/****************************************************************************** - * Structs - *****************************************************************************/ -typedef struct { - guint32 hash[MD4_HASH_WORDS]; - guint32 block[MD4_BLOCK_WORDS]; - guint64 byte_count; -} PurpleMD4HashPrivate; - -/****************************************************************************** - * Globals - *****************************************************************************/ -static GObjectClass *parent_class = NULL; - -/****************************************************************************** - * Helpers - *****************************************************************************/ -#define ROUND1(a,b,c,d,k,s) \ - (a = lshift(a + F(b,c,d) + k, s)) - -#define ROUND2(a,b,c,d,k,s) \ - (a = lshift(a + G(b,c,d) + k + (guint32)0x5a827999,s)) - -#define ROUND3(a,b,c,d,k,s) \ - (a = lshift(a + H(b,c,d) + k + (guint32)0x6ed9eba1,s)) - -static inline guint32 -lshift(guint32 x, unsigned int s) { - x &= 0xffffffff; - return (((x << s) & 0xffffffff) | (x >> (32 - s))); -} - -static inline guint32 -F(guint32 x, guint32 y, guint32 z) { - return ((x & y) | ((~x) & z)); -} - -static inline guint32 -G(guint32 x, guint32 y, guint32 z) { - return ((x & y) | (x & z) | (y & z)); -} - -static inline guint32 -H(guint32 x, guint32 y, guint32 z) { - return (x ^ y ^ z); -} - -static inline void -le32_to_cpu_array(guint32 *buf, unsigned int words) { - while(words--) { - *buf = GUINT_FROM_LE(*buf); - buf++; - } -} - -static inline void -cpu_to_le32_array(guint32 *buf, unsigned int words) { - while(words--) { - *buf = GUINT_TO_LE(*buf); - buf++; - } -} - -static void -md4_transform(guint32 *hash, guint32 const *in) { - guint32 a, b, c, d; - - a = hash[0]; - b = hash[1]; - c = hash[2]; - d = hash[3]; - - ROUND1(a, b, c, d, in[0], 3); - ROUND1(d, a, b, c, in[1], 7); - ROUND1(c, d, a, b, in[2], 11); - ROUND1(b, c, d, a, in[3], 19); - ROUND1(a, b, c, d, in[4], 3); - ROUND1(d, a, b, c, in[5], 7); - ROUND1(c, d, a, b, in[6], 11); - ROUND1(b, c, d, a, in[7], 19); - ROUND1(a, b, c, d, in[8], 3); - ROUND1(d, a, b, c, in[9], 7); - ROUND1(c, d, a, b, in[10], 11); - ROUND1(b, c, d, a, in[11], 19); - ROUND1(a, b, c, d, in[12], 3); - ROUND1(d, a, b, c, in[13], 7); - ROUND1(c, d, a, b, in[14], 11); - ROUND1(b, c, d, a, in[15], 19); - - ROUND2(a, b, c, d,in[ 0], 3); - ROUND2(d, a, b, c, in[4], 5); - ROUND2(c, d, a, b, in[8], 9); - ROUND2(b, c, d, a, in[12], 13); - ROUND2(a, b, c, d, in[1], 3); - ROUND2(d, a, b, c, in[5], 5); - ROUND2(c, d, a, b, in[9], 9); - ROUND2(b, c, d, a, in[13], 13); - ROUND2(a, b, c, d, in[2], 3); - ROUND2(d, a, b, c, in[6], 5); - ROUND2(c, d, a, b, in[10], 9); - ROUND2(b, c, d, a, in[14], 13); - ROUND2(a, b, c, d, in[3], 3); - ROUND2(d, a, b, c, in[7], 5); - ROUND2(c, d, a, b, in[11], 9); - ROUND2(b, c, d, a, in[15], 13); - - ROUND3(a, b, c, d,in[ 0], 3); - ROUND3(d, a, b, c, in[8], 9); - ROUND3(c, d, a, b, in[4], 11); - ROUND3(b, c, d, a, in[12], 15); - ROUND3(a, b, c, d, in[2], 3); - ROUND3(d, a, b, c, in[10], 9); - ROUND3(c, d, a, b, in[6], 11); - ROUND3(b, c, d, a, in[14], 15); - ROUND3(a, b, c, d, in[1], 3); - ROUND3(d, a, b, c, in[9], 9); - ROUND3(c, d, a, b, in[5], 11); - ROUND3(b, c, d, a, in[13], 15); - ROUND3(a, b, c, d, in[3], 3); - ROUND3(d, a, b, c, in[11], 9); - ROUND3(c, d, a, b, in[7], 11); - ROUND3(b, c, d, a, in[15], 15); - - hash[0] += a; - hash[1] += b; - hash[2] += c; - hash[3] += d; -} - -static inline void -md4_transform_helper(PurpleHash *hash) { - PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash); - - le32_to_cpu_array(priv->block, sizeof(priv->block) / sizeof(guint32)); - md4_transform(priv->hash, priv->block); -} - -/****************************************************************************** - * Hash Stuff - *****************************************************************************/ -static void -purple_md4_hash_reset(PurpleHash *hash) { - PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash); - - priv->hash[0] = 0x67452301; - priv->hash[1] = 0xefcdab89; - priv->hash[2] = 0x98badcfe; - priv->hash[3] = 0x10325476; - - priv->byte_count = 0; - - memset(priv->block, 0, sizeof(priv->block)); -} - -static void -purple_md4_hash_append(PurpleHash *hash, const guchar *data, size_t len) { - PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash); - const guint32 avail = sizeof(priv->block) - (priv->byte_count & 0x3f); - - priv->byte_count += len; - - if(avail > len) { - memcpy((char *)priv->block + - (sizeof(priv->block) - avail), - data, len); - return; - } - - memcpy((char *)priv->block + - (sizeof(priv->block) - avail), - data, avail); - - md4_transform_helper(hash); - data += avail; - len -= avail; - - while(len >= sizeof(priv->block)) { - memcpy(priv->block, data, sizeof(priv->block)); - md4_transform_helper(hash); - data += sizeof(priv->block); - len -= sizeof(priv->block); - } - - memcpy(priv->block, data, len); -} - -static gboolean -purple_md4_hash_digest(PurpleHash *hash, guchar *out, size_t len) -{ - PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash); - const unsigned int offset = priv->byte_count & 0x3f; - gchar *p = (gchar *)priv->block + offset; - gint padding = 56 - (offset + 1); - - if(len < 16) - return FALSE; - - *p++ = 0x80; - - if(padding < 0) { - memset(p, 0x00, padding + sizeof(guint64)); - md4_transform_helper(hash); - p = (gchar *)priv->block; - padding = 56; - } - - memset(p, 0, padding); - priv->block[14] = priv->byte_count << 3; - priv->block[15] = priv->byte_count >> 29; - le32_to_cpu_array(priv->block, - (sizeof(priv->block) - sizeof(guint64)) / - sizeof(guint32)); - md4_transform(priv->hash, priv->block); - cpu_to_le32_array(priv->hash, sizeof(priv->hash) / sizeof(guint32)); - memcpy(out, priv->hash, sizeof(priv->hash)); - - return TRUE; -} - -static size_t -purple_md4_hash_get_digest_size(PurpleHash *hash) -{ - return 16; -} - -static size_t -purple_md4_hash_get_block_size(PurpleHash *hash) -{ - /* This does not change (in this case) */ - return 64; -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_md4_hash_class_init(PurpleMD4HashClass *klass) { - PurpleHashClass *hash_class = PURPLE_HASH_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - g_type_class_add_private(klass, sizeof(PurpleMD4HashPrivate)); - - hash_class->reset = purple_md4_hash_reset; - hash_class->reset_state = purple_md4_hash_reset; - hash_class->append = purple_md4_hash_append; - hash_class->digest = purple_md4_hash_digest; - hash_class->get_digest_size = purple_md4_hash_get_digest_size; - hash_class->get_block_size = purple_md4_hash_get_block_size; -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_md4_hash_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleMD4HashClass), - NULL, - NULL, - (GClassInitFunc)purple_md4_hash_class_init, - NULL, - NULL, - sizeof(PurpleMD4Hash), - 0, - (GInstanceInitFunc)purple_hash_reset, - NULL, - }; - - type = g_type_register_static(PURPLE_TYPE_HASH, - "PurpleMD4Hash", - &info, 0); - } - - return type; -} - -PurpleHash * -purple_md4_hash_new(void) { - return g_object_new(PURPLE_TYPE_MD4_HASH, NULL); -} diff --git a/libpurple/ciphers/md4hash.h b/libpurple/ciphers/md4hash.h deleted file mode 100644 index 101a6be950..0000000000 --- a/libpurple/ciphers/md4hash.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PURPLE_MD4_HASH_H -#define PURPLE_MD4_HASH_H -/** - * SECTION:md4hash - * @section_id: libpurple-md4hash - * @short_description: <filename>ciphers/md4hash.h</filename> - * @title: MD4 Hash - */ - -#include "cipher.h" - -#define PURPLE_TYPE_MD4_HASH (purple_md4_hash_get_type()) -#define PURPLE_MD4_HASH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4Hash)) -#define PURPLE_MD4_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_MD4_HASH, PurpleMD4HashClass)) -#define PURPLE_IS_MD4_HASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_MD4_HASH)) -#define PURPLE_IS_MD4_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_MD4_HASH)) -#define PURPLE_MD4_HASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4HashClass)) - -typedef struct _PurpleMD4Hash PurpleMD4Hash; -typedef struct _PurpleMD4HashClass PurpleMD4HashClass; - -struct _PurpleMD4Hash { - PurpleHash parent; -}; - -struct _PurpleMD4HashClass { - PurpleHashClass parent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_md4_hash_get_type(void); - -PurpleHash *purple_md4_hash_new(void); - -G_END_DECLS - -#endif /* PURPLE_MD4_HASH_H */ diff --git a/libpurple/ciphers/pbkdf2cipher.c b/libpurple/ciphers/pbkdf2cipher.c deleted file mode 100644 index e598d4c8d5..0000000000 --- a/libpurple/ciphers/pbkdf2cipher.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - * Written by Tomek Wasilczyk <twasilczyk@pidgin.im> - */ -#include "internal.h" -#include "glibcompat.h" - -#include "pbkdf2cipher.h" -#include "debug.h" - -/* 1024bit */ -#define PBKDF2_HASH_MAX_LEN 128 - -/****************************************************************************** - * Structs - *****************************************************************************/ -#define PURPLE_PBKDF2_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PBKDF2_CIPHER, PurplePBKDF2CipherPrivate)) - -typedef struct { - GChecksumType hash_type; - guint iter_count; - size_t out_len; - - guchar *salt; - size_t salt_len; - guchar *passphrase; - size_t passphrase_len; -} PurplePBKDF2CipherPrivate; - -/****************************************************************************** - * Enums - *****************************************************************************/ -enum { - PROP_NONE, - PROP_HASH_TYPE, - PROP_ITER_COUNT, - PROP_OUT_LEN, - PROP_LAST, -}; - -/******************************************************************************* - * Globals - ******************************************************************************/ -static GObjectClass *parent_class = NULL; -static GParamSpec *properties[PROP_LAST]; - -/****************************************************************************** - * Cipher Stuff - *****************************************************************************/ -static void -purple_pbkdf2_cipher_reset(PurpleCipher *cipher) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - g_return_if_fail(priv != NULL); - - priv->iter_count = 1; - priv->out_len = 256; - - purple_cipher_reset_state(cipher); -} - -static void -purple_pbkdf2_cipher_reset_state(PurpleCipher *cipher) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - g_return_if_fail(priv != NULL); - - purple_cipher_set_salt(cipher, NULL, 0); - purple_cipher_set_key(cipher, NULL, 0); -} - -static size_t -purple_pbkdf2_cipher_get_digest_size(PurpleCipher *cipher) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - g_return_val_if_fail(priv != NULL, 0); - - return priv->out_len; -} - -static void -purple_pbkdf2_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - g_return_if_fail(priv != NULL); - - g_free(priv->salt); - priv->salt = NULL; - priv->salt_len = 0; - - if (len == 0) - return; - g_return_if_fail(salt != NULL); - - priv->salt = g_memdup(salt, len); - priv->salt_len = len; -} - -static void -purple_pbkdf2_cipher_set_key(PurpleCipher *cipher, const guchar *key, - size_t len) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - g_return_if_fail(priv != NULL); - - if (priv->passphrase != NULL) { - memset(priv->passphrase, 0, priv->passphrase_len); - g_free(priv->passphrase); - priv->passphrase = NULL; - } - priv->passphrase_len = 0; - - if (len == 0) - return; - g_return_if_fail(key != NULL); - - priv->passphrase = g_memdup(key, len); - priv->passphrase_len = len; -} - -/* inspired by gnutls 3.1.10, pbkdf2-sha1.c */ -static gboolean -purple_pbkdf2_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len) -{ - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - guchar halfkey[PBKDF2_HASH_MAX_LEN], halfkey_hash[PBKDF2_HASH_MAX_LEN]; - guint halfkey_count, halfkey_pad, halfkey_no; - gsize halfkey_len; - guchar *salt_ext; - size_t salt_ext_len; - guint iter_no; - - g_return_val_if_fail(priv != NULL, FALSE); - g_return_val_if_fail(digest != NULL, FALSE); - g_return_val_if_fail(len >= priv->out_len, FALSE); - - g_return_val_if_fail(priv->iter_count > 0, FALSE); - g_return_val_if_fail(priv->passphrase != NULL || - priv->passphrase_len == 0, FALSE); - g_return_val_if_fail(priv->salt != NULL || priv->salt_len == 0, - FALSE); - g_return_val_if_fail(priv->out_len > 0, FALSE); - g_return_val_if_fail(priv->out_len < 0xFFFFFFFFU, FALSE); - - salt_ext_len = priv->salt_len + 4; - - halfkey_len = g_checksum_type_get_length(priv->hash_type); - if (halfkey_len <= 0 || halfkey_len > PBKDF2_HASH_MAX_LEN) { - purple_debug_error("pbkdf2", "Unsupported hash function. " - "(digest size: %" G_GSIZE_FORMAT ")\n", halfkey_len); - return FALSE; - } - - halfkey_count = ((priv->out_len - 1) / halfkey_len) + 1; - halfkey_pad = priv->out_len - (halfkey_count - 1) * halfkey_len; - - salt_ext = g_new(guchar, salt_ext_len); - if (priv->salt_len > 0) - memcpy(salt_ext, priv->salt, priv->salt_len); - - for (halfkey_no = 1; halfkey_no <= halfkey_count; halfkey_no++) { - memset(halfkey, 0, halfkey_len); - - for (iter_no = 1; iter_no <= priv->iter_count; iter_no++) { - GHmac *hmac; - guint i; - - hmac = g_hmac_new(priv->hash_type, - (const guchar*)priv->passphrase, - priv->passphrase_len); - if (hmac == NULL) { - purple_debug_error("pbkdf2", - "Couldn't create new hmac cipher\n"); - g_free(salt_ext); - return FALSE; - } - - if (iter_no == 1) { - salt_ext[salt_ext_len - 4] = - (halfkey_no & 0xff000000) >> 24; - salt_ext[salt_ext_len - 3] = - (halfkey_no & 0x00ff0000) >> 16; - salt_ext[salt_ext_len - 2] = - (halfkey_no & 0x0000ff00) >> 8; - salt_ext[salt_ext_len - 1] = - (halfkey_no & 0x000000ff) >> 0; - - g_hmac_update(hmac, salt_ext, salt_ext_len); - } - else - g_hmac_update(hmac, halfkey_hash, halfkey_len); - - g_hmac_get_digest(hmac, halfkey_hash, &halfkey_len); - g_hmac_unref(hmac); - - for (i = 0; i < halfkey_len; i++) - halfkey[i] ^= halfkey_hash[i]; - } - - memcpy(digest + (halfkey_no - 1) * halfkey_len, halfkey, - (halfkey_no == halfkey_count) ? halfkey_pad : - halfkey_len); - } - - g_free(salt_ext); - - return TRUE; -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_pbkdf2_cipher_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurplePBKDF2Cipher *cipher = PURPLE_PBKDF2_CIPHER(obj); - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - switch(param_id) { - case PROP_HASH_TYPE: - g_value_set_int(value, priv->hash_type); - break; - case PROP_ITER_COUNT: - g_value_set_uint(value, priv->iter_count); - break; - case PROP_OUT_LEN: - g_value_set_uint(value, priv->out_len); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_pbkdf2_cipher_set_property(GObject *obj, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - switch(param_id) { - case PROP_HASH_TYPE: - priv->hash_type = g_value_get_int(value); - break; - case PROP_ITER_COUNT: - priv->iter_count = g_value_get_uint(value); - break; - case PROP_OUT_LEN: - priv->out_len = g_value_get_uint(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_pbkdf2_cipher_finalize(GObject *obj) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - purple_pbkdf2_cipher_reset(cipher); - - parent_class->finalize(obj); -} - -static void -purple_pbkdf2_cipher_class_init(PurplePBKDF2CipherClass *klass) { - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->finalize = purple_pbkdf2_cipher_finalize; - obj_class->get_property = purple_pbkdf2_cipher_get_property; - obj_class->set_property = purple_pbkdf2_cipher_set_property; - - cipher_class->reset = purple_pbkdf2_cipher_reset; - cipher_class->reset_state = purple_pbkdf2_cipher_reset_state; - cipher_class->digest = purple_pbkdf2_cipher_digest; - cipher_class->get_digest_size = purple_pbkdf2_cipher_get_digest_size; - cipher_class->set_salt = purple_pbkdf2_cipher_set_salt; - cipher_class->set_key = purple_pbkdf2_cipher_set_key; - - g_type_class_add_private(klass, sizeof(PurplePBKDF2CipherPrivate)); - - properties[PROP_HASH_TYPE] = g_param_spec_int("hash-type", "hash-type", "hash-type", - G_MININT, G_MAXINT, -1, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ITER_COUNT] = g_param_spec_uint("iter-count", "iter-count", - "iter-count", 0, - G_MAXUINT, 0, G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_OUT_LEN] = g_param_spec_uint("out-len", "out-len", - "out-len", 0, - G_MAXUINT, 0, G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(obj_class, PROP_LAST, properties); -} - -static void -purple_pbkdf2_cipher_init(PurpleCipher *cipher) -{ - PurplePBKDF2CipherPrivate *priv = - PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - priv->hash_type = -1; - - purple_cipher_reset(cipher); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_pbkdf2_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurplePBKDF2CipherClass), - NULL, - NULL, - (GClassInitFunc)purple_pbkdf2_cipher_class_init, - NULL, - NULL, - sizeof(PurplePBKDF2Cipher), - 0, - (GInstanceInitFunc)purple_pbkdf2_cipher_init, - NULL - }; - - type = g_type_register_static(PURPLE_TYPE_CIPHER, - "PurplePBKDF2Cipher", - &info, 0); - } - - return type; -} - -PurpleCipher * -purple_pbkdf2_cipher_new(GChecksumType hash_type) { - return g_object_new(PURPLE_TYPE_PBKDF2_CIPHER, - "hash-type", hash_type, - NULL); -} - -GChecksumType -purple_pbkdf2_cipher_get_hash_type(const PurplePBKDF2Cipher *cipher) { - PurplePBKDF2CipherPrivate *priv = NULL; - - g_return_val_if_fail(PURPLE_IS_PBKDF2_CIPHER(cipher), -1); - - priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); - - if(priv) - return priv->hash_type; - - return -1; -} diff --git a/libpurple/ciphers/pbkdf2cipher.h b/libpurple/ciphers/pbkdf2cipher.h deleted file mode 100644 index 1a635bda3a..0000000000 --- a/libpurple/ciphers/pbkdf2cipher.h +++ /dev/null @@ -1,68 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_PBKDF2_CIPHER_H -#define PURPLE_PBKDF2_CIPHER_H -/** - * SECTION:pbkdf2cipher - * @section_id: libpurple-pbkdf2cipher - * @short_description: <filename>ciphers/pbkdf2cipher.h</filename> - * @title: PBKDF2 Cipher - */ - -#include "cipher.h" - -#define PURPLE_TYPE_PBKDF2_CIPHER (purple_pbkdf2_cipher_get_type()) -#define PURPLE_PBKDF2_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_PBKDF2_CIPHER, PurplePBKDF2Cipher)) -#define PURPLE_PBKDF2_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_PBKDF2_CIPHER, PurplePBKDF2CipherClass)) -#define PURPLE_IS_PBKDF2_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PBKDF2_CIPHER)) -#define PURPLE_IS_PBKDF2_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_PBKDF2_CIPHER)) -#define PURPLE_PBKDF2_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_PBKDF2_CIPHER, PurplePBKDF2CipherClass)) - -typedef struct _PurplePBKDF2Cipher PurplePBKDF2Cipher; -typedef struct _PurplePBKDF2CipherClass PurplePBKDF2CipherClass; - -struct _PurplePBKDF2Cipher { - PurpleCipher gparent; -}; - -struct _PurplePBKDF2CipherClass { - PurpleCipherClass gparent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_pbkdf2_cipher_get_type(void); - -PurpleCipher *purple_pbkdf2_cipher_new(GChecksumType hash_type); - -GChecksumType purple_pbkdf2_cipher_get_hash_type(const PurplePBKDF2Cipher *cipher); - -G_END_DECLS - -#endif /* PURPLE_PBKDF2_CIPHER_H */ - diff --git a/libpurple/ciphers/rc4cipher.c b/libpurple/ciphers/rc4cipher.c deleted file mode 100644 index 7480b8f7f2..0000000000 --- a/libpurple/ciphers/rc4cipher.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ -#include "internal.h" -#include "glibcompat.h" - -#include "rc4cipher.h" - -/******************************************************************************* - * Structs - ******************************************************************************/ -#define PURPLE_RC4_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_RC4_CIPHER, PurpleRC4CipherPrivate)) - -typedef struct { - guchar state[256]; - guchar x; - guchar y; - gint key_len; -} PurpleRC4CipherPrivate; - -/****************************************************************************** - * Enums - *****************************************************************************/ -enum { - PROP_ZERO, - PROP_KEY_LEN, - PROP_KEY, - PROP_LAST, -}; - -/****************************************************************************** - * Globals - *****************************************************************************/ -static GObjectClass *parent_class = NULL; -static GParamSpec *properties[PROP_LAST]; - -/****************************************************************************** - * Cipher Stuff - *****************************************************************************/ -static void -purple_rc4_cipher_reset(PurpleCipher *cipher) { - PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher); - PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher); - guint i; - - for(i = 0; i < 256; i++) - priv->state[i] = i; - priv->x = 0; - priv->y = 0; - - /* default is 5 bytes (40bit key) */ - priv->key_len = 5; -} - -static void -purple_rc4_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) { - PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher); - PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher); - guchar *state; - guchar temp_swap; - guchar x, y; - guint i; - - x = 0; - y = 0; - state = &priv->state[0]; - priv->key_len = len; - for(i = 0; i < 256; i++) - { - y = (key[x] + state[i] + y) % 256; - temp_swap = state[i]; - state[i] = state[y]; - state[y] = temp_swap; - x = (x + 1) % len; - } - - g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_KEY]); -} - -static ssize_t -purple_rc4_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, - guchar output[], size_t out_size) -{ - PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher); - guchar temp_swap; - guchar x, y, z; - guchar *state; - guint i; - PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher); - - x = priv->x; - y = priv->y; - state = &priv->state[0]; - - for(i = 0; i < in_len; i++) - { - x = (x + 1) % 256; - y = (state[x] + y) % 256; - temp_swap = state[x]; - state[x] = state[y]; - state[y] = temp_swap; - z = state[x] + (state[y]) % 256; - output[i] = input[i] ^ state[z]; - } - priv->x = x; - priv->y = y; - - return in_len; -} - -/****************************************************************************** - * Object Stuff - *****************************************************************************/ -static void -purple_rc4_cipher_set_property(GObject *obj, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj); - - switch(param_id) { - case PROP_KEY_LEN: - purple_rc4_cipher_set_key_len(rc4_cipher, g_value_get_int(value)); - break; - case PROP_KEY: - { - guchar *key = (guchar *)g_value_get_string(value); - purple_rc4_cipher_set_key(cipher, key, strlen((gchar *) key)); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_rc4_cipher_get_property(GObject *obj, guint param_id, GValue *value, - GParamSpec *pspec) -{ - PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj); - - switch(param_id) { - case PROP_KEY_LEN: - g_value_set_int(value, - purple_rc4_cipher_get_key_len(rc4_cipher)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -static void -purple_rc4_cipher_class_init(PurpleRC4CipherClass *klass) { - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - obj_class->set_property = purple_rc4_cipher_set_property; - obj_class->get_property = purple_rc4_cipher_get_property; - - cipher_class->reset = purple_rc4_cipher_reset; - cipher_class->encrypt = purple_rc4_cipher_encrypt; - cipher_class->set_key = purple_rc4_cipher_set_key; - - g_type_class_add_private(klass, sizeof(PurpleRC4CipherPrivate)); - - properties[PROP_KEY_LEN] = g_param_spec_int("key-len", "key-len", "key-len", - G_MININT, G_MAXINT, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - properties[PROP_KEY] = g_param_spec_string("key", "key", "key", NULL, - G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(obj_class, PROP_LAST, properties); -} - -static void -purple_rc4_cipher_init(PurpleCipher *cipher) { - purple_rc4_cipher_reset(cipher); -} - -/****************************************************************************** - * API - *****************************************************************************/ -GType -purple_rc4_cipher_get_type(void) { - static GType type = 0; - - if(type == 0) { - static const GTypeInfo info = { - sizeof(PurpleRC4CipherClass), - NULL, - NULL, - (GClassInitFunc)purple_rc4_cipher_class_init, - NULL, - NULL, - sizeof(PurpleRC4Cipher), - 0, - (GInstanceInitFunc)purple_rc4_cipher_init, - NULL, - }; - - type = g_type_register_static(PURPLE_TYPE_CIPHER, - "PurpleRC4Cipher", - &info, 0); - } - - return type; -} - -PurpleCipher * -purple_rc4_cipher_new(void) { - return g_object_new(PURPLE_TYPE_RC4_CIPHER, NULL); -} - -void -purple_rc4_cipher_set_key_len(PurpleRC4Cipher *rc4_cipher, - gint key_len) -{ - PurpleRC4CipherPrivate *priv; - - g_return_if_fail(PURPLE_IS_RC4_CIPHER(rc4_cipher)); - - priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher); - priv->key_len = key_len; - - g_object_notify_by_pspec(G_OBJECT(rc4_cipher), properties[PROP_KEY_LEN]); -} - -gint -purple_rc4_cipher_get_key_len(PurpleRC4Cipher *rc4_cipher) -{ - PurpleRC4CipherPrivate *priv; - - g_return_val_if_fail(PURPLE_IS_RC4_CIPHER(rc4_cipher), 0); - - priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher); - - return priv->key_len; -} diff --git a/libpurple/ciphers/rc4cipher.h b/libpurple/ciphers/rc4cipher.h deleted file mode 100644 index 94423fb9d5..0000000000 --- a/libpurple/ciphers/rc4cipher.h +++ /dev/null @@ -1,70 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_RC4_CIPHER_H -#define PURPLE_RC4_CIPHER_H -/** - * SECTION:rc4cipher - * @section_id: libpurple-rc4cipher - * @short_description: <filename>ciphers/rc4cipher.h</filename> - * @title: RC4 Cipher - */ - -#include "cipher.h" - -#define PURPLE_TYPE_RC4_CIPHER (purple_rc4_cipher_get_type()) -#define PURPLE_RC4_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_RC4_CIPHER, PurpleRC4Cipher)) -#define PURPLE_RC4_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_RC4_CIPHER, PurpleRC4CipherClass)) -#define PURPLE_IS_RC4_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_RC4_CIPHER)) -#define PURPLE_IS_RC4_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_RC4_CIPHER)) -#define PURPLE_RC4_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_RC4_CIPHER, PurpleRC4CipherClass)) - -typedef struct _PurpleRC4Cipher PurpleRC4Cipher; -typedef struct _PurpleRC4CipherClass PurpleRC4CipherClass; - -struct _PurpleRC4Cipher { - PurpleCipher gparent; -}; - -struct _PurpleRC4CipherClass { - PurpleCipherClass gparent; - - /*< private >*/ - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); - void (*_purple_reserved3)(void); - void (*_purple_reserved4)(void); -}; - -G_BEGIN_DECLS - -GType purple_rc4_cipher_get_type(void); - -PurpleCipher *purple_rc4_cipher_new(void); - -gint purple_rc4_cipher_get_key_len(PurpleRC4Cipher *rc4_cipher); -void purple_rc4_cipher_set_key_len(PurpleRC4Cipher *rc4_cipher, gint key_len); - -G_END_DECLS - -#endif /* PURPLE_RC4_CIPHER_H */ - - diff --git a/libpurple/core.c b/libpurple/core.c index 3ddda9c2b4..016c7f5232 100644 --- a/libpurple/core.c +++ b/libpurple/core.c @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #include "internal.h" -#include "cipher.h" #include "cmds.h" #include "connection.h" #include "conversation.h" diff --git a/libpurple/plugins/Makefile.am b/libpurple/plugins/Makefile.am index 343585edc5..aa9f5f489a 100644 --- a/libpurple/plugins/Makefile.am +++ b/libpurple/plugins/Makefile.am @@ -11,8 +11,6 @@ plugindir = @PURPLE_PLUGINDIR@ autoaccept_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ buddynote_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ -caesarcipher_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ -caesarcipher_consumer_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ codeinline_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ debug_example_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ helloworld_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ @@ -44,8 +42,6 @@ plugin_LTLIBRARIES = \ statenotify.la noinst_LTLIBRARIES = \ - caesarcipher.la \ - caesarcipher_consumer.la \ codeinline.la \ debug_example.la \ helloworld.la \ @@ -58,8 +54,6 @@ noinst_LTLIBRARIES = \ autoaccept_la_SOURCES = autoaccept.c buddynote_la_SOURCES = buddynote.c -caesarcipher_la_SOURCES = caesarcipher.c caesarcipher.h -caesarcipher_consumer_la_SOURCES = caesarcipher_consumer.c codeinline_la_SOURCES = codeinline.c debug_example_la_SOURCES = debug_example.c helloworld_la_SOURCES = helloworld.c @@ -77,8 +71,6 @@ statenotify_la_SOURCES = statenotify.c autoaccept_la_LIBADD = @PURPLE_LIBS@ buddynote_la_LIBADD = @PURPLE_LIBS@ -caesarcipher_la_LIBADD = @PURPLE_LIBS@ -caesarcipher_consumer_la_LIBADD = @PURPLE_LIBS@ codeinline_la_LIBADD = @PURPLE_LIBS@ idle_la_LIBADD = @PURPLE_LIBS@ joinpart_la_LIBADD = @PURPLE_LIBS@ @@ -128,11 +120,9 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GPLUGIN_CFLAGS) \ $(PLUGIN_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(NSS_CFLAGS) + $(DBUS_CFLAGS) -PLUGIN_LIBS = \ - $(NSS_LIBS) +PLUGIN_LIBS = # # This part allows people to build their own plugins in here. diff --git a/libpurple/plugins/caesarcipher.c b/libpurple/plugins/caesarcipher.c deleted file mode 100644 index 0c79589b5a..0000000000 --- a/libpurple/plugins/caesarcipher.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * An example plugin that demonstrates exporting of a cipher object - * type to be used in another plugin. - * - * This plugin only provides the CaesarCipher type. See caesarcipher_consumer - * plugin for its use. - * - * Copyright (C) 2013, Ankit Vani <a@nevitus.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02111-1301, USA. - */ - -/* When writing a third-party plugin, do not include libpurple's internal.h - * included below. This file is for internal libpurple use only. We're including - * it here for our own convenience. */ -#include "internal.h" - -/* This file defines PURPLE_PLUGINS and includes all the libpurple headers */ -#include <purple.h> - -#include "caesarcipher.h" - -#define CAESAR_CIPHER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj), CAESAR_TYPE_CIPHER, CaesarCipherPrivate)) - -typedef struct { - gint8 offset; -} CaesarCipherPrivate; - -enum { - PROP_NONE, - PROP_OFFSET, - PROP_LAST, -}; - -/****************************************************************************** - * Cipher stuff - *****************************************************************************/ -static void -caesar_shift(const guchar input[], size_t in_len, guchar output[], gint8 offset) -{ - size_t i; - - for (i = 0; i < in_len; ++i) { - if (input[i] >= 'a' && input[i] <= 'z') - output[i] = (((input[i] - 'a') + offset + 26) % 26) + 'a'; - else if (input[i] >= 'A' && input[i] <= 'Z') - output[i] = (((input[i] - 'A') + offset + 26) % 26) + 'A'; - else - output[i] = input[i]; - } - - output[i] = '\0'; -} - -static void -caesar_cipher_set_offset(PurpleCipher *cipher, gint8 offset) -{ - CaesarCipherPrivate *priv = CAESAR_CIPHER_GET_PRIVATE(cipher); - - priv->offset = offset % 26; -} - -static ssize_t -caesar_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, - guchar output[], size_t out_size) -{ - CaesarCipherPrivate *priv = CAESAR_CIPHER_GET_PRIVATE(cipher); - - g_return_val_if_fail(out_size > in_len, -1); - - caesar_shift(input, in_len, output, priv->offset); - - return in_len; -} - -static ssize_t -caesar_cipher_decrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, - guchar output[], size_t out_size) -{ - CaesarCipherPrivate *priv = CAESAR_CIPHER_GET_PRIVATE(cipher); - - g_return_val_if_fail(out_size > in_len, -1); - - caesar_shift(input, in_len, output, -priv->offset); - - return in_len; -} - -static void -caesar_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) -{ - caesar_cipher_set_offset(cipher, len); -} - -/****************************************************************************** - * Object stuff - *****************************************************************************/ -static void -caesar_cipher_set_property(GObject *obj, guint param_id, const GValue *value, - GParamSpec *pspec) -{ - PurpleCipher *cipher = PURPLE_CIPHER(obj); - - switch(param_id) { - case PROP_OFFSET: - caesar_cipher_set_offset(cipher, g_value_get_schar(value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; - } -} - -/* initialize the cipher object. used in PURPLE_DEFINE_TYPE. */ -static void -caesar_cipher_init(CaesarCipher *cipher) -{ - /* classic caesar cipher uses a shift of 3 */ - CAESAR_CIPHER_GET_PRIVATE(cipher)->offset = 3; -} - -/* initialize the cipher class. used in PURPLE_DEFINE_TYPE. */ -static void -caesar_cipher_class_init(PurpleCipherClass *klass) -{ - GObjectClass *obj_class = G_OBJECT_CLASS(klass); - - obj_class->set_property = caesar_cipher_set_property; - g_type_class_add_private(obj_class, sizeof(CaesarCipherPrivate)); - - klass->encrypt = caesar_cipher_encrypt; - klass->decrypt = caesar_cipher_decrypt; - klass->set_key = caesar_cipher_set_key; - - g_object_class_install_property(obj_class, PROP_OFFSET, - g_param_spec_char("offset", "offset", - "The offset by which to shift alphabets", - -25, 25, 3, - G_PARAM_WRITABLE) - ); -} - -/* - * define the CaesarCipher type. this function defines - * caesar_cipher_get_type() and caesar_cipher_register_type(). - */ -PURPLE_DEFINE_TYPE(CaesarCipher, caesar_cipher, PURPLE_TYPE_CIPHER); - -G_MODULE_EXPORT PurpleCipher * -caesar_cipher_new(void) -{ - return g_object_new(CAESAR_TYPE_CIPHER, NULL); -} - -/****************************************************************************** - * Plugin stuff - *****************************************************************************/ -static PurplePluginInfo * -plugin_query(GError **error) -{ - const gchar * const authors[] = { - "Ankit Vani <a@nevitus.org>", - NULL - }; - - return purple_plugin_info_new( - "id", "core-caesarcipher", - "name", N_("Caesar Cipher Provider Example"), - "version", DISPLAY_VERSION, - "category", N_("Example"), - "summary", N_("An example plugin that demonstrates exporting of a " - "cipher type."), - "description", N_("An example plugin that demonstrates exporting of " - "a cipher object type to be used in another " - "plugin."), - "authors", authors, - "website", PURPLE_WEBSITE, - "abi-version", PURPLE_ABI_VERSION, - NULL - ); -} - -static gboolean -plugin_load(PurplePlugin *plugin, GError **error) -{ - /* register the CaesarCipher type in the type system */ - caesar_cipher_register_type(plugin); - - return TRUE; -} - -static gboolean -plugin_unload(PurplePlugin *plugin, GError **error) -{ - return TRUE; -} - -PURPLE_PLUGIN_INIT(caesarcipher, plugin_query, plugin_load, plugin_unload); diff --git a/libpurple/plugins/caesarcipher.h b/libpurple/plugins/caesarcipher.h deleted file mode 100644 index 475c6218a1..0000000000 --- a/libpurple/plugins/caesarcipher.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * An example plugin that demonstrates exporting of a cipher object - * type to be used in another plugin. - * - * Copyright (C) 2013, Ankit Vani <a@nevitus.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02111-1301, USA. - */ - -#ifndef _CAESAR_CIPHER_H_ -#define _CAESAR_CIPHER_H_ - -#include "cipher.h" - -#define CAESAR_TYPE_CIPHER (caesar_cipher_get_type()) -#define CAESAR_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CAESAR_TYPE_CIPHER, CaesarCipher)) -#define CAESAR_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CAESAR_TYPE_CIPHER, CaesarCipherClass)) -#define CAESAR_IS_CIPHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CAESAR_TYPE_CIPHER)) -#define CAESAR_IS_CIPHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CAESAR_TYPE_CIPHER)) -#define CAESAR_CIPHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CAESAR_TYPE_CIPHER, CaesarCipherClass)) - -typedef struct _CaesarCipher CaesarCipher; -typedef struct _CaesarCipherClass CaesarCipherClass; - -/* - * A caesar cipher object. - * - * The Caesar cipher is one of the simplest and most widely known encryption - * techniques. It is a type of substitution cipher in which each letter in the - * plaintext is replaced by a letter some fixed number of positions down the - * alphabet. - */ -struct _CaesarCipher -{ - PurpleCipher gparent; -}; - -/* The base class for all CaesarCipher's. */ -struct _CaesarCipherClass -{ - PurpleCipherClass gparent; -}; - -/* - * Returns the GType for the CaesarCipher object. - */ -G_MODULE_EXPORT GType caesar_cipher_get_type(void); - -/* - * Creates a new CaesarCipher instance and returns it. - */ -G_MODULE_EXPORT PurpleCipher *caesar_cipher_new(void); - -#endif /* _CAESAR_CIPHER_H_ */ diff --git a/libpurple/plugins/caesarcipher_consumer.c b/libpurple/plugins/caesarcipher_consumer.c deleted file mode 100644 index dc70edeeb5..0000000000 --- a/libpurple/plugins/caesarcipher_consumer.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * An example plugin that demonstrates usage of a cipher object type - * registered in another plugin. - * - * This plugin requires the caesarcipher plugin to be loaded to use the - * CaesarCipher type. - * - * Copyright (C) 2013, Ankit Vani <a@nevitus.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02111-1301, USA. - */ - -/* When writing a third-party plugin, do not include libpurple's internal.h - * included below. This file is for internal libpurple use only. We're including - * it here for our own convenience. */ -#include "internal.h" - -/* This file defines PURPLE_PLUGINS and includes all the libpurple headers */ -#include <purple.h> - -#include "caesarcipher.h" - -static void -debug_cipher(PurpleCipher *cipher, const gchar *input) -{ - gchar ciphertext[512], plaintext[512]; - - purple_debug_info("caesarcipher_consumer", "Encrypting..."); - - purple_debug_info("caesarcipher_consumer", "INPUT: %s\n", input); - purple_cipher_encrypt(cipher, (const guchar *)input, strlen(input), - (guchar *)ciphertext, 512); - purple_debug_info("caesarcipher_consumer", "OUTPUT: %s\n", ciphertext); - - purple_debug_info("caesarcipher_consumer", "Decrypting..."); - - purple_debug_info("caesarcipher_consumer", "INPUT: %s\n", ciphertext); - purple_cipher_decrypt(cipher, (const guchar *)ciphertext, - strlen(ciphertext), (guchar *)plaintext, 512); - purple_debug_info("caesarcipher_consumer", "OUTPUT: %s\n", plaintext); -} - -static PurplePluginInfo * -plugin_query(GError **error) -{ - const gchar * const authors[] = { - "Ankit Vani <a@nevitus.org>", - NULL - }; - - /* we need to ensure the object provider is loaded for its type to be - * registered in the type system. */ - const gchar * const dependencies[] = { - "core-caesarcipher", - NULL - }; - - return purple_plugin_info_new( - "id", "core-caesarcipher_consumer", - "name", N_("Caesar Cipher Consumer Example"), - "version", DISPLAY_VERSION, - "category", N_("Example"), - "summary", N_("An example plugin that demonstrates usage of a " - "loaded cipher type."), - "description", N_("An example plugin that demonstrates usage of " - "a cipher object type registered in another " - "plugin."), - "authors", authors, - "website", PURPLE_WEBSITE, - "abi-version", PURPLE_ABI_VERSION, - "dependencies", dependencies, - - NULL - ); -} - -static gboolean -plugin_load(PurplePlugin *plugin, GError **error) -{ - PurpleCipher *cipher = caesar_cipher_new(); - purple_debug_info("caesarcipher_consumer", "Created caesar cipher " - "object.\n"); - - debug_cipher(cipher, "Input string for cipher!"); - - purple_cipher_set_key(cipher, NULL, 13); - purple_debug_info("caesarcipher_consumer", "Offset set to 13.\n"); - - debug_cipher(cipher, "An0ther input 4 cipher.."); - - g_object_unref(cipher); - purple_debug_info("caesarcipher_consumer", "Destroyed caesar cipher " - "object.\n"); - - return TRUE; -} - -static gboolean -plugin_unload(PurplePlugin *plugin, GError **error) -{ - return TRUE; -} - -PURPLE_PLUGIN_INIT(caesarcipher_consumer, plugin_query, plugin_load, plugin_unload); diff --git a/libpurple/plugins/keyrings/Makefile.am b/libpurple/plugins/keyrings/Makefile.am index d780a91d3e..44479071c5 100644 --- a/libpurple/plugins/keyrings/Makefile.am +++ b/libpurple/plugins/keyrings/Makefile.am @@ -5,10 +5,14 @@ CLEANFILES = plugindir = @PURPLE_PLUGINDIR@ -internalkeyring_la_CFLAGS = $(AM_CPPFLAGS) +if ENABLE_NETTLE + +internalkeyring_la_CFLAGS = $(AM_CPPFLAGS) $(NETTLE_CFLAGS) internalkeyring_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ internalkeyring_la_SOURCES = internalkeyring.c -internalkeyring_la_LIBADD = @PURPLE_LIBS@ +internalkeyring_la_LIBADD = @PURPLE_LIBS@ $(NETTLE_LIBS) + +endif if ENABLE_SECRETSERVICE @@ -56,8 +60,12 @@ endif if PLUGINS -plugin_LTLIBRARIES = \ +plugin_LTLIBRARIES = + +if ENABLE_NETTLE +plugin_LTLIBRARIES += \ internalkeyring.la +endif if ENABLE_SECRETSERVICE plugin_LTLIBRARIES += \ diff --git a/libpurple/plugins/keyrings/internalkeyring.c b/libpurple/plugins/keyrings/internalkeyring.c index ea662eade5..7492b83023 100644 --- a/libpurple/plugins/keyrings/internalkeyring.c +++ b/libpurple/plugins/keyrings/internalkeyring.c @@ -31,8 +31,9 @@ #include "plugins.h" #include "version.h" -#include "ciphers/aescipher.h" -#include "ciphers/pbkdf2cipher.h" +#include <nettle/aes.h> +#include <nettle/cbc.h> +#include <nettle/pbkdf2.h> #define INTKEYRING_NAME N_("Internal keyring") #define INTKEYRING_DESCRIPTION N_("This plugin provides the default password " \ @@ -45,7 +46,7 @@ #define INTKEYRING_PBKDF2_ITERATIONS 10000 #define INTKEYRING_PBKDF2_ITERATIONS_MIN 1000 #define INTKEYRING_PBKDF2_ITERATIONS_MAX 1000000000 -#define INTKEYRING_KEY_LEN (256/8) +#define INTKEYRING_KEY_LEN AES256_KEY_SIZE #define INTKEYRING_ENCRYPT_BUFF_LEN 1000 #define INTKEYRING_ENCRYPTED_MIN_LEN 50 #define INTKEYRING_ENCRYPTION_METHOD "pbkdf2-sha256-aes256" @@ -150,33 +151,16 @@ intkeyring_buff_from_base64(const gchar *base64) static intkeyring_buff_t * intkeyring_derive_key(const gchar *passphrase, intkeyring_buff_t *salt) { - PurpleCipher *cipher; - gboolean succ; intkeyring_buff_t *ret; g_return_val_if_fail(passphrase != NULL, NULL); - cipher = purple_pbkdf2_cipher_new(G_CHECKSUM_SHA256); - - g_object_set(G_OBJECT(cipher), "iter_count", - GUINT_TO_POINTER(purple_prefs_get_int(INTKEYRING_PREFS - "pbkdf2_iterations")), NULL); - g_object_set(G_OBJECT(cipher), "out_len", GUINT_TO_POINTER( - INTKEYRING_KEY_LEN), NULL); - purple_cipher_set_salt(cipher, salt->data, salt->len); - purple_cipher_set_key(cipher, (const guchar*)passphrase, - strlen(passphrase)); - ret = intkeyring_buff_new(g_new(guchar, INTKEYRING_KEY_LEN), INTKEYRING_KEY_LEN); - succ = purple_cipher_digest(cipher, ret->data, ret->len); - - g_object_unref(cipher); - if (!succ) { - intkeyring_buff_free(ret); - return NULL; - } + pbkdf2_hmac_sha256(strlen(passphrase), (const uint8_t *)passphrase, + purple_prefs_get_int(INTKEYRING_PREFS"pbkdf2_iterations"), + salt->len, salt->data, ret->len, ret->data); return ret; } @@ -230,10 +214,11 @@ intkeyring_gen_salt(size_t len) static gchar * intkeyring_encrypt(intkeyring_buff_t *key, const gchar *str) { - PurpleCipher *cipher; + struct CBC_CTX(struct aes256_ctx, AES_BLOCK_SIZE) ctx; intkeyring_buff_t *iv; guchar plaintext[INTKEYRING_ENCRYPT_BUFF_LEN]; size_t plaintext_len, text_len, verify_len; + int padding_len; guchar encrypted_raw[INTKEYRING_ENCRYPT_BUFF_LEN]; ssize_t encrypted_size; @@ -249,31 +234,38 @@ intkeyring_encrypt(intkeyring_buff_t *key, const gchar *str) g_return_val_if_fail(plaintext_len + verify_len <= sizeof(plaintext), NULL); - cipher = purple_aes_cipher_new(); - g_return_val_if_fail(cipher != NULL, NULL); - memset(plaintext, 0, plaintext_len); memcpy(plaintext, str, text_len); memcpy(plaintext + plaintext_len, INTKEYRING_VERIFY_STR, verify_len); plaintext_len += verify_len; - iv = intkeyring_gen_salt(purple_cipher_get_block_size(cipher)); + /* Pad PKCS7 */ + padding_len = AES_BLOCK_SIZE - (plaintext_len % AES_BLOCK_SIZE); + + if (plaintext_len + padding_len > INTKEYRING_ENCRYPT_BUFF_LEN) { + purple_debug_error("keyring-internal", + "Internal keyring encrypt buffer too small"); + return NULL; + } + + memset(plaintext + plaintext_len, padding_len, padding_len); + plaintext_len += padding_len; + + /* Encrypt */ + iv = intkeyring_gen_salt(AES_BLOCK_SIZE); g_return_val_if_fail(iv != NULL, NULL); - purple_cipher_set_iv(cipher, iv->data, iv->len); - purple_cipher_set_key(cipher, key->data, key->len); - purple_cipher_set_batch_mode(cipher, - PURPLE_CIPHER_BATCH_MODE_CBC); + aes256_set_encrypt_key(&ctx.ctx, key->data); + CBC_SET_IV(&ctx, iv->data); memcpy(encrypted_raw, iv->data, iv->len); - encrypted_size = purple_cipher_encrypt(cipher, - plaintext, plaintext_len, encrypted_raw + iv->len, - sizeof(encrypted_raw) - iv->len); + CBC_ENCRYPT(&ctx, aes256_encrypt, plaintext_len, + encrypted_raw + iv->len, plaintext); + encrypted_size = plaintext_len; encrypted_size += iv->len; memset(plaintext, 0, plaintext_len); intkeyring_buff_free(iv); - g_object_unref(cipher); if (encrypted_size < 0) return NULL; @@ -285,42 +277,63 @@ intkeyring_encrypt(intkeyring_buff_t *key, const gchar *str) static gchar * intkeyring_decrypt(intkeyring_buff_t *key, const gchar *str) { - PurpleCipher *cipher; + struct CBC_CTX(struct aes256_ctx, AES_BLOCK_SIZE) ctx; guchar *encrypted_raw; gsize encrypted_size; size_t iv_len, verify_len, text_len; guchar plaintext[INTKEYRING_ENCRYPT_BUFF_LEN]; const gchar *verify_str = NULL; - ssize_t plaintext_len; + size_t plaintext_len; + guint padding_len; + guint i; gchar *ret; g_return_val_if_fail(key != NULL, NULL); g_return_val_if_fail(str != NULL, NULL); - cipher = purple_aes_cipher_new(); - g_return_val_if_fail(cipher != NULL, NULL); - encrypted_raw = g_base64_decode(str, &encrypted_size); g_return_val_if_fail(encrypted_raw != NULL, NULL); - iv_len = purple_cipher_get_block_size(cipher); + iv_len = AES_BLOCK_SIZE; if (encrypted_size < iv_len) { g_free(encrypted_raw); return NULL; } - purple_cipher_set_iv(cipher, encrypted_raw, iv_len); - purple_cipher_set_key(cipher, key->data, key->len); - purple_cipher_set_batch_mode(cipher, - PURPLE_CIPHER_BATCH_MODE_CBC); + /* Decrypt */ + aes256_set_decrypt_key(&ctx.ctx, key->data); + CBC_SET_IV(&ctx, encrypted_raw); + CBC_DECRYPT(&ctx, aes256_decrypt, encrypted_size - iv_len, + plaintext, encrypted_raw + iv_len); + plaintext_len = encrypted_size - iv_len; + g_free(encrypted_raw); - plaintext_len = purple_cipher_decrypt(cipher, - encrypted_raw + iv_len, encrypted_size - iv_len, - plaintext, sizeof(plaintext)); + /* Unpad PKCS7 */ + padding_len = plaintext[plaintext_len - 1]; + if (padding_len == 0 || padding_len > AES_BLOCK_SIZE || + padding_len > plaintext_len) { + purple_debug_warning("internal-keyring", + "Invalid padding length: %d (total %" G_GSIZE_FORMAT + ") - most probably, the key was invalid\n", + padding_len, plaintext_len); + return NULL; + } - g_free(encrypted_raw); - g_object_unref(cipher); + plaintext_len -= padding_len; + for (i = 0; i < padding_len; ++i) { + if (plaintext[plaintext_len + i] != padding_len) { + purple_debug_warning("internal-keyring", + "Padding doesn't match at pos %d (found %02x, " + "expected %02x) - " + "most probably, the key was invalid\n", + i, plaintext[plaintext_len + i], padding_len); + return NULL; + } + } + + memset(plaintext + plaintext_len, 0, padding_len); + /* Verify */ verify_len = strlen(INTKEYRING_VERIFY_STR); /* Don't remove the len > 0 check! */ if (plaintext_len > 0 && (gsize)plaintext_len > verify_len && diff --git a/libpurple/protocols/jabber/tests/Makefile.am b/libpurple/protocols/jabber/tests/Makefile.am index b80b9d123a..9c27452dad 100644 --- a/libpurple/protocols/jabber/tests/Makefile.am +++ b/libpurple/protocols/jabber/tests/Makefile.am @@ -33,5 +33,4 @@ AM_CPPFLAGS = \ $(GPLUGIN_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(DBUS_CFLAGS) \ - $(LIBXML_CFLAGS) \ - $(NSS_CFLAGS) + $(LIBXML_CFLAGS) diff --git a/libpurple/protocols/oscar/tests/Makefile.am b/libpurple/protocols/oscar/tests/Makefile.am index 55bd659569..cc6dec34a8 100644 --- a/libpurple/protocols/oscar/tests/Makefile.am +++ b/libpurple/protocols/oscar/tests/Makefile.am @@ -19,5 +19,4 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GPLUGIN_CFLAGS) \ $(PLUGIN_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(NSS_CFLAGS) + $(DBUS_CFLAGS) diff --git a/libpurple/protocols/simple/Makefile.am b/libpurple/protocols/simple/Makefile.am index 216e719b16..2515609a20 100644 --- a/libpurple/protocols/simple/Makefile.am +++ b/libpurple/protocols/simple/Makefile.am @@ -14,6 +14,7 @@ SIMPLESOURCES = \ AM_CFLAGS = $(st) libsimple_la_LDFLAGS = -module @PLUGIN_LDFLAGS@ +libsimple_la_LIBADD = $(NETTLE_LIBS) if STATIC_SIMPLE @@ -27,7 +28,7 @@ else st = pkg_LTLIBRARIES = libsimple.la libsimple_la_SOURCES = $(SIMPLESOURCES) -libsimple_la_LIBADD = @PURPLE_LIBS@ +libsimple_la_LIBADD += @PURPLE_LIBS@ endif @@ -36,4 +37,5 @@ AM_CPPFLAGS = \ -I$(top_builddir)/libpurple \ $(GLIB_CFLAGS) \ $(GPLUGIN_CFLAGS) \ - $(DEBUG_CFLAGS) + $(DEBUG_CFLAGS) \ + $(NETTLE_CFLAGS) diff --git a/libpurple/protocols/simple/ntlm.c b/libpurple/protocols/simple/ntlm.c index 14141dc186..55afcaba97 100644 --- a/libpurple/protocols/simple/ntlm.c +++ b/libpurple/protocols/simple/ntlm.c @@ -26,8 +26,10 @@ #include "ntlm.h" #include "debug.h" -#include "ciphers/descipher.h" -#include "ciphers/md4hash.h" +#ifdef HAVE_NETTLE +#include <nettle/des.h> +#include <nettle/md4.h> +#endif #include <string.h> @@ -112,6 +114,7 @@ purple_ntlm_parse_type2(const gchar *type2, guint32 *flags) return nonce; } +#ifdef HAVE_NETTLE /* * Create a 64bit DES key by taking a 56bit key and adding * a parity bit after every 7th bit. @@ -130,19 +133,15 @@ setup_des_key(const guint8 key_56[], guint8 *key) } /* - * helper function for purple cipher.c + * helper function for des encryption */ static void des_ecb_encrypt(const guint8 *plaintext, guint8 *result, const guint8 *key) { - PurpleCipher *cipher; - gssize encsiz; - - cipher = purple_des_cipher_new(); - purple_cipher_set_key(cipher, key, 8); - encsiz = purple_cipher_encrypt(cipher, plaintext, 8, result, 8); - g_warn_if_fail(encsiz == 8); - g_object_unref(cipher); + struct des_ctx ctx; + + des_set_key(&ctx, key); + des_encrypt(&ctx, DES_BLOCK_SIZE, result, plaintext); } /* @@ -201,10 +200,12 @@ gensesskey(char *buffer) buffer[i] = (char)(g_random_int() & 0xff); } } +#endif /* HAVE_NETTLE */ gchar * purple_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) { +#ifdef HAVE_NETTLE char lm_pw[14]; unsigned char lm_hpw[21]; char sesskey[16]; @@ -219,7 +220,7 @@ purple_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *ho unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 }; unsigned char nt_hpw[21]; char nt_pw[128]; - PurpleHash *hash; + struct md4_ctx ctx; char *tmp; int idx; gchar *ucs2le; @@ -320,10 +321,9 @@ purple_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *ho nt_pw[2 * idx + 1] = 0; } - hash = purple_md4_hash_new(); - purple_hash_append(hash, (guint8 *)nt_pw, 2 * lennt); - purple_hash_digest(hash, nt_hpw, sizeof(nt_hpw)); - g_object_unref(hash); + md4_init(&ctx); + md4_update(&ctx, 2 * lennt, (uint8_t *)nt_pw); + md4_digest(&ctx, MD4_DIGEST_SIZE, nt_hpw); memset(nt_hpw + 16, 0, 5); calc_resp(nt_hpw, nonce, nt_resp); @@ -344,4 +344,8 @@ purple_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *ho g_free(tmsg); return tmp; +#else + /* Used without support enabled */ + g_return_val_if_reached(NULL); +#endif /* HAVE_NETTLE */ } diff --git a/libpurple/protocols/simple/simple.c b/libpurple/protocols/simple/simple.c index 03b8aeeb0d..275d34975d 100644 --- a/libpurple/protocols/simple/simple.c +++ b/libpurple/protocols/simple/simple.c @@ -265,11 +265,8 @@ static gchar *auth_header(struct simple_account_data *sip, gchar noncecount[9]; gchar *response; gchar *ret; - gchar *tmp; - const char *authdomain; const char *authuser; - authdomain = purple_account_get_string(sip->account, "authdomain", ""); authuser = purple_account_get_string(sip->account, "authuser", sip->username); if(!authuser || strlen(authuser) < 1) { @@ -287,6 +284,13 @@ static gchar *auth_header(struct simple_account_data *sip, g_free(response); return ret; } else if(auth->type == 2) { /* NTLM */ +#ifdef HAVE_NETTLE + const gchar *authdomain; + gchar *tmp; + + authdomain = purple_account_get_string(sip->account, + "authdomain", ""); + if(auth->nc == 3 && auth->nonce) { /* TODO: Don't hardcode "purple" as the hostname */ ret = purple_ntlm_gen_type3(authuser, sip->password, "purple", authdomain, (const guint8 *)auth->nonce, &auth->flags); @@ -296,6 +300,10 @@ static gchar *auth_header(struct simple_account_data *sip, } tmp = g_strdup_printf("NTLM qop=\"auth\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"\"", auth->realm, auth->target); return tmp; +#else + /* Used without support enabled */ + g_return_val_if_reached(NULL); +#endif /* HAVE_NETTLE */ } sprintf(noncecount, "%08d", auth->nc++); @@ -350,6 +358,7 @@ static void fill_auth(struct simple_account_data *sip, const gchar *hdr, struct } if(!g_ascii_strncasecmp(hdr, "NTLM", 4)) { +#ifdef HAVE_NETTLE purple_debug_info("simple", "found NTLM\n"); auth->type = 2; parts = g_strsplit(hdr+5, "\",", 0); @@ -382,6 +391,11 @@ static void fill_auth(struct simple_account_data *sip, const gchar *hdr, struct } return; +#else + purple_debug_error("simple", "NTLM auth unsupported without " + "libnettle support. Please rebuild with " + "libnettle support for this feature.\n"); +#endif /* HAVE_NETTLE */ } else if(!g_ascii_strncasecmp(hdr, "DIGEST", 6)) { purple_debug_info("simple", "found DIGEST\n"); diff --git a/libpurple/protocols/simple/simple.h b/libpurple/protocols/simple/simple.h index 524441a98f..a9bad5801c 100644 --- a/libpurple/protocols/simple/simple.h +++ b/libpurple/protocols/simple/simple.h @@ -28,7 +28,6 @@ #include <gio/gio.h> #include <time.h> -#include "cipher.h" #include "circularbuffer.h" #include "network.h" #include "proxy.h" diff --git a/libpurple/purple.h.in b/libpurple/purple.h.in index b1bbd627bf..6079fe3759 100644 --- a/libpurple/purple.h.in +++ b/libpurple/purple.h.in @@ -53,7 +53,6 @@ #include <accountopt.h> #include <buddylist.h> #include <buddyicon.h> -#include <cipher.h> #include <circularbuffer.h> #include <cmds.h> #include <connection.h> diff --git a/libpurple/smiley-list.c b/libpurple/smiley-list.c index 26c4e494a0..c6a914e9b3 100644 --- a/libpurple/smiley-list.c +++ b/libpurple/smiley-list.c @@ -26,6 +26,8 @@ #include "smiley-parser.h" #include "trie.h" +#include <string.h> + #define PURPLE_SMILEY_LIST_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_SMILEY_LIST, \ PurpleSmileyListPrivate)) diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am index 4079524dd9..8475a79ea5 100644 --- a/libpurple/tests/Makefile.am +++ b/libpurple/tests/Makefile.am @@ -6,28 +6,12 @@ COMMON_LIBS=\ $(GPLUGIN_LIBS) test_programs=\ - test_des \ - test_des3 \ - test_image \ - test_md4 \ test_smiley \ test_smiley_list \ test_trie \ test_util \ test_xmlnode -test_des_SOURCES=test_des.c -test_des_LDADD=$(COMMON_LIBS) - -test_des3_SOURCES=test_des3.c -test_des3_LDADD=$(COMMON_LIBS) - -test_image_SOURCES=test_image.c -test_image_LDADD=$(COMMON_LIBS) - -test_md4_SOURCES=test_md4.c -test_md4_LDADD=$(COMMON_LIBS) - test_smiley_SOURCES=test_smiley.c test_smiley_LDADD=$(COMMON_LIBS) @@ -51,8 +35,7 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GPLUGIN_CFLAGS) \ $(PLUGIN_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(NSS_CFLAGS) + $(DBUS_CFLAGS) EXTRA_DIST += \ data/test-image.png diff --git a/libpurple/tests/test_des.c b/libpurple/tests/test_des.c deleted file mode 100644 index beb43305ed..0000000000 --- a/libpurple/tests/test_des.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ -#include <glib.h> - -#include <purple.h> - -#include "ciphers/descipher.h" - -static void -test_des_cipher(const gchar *in, const gchar *key, const gchar *out, size_t len) { - PurpleCipher *cipher = NULL; - guchar *decrypt = NULL, *encrypt = NULL, *answer = NULL; - size_t ret = 0; - - decrypt = g_memdup(in, len + 1); - encrypt = g_memdup(out, len + 1); - - cipher = purple_des_cipher_new(); - - purple_cipher_set_key(cipher, (const guchar *)key, 8); - - answer = g_new0(guchar, len + 1); - ret = purple_cipher_encrypt(cipher, decrypt, len, answer, len); - g_assert(ret == len); - g_assert_cmpmem(encrypt, len, answer, len); - g_free(answer); - - answer = g_new0(guchar, len + 1); - ret = purple_cipher_decrypt(cipher, encrypt, len, answer, len); - g_assert(ret == len); - g_assert_cmpmem(decrypt, len, answer, len); - g_free(answer); - - g_free(encrypt); - g_free(decrypt); - - g_object_unref(G_OBJECT(cipher)); -} - -static void -test_des_cipher_12345678(void) { - test_des_cipher( - "12345678", - "\x3b\x38\x98\x37\x15\x20\xf7\x5e", - "\x06\x22\x05\xac\x6a\x0d\x55\xdd", - 8 - ); -} - -static void -test_des_cipher_abcdefgh(void) { - test_des_cipher( - "abcdefgh", - "\x3b\x38\x98\x37\x15\x20\xf7\x5e", - "\x62\xe0\xc6\x8c\x48\xe4\x75\xed", - 8 - ); -} - -gint -main(gint argc, gchar **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/cipher/des/12345678", - test_des_cipher_12345678); - - g_test_add_func("/cipher/des/abcdefgh", - test_des_cipher_abcdefgh); - - return g_test_run(); -} diff --git a/libpurple/tests/test_des3.c b/libpurple/tests/test_des3.c deleted file mode 100644 index cd8bb43b54..0000000000 --- a/libpurple/tests/test_des3.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ -#include <glib.h> - -#include <purple.h> - -#include "ciphers/des3cipher.h" - -/****************************************************************************** - * DES3 Tests - * See http://csrc.nist.gov/groups/ST/toolkit/examples.html - * and some NULL things I made up - *****************************************************************************/ -static void -test_des3_cipher(const gchar *in, const gchar *key, const gchar *iv, - const gchar *out, size_t len, PurpleCipherBatchMode mode) -{ - PurpleCipher *cipher = NULL; - guchar *decrypt = NULL, *encrypt = NULL, *answer = NULL; - size_t ret = 0; - - decrypt = g_memdup(in, len + 1); - encrypt = g_memdup(out, len + 1); - - cipher = purple_des3_cipher_new(); - - purple_cipher_set_key(cipher, (const guchar *)key, 24); - purple_cipher_set_batch_mode(cipher, mode); - purple_cipher_set_iv(cipher, (guchar *)iv, 8); - - answer = g_new0(guchar, len + 1); - ret = purple_cipher_encrypt(cipher, decrypt, len, answer, len); - g_assert(ret == len); - g_assert_cmpmem(encrypt, len, answer, len); - g_free(answer); - - answer = g_new0(guchar, len + 1); - ret = purple_cipher_decrypt(cipher, encrypt, len, answer, len); - g_assert(ret == len); - g_assert_cmpmem(decrypt, len, answer, len); - g_free(answer); - - g_free(encrypt); - g_free(decrypt); - - g_object_unref(G_OBJECT(cipher)); -} - -static void -test_des3_cipher_ecb_nist1(void) { - test_des3_cipher( - "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A" - "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51", - "\x01\x23\x45\x67\x89\xAB\xCD\xEF" - "\x23\x45\x67\x89\xAB\xCD\xEF\x01" - "\x45\x67\x89\xAB\xCD\xEF\x01\x23", - "00000000", /* ignored */ - "\x71\x47\x72\xF3\x39\x84\x1D\x34\x26\x7F\xCC\x4B\xD2\x94\x9C\xC3" - "\xEE\x11\xC2\x2A\x57\x6A\x30\x38\x76\x18\x3F\x99\xC0\xB6\xDE\x87", - 32, - PURPLE_CIPHER_BATCH_MODE_ECB - ); -} - -static void -test_des3_cipher_ecb_nist2(void) { - test_des3_cipher( - "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A" - "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51", - "\x01\x23\x45\x67\x89\xAB\xCD\xEF" - "\x23\x45\x67\x89\xAB\xCD\xEF\x01" - "\x01\x23\x45\x67\x89\xAB\xCD\xEF", - "00000000", /* ignored */ - "\x06\xED\xE3\xD8\x28\x84\x09\x0A\xFF\x32\x2C\x19\xF0\x51\x84\x86" - "\x73\x05\x76\x97\x2A\x66\x6E\x58\xB6\xC8\x8C\xF1\x07\x34\x0D\x3D", - 32, - PURPLE_CIPHER_BATCH_MODE_ECB - ); -} - -static void -test_des3_cipher_ecb_null_key(void) { - test_des3_cipher( - "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca", - "\x38\x00\x88\x6a\xef\xcb\x00\xad" - "\x5d\xe5\x29\x00\x7d\x98\x64\x4c" - "\x86\x00\x7b\xd3\xc7\x00\x7b\x32", - "00000000", /* ignored */ - "\xc0\x60\x30\xa1\xb7\x25\x42\x44", - 8, - PURPLE_CIPHER_BATCH_MODE_ECB - ); -} - -static void -test_des3_cipher_ecb_null_text(void) { - test_des3_cipher( - "\x65\x73\x34\xc1\x19\x00\x79\x65", - "\x32\x64\xda\x10\x13\x6a\xfe\x1e" - "\x37\x54\xd1\x2c\x41\x04\x10\x40" - "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5", - "00000000", /* ignored */ - "\xe5\x80\xf6\x12\xf8\x4e\xd9\x6c", - 8, - PURPLE_CIPHER_BATCH_MODE_ECB - ); -} - -static void -test_des3_cipher_ecb_null_key_and_text(void) { - test_des3_cipher( - "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2", - "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1" - "\x66\x49\x42\x63\x22\x00\xf0\x99" - "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f", - "00000000", /* ignored */ - "\x73\xd8\x1f\x1f\x50\x01\xe4\x79", - 8, - PURPLE_CIPHER_BATCH_MODE_ECB - ); -} - -static void -test_des3_cipher_cbc_nist1(void) { - test_des3_cipher( - "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A" - "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51", - "\x01\x23\x45\x67\x89\xAB\xCD\xEF" - "\x23\x45\x67\x89\xAB\xCD\xEF\x01" - "\x45\x67\x89\xAB\xCD\xEF\x01\x23", - "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17", - "\x20\x79\xC3\xD5\x3A\xA7\x63\xE1\x93\xB7\x9E\x25\x69\xAB\x52\x62" - "\x51\x65\x70\x48\x1F\x25\xB5\x0F\x73\xC0\xBD\xA8\x5C\x8E\x0D\xA7", - 32, - PURPLE_CIPHER_BATCH_MODE_CBC - ); -} - -static void -test_des3_cipher_cbc_nist2(void) { - test_des3_cipher( - "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A" - "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51", - "\x01\x23\x45\x67\x89\xAB\xCD\xEF" - "\x23\x45\x67\x89\xAB\xCD\xEF\x01" - "\x01\x23\x45\x67\x89\xAB\xCD\xEF", - "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17", - "\x74\x01\xCE\x1E\xAB\x6D\x00\x3C\xAF\xF8\x4B\xF4\x7B\x36\xCC\x21" - "\x54\xF0\x23\x8F\x9F\xFE\xCD\x8F\x6A\xCF\x11\x83\x92\xB4\x55\x81", - 32, - PURPLE_CIPHER_BATCH_MODE_CBC - ); -} - -static void -test_des3_cipher_cbc_null_key(void) { - test_des3_cipher( - "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca", - "\x38\x00\x88\x6a\xef\xcb\x00\xad" - "\x5d\xe5\x29\x00\x7d\x98\x64\x4c" - "\x86\x00\x7b\xd3\xc7\x00\x7b\x32", - "\x31\x32\x33\x34\x35\x36\x37\x38", - "\x52\xe7\xde\x96\x39\x87\x87\xdb", - 8, - PURPLE_CIPHER_BATCH_MODE_CBC - ); -} - -static void -test_des3_cipher_cbc_null_text(void) { - test_des3_cipher( - "\x65\x73\x34\xc1\x19\x00\x79\x65", - "\x32\x64\xda\x10\x13\x6a\xfe\x1e" - "\x37\x54\xd1\x2c\x41\x04\x10\x40" - "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5", - "\x7C\xAF\x0D\x57\x1E\x57\x10\xDA", - "\x40\x12\x0e\x00\x85\xff\x6c\xc2", - 8, - PURPLE_CIPHER_BATCH_MODE_CBC - ); -} - -static void -test_des3_cipher_cbc_null_key_and_text(void) { - test_des3_cipher( - "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2", - "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1" - "\x66\x49\x42\x63\x22\x00\xf0\x99" - "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f", - "\x01\x19\x0D\x2c\x40\x67\x89\x67", - "\xa7\xc1\x10\xbe\x9b\xd5\x8a\x67", - 8, - PURPLE_CIPHER_BATCH_MODE_CBC - ); -} - - -gint -main(gint argc, gchar **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/cipher/des3/ecb nist1", - test_des3_cipher_ecb_nist1); - g_test_add_func("/cipher/des3/ecb nist2", - test_des3_cipher_ecb_nist2); - g_test_add_func("/cipher/des3/ecb null key", - test_des3_cipher_ecb_null_key); - g_test_add_func("/cipher/des3/ecb null text", - test_des3_cipher_ecb_null_text); - g_test_add_func("/cipher/des3/ebc null key and text", - test_des3_cipher_ecb_null_key_and_text); - - g_test_add_func("/cipher/des3/cbc nist1", - test_des3_cipher_cbc_nist1); - g_test_add_func("/cipher/des3/cbc nist2", - test_des3_cipher_cbc_nist2); - g_test_add_func("/cipher/des3/cbc null key", - test_des3_cipher_cbc_null_key); - g_test_add_func("/cipher/des3/cbc null text", - test_des3_cipher_cbc_null_text); - g_test_add_func("/cipher/des3/cbc null key and text", - test_des3_cipher_cbc_null_key_and_text); - - return g_test_run(); -} diff --git a/libpurple/tests/test_md4.c b/libpurple/tests/test_md4.c deleted file mode 100644 index 6083be1e4b..0000000000 --- a/libpurple/tests/test_md4.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ -#include <glib.h> - -#include <purple.h> - -#include "ciphers/md4hash.h" - -static void -test_md4hash(gchar *data, gchar *digest) { - PurpleHash *hash = NULL; - gchar cdigest[33]; - gboolean ret = FALSE; - - hash = purple_md4_hash_new(); - - purple_hash_append(hash, (guchar *)data, strlen(data)); - - ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest)); - - g_assert(ret); - g_assert_cmpstr(digest, ==, cdigest); -} - -static void -test_md4hash_empty_string(void) { - test_md4hash("", - "31d6cfe0d16ae931b73c59d7e0c089c0"); -} - -static void -test_md4hash_a(void) { - test_md4hash("a", - "bde52cb31de33e46245e05fbdbd6fb24"); -} - -static void -test_md4hash_abc(void) { - test_md4hash("abc", - "a448017aaf21d8525fc10ae87aa6729d"); -} - -static void -test_md4hash_message_digest(void) { - test_md4hash("message digest", - "d9130a8164549fe818874806e1c7014b"); -} - -static void -test_md4hash_a_to_z(void) { - test_md4hash("abcdefghijklmnopqrstuvwxyz", - "d79e1c308aa5bbcdeea8ed63df412da9"); -} - -static void -test_md4hash_A_to_Z_a_to_z_0_to_9(void) { - test_md4hash("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "043f8582f241db351ce627e153e7f0e4"); -} - -static void -test_md4hash_1_to_0_eight_times(void) { - test_md4hash("12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "e33b4ddc9c38f2199c3e7b164fcc0536"); -} - -gint -main(gint argc, gchar **argv) { - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/hash/md4/empty-string", - test_md4hash_empty_string); - g_test_add_func("/hash/md4/a", - test_md4hash_a); - g_test_add_func("/hash/md4/abc", - test_md4hash_abc); - g_test_add_func("/hash/md4/message digest", - test_md4hash_message_digest); - g_test_add_func("/hash/md4/a to z", - test_md4hash_a_to_z); - g_test_add_func("/hash/md4/A to Z, a to z, 0 to 9" , - test_md4hash_A_to_Z_a_to_z_0_to_9); - g_test_add_func("/hash/md4/1 to 0 eight times", - test_md4hash_1_to_0_eight_times); - - return g_test_run(); -} |