gPass/server/resources/hmac.js

47 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

/*
Copyright (C) 2013 Grégory Soutadé
This file is part of gPass.
gPass 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 3 of the License, or
(at your option) any later version.
gPass 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 gPass. If not, see <http://www.gnu.org/licenses/>.
*/
2013-10-16 07:55:13 +02:00
function hmac256(key, message) {
var ipad = "";
var opad = "";
if (key.length > 512/8)
2013-10-16 07:55:13 +02:00
{
key = digest256(key);
2013-10-16 07:55:13 +02:00
}
for(i=0; i<512/8; i++)
2013-10-16 07:55:13 +02:00
{
if (i >= key.length)
{
ipad += String.fromCharCode(0x36);
opad += String.fromCharCode(0x5c);
}
else
{
ipad += String.fromCharCode(key.charCodeAt(i) ^ 0x36);
opad += String.fromCharCode(key.charCodeAt(i) ^ 0x5c);
}
2013-10-16 07:55:13 +02:00
}
2013-10-16 07:55:13 +02:00
result = digest256(opad + digest256(ipad + message));
2013-10-16 07:55:13 +02:00
return result;
}