b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta Jan Cholasta <jcholast@redhat.com>
e07a94a66985b674c5df11ca466792902164c4e2George McCollister George McCollister <george.mccollister@gmail.com>
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta Copyright (C) 2012 Red Hat
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta This program is free software; you can redistribute it and/or modify
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta it under the terms of the GNU General Public License as published by
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta the Free Software Foundation; either version 3 of the License, or
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta (at your option) any later version.
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta This program is distributed in the hope that it will be useful,
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta but WITHOUT ANY WARRANTY; without even the implied warranty of
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta GNU General Public License for more details.
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta You should have received a copy of the GNU General Public License
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta along with this program. If not, see <http://www.gnu.org/licenses/>.
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta const unsigned char *in,
b35f20cd8ecdc8308a3201e55752fb0443ec6ae4Jan Cholasta unsigned char *out)
e07a94a66985b674c5df11ca466792902164c4e2George McCollister unsigned char ikey[HMAC_SHA1_BLOCKSIZE], okey[HMAC_SHA1_BLOCKSIZE];
e07a94a66985b674c5df11ca466792902164c4e2George McCollister /* keys longer than blocksize are shortened */
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik EVP_DigestUpdate(ctx, (const unsigned char *)key, key_len);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister memset(ikey + SSS_SHA1_LENGTH, 0, HMAC_SHA1_BLOCKSIZE - SSS_SHA1_LENGTH);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister /* keys shorter than blocksize are zero-padded */
e07a94a66985b674c5df11ca466792902164c4e2George McCollister memset(ikey + key_len, 0, HMAC_SHA1_BLOCKSIZE - key_len);
e07a94a66985b674c5df11ca466792902164c4e2George McCollister /* HMAC(key, msg) = HASH(key XOR opad, HASH(key XOR ipad, msg)) */
e07a94a66985b674c5df11ca466792902164c4e2George McCollister for (i = 0; i < HMAC_SHA1_BLOCKSIZE; i++) {
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik EVP_DigestUpdate(ctx, (const unsigned char *)ikey, HMAC_SHA1_BLOCKSIZE);
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik EVP_DigestUpdate(ctx, (const unsigned char *)in, in_len);
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik EVP_DigestUpdate(ctx, (const unsigned char *)okey, HMAC_SHA1_BLOCKSIZE);
8f1316a0c677f211eaaa1346e21a03446b8c4fb1Lukas Slebodnik EVP_DigestUpdate(ctx, (const unsigned char *)hash, SSS_SHA1_LENGTH);