aboutsummaryrefslogtreecommitdiffstats
path: root/util/sasl
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-09-07 13:38:02 +0200
committerKim Alvefur <zash@zash.se>2019-09-07 13:38:02 +0200
commit203b48b127ebfc16ec092b7dfba1836b3a70a8fd (patch)
treeee6867e7c6dfbc708e0404c71dd17bcfa2fc2a4a /util/sasl
parent4d1b9f7c60d74bc8163f9900195c53f3b8552717 (diff)
downloadprosody-203b48b127ebfc16ec092b7dfba1836b3a70a8fd.tar.gz
prosody-203b48b127ebfc16ec092b7dfba1836b3a70a8fd.zip
util.sasl.scram: Use util.strbitop for XOR step
Diffstat (limited to 'util/sasl')
-rw-r--r--util/sasl/scram.lua30
1 files changed, 1 insertions, 29 deletions
diff --git a/util/sasl/scram.lua b/util/sasl/scram.lua
index 009a01ce..865f8cf7 100644
--- a/util/sasl/scram.lua
+++ b/util/sasl/scram.lua
@@ -19,9 +19,7 @@ local generate_uuid = require "util.uuid".generate;
local saslprep = require "util.encodings".stringprep.saslprep;
local nodeprep = require "util.encodings".stringprep.nodeprep;
local log = require "util.logger".init("sasl");
-local t_concat = table.concat;
-local char = string.char;
-local byte = string.byte;
+local binaryXOR = require "util.strbitop".sxor;
local _ENV = nil;
-- luacheck: std none
@@ -45,32 +43,6 @@ Supported Channel Binding Backends
local default_i = 4096
-local xor_map = {
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,0,3,2,5,4,7,6,9,8,11,10,
- 13,12,15,14,2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13,3,2,1,0,7,6,5,
- 4,11,10,9,8,15,14,13,12,4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11,5,
- 4,7,6,1,0,3,2,13,12,15,14,9,8,11,10,6,7,4,5,2,3,0,1,14,15,12,13,
- 10,11,8,9,7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,8,9,10,11,12,13,
- 14,15,0,1,2,3,4,5,6,7,9,8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,10,
- 11,8,9,14,15,12,13,2,3,0,1,6,7,4,5,11,10,9,8,15,14,13,12,3,2,1,
- 0,7,6,5,4,12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3,13,12,15,14,9,8,
- 11,10,5,4,7,6,1,0,3,2,14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1,15,
- 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
-};
-
-local result = {};
-local function binaryXOR( a, b )
- for i=1, #a do
- local x, y = byte(a, i), byte(b, i);
- local lowx, lowy = x % 16, y % 16;
- local hix, hiy = (x - lowx) / 16, (y - lowy) / 16;
- local lowr, hir = xor_map[lowx * 16 + lowy + 1], xor_map[hix * 16 + hiy + 1];
- local r = hir * 16 + lowr;
- result[i] = char(r)
- end
- return t_concat(result);
-end
-
local function validate_username(username, _nodeprep)
-- check for forbidden char sequences
for eq in username:gmatch("=(.?.?)") do