在 STUN 服务器上实现 XOR-MAPPED-ADDRESS 属性
Implementing XOR-MAPPED-ADDRESS attribute on STUN server
If the IP
address family is IPv4, X-Address is computed by taking the mapped IP
address in host byte order, XOR'ing it with the magic cookie, and
converting the result to network byte order. If the IP address
family is IPv6, X-Address is computed by taking the mapped IP address
in host byte order, XOR'ing it with the concatenation of the magic
cookie and the 96-bit transaction ID, and converting the result to
network byte order.
我正在 Node.JS 中编写一个 STUN 服务器,我试图了解如何对 128 位值进行异或运算。我觉得好像它会涉及使用 Buffer
模块中的这些功能之一,尽管它说它最多只支持 48 位。关于如何为 IPv6 地址实现 128 位 XOR 运算符的任何建议?
这是我的 CryptoPals 代码中的 XOR 运算符:
var xor = function (b0, b1) {
if (Buffer.isBuffer(b0)) {
b0 = new Buffer(b0);
}
if (Buffer.isBuffer(b1)) {
b1 = new Buffer(b1);
}
if (b0.length !== b1.length) {
console.log(b0.length, b1.length);
throw new Error('Tried to xor two buffers of differing length');
}
var arr = [];
for (var i = 0; i < b0.length; i++) {
arr.push(b0[i] ^ b1[i]);
}
return new Buffer(arr);
};
If the IP address family is IPv4, X-Address is computed by taking the mapped IP address in host byte order, XOR'ing it with the magic cookie, and converting the result to network byte order. If the IP address family is IPv6, X-Address is computed by taking the mapped IP address in host byte order, XOR'ing it with the concatenation of the magic cookie and the 96-bit transaction ID, and converting the result to network byte order.
我正在 Node.JS 中编写一个 STUN 服务器,我试图了解如何对 128 位值进行异或运算。我觉得好像它会涉及使用 Buffer
模块中的这些功能之一,尽管它说它最多只支持 48 位。关于如何为 IPv6 地址实现 128 位 XOR 运算符的任何建议?
这是我的 CryptoPals 代码中的 XOR 运算符:
var xor = function (b0, b1) {
if (Buffer.isBuffer(b0)) {
b0 = new Buffer(b0);
}
if (Buffer.isBuffer(b1)) {
b1 = new Buffer(b1);
}
if (b0.length !== b1.length) {
console.log(b0.length, b1.length);
throw new Error('Tried to xor two buffers of differing length');
}
var arr = [];
for (var i = 0; i < b0.length; i++) {
arr.push(b0[i] ^ b1[i]);
}
return new Buffer(arr);
};