gPass/server/ressources/hmac.js
2013-10-16 07:55:13 +02:00

39 lines
1.1 KiB
JavaScript

/*
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/>.
*/
function hmac256(key, message) {
var ipad = "";
var opad = "";
for(i=0; i<key.length; i++)
{
ipad += String.fromCharCode(key.charCodeAt(i) ^ 0x36);
opad += String.fromCharCode(key.charCodeAt(i) ^ 0x5c);
}
while (ipad.length < 512/8)
{
ipad += String.fromCharCode(0x36);
opad += String.fromCharCode(0x5c);
}
result = digest256(opad + digest256(ipad + message));
return result;
}