|
 |
|
SQL Server Tips by Burleson |
Helix Stream Cipher
Helix is a high-speed cipher developed by Niels Ferguson, Doug
Whiting, Bruce Schneier, John Kelsey, Stefan Lucks, and Tadayoshi
Kohno. It includes encryption / decryption and a Message
Authentication Code (MAC) in the one algorithm. It incorporates a
128-bit key and is designed to operate quickly on modern CPU’s such
as a Pentium 2 and later. Because the MS CryptoAPI does not include
support for this algorithm, we must implement support directly for
it in XP_CRYPTOAPI. A C++ implementation of the algorithm is
available from PJ’s web site at www.naughter.com and we simply
incorporate this code directly into the XP_CRYPTOAPI code. Because
it includes hashing as well as encryption, the parameters to the
Helix XP’s are different than the MS CryptoAPI examples provided so
far. For encryption we have an additional output parameter, which
contains the MAC. For decryption, this MAC becomes an additional
input parameter. The code continues to use the CryptoAPI to create
the contents for the key from the password parameter. The key is
setup using the following code:
BYTE* pHashData = (BYTE*) _alloca(dwHashSize);
if (CryptGetHashParam(hHash, HP_HASHVAL, pHashData, &dwHashSize, 0))
{
CHelix helix;
helix.SetKey(pHashData, dwHashSize);
The encryption process is implemented by calling the ‘CHelix::Encrypt’
method as follows:
helix.Encrypt(m_pParameterData[HELIX_ENCRYPT_DATA_TO_ENCRYPT_INDEX].m_pData,
m_pParameterData[HELIX_ENCRYPT_DATA_TO_ENCRYPT_INDEX].m_cbActualLen,
nonce, pbyEncryptedData, mac)
The decryption XP is implemented using similar code.
The above book excerpt is from:
Super SQL
Server Systems
Turbocharge Database Performance with C++ External Procedures
ISBN:
0-9761573-2-2
Joseph Gama, P. J. Naughter
http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm |