mirror of
https://github.com/MariaDB/server.git
synced 2026-05-06 15:15:34 +02:00
into mysql.com:/home/my/mysql-5.0 BitKeeper/etc/ignore: auto-union BUILD/SETUP.sh: Auto merged Makefile.am: Auto merged client/mysql.cc: Auto merged cmd-line-utils/readline/display.c: Auto merged configure.in: Auto merged extra/yassl/include/buffer.hpp: Auto merged extra/yassl/include/crypto_wrapper.hpp: Auto merged extra/yassl/include/yassl_imp.hpp: Auto merged extra/yassl/include/yassl_int.hpp: Auto merged extra/yassl/src/crypto_wrapper.cpp: Auto merged extra/yassl/taocrypt/include/algebra.hpp: Auto merged extra/yassl/taocrypt/include/des.hpp: Auto merged extra/yassl/taocrypt/include/hash.hpp: Auto merged extra/yassl/taocrypt/include/hmac.hpp: Auto merged extra/yassl/taocrypt/include/modarith.hpp: Auto merged extra/yassl/taocrypt/include/modes.hpp: Auto merged extra/yassl/taocrypt/include/rsa.hpp: Auto merged extra/yassl/taocrypt/include/type_traits.hpp: Auto merged extra/yassl/taocrypt/mySTL/list.hpp: Auto merged extra/yassl/taocrypt/src/aes.cpp: Auto merged extra/yassl/taocrypt/src/algebra.cpp: Auto merged extra/yassl/testsuite/testsuite.cpp: Auto merged include/my_global.h: Auto merged include/my_pthread.h: Auto merged libmysqld/lib_sql.cc: Auto merged myisam/mi_open.c: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/r/mysqltest.result: Auto merged mysql-test/t/mysqltest.test: Auto merged mysys/default.c: Auto merged ndb/src/common/transporter/Transporter.cpp: Auto merged ndb/src/common/util/File.cpp: Auto merged ndb/src/common/util/SocketClient.cpp: Auto merged ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp: Auto merged ndb/src/kernel/blocks/dbtc/Dbtc.hpp: Auto merged ndb/src/kernel/blocks/qmgr/Qmgr.hpp: Auto merged ndb/src/kernel/blocks/qmgr/QmgrMain.cpp: Auto merged ndb/src/mgmapi/mgmapi.cpp: Auto merged ndb/src/mgmclient/CommandInterpreter.cpp: Auto merged ndb/src/mgmsrv/ConfigInfo.cpp: Auto merged ndb/src/mgmsrv/MgmtSrvr.cpp: Auto merged ndb/src/ndbapi/ClusterMgr.hpp: Auto merged ndb/src/ndbapi/Ndb.cpp: Auto merged ndb/src/ndbapi/NdbScanOperation.cpp: Auto merged ndb/src/ndbapi/SignalSender.cpp: Auto merged sql/field.cc: Auto merged sql/filesort.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/handler.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.h: Auto merged sql/item_func.cc: Auto merged sql/item_strfunc.cc: Auto merged sql/item_subselect.h: Auto merged sql/item_sum.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/mysql_priv.h: Auto merged sql/net_serv.cc: Auto merged sql/opt_range.cc: Auto merged sql/opt_range.h: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/slave.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_union.cc: Auto merged sql/sql_update.cc: Auto merged sql-common/client.c: Auto merged sql/sql_view.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/table.cc: Auto merged sql/unireg.cc: Auto merged extra/yassl/taocrypt/src/asn.cpp: Manual merge (Fix shadowed variable name) extra/yassl/taocrypt/test/test.cpp: No changes ndb/src/common/util/ConfigValues.cpp: Manual merge (Fix shadowed variable name) sql/field.h: manual merge sql/ha_myisam.cc: manual merge sql/ha_ndbcluster.cc: manual merge sql/item_cmpfunc.cc: manual merge sql/item_subselect.cc: Manual merge (Fix shadowed variable name) sql/mysqld.cc: no changes
138 lines
3 KiB
C++
138 lines
3 KiB
C++
/*
|
|
Copyright (C) 2000-2007 MySQL AB
|
|
|
|
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; version 2 of the License.
|
|
|
|
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; see the file COPYING. If not, write to the
|
|
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
MA 02110-1301 USA.
|
|
*/
|
|
|
|
/* hamc.hpp implements HMAC, see RFC 2104
|
|
*/
|
|
|
|
|
|
#ifndef TAO_CRYPT_HMAC_HPP
|
|
#define TAO_CRYPT_HMAC_HPP
|
|
|
|
#include "hash.hpp"
|
|
|
|
namespace TaoCrypt {
|
|
|
|
|
|
// HMAC class template
|
|
template <class T>
|
|
class HMAC {
|
|
public:
|
|
enum { IPAD = 0x36, OPAD = 0x5C };
|
|
|
|
HMAC() : ipad_(reinterpret_cast<byte*>(&ip_)),
|
|
opad_(reinterpret_cast<byte*>(&op_)),
|
|
innerHash_(reinterpret_cast<byte*>(&innerH_))
|
|
{
|
|
Init();
|
|
}
|
|
void Update(const byte*, word32);
|
|
void Final(byte*);
|
|
void Init();
|
|
|
|
void SetKey(const byte*, word32);
|
|
private:
|
|
byte* ipad_;
|
|
byte* opad_;
|
|
byte* innerHash_;
|
|
bool innerHashKeyed_;
|
|
T mac_;
|
|
|
|
// MSVC 6 HACK, gives compiler error if calculated in array
|
|
enum { HMAC_BSIZE = T::BLOCK_SIZE / sizeof(word32),
|
|
HMAC_DSIZE = T::DIGEST_SIZE / sizeof(word32) };
|
|
|
|
word32 ip_[HMAC_BSIZE]; // align ipad_ on word32
|
|
word32 op_[HMAC_BSIZE]; // align opad_ on word32
|
|
word32 innerH_[HMAC_DSIZE]; // align innerHash_ on word32
|
|
|
|
void KeyInnerHash();
|
|
|
|
HMAC(const HMAC&);
|
|
HMAC& operator= (const HMAC&);
|
|
};
|
|
|
|
|
|
// Setup
|
|
template <class T>
|
|
void HMAC<T>::Init()
|
|
{
|
|
mac_.Init();
|
|
innerHashKeyed_ = false;
|
|
}
|
|
|
|
|
|
// Key generation
|
|
template <class T>
|
|
void HMAC<T>::SetKey(const byte* key, word32 length)
|
|
{
|
|
Init();
|
|
|
|
if (length <= T::BLOCK_SIZE)
|
|
memcpy(ipad_, key, length);
|
|
else {
|
|
mac_.Update(key, length);
|
|
mac_.Final(ipad_);
|
|
length = T::DIGEST_SIZE;
|
|
}
|
|
memset(ipad_ + length, 0, T::BLOCK_SIZE - length);
|
|
|
|
for (word32 i = 0; i < T::BLOCK_SIZE; i++) {
|
|
opad_[i] = ipad_[i] ^ OPAD;
|
|
ipad_[i] ^= IPAD;
|
|
}
|
|
}
|
|
|
|
|
|
// Inner Key Hash
|
|
template <class T>
|
|
void HMAC<T>::KeyInnerHash()
|
|
{
|
|
mac_.Update(ipad_, T::BLOCK_SIZE);
|
|
innerHashKeyed_ = true;
|
|
}
|
|
|
|
|
|
// Update
|
|
template <class T>
|
|
void HMAC<T>::Update(const byte* msg_arg, word32 length)
|
|
{
|
|
if (!innerHashKeyed_)
|
|
KeyInnerHash();
|
|
mac_.Update(msg_arg, length);
|
|
}
|
|
|
|
|
|
// Final
|
|
template <class T>
|
|
void HMAC<T>::Final(byte* hash)
|
|
{
|
|
if (!innerHashKeyed_)
|
|
KeyInnerHash();
|
|
mac_.Final(innerHash_);
|
|
|
|
mac_.Update(opad_, T::BLOCK_SIZE);
|
|
mac_.Update(innerHash_, T::DIGEST_SIZE);
|
|
mac_.Final(hash);
|
|
|
|
innerHashKeyed_ = false;
|
|
}
|
|
|
|
|
|
} // namespace
|
|
|
|
#endif // TAO_CRYPT_HMAC_HPP
|