Skip to content

Commit

Permalink
Merge pull request kjur#303 from davedoesdev/master
Browse files Browse the repository at this point in the history
Fix OAEP padding and unpadding
  • Loading branch information
kjur authored Mar 24, 2018
2 parents 54e10e9 + b90dc17 commit b6ff004
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions ext/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ function oaep_pad(s, n, hash, hashLen) {
if (!hash) hash = "sha1";

if (typeof hash === "string") {
algName = MD.getCanonicalAlgName(hash);
hashLen = MD.getHashLength(algName);
hash = function(s) { return hextorstr(Util.hashString(s, algName)); };
algName = MD.getCanonicalAlgName(hash);
hashLen = MD.getHashLength(algName);
hash = function(s) {
return hextorstr(Util.hashHex(rstrtohex(s), algName));
};
}

if (s.length + 2 * hashLen + 2 > n) {
Expand Down
8 changes: 5 additions & 3 deletions ext/rsa2.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ function oaep_unpad(d, n, hash, hashLen) {
if (!hash) hash = "sha1";

if (typeof hash === "string") {
algName = MD.getCanonicalAlgName(hash);
hashLen = MD.getHashLength(algName);
hash = function(s) { return hextorstr(Util.hashString(s, algName)); };
algName = MD.getCanonicalAlgName(hash);
hashLen = MD.getHashLength(algName);
hash = function(s) {
return hextorstr(Util.hashHex(rstrtohex(s), algName));
};
}

d = d.toByteArray();
Expand Down

0 comments on commit b6ff004

Please sign in to comment.