gPass/server/ressources/hmac.js

39 lines
1.1 KiB
JavaScript
Raw 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 = "";
2013-10-16 07:55:13 +02:00
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);
}
2013-10-16 07:55:13 +02:00
result = digest256(opad + digest256(ipad + message));
2013-10-16 07:55:13 +02:00
return result;
}